CTR Pia  4.11.3
Game Communication Engine
clone_UnreliableCloneElementBase.h
1 /*---------------------------------------------------------------------------*
2  Project: Pia
3  File: clone_UnreliableCloneElementBase.h
4 
5  Copyright Nintendo. All rights reserved.
6 
7  These coded instructions, statements, and computer programs contain
8  proprietary information of Nintendo of America Inc. and/or Nintendo
9  Company Ltd., and are protected by Federal copyright law. They may
10  not be disclosed to third parties or copied or duplicated in any form,
11  in whole or in part, without the prior written consent of Nintendo.
12  *---------------------------------------------------------------------------*/
13 
14 
15 #pragma once
16 
17 #include <pia/clone/clone_definitions.h>
18 #include <pia/clone/clone_CloneElementBase.h>
19 
20 
21 namespace nn
22 {
23 namespace pia
24 {
25 namespace clone
26 {
27 
28 
29 class IDataPacker;
30 
31 /*!
32 @brief This is the base class for managing the sending and receiving of unreliable data.
33 
34 @date 2013-07-18 Initial version.
35 */
37 {
38 protected:
39 /*!
40 @brief Instantiates the object with default parameters (default constructor).
41 */
43 
44 public:
45 /*!
46 @brief Destroys the object (destructor).
47 */
49 
50 
51 /*!
52 @brief Gets whether a valid value can be obtained using <tt>@ref UnreliableCloneElement::GetValue "GetValue"</tt>.
53 @return Returns <tt>true</tt> if a valid value can be obtained using <tt>@ref UnreliableCloneElement::GetValue "GetValue"</tt>.
54 */
55  bool IsValidValue() const
56  {
57  return m_IsValidValue;
58  }
59 
60 
61 /*!
62 @brief Gets the clock for when the value was set.
63 @return Returns the clock for when the value was set. This value is undefined when <tt>@ref IsValidValue</tt> returns <tt>false</tt>.
64 */
66  {
67  return m_Clock;
68  }
69 
70 
71 /*!
72 @brief Prints information that is useful for debugging.
73 
74 @param[in] flag Specifies the bitwise OR of trace flags. For more information, see the <tt>@ref TraceFlag</tt> type.
75 */
76  void Trace(u64 flag) const;
77 
78 
79  //! @cond PRIVATE
80 
81 public:
82  virtual u16 GetType() const
83  {
84  return GetTypeStatic();
85  }
86 
87  static u16 GetTypeStatic()
88  {
89  return TYPE_UNRELIABLE;
90  }
91  static bool Receive(CloneElementBase* pElement, IDataPacker* pAckPacker, const void* cpChunk, u16 chunkSize, Id elementId, StationIndex src, StationIndex localStationIndex, u32 dispatchCount);
92  static size_t GetDataChunkHeaderSize();
93 
94 private:
95  void ReceiveData(const void* cpData, size_t size, ClockValue clock);
96 
97 public:
98  virtual void ClearData();
99 
100 private:
101  class UnreliableSendToken : public CloneElementBase::ISendToken
102  {
103  public:
104  explicit UnreliableSendToken(UnreliableCloneElementBase* pElement)
105  : CloneElementBase::ISendToken(), m_pElement(pElement)
106  {
107  }
108  virtual Type GetElementType() const
109  {
110  return TYPE_UNRELIABLE;
111  }
112  virtual u32 GetDestBitmap() const;
113  virtual size_t GetChunkSize() const;
114  virtual void WriteChunk(void* pChunkBuffer) const;
115  virtual CloneElementBase* GetElement()
116  {
117  return m_pElement;
118  }
119 
120  private:
121  Id GetId() const
122  {
123  return m_pElement->GetId();
124  }
125  size_t GetSize() const
126  {
127  return m_pElement->GetSize();
128  }
129  ClockValue GetClock() const
130  {
131  return m_pElement->m_Clock;
132  }
133  void Serialize(void* pBuffer) const
134  {
135  m_pElement->Serialize(pBuffer);
136  }
137 
138  private:
139  UnreliableCloneElementBase* m_pElement;
140  };
141 
142 protected:
143  nn::Result SetValueCore(bool* pIsCopyValue);
144 
145  virtual void Serialize(void* pBuffer) const = 0;
146  virtual void Deserialize(const void* cpData) = 0;
147  virtual void ClearValue() = 0;
148 
149 private:
150  bool m_IsValidValue;
151  ClockValue m_Clock;
152  UnreliableSendToken m_SendDataToken;
153 
154  static Definition<UnreliableCloneElementBase> s_Definition;
155 
156 public:
157  template <int TEST_ID, typename Arg>
158  static void Test(const UnreliableCloneElementBase& obj, Arg* pArg = NULL);
159 
160  //! @endcond
161 };
162 }
163 }
164 } // end of namespace nn::pia::clone
This is the base class for managing data that is sent and received. .
Definition: clone_CloneElementBase.h:40
void Trace(u64 flag) const
Prints information that is useful for debugging.
This is the base class for managing the sending and receiving of unreliable data. ...
Definition: clone_UnreliableCloneElementBase.h:36
u32 ClockValue
Defines a type that holds a clock value.
Definition: clone_definitions.h:44
StationIndex
Enumerates StationIndex values.
Definition: platformCtr.h:44
Definition: assert.h:115
bool IsValidValue() const
Gets whether a valid value can be obtained using GetValue.
Definition: clone_UnreliableCloneElementBase.h:55
ClockValue GetClock() const
Gets the clock for when the value was set.
Definition: clone_UnreliableCloneElementBase.h:65
virtual ~UnreliableCloneElementBase()
Destroys the object (destructor).
u16 Id
Specifies the type of the ID for identifying clone elements.
Definition: clone_CloneElementBase.h:59
Id GetId() const
Gets the ID.
Definition: clone_CloneElementBase.h:67