CTR Pia  4.11.3
Game Communication Engine
clone_SendClone.h
1 /*---------------------------------------------------------------------------*
2  Project: Pia
3  File: clone_SendClone.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 namespace nn
21 {
22 namespace pia
23 {
24 namespace clone
25 {
26 
27 
28 /*!
29 @brief This class is a derivative of <tt>CloneBase</tt> and provides functionality for managing unidirectional sending.
30 @date 2013-07-18 Initial version.
31 
32 */
34 {
35 public:
36 /*!
37 @brief Instantiates the object with default parameters (default constructor).
38 */
39  SendClone();
40 
41 
42 /*!
43 @brief Destructor.
44 */
45  virtual ~SendClone();
46 
47 
48 /*!
49 @brief Determines whether there is a <tt>ReceiveClone</tt> to receive data from this <tt>SendClone</tt>.
50 @details Note that if the paired <tt>ReceiveClone</tt> is unregistered in the middle of an operation, the change is not applied until after something takes place, like data being sent or received by the application or internally, the ending of <tt>CloneProtocol</tt> communications, or a station leaving the session.
51 @param[in] stationId Specifies the <tt>@ref StationId</tt> of the recipient.
52 @return Returns <tt>true</tt> if there is a <tt>ReceiveClone</tt> to receive data from this <tt>SendClone</tt>.
53 @see IsConnectedWithAll, ReceiveClone::IsConnected
54 
55 */
56  bool IsConnected(StationId stationId) const;
57 
58 
59 /*!
60 @brief Determines whether all stations have a <tt>ReceiveClone</tt> to receive data from this <tt>SendClone</tt>.
61 @details The stations that are assessed are those for which the <tt>CloneProtocol::IsActiveStation</tt> function returns <tt>true</tt>.
62 @details Note that if the paired <tt>ReceiveClone</tt> is unregistered in the middle of an operation, the change is not applied until something takes place, like data being sent or received by the application or internally.
63 @return Returns <tt>true</tt> if all stations have a <tt>ReceiveClone</tt> to receive data from this <tt>SendClone</tt>.
64 @see IsConnected, ReceiveClone::IsConnected
65 
66 */
67  bool IsConnectedWithAll() const;
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 /*!
80 @cond PRIVATE
81 @brief Gets the receiver. (For debugging.)
82 */
83  u32 GetReceiverBmp() const
84  {
85  return m_ReceiverBmp;
86  }
87  //! @endcond
88 
89 /*!
90 @cond PRIVATE
91 @brief Gets whether startup is being announced. (For debugging.)
92 */
93  bool IsAnnounce() const
94  {
95  return m_AnnounceCommandToken.IsInList();
96  }
97  //! @endcond
98 
99 /*!
100 @cond PRIVATE
101 @brief Gets the destination of the startup announcement. (For debugging.)
102 */
103  u32 GetAnnounceBmp() const
104  {
105  return m_AnnounceCommandToken.GetDestStationBitmap();
106  }
107  //! @endcond
108 
109 /*!
110 @cond PRIVATE
111 @brief Gets whether the end is being announced. (For debugging.)
112 */
113  bool IsEnding() const
114  {
115  return m_EndCommandToken.IsInList();
116  }
117  //! @endcond
118 
119 
120  //! @cond PRIVATE
121 public:
122  static Type GetTypeStatic()
123  {
124  return TYPE_SEND;
125  }
126  static Key ToKey(Id id)
127  {
128  return CloneBase::ToKey(TYPE_SEND, STATION_INDEX_INVALID, id);
129  }
130  virtual Type GetTypeVirtual() const
131  {
132  return GetTypeStatic();
133  }
134 
135 
136 protected:
137  virtual void OnStartup();
138  virtual void OnCleanup();
139  virtual void OnEnd();
140  virtual void OnComplete();
141  virtual bool OnCheckEnd();
142 
143  //virtual void OnEnter(StationIndex stationId) {(void)stationId;}
144  virtual void OnExit(StationIndex stationId);
145  virtual void OnDisconnect(StationIndex stationId, bool isValid);
146 
147 public:
148  bool ReceiveRequest(StationIndex src, ClockValue clock, u8 count);
149  void ReceiveAnnounceAck(StationIndex src);
150  void ReceiveStop(StationIndex src);
151 
152 public:
153  virtual bool IsReadyToSetValue() const;
154  virtual u32 GetDestBitmap() const;
155 
156  virtual u64 GetRegisterCountAll() const
157  {
158  return m_RegisterCountAll;
159  }
160  void SetRegisterCountAll(StationIndex stationIndex, u8 count);
161 
162 public:
163  class AnnounceCommandToken : public CommandToken
164  {
165  public:
166  explicit AnnounceCommandToken(SendClone* pClone)
167  : CommandToken(pClone), m_DestBitmap(0)
168  {
169  }
170  virtual CommandType GetType() const
171  {
172  return COMMAND_ANNOUNCE;
173  }
174  virtual u32 GetDestStationBitmap() const
175  {
176  return m_DestBitmap;
177  }
178  void SetDestBitmap(u32 destBitmap)
179  {
180  m_DestBitmap = destBitmap;
181  }
182  void Exit(StationIndex stationId)
183  {
184  m_DestBitmap &= ~(0x1 << stationId);
185  }
186 
187  private:
188  u32 m_DestBitmap;
189  };
190 
191 
192  class EndCommandToken : public CommandToken
193  {
194  public:
195  explicit EndCommandToken(SendClone* pClone)
196  : CommandToken(pClone)
197  {
198  }
199  virtual CommandType GetType() const
200  {
201  return COMMAND_END;
202  }
203  virtual u32 GetDestStationBitmap() const
204  {
205  return static_cast<const SendClone*>(GetClone())->m_ReceiverBmp;
206  }
207  };
208 
209 
210 private:
211  u32 m_ReceiverBmp;
212 
213  AnnounceCommandToken m_AnnounceCommandToken;
214  EndCommandToken m_EndCommandToken;
215 
216  u64 m_RegisterCountAll; // Register counters for all stations (each 2-bit).
217 
218 public:
219  template <int TEST_ID, typename Arg>
220  static void Test(const SendClone& obj, Arg* pArg = NULL);
221 
222  //! @endcond
223 };
224 }
225 }
226 } // end of namespace nn::pia::clone
bool IsConnected(StationId stationId) const
Determines whether there is a ReceiveClone to receive data from this SendClone.
SendClone()
Instantiates the object with default parameters (default constructor).
u32 ClockValue
Defines a type that holds a clock value.
Definition: clone_definitions.h:44
StationIndex
Enumerates StationIndex values.
Definition: platformCtr.h:44
Definition of the StationId identifying the station within the session.
Definition: types.h:33
Definition: assert.h:115
ID indicating a station that is not present in the session.
Definition: platformCtr.h:59
This class is a derivative of CloneBase and provides functionality for managing unidirectional sendin...
Definition: clone_SendClone.h:33
This is the base class for managing sending and receiving. .
Definition: clone_CloneBase.h:38
virtual void Trace(u64 flag) const
Prints information that is useful for debugging.
u32 Id
Specifies the type of the ID for identifying clones.
Definition: clone_CloneBase.h:68
bool IsConnectedWithAll() const
Determines whether all stations have a ReceiveClone to receive data from this SendClone.
virtual ~SendClone()
Destructor.