CTR Pia  4.11.3
Game Communication Engine
clone_ReceiveClone.h
1 /*---------------------------------------------------------------------------*
2  Project: Pia
3  File: clone_ReceiveClone.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_CloneBase.h>
19 
20 
21 namespace nn
22 {
23 namespace pia
24 {
25 namespace clone
26 {
27 
28 
29 /*!
30 @brief This class is a derivative of <tt>CloneBase</tt> and provides functionality for managing unidirectional receiving.
31 @date 2013-07-18 Initial version.
32 
33 */
35 {
36 public:
37 /*!
38 @brief Instantiates the object with default parameters (default constructor).
39 */
40  ReceiveClone();
41 
42 
43 /*!
44 @brief Destructor.
45 */
46  virtual ~ReceiveClone();
47 
48 
49 /*!
50 @brief Gets the <tt>@ref StationIndex</tt> that was specified as the sender when registering this object with <tt>CloneProtocol</tt>.
51 @return Returns the <tt>@ref StationIndex</tt> of the sender. Returns <tt>@ref STATION_INDEX_INVALID</tt> if not registered with <tt>CloneProtocol</tt>.
52 */
54  {
55  return GetStationIndex();
56  }
57 
58 
59 /*!
60 @brief Determines whether there is a <tt>SendClone</tt> that sends to this <tt>ReceiveClone</tt>.
61 @return Returns <tt>true</tt> if there is a <tt>SendClone</tt> that sends to this <tt>ReceiveClone</tt>.
62 @see SendClone::IsConnected, SendClone::IsConnectedWithAll
63 */
64  bool IsConnected() const
65  {
66  return IsActive() && m_IsReceiving;
67  }
68 
69 
70 /*!
71 @brief Prints information that is useful for debugging.
72 @param[in] flag Specifies the bitwise OR of trace flags. For more information, see the <tt>@ref TraceFlag</tt> type.
73 
74 */
75  virtual void Trace(u64 flag) const;
76 
77 
78 public:
79  // For debugging.
80 /*!
81 @cond PRIVATE
82 @brief Gets whether the object is receiving. (For debugging.)
83 */
84  bool IsReceiving() const
85  {
86  return m_IsReceiving;
87  }
88  //! @endcond
89 
90 /*!
91 @cond PRIVATE
92 @brief Gets whether a connection is being requested. (For debugging.)
93 */
94  bool IsRequest() const
95  {
96  return m_RequestCommandToken.IsInList();
97  }
98  //! @endcond
99 
100 
101  //! @cond PRIVATE
102 
103 public:
104  static Type GetTypeStatic()
105  {
106  return TYPE_RECEIVE;
107  }
108  static Key ToKey(StationIndex stationId, Id id)
109  {
110  return CloneBase::ToKey(TYPE_RECEIVE, stationId, id);
111  }
112  virtual Type GetTypeVirtual() const
113  {
114  return GetTypeStatic();
115  }
116 
117 protected:
118  virtual void OnStartup();
119  virtual void OnCleanup();
120  virtual void OnEnd();
121  virtual bool OnCheckEnd();
122 
123  virtual void OnEnter(StationIndex stationId);
124  virtual void OnExit(StationIndex stationId);
125  virtual void OnDisconnect(StationIndex stationId, bool isValid);
126  virtual void OnRegister();
127 
128 public:
129  virtual u32 GetDestBitmap() const;
130  virtual bool IsInRequest() const
131  {
132  return m_RequestCommandToken.IsInList();
133  }
134 
135  virtual u8 GetLocalRegisterCount() const
136  {
137  return m_LocalRegisterCount;
138  }
139  virtual bool IsMatchLocalRegisterCount(u64 registerCountAll) const;
140  void IncrementLocalRegisterCount();
141 
142 public:
143  bool ReceiveAnnounce();
144  void ReceiveAccept(ClockValue clock);
145  void ReceiveReject(ClockValue clock);
146  void ReceiveEnd();
147  void ReceiveStop(StationIndex src);
148 
149 public:
150  class RequestCommandToken : public ClockCommandToken
151  {
152  public:
153  explicit RequestCommandToken(ReceiveClone* pClone)
154  : ClockCommandToken(pClone), m_Clock(INVALID_CLOCK)
155  {
156  }
157  virtual CommandType GetType() const
158  {
159  return COMMAND_REQUEST;
160  }
161  virtual u32 GetDestStationBitmap() const
162  {
163  return (0x1 << (static_cast<const ReceiveClone*>(GetClone())->GetStationIndex()));
164  }
165  virtual ClockValue GetClock() const
166  {
167  return m_Clock;
168  }
169  void SetClock(ClockValue clock)
170  {
171  m_Clock = clock;
172  }
173 
174  private:
175  ClockValue m_Clock;
176  };
177 
178 private:
179  RequestCommandToken m_RequestCommandToken;
180  bool m_IsReceiving;
181 
182  u8 m_LocalRegisterCount; // Register counter for the local station (2-bit).
183 
184 public:
185  template <int TEST_ID, typename Arg>
186  static void Test(const ReceiveClone& obj, Arg* pArg = NULL);
187 
188  //! @endcond
189 };
190 }
191 }
192 } // end of namespace nn::pia::clone
virtual void Trace(u64 flag) const
Prints information that is useful for debugging.
ReceiveClone()
Instantiates the object with default parameters (default constructor).
u32 ClockValue
Defines a type that holds a clock value.
Definition: clone_definitions.h:44
bool IsConnected() const
Determines whether there is a SendClone that sends to this ReceiveClone.
Definition: clone_ReceiveClone.h:64
StationIndex
Enumerates StationIndex values.
Definition: platformCtr.h:44
Definition: assert.h:115
virtual ~ReceiveClone()
Destructor.
bool IsActive() const
Determines whether this object is active.
Definition: clone_CloneBase.h:154
This is the base class for managing sending and receiving. .
Definition: clone_CloneBase.h:38
static const ClockValue INVALID_CLOCK
Specifies an invalid clock value.
Definition: clone_definitions.h:50
StationIndex GetSendStationIndex() const
Gets the StationIndex that was specified as the sender when registering this object with CloneProtoco...
Definition: clone_ReceiveClone.h:53
This class is a derivative of CloneBase and provides functionality for managing unidirectional receiv...
Definition: clone_ReceiveClone.h:34
u32 Id
Specifies the type of the ID for identifying clones.
Definition: clone_CloneBase.h:68