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