CTR-Pia  5.4.3
Game Communication Engine
 全て クラス ネームスペース 関数 変数 型定義 列挙型 列挙型の値 ページ
transport_ProtocolManager.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_OffsetList.h>
19 #include <nn/pia/transport/transport_ProtocolId.h>
20 #include <nn/pia/transport/transport_ProtocolEvent.h>
21 #include <nn/pia/transport/transport_Protocol.h>
22 
23 namespace nn
24 {
25 namespace pia
26 {
27 namespace transport
28 {
29 
30 class NetworkFactory;
31 class PacketHandler;
32 
33 /*!
34  @cond PRIVATE
35  @brief プロトコルを管理します。
36 
37  */
38 class ProtocolManager : public common::RootObject
39 {
40 public:
41  /*!
42  @brief デフォルトコンストラクタです。
43  */
44  ProtocolManager(void);
45 
46 
47  /*!
48  @brief デストラクタです。
49  */
50  virtual ~ProtocolManager(void);
51 
52 
53  /*!
54  @brief 初期化します。
55  @return ResultSuccess を返します。
56  */
57  Result Initialize(NetworkFactory* pNetworkFactory);
58 
59 
60  /*!
61  @brief 終了します。
62  */
63  void Finalize();
64 
65 
66  /*!
67  @brief T型のプロトコルのインスタンスを生成します。
68 
69  @param[in] port プロトコルのポートの値です。
70 
71  @return 生成したプロトコルのハンドルです。同じプロトコル ID のものが既にある場合は 0 を返します。
72  Startup() 後は生成できないので、その場合も 0 を返します。
73  */
74  template <typename T>
75  uint32_t CreateProtocol(uint16_t port = 0)
76  {
77  if (m_IsRunning)
78  {
79  return 0;
80  }
81 
82  transport::Protocol* pProtocol = new (AllocProtocol(sizeof(T))) T();
83  transport::ProtocolId id(T::GetProtocolTypeStatic(), port);
84  return CreateProtocolImpl(pProtocol, id);
85  }
86 
87 
88  /*!
89  @brief プロトコルのインスタンスを破棄します。
90 
91  @param[in] protocolHandle 削除したいプロトコルのハンドルです。
92  */
93  void DestroyProtocol(uint32_t protocolHandle);
94 
95 
96  /*!
97  @brief T型のプロトコルのインスタンスを取得します。
98 
99  @param[in] protocolHandle 取得したいプロトコルのハンドルです。
100 
101  @return プロトコルのインスタンスのアドレスです。指定されたハンドルのプロトコルが存在しなかったり、T型でなかったりした場合は NULL を返します。
102  */
103  template <typename T>
104  T* GetProtocol(uint32_t protocolHandle)
105  {
106  return static_cast<T*>(SearchProtocol(ProtocolId(protocolHandle), T::GetProtocolTypeStatic()));
107  }
108 
109 
110  /*!
111  @cond PRIVATE
112  @brief 通信を開始します。
113 
114  @param[in] pPacketHandler 使用する PacketHandler です。
115 
116  @return 成功すれば、 IsSuccess() が true を返す Result が返されます。
117  */
118  Result Startup(PacketHandler* pPacketHandler);
119  //! @endcond
120 
121 
122  /*!
123  @cond PRIVATE
124  @brief 通信を終了します。
125  */
126  void Cleanup();
127  //! @endcond
128 
129 
130  /*!
131  @cond PRIVATE
132  @brief 各プロトコルの Protocol::StartupWithStationAddress() を呼び出します。
133 
134  @param[in] localStationAddress 自分の StationAddress です。
135 
136  @return 成功すれば、 IsSuccess() が true を返す Result が返されます。
137  */
138  Result StartupProtocolsWithStationAddress(const common::StationAddress& localStationAddress);
139  //! @endcond
140 
141 
142  /*!
143  @cond PRIVATE
144  @brief 各プロトコルの Protocol::Startup() を呼び出します。
145 
146  @return 成功すれば、 IsSuccess() が true を返す Result が返されます。
147  */
148  Result StartupProtocols();
149  //! @endcond
150 
151 
152  /*!
153  @cond PRIVATE
154  @brief 各プロトコルの Protocol::CleanupWithStationAddress() を呼び出します。
155  */
156  void CleanupProtocolsWithStationAddress();
157  //! @endcond
158 
159 
160  /*!
161  @cond PRIVATE
162  @brief 各プロトコルの Protocol::Cleanup() を呼び出します。
163  */
164  void CleanupProtocols();
165  //! @endcond
166 
167 
168  /*!
169  @cond PRIVATE
170  @brief メインの処理
171 
172  @return 成功すれば、 IsSuccess() が true を返す Result が返されます。
173  */
174  Result Dispatch();
175  //! @endcond
176 
177 
178  /*!
179  @cond PRIVATE
180  @brief 接続状態の切り替え
181 
182  @param[in] event 操作内容を表すイベントです。
183 
184  @return 成功すれば、 IsSuccess() が true を返す Result が返されます。
185  */
186  Result UpdateProtocolEvent(const ProtocolEvent& event);
187  //! @endcond
188 
189 
190  /*!
191  @brief デバッグに有用な情報をプリントします。
192 
193  @param[in] flag トレースフラグの論理和。詳細は@ref TraceFlag 型を参照してください。
194  */
195  virtual void Trace(uint64_t flag) const;
196 
197 #if PIA_STATISTIC_PROTOCOL_BLOCK_TIME_ENABLE
198  void ResetProtocolStatistic();
199  void PrintProtocolStatistic(uint32_t printMaxDataNum);
200 #endif
201 
202 private:
203  void* AllocProtocol(uint32_t size);
204 
205  uint32_t CreateProtocolImpl(Protocol* pProtocol, ProtocolId id);
206 
207  Protocol* SearchProtocol(ProtocolId protocolId, uint16_t protocolType);
208 
209 private:
210  typedef common::OffsetList<Protocol> ProtocolList;
211 
212  NetworkFactory* m_pNetworkFactory;
213 
214  ProtocolList m_ProtocolList;
215 
216  bool m_IsRunning;
217 
218  ProtocolManager(const ProtocolManager&);
219  ProtocolManager& operator=(const ProtocolManager&);
220 };
221 //! @endcond
222 }
223 }
224 } // end of namespace nn::pia::transport