CTR-Pia  5.4.3
Game Communication Engine
 全て クラス ネームスペース 関数 変数 型定義 列挙型 列挙型の値 ページ
clone_ReliableCloneElementBase.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_CloneElementBase.h>
18 
19 
20 namespace nn
21 {
22 namespace pia
23 {
24 namespace clone
25 {
26 
27 
28 class IDataPacker;
29 
30 /*!
31  @brief 到達保証された値の送受信を管理する基底クラスです。
32  */
34 {
35 protected:
36  /*!
37  @brief デフォルトコンストラクタです。
38  */
40 
41 public:
42  /*!
43  @brief デストラクタです。
44  */
45  virtual ~ReliableCloneElementBase();
46 
47 
48  /*!
49  @brief @ref ReliableCloneElement::GetValue "GetValue()" で有効な値が取得できるかどうかを取得します。
50  @return @ref ReliableCloneElement::GetValue "GetValue()" で有効な値を取得できる場合は true を返します。
51  */
52  bool IsValidValue() const
53  {
54  return m_SetterStationIndex != StationIndex_Invalid;
55  }
56 
57 
58  /*!
59  @brief 値が設定された時刻を取得します。
60  @return 値が設定された時刻です。 IsValidValue() が false の場合に取得できる値は不定です。
61  */
63  {
64  return m_Clock;
65  }
66 
67 
68  /*!
69  @brief デバッグに有用な情報をプリントします。
70 
71  @param[in] flag トレースフラグの論理和。詳細は @ref TraceFlag 型を参照してください。
72  */
73  void Trace(uint64_t flag) const;
74 
75 
76 public:
77  /*!
78  @cond PRIVATE
79  @brief 現在の値をセットした StationIndex を取得します。(デバッグ用)
80  */
81  StationIndex GetSetter() const
82  {
83  return m_SetterStationIndex;
84  }
85  //! @endcond
86 
87  /*!
88  @cond PRIVATE
89  @brief 現在の値の送信責任のある StationIndex を取得します。(デバッグ用)
90  */
91  StationIndex GetPreserver() const
92  {
93  return m_PreserverStationIndex;
94  }
95  //! @endcond
96 
97  /*!
98  @cond PRIVATE
99  @brief 現在の値の送信先ビットマップを取得します。(デバッグ用)
100  */
101  uint32_t GetDestBitmap() const
102  {
103  return m_DestBitmap;
104  }
105  //! @endcond
106 
107  //! @cond PRIVATE
108 
109 public:
110  virtual Type GetType() const
111  {
112  return GetTypeStatic();
113  }
114 
115  static Type GetTypeStatic()
116  {
117  return Type_Reliable;
118  }
119  static bool Receive(CloneElementBase* pElement, IDataPacker* pAckPacker, const void* cpChunk, uint16_t chunkSize, Id elementId, StationIndex src, StationIndex localStationIndex, uint32_t dispatchCount);
120  static uint32_t GetDataChunkHeaderSize();
121 
122 private:
123  bool ReceiveRequest(StationIndex src);
124  bool ReceiveData(const void* cpData, uint32_t size, StationIndex src, StationIndex setter, ClockValue clock, uint32_t destBitmap);
125  void ReceiveNoData(StationIndex src);
126  void ReceivePreserverMigration(StationIndex src, StationIndex setter, ClockValue clock);
127  void ReceiveAck(StationIndex src, StationIndex setter, ClockValue clock);
128 
129 public:
130  virtual void ClearData();
131 
132  virtual void AddDest(StationIndex stationIndex);
133  virtual void RemoveDest(StationIndex stationIndex);
134  virtual void Complement(StationIndex stationIndex);
135 
136  virtual void RequestInitialData();
137 
138 private:
139  class ReliableSendToken : public CloneElementBase::ResendableSendToken
140  {
141  public:
142  enum TokenType
143  {
144  TokenType_Request,
145  TokenType_Data
146  };
147  virtual TokenType GetTokenType() const = 0;
148  };
149 
150 
151  class ReliableRequestToken : public ReliableSendToken
152  {
153  public:
154  explicit ReliableRequestToken(ReliableCloneElementBase* pElement)
155  : ReliableSendToken(), m_pElement(pElement)
156  {
157  }
158  virtual Type GetElementType() const
159  {
160  return Type_Reliable;
161  }
162  virtual uint32_t GetDestBitmap() const
163  {
164  return m_pElement->m_DestBitmap;
165  }
166  virtual TokenType GetTokenType() const
167  {
168  return TokenType_Request;
169  }
170  virtual uint32_t GetChunkSize() const;
171  virtual void WriteChunk(void* pChunkBuffer) const;
172  virtual CloneElementBase* GetElement()
173  {
174  return m_pElement;
175  }
176  virtual void TraceTokenType()
177  {
178  PIA_TRACE_EX(common::TraceFlagClone, "TokenType: ReliableRequestToken");
179  };
180 
181  private:
182  Id GetId() const
183  {
184  return m_pElement->GetId();
185  }
186 
187  private:
188  ReliableCloneElementBase* m_pElement;
189  };
190 
191 
192  class ReliableDataToken : public ReliableSendToken
193  {
194  public:
195  explicit ReliableDataToken(ReliableCloneElementBase* pElement)
196  : ReliableSendToken(), m_pElement(pElement)
197  {
198  }
199  virtual Type GetElementType() const
200  {
201  return Type_Reliable;
202  }
203  virtual uint32_t GetDestBitmap() const
204  {
205  return m_pElement->m_DestBitmap;
206  }
207  virtual TokenType GetTokenType() const
208  {
209  return TokenType_Data;
210  }
211  virtual uint32_t GetChunkSize() const;
212  virtual void WriteChunk(void* pChunkBuffer) const;
213  virtual CloneElementBase* GetElement()
214  {
215  return m_pElement;
216  }
217  virtual bool IsUnicast() const
218  {
219 #if NN_PIA_ENABLE_CLONE_BROADCAST_RESEND
220  return false;
221 #else
222  return true;
223 #endif
224  }
225  virtual void TraceTokenType()
226  {
227  PIA_TRACE_EX(common::TraceFlagClone, "TokenType: ReliableDataToken");
228  };
229 
230  private:
231  uint32_t GetSize() const
232  {
233  return m_pElement->GetSize();
234  }
235  Id GetId() const
236  {
237  return m_pElement->GetId();
238  }
239  ClockValue GetClock() const
240  {
241  return m_pElement->m_Clock;
242  }
243  StationIndex GetSetterStationIndex() const
244  {
245  return m_pElement->m_SetterStationIndex;
246  }
247  void Serialize(void* pBuffer) const
248  {
249  m_pElement->Serialize(pBuffer);
250  }
251 
252  private:
253  ReliableCloneElementBase* m_pElement;
254  };
255 
256 
257  class ReliableInitialToken : public CloneElementBase::ISendToken
258  {
259  public:
260  explicit ReliableInitialToken(ReliableCloneElementBase* pElement)
261  : ISendToken(), m_pElement(pElement)
262  {
263  }
264  virtual Type GetElementType() const
265  {
266  return Type_Reliable;
267  }
268  virtual uint32_t GetDestBitmap() const
269  {
270  return m_DestBitmap;
271  }
272  virtual uint32_t GetChunkSize() const;
273  virtual void WriteChunk(void* pChunkBuffer) const;
274  virtual CloneElementBase* GetElement()
275  {
276  return m_pElement;
277  }
278  virtual void TraceTokenType()
279  {
280  PIA_TRACE_EX(common::TraceFlagClone, "TokenType: ReliableInitialToken");
281  };
282 
283  private:
284  uint32_t GetSize() const
285  {
286  return m_pElement->GetSize();
287  }
288  bool IsValidValue() const
289  {
290  PIA_ASSERT(m_pElement->IsValidValue());
291  return true;
292  }
293  Id GetId() const
294  {
295  return m_pElement->GetId();
296  }
297  ClockValue GetClock() const
298  {
299  return m_pElement->m_Clock;
300  }
301  StationIndex GetSetterStationIndex() const
302  {
303  return m_pElement->m_SetterStationIndex;
304  }
305  void Serialize(void* pBuffer) const
306  {
307  m_pElement->Serialize(pBuffer);
308  }
309 
310  public:
311  void AddDest(StationIndex stationIndex)
312  {
313  m_DestBitmap |= (0x1 << stationIndex);
314  }
315  void RemoveDest(StationIndex stationIndex)
316  {
317  m_DestBitmap &= (0x1 << stationIndex);
318  }
319  void ClearDest()
320  {
321  m_DestBitmap = 0;
322  }
323 
324  private:
325  ReliableCloneElementBase* m_pElement;
326  uint32_t m_DestBitmap;
327  };
328 
329 
330 protected:
331  Result SetValueCore();
332 
333  virtual void Serialize(void* pBuffer) const = 0;
334  virtual void Deserialize(const void* cpData) = 0;
335  virtual void ClearValue() = 0;
336 
337 private:
338  StationIndex m_SetterStationIndex;
339  StationIndex m_PreserverStationIndex;
340  ClockValue m_Clock;
341  uint32_t m_DestBitmap;
342  ReliableRequestToken m_RequestToken;
343  ReliableDataToken m_DataToken;
344  ReliableInitialToken m_InitialToken;
345 
346  static Definition<ReliableCloneElementBase> s_Definition;
347 
348 public:
349  template <int TEST_ID, typename Arg>
350  static void Test(const ReliableCloneElementBase& obj, Arg* pArg = NULL);
351 
352  NN_PIA_DISALLOW_COPY(ReliableCloneElementBase);
353  //! @endcond
354 };
355 }
356 }
357 } // end of namespace nn::pia::clone