1 /*--------------------------------------------------------------------------
2   Project:  HorizonSDK
3   File:     rdt_HostBase.h
4 
5   Copyright 2009 Nintendo.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Date:: 2010-09-14#$
14   $Rev: 25753 $
15   $Author: hiratsu_daisuke $
16  *-------------------------------------------------------------------------*/
17 
18 #include "stdafx.h"
19 
20 #ifndef NN_RDT_HOSTBASE_H_
21 #define NN_RDT_HOSTBASE_H_
22 
23 
24 #include "rdt_Transceiver.h"
25 
26 namespace nn { namespace rdt { namespace CTR {
27 
28 /*!
29     @brief これはSender, Receiverの基底クラスです。
30            両者に共通する処理をまとめています。
31 */
32 class HostBase{
33 public:
34 
35 /*!
36     @brief コンストラクタです。初期化フラグを下ろす以外のことはしません。
37 */
38     HostBase(void);
39 
40 /*!
41     @brief デストラクタです。基底クラスなので、仮想とします。
42 */
43     virtual ~HostBase(void);
44 
45 /*!
46     @brief 初期化します。
47 */
48 #ifdef _WIN32
49     nn::Result Initialize(SOCKET &sock);
50 #elif defined(NN_PLATFORM_CTR)
51     nn::Result Initialize(u16 nodeId, u8 port);  // 送信先のノードIDとポート番号
52 #else
53     #error no platform selected
54 #endif
55 
56 /*!
57     @brief 解放します。
58 */
59     void Finalize(void);
60 
61 /*!
62     @brief パケロス率を設定します(デバッグ用)。
63     0 <= per <= 100の値を与えます。
64 */
65     void SetPacketLossRatio(int per);
66 
67 /*!
68     @brief 直近のエラーコードを取得します。
69 */
GetErrorCode(void)70     nn::Result GetErrorCode(void) const { return m_resultCode; }
71 
72 /*!
73     @brief このクラスの各種情報をプリントします(解析用)
74 */
75     static void PrintProperty(void);
76 
77 
78 protected:
79     // セグメントを送信。再送処理がしたい場合は、この関数の外でやりましょう。
80     // パケロス率に応じて、送信が失敗します(送信が行われない)
81     void putSegment(const Segment &seg);
82 
83     // セグメントを受信。
84     nn::Result pullSegment(Segment *pSeg);
85 
86     // RSTコントロールビットを含んだセグメントを送信。
87     // このセグメントは再送対象とはしない。
88     void sendRstSegment(u32 seq);
89 
90     // RSTとACKコントロールビットを含んだセグメントを送信。
91     // このセグメントは再送対象とはしない。
92     void sendRstAckSegment(u32 seq, u32 ack);
93 
94     // エラー情報の記録。エラーが発生する状況になったら、この関数を呼ぶこと。
95     void errorHandling(Result resultCode);
96 
97 
98 private:
99 /*!
100     @brief コピーコンストラクタは封印します。
101 */
102     HostBase           (const HostBase&);
103 
104 /*!
105     @brief 代入演算子は封印します。
106 */
107     HostBase& operator=(const HostBase&);
108 
109     Transceiver   m_transceiver; // 送受信オブジェクト
110 
111     int m_packetLossRatio;       // パケロス率。ゼロ以上、100以下。
112 
113     Result m_resultCode;         // 直近のリザルトコードをここに記録する
114 
115     bool m_initialized;
116     u8   m_padding[3];
117 };
118 
119 
120 }}} // namespace nn::rdt::CTR
121 
122 #endif  // end of NN_RDT_HOSTBASE_H_
123