CTR-Pia  5.4.3
Game Communication Engine
 全て クラス ネームスペース 関数 変数 型定義 列挙型 列挙型の値 ページ
framework_NexService.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/framework/framework_Definitions.h>
17 
18 #if NN_PIA_FRAMEWORK_ENABLE_NEX
19 
20 #include <nn/pia/framework/framework_InetService.h>
21 
22 #include <nn/pia/inet/inet_NexFacade.h>
23 #include <nn/pia/inet/inet_Api.h>
24 #include <nn/pia/inet/inet_NexNetworkFactory.h>
25 #include <nn/pia/inet/inet_NexFacade.h>
26 
27 #if NN_PIA_NINTENDOSDK
28 #include <nn/account.h>
29 #include <nn/account/account_Result.h>
30 #endif
31 
32 namespace nn
33 {
34 namespace pia
35 {
36 namespace framework
37 {
38 
39 /*!
40 @brief NEX サービスの管理クラスです。
41 */
42 class NexService : public InetService
43 {
44 private:
45  static const nn::nex::Core::ThreadMode NexThreadMode;
46 
47 public:
48 
49  /*!
50  @brief Initialize() に NEX のパラメータを渡すための構造体です。
51  */
52  struct InitializeNexServiceSetting : public InitializeInetServiceSetting
53  {
54  uint8_t* nexMemory; //!< NEX で使用するメモリ。@if NIN_DOC 4 KB アラインメントされている必要があります。また、16 KB 以上である必要があります。 @endif
55  uint32_t totalMemorySize; //!< nexMemory のサイズです。
56  uint32_t emergencyMemorySize; //!< nexMemory の内、NEX のヒープ枯渇時に使用する緊急用メモリとして割り当てるサイズです。
57  };
58 
59  /*!
60  @cond PRIVATE
61  @brief コンストラクタです。
62  */
63  NexService();
64  //! @endcond
65 
66  /*!
67  @cond PRIVATE
68  @brief デストラクタです。
69  */
70  virtual ~NexService();
71  //! @endcond
72 
73  /*!
74  @brief NEX の NgsFacade のインスタンスを取得します。
75  @return NgsFacade のインスタンスへのポインタが返されます。
76  */
77  nn::nex::NgsFacade* GetNgsFacade();
78 
79  /*!
80  @brief NEX サービスにアクセスするための証明書(Credentials)のインスタンスを取得します。
81  @return 証明書のインスタンスへのポインタが返されます。
82  */
83  nn::nex::Credentials* GetCredential();
84 
85  /*!
86  @cond PRIVATE
87  @brief inet 初期化処理です。
88  @param[in] setting inet の初期化で必要なパラメータです。
89  @return 成功すれば、 IsSuccess() が true を返す Result が返されます。
90  */
91  virtual Result InitializeInet(const InitializeInetSetting& setting);
92  //! @endcond
93 
94  /*!
95  @cond PRIVATE
96  @brief Inet 終了処理です。
97  */
98  virtual void FinalizeInet();
99  //! @endcond
100 
101  /*!
102  @cond PRIVATE
103  @brief 初期化処理です。
104  @param[in] setting 各種パラメータが書き込まれた Setting 構造体です。
105  @return 成功すれば、 IsSuccess() が true を返す Result が返されます。
106  */
107  virtual Result InitializeInetService(const InitializeInetServiceSetting& setting);
108  //! @endcond
109 
110  /*!
111  @cond PRIVATE
112  @brief 終了処理です。
113  */
114  virtual void FinalizeInetService();
115  //! @endcond
116 
117  /*!
118  @cond PRIVATE
119  @brief ディスパッチ処理を行います。
120  */
121  virtual Result Dispatch();
122  //! @endcond
123 
124  /*!
125  @cond PRIVATE
126  @brief サービス接続状態をチェックします。
127  */
128  virtual Result CheckConnection();
129  //! @endcond
130 
131  /*!
132  @cond PRIVATE
133  @brief transport の初期化に必要な NetworkFactory を取得します。
134  @return NetworkFactory が返されます。
135  */
136  virtual transport::NetworkFactory* GetNetworkFactory();
137  //! @endcond
138 
139  /*!
140  @cond PRIVATE
141  @brief フレンドサーバーへのログイン処理です。
142  @return 成功すれば、 IsSuccess() が true を返す Result が返されます。
143  */
144  virtual Result LoginFriendServer();
145  //! @endcond
146 
147  /*!
148  @cond PRIVATE
149  @brief ログアウト処理です。
150  @return 成功すれば、 IsSuccess() が true を返す Result が返されます。
151  */
152  virtual Result LogoutFriendServer();
153  //! @endcond
154 
155  /*!
156  @cond PRIVATE
157  @brief ゲームサーバーへのログインを行います。
158  @param[in] pSetting ログインに必要なパラメータです。
159  @param[in] timeout タイムアウトまでの時間を指定します。
160  @return 成功すれば、 IsSuccess() が true を返す Result が返されます。
161  */
162  virtual Result LoginGameServer(const InitializeInetSetting* pSetting, uint32_t timeout = 30 * 1000);
163  //! @endcond
164 
165  /*!
166  @cond PRIVATE
167  @brief ログイン処理中かをチェックします。
168  @return ログイン処理中であれば true が返ります。
169  */
170  virtual bool IsInLoginProcess()
171  {
172  return (m_pCallContext->GetState() == nn::nex::CallContext::CallInProgress);
173  }
174  //! @endcond
175 
176  virtual bool IsInLogoutProcess()
177  {
178  return (m_pCallContext->GetState() == nn::nex::CallContext::CallInProgress);
179  }
180 
181  /*!
182  @cond PRIVATE
183  @brief ゲームサーバーへのログインの前処理を行います。
184  @return 成功すれば、 IsSuccess() が true を返す Result が返されます。
185  @endif
186  */
187  virtual Result PreLoginProcess(const InitializeInetSetting* pSetting);
188  //! @endcond
189 
190  /*!
191  @cond PRIVATE
192  @brief ログイン前処理中かをチェックします。
193  @return ログイン前処理中であれば true が返ります。
194  */
195  virtual bool IsInPreLoginProcess();
196  //! @endcond
197 
198  /*!
199  @cond PRIVATE
200  @brief ゲームサーバーへのログイン完了後の処理を行います。
201  @return 成功すれば、 IsSuccess() が true を返す Result が返されます。
202  @endif
203  */
204  virtual Result PostLoginProcess();
205  //! @endcond
206 
207  /*!
208  @cond PRIVATE
209  @brief ゲームサーバーからログアウトを行います。
210  @param[in] isBlock true なら処理が完了するまでブロックします。
211  false なら非同期で処理を行います。
212  ログアウト処理の完了は IsInLogoutProcess() で確認してください。
213  @return 成功すれば、 IsSuccess() が true を返す Result が返されます。
214  */
215  virtual Result LogoutGameServer(bool isBlock, bool isInChangeStateAsync);
216  //! @endcond
217 
218  /*!
219  @cond PRIVATE
220  @brief ログアウト結果を取得します。
221  @return 成功すれば、 IsSuccess() が true を返す Result が返されます。
222  @endif
223  */
224  virtual Result GetLogoutOutcome();
225  //! @endcond
226 
227  /*!
228  @cond PRIVATE
229  @brief ゲームサーバーへの接続状態を取得します。
230  @return 成功すれば、 IsSuccess() が true を返す Result が返されます。
231  */
232  Result IsNgsConnected();
233  //! @endcond
234 
235  /*!
236  @cond PRIVATE
237  @brief ログイン情報を設定します。
238  */
239  void SetLoginInfo(const inet::NexFacade::LoginInfo& info)
240  {
241  m_LoginInfo = info;
242  }
243  //! @endcond
244 
245 private:
246  bool IsInitialized()
247  {
248  return m_IsNexInitialized;
249  }
250 
251  // NEX 用ヒープの初期化(ExpHeap)
252  static void InitializeRuntimeMemory(uint8_t* pNexMemory, uint32_t totalMemorySize, uint32_t emergencyMemorySize);
253 
254  // アプリケーション定義のメモリ確保関数
255  static void* AllocFunction(size_t size);
256 
257  // アプリケーション定義のメモリ解放関数
258  static void FreeFunction(void* pointer);
259 
260  // AllocFunction から呼ばれる内部メモリ関数
261  static void* InnerAlloc(uint32_t size);
262 
263  // FreeFunction から呼ばれる内部メモリ関数
264  static void InnerFree(void* ptr);
265 
266  //緊急用のメモリを解放します
267  static void ReleaseReservedMemory();
268 
269  // 緊急用のメモリを確保します
270  static void AcquireReservedMemory();
271 
272  // NEX 用ヒープの終了処理(ExpHeap)
273  static void FinalizeRuntimeMemory();
274 
275 private:
276  bool m_IsNexInitialized;
277  bool m_IsInetInitialized;
278  nn::nex::NgsFacade* m_pNgsFacade;
279  nn::nex::ProtocolCallContext* m_pCallContext;
280  inet::NexFacade::LoginInfo m_LoginInfo;
281  inet::NexNetworkFactory m_NexNetworkFactory;
282 
283 #if NN_PIA_NINTENDOSDK_NX
284 #if (NEX_CURRENT_VERSION_NUMBER >= NEX_VERSION_NUMBER(4, 1, 1))
285  char m_NsaIdToken[nn::account::NetworkServiceAccountIdTokenLengthMax];
286  size_t m_NsaIdTokenSize;
287  nn::account::NetworkServiceAccountId m_NsaId;
288  nn::account::AsyncContext m_AccountAsyncContext;
289  nn::os::SystemEvent m_AccountSystemEvent;
290 #endif
291 #endif
292 
293  NN_PIA_DISALLOW_COPY(NexService);
294 };
295 }
296 }
297 } // end of namespace nn::pia::framework
298 
299 #endif // NN_PIA_FRAMEWORK_ENABLE_NEX