CTR-Pia  5.4.3
Game Communication Engine
 全て クラス ネームスペース 関数 変数 型定義 列挙型 列挙型の値 ページ
clone_SharingClone.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/clone/clone_Definitions.h>
17 #include <nn/pia/clone/clone_CloneBase.h>
18 
19 
20 namespace nn
21 {
22 namespace pia
23 {
24 namespace clone
25 {
26 
27 
28 /*!
29  @brief 双方向の送受信を行う CloneBase 派生クラスです。
30  */
31 class SharingClone : public CloneBase
32 {
33 protected:
34  /*!
35  @brief デフォルトコンストラクタです。
36  */
37  SharingClone();
38 
39 public:
40  /*!
41  @brief デストラクタです。
42  */
43  virtual ~SharingClone();
44 
45 
46  /*!
47  @brief この SharingClone とデータをやり取りする他のステーションの SharingClone が存在するかどうかを判定します。
48  @details 相手の SharingClone が途中で登録解除された場合、アプリケーションや内部によるデータの送受信や、
49  CloneProtocol の通信終了、ステーションの離脱等が起こるまでは反映されないので注意してください。
50  @param[in] stationId 相手の @ref nn::pia::StationId "StationId" です。
51  @return この SharingClone とデータをやり取りする SharingClone が存在すれば true を返します。
52  @see IsConnectedWithAll
53  */
54  bool IsConnected(StationId stationId) const;
55 
56 
57  /*!
58  @brief この SharingClone とデータをやり取りする SharingClone が全てのステーションに存在するかどうかを判定します。
59  @details CloneProtocol::IsActiveStation() が true となるステーションが判定対象です。
60  @details 相手の SharingClone が途中で登録解除された場合、アプリケーションや内部によるデータの送受信等が
61  起こるまでは反映されないので注意してください。
62  @return この SharingClone とデータをやり取りする SharingClone が全てのステーションに存在すれば true を返します。
63  @see IsConnected
64  */
65  bool IsConnectedWithAll() const;
66 
67 
68 public:
69  /*!
70  @cond PRIVATE
71  @brief 宛先を取得します。(デバッグ用)
72  */
73  uint32_t GetParticipantBmp() const
74  {
75  return m_ParticipantBmp;
76  }
77  //! @endcond
78 
79  /*!
80  @cond PRIVATE
81  @brief 接続要求の宛先を取得します。(デバッグ用)
82  */
83  uint32_t GetRequestBmp() const
84  {
85  return m_RequestCommandToken.GetDestStationBitmap();
86  }
87  //! @endcond
88 
89  virtual void Trace(uint64_t flag) const;
90 
91  //! @cond PRIVATE
92 
93 protected:
94  virtual void OnStartup();
95  virtual void OnCleanup();
96  virtual void OnEnd();
97  virtual void OnSendFinished();
98  virtual bool IsEndProcessFinished();
99 
100  virtual void OnExit(StationIndex stationIndex);
101  virtual void OnDisconnect(StationIndex stationIndex, bool isValid);
102  virtual void OnRegister();
103 
104  virtual void OnAddParticipant(StationIndex stationIndex)
105  {
106  NN_PIA_UNUSED(stationIndex);
107  }
108 
109 public:
110  enum RequestResponse
111  {
112  RequestResponse_Accept,
113  RequestResponse_Reject,
114  RequestResponse_Ignore
115  };
116  RequestResponse ReceiveRequest(StationIndex src, ClockValue clock, uint8_t count);
117  void ReceiveAccept(StationIndex src, ClockValue clock, uint8_t count);
118  virtual void ReceiveReject(StationIndex src, ClockValue clock);
119  void ReceiveEnd(StationIndex src);
120  virtual void ReceiveStop(StationIndex src);
121 
122 public:
123  virtual uint32_t GetDestBitmap() const;
124  virtual bool IsInRequest() const
125  {
126  return m_RequestCommandToken.IsInList();
127  }
128 
129  virtual uint8_t GetLocalRegisterCount() const
130  {
131  return m_LocalRegisterCount;
132  }
133  virtual uint64_t GetRegisterCountAll() const
134  {
135  return m_RegisterCountAll;
136  }
137  virtual bool IsMatchLocalRegisterCount(uint64_t registerCountAll) const;
138  void IncrementLocalRegisterCount();
139  void SetRegisterCountAll(StationIndex stationIndex, uint8_t count);
140 
141 protected:
142  bool IsSendingRequest(StationIndex stationIndex) const;
143 
144 public:
145  class RequestCommandToken : public ClockCommandToken
146  {
147  public:
148  explicit RequestCommandToken(SharingClone* pClone)
149  : ClockCommandToken(pClone), m_DestBitmap(0), m_Clock(InvalidClock)
150  {
151  }
152  virtual CommandType GetType() const
153  {
154  return CommandType_Request;
155  }
156  virtual uint32_t GetDestStationBitmap() const
157  {
158  return m_DestBitmap;
159  }
160  void SetDestBitmap(uint32_t destBitmap)
161  {
162  m_DestBitmap = destBitmap;
163  }
164  void Exit(StationIndex stationIndex)
165  {
166  m_DestBitmap &= ~(0x1 << stationIndex);
167  }
168  virtual ClockValue GetClock() const
169  {
170  return m_Clock;
171  }
172  void SetClock(ClockValue clock)
173  {
174  m_Clock = clock;
175  }
176 
177  private:
178  uint32_t m_DestBitmap;
179  ClockValue m_Clock;
180  };
181 
182  class EndCommandToken : public CommandToken
183  {
184  public:
185  explicit EndCommandToken(SharingClone* pClone)
186  : CommandToken(pClone)
187  {
188  }
189  virtual CommandType GetType() const
190  {
191  return CommandType_End;
192  }
193  virtual uint32_t GetDestStationBitmap() const
194  {
195  return static_cast<const SharingClone*>(GetClone())->m_ParticipantBmp;
196  }
197  };
198 
199 private:
200  uint32_t m_ParticipantBmp;
201 
202  RequestCommandToken m_RequestCommandToken;
203  EndCommandToken m_EndCommandToken;
204 
205  uint8_t m_LocalRegisterCount; // 自分の Register カウンタ (2 bit)
206  uint64_t m_RegisterCountAll; // 全員の Register カウンタ (各ステーション 2 bit)
207 
208 public:
209  template <int TEST_ID, typename Arg>
210  static void Test(const SharingClone& obj, Arg* pArg = NULL);
211 
212  NN_PIA_DISALLOW_COPY(SharingClone);
213  //! @endcond
214 };
215 }
216 }
217 } // end of namespace nn::pia::clone