CTR-Pia  5.4.3
Game Communication Engine
 全て クラス ネームスペース 関数 変数 型定義 列挙型 列挙型の値 ページ
transport_Protocol.h
1 /*--------------------------------------------------------------------------------*
2  Copyright (C)Nintendo All rights reserved.
3 
4  These coded instructions, statements, and computer programs contain proprietary
5  information of Nintendo and/or its licensed developers and are protected by
6  national and international copyright laws. They may not be disclosed to third
7  parties or copied or duplicated in any form, in whole or in part, without the
8  prior written consent of Nintendo.
9 
10  The content herein is highly confidential and should be handled accordingly.
11  *--------------------------------------------------------------------------------*/
12 
13 
14 #pragma once
15 
16 #include <nn/pia/transport/transport_Definitions.h>
17 
18 #include <nn/pia/common/common_ListNode.h>
19 #include <nn/pia/transport/transport_ProtocolId.h>
20 #include <nn/pia/transport/transport_ProtocolEvent.h>
21 
22 #define PIA_STATISTIC_PROTOCOL_BLOCK_TIME_ENABLE 0
23 #if PIA_STATISTIC_PROTOCOL_BLOCK_TIME_ENABLE
24 #include <nn/pia/common/private/common_Statistic.h>
25 #include <nn/pia/common/common_TimeSpan.h>
26 #endif
27 
28 namespace nn
29 {
30 namespace pia
31 {
32 namespace common
33 {
34 class StationAddress;
35 }
36 
37 namespace transport
38 {
39 
40 class PacketHandler;
41 class StationPacketHandler;
42 
43 /*!
44  @brief プロトコルの基底クラスです。
45 
46  */
48 {
49 public:
50  /*!
51  @brief デフォルトコンストラクタです。
52  */
53  Protocol(void);
54 
55 
56  /*!
57  @brief デストラクタです。
58  */
59  virtual ~Protocol(void);
60 
61 
62  /*!
63  @cond PRIVATE
64  @brief 使用するパケットハンドラを設定します。
65 
66  @param[in] pPacketHandler パケットハンドラです。
67  */
68  void SetPacketHandler(PacketHandler* pPacketHandler)
69  {
70  m_pPacketHandler = pPacketHandler;
71  }
72  //! @endcond
73 
74  /*!
75  @brief デバッグに有用な情報をプリントします。
76 
77  @param[in] flag トレースフラグの論理和。詳細は@ref TraceFlag 型を参照してください。
78 
79  */
80  virtual void Trace(uint64_t flag) const;
81 
82 
83  /*!
84  @cond PRIVATE
85  @brief リストノードへのオフセットを取得します。
86 
87  @return リストノードへのオフセットです。
88  */
89  static uint32_t GetListNodeOffset()
90  {
91  NN_PIA_PRAGMA_PUSH_WARNINGS
92  NN_PIA_DISABLE_WARNING_CLANG_INVALID_OFFSETOF
93  return offsetof(Protocol, m_ListNode);
94  NN_PIA_PRAGMA_POP_WARNINGS
95  }
96  //! @endcond
97 
98 
99  /*!
100  @cond PRIVATE
101  @brief ポートを設定。
102 
103  @param[in] port ポート番号。
104  */
105  void SetPort(uint16_t port);
106  //! @endcond
107 
108 
109  /*!
110  @cond PRIVATE
111  @brief プロトコルIDを取得
112 
113  @return プロトコルID。
114  */
115  ProtocolId GetProtocolId() const
116  {
117  return m_ProtocolId;
118  }
119  //! @endcond
120 
121 
122  /*!
123  @cond PRIVATE
124  @brief プロトコルのタイプを取得
125 
126  @return プロトコルのタイプ。
127  */
128  virtual uint16_t GetProtocolType() const = 0;
129  //! @endcond
130 
131 
132  /*!
133  @cond PRIVATE
134  @brief 通信を開始
135 
136  @param[in] localStationAddress 自分の StationAddress です。
137 
138  @return 成功すれば、IsSuccess()がtrueを返すResultが返されます。
139  */
140  virtual Result StartupWithStationAddress(const common::StationAddress& localStationAddress);
141  //! @endcond
142 
143 
144  /*!
145  @cond PRIVATE
146  @brief 通信を開始
147 
148  @return 成功すれば、IsSuccess()がtrueを返すResultが返されます。
149  */
150  virtual Result Startup();
151  //! @endcond
152 
153 
154  /*!
155  @cond PRIVATE
156  @brief 通信を終了
157  */
158  virtual void CleanupWithStationAddress();
159  //! @endcond
160 
161 
162  /*!
163  @cond PRIVATE
164  @brief 通信を終了
165  */
166  virtual void Cleanup();
167  //! @endcond
168 
169 
170  /*!
171  @cond PRIVATE
172  @brief メインの処理
173 
174  @return 成功すれば、IsSuccess()がtrueを返すResultが返されます。
175  */
176  virtual Result Dispatch();
177  //! @endcond
178 
179 
180  /*!
181  @cond PRIVATE
182  @brief 接続状態の切り替え
183 
184  @param[in] event 操作内容を表すイベントです。
185 
186  @return 成功すれば、IsSuccess()がtrueを返すResultが返されます。
187  */
188  virtual Result UpdateProtocolEvent(const ProtocolEvent& event);
189  //! @endcond
190 
191 
192 #if PIA_STATISTIC_PROTOCOL_BLOCK_TIME_ENABLE
193  Statistic<TimeSpan>* GetBlockTimeStatistic()
194  {
195  return &m_BlockTimeStatistic;
196  }
197 #endif
198 
199  /*!
200  @cond PRIVATE
201  @brief 旧いステーションなどから届いてしまったメッセージを
202  フィルタリングするかどうかを制御するための関数です。
203 
204  @return デフォルトの実装では true を返し、フィルタリングを許可します。
205  フィルタリングを許可すべきでない Protocol 派生クラスでは、
206  false を返すようにオーバーライドしてください。
207  */
208  virtual bool IsProtocolFilteringEnabled() const;
209  //! @endcond
210 
211 protected:
212  /*!
213  @cond PRIVATE
214  @brief パケットハンドラを取得します。
215 
216  @return パケットハンドラのポインタです。
217  */
218  PacketHandler* GetPacketHandler()
219  {
220  return m_pPacketHandler;
221  }
222  //! @endcond
223 
224 
225  /*!
226  @cond PRIVATE
227  @brief パケットハンドラを取得します(const 版)。
228 
229  @return パケットハンドラの const ポインタです。
230  */
231  const PacketHandler* GetPacketHandler() const
232  {
233  return m_pPacketHandler;
234  }
235  //! @endcond
236 
237  StationPacketHandler* GetStationPacketHandler();
238  const StationPacketHandler* GetStationPacketHandler() const;
239 
240 private:
241  common::ListNode m_ListNode;
242  ProtocolId m_ProtocolId;
243  PacketHandler* m_pPacketHandler;
244 
245 #if PIA_STATISTIC_PROTOCOL_BLOCK_TIME_ENABLE
246  Statistic<TimeSpan> m_BlockTimeStatistic;
247 #endif
248 };
249 }
250 }
251 } // end of namespace nn::pia::transport
252 
253 
254 #define PIA_PROTOCOL_TYPE_INFO(protocolType) \
255  static uint16_t GetProtocolTypeStatic() \
256  { \
257  return protocolType; \
258  } \
259  virtual uint16_t GetProtocolType() const \
260  { \
261  return GetProtocolTypeStatic(); \
262  }