CTR Pia  4.11.3
Game Communication Engine
clone_SharingClone.h
1 /*---------------------------------------------------------------------------*
2  Project: Pia
3  File: clone_SharingClone.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 bidirectional sending and receiving.
31 @date 2013-09-25 Initial version.
32 
33 */
34 class SharingClone : public CloneBase
35 {
36 protected:
37 /*!
38 @brief Instantiates the object with default parameters (default constructor).
39 */
40  SharingClone();
41 
42 public:
43 /*!
44 @brief Destructor.
45 */
46  virtual ~SharingClone();
47 
48 
49 /*!
50 @brief Determines whether another station's <tt>SharingClone</tt> exchanges data with this <tt>SharingClone</tt>.
51 @details Note that if the paired <tt>SharingClone</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.
52 @param[in] stationId Specifies the paired <tt>@ref nn::pia::StationId "StationId"</tt>.
53 @return Returns <tt>true</tt> if there is a <tt>SharingClone</tt> that exchanges data with this <tt>SharingClone</tt>.
54 @see IsConnectedWithAll
55 
56 */
57  bool IsConnected(StationId stationId) const;
58 
59 
60 /*!
61 @brief Determines whether all stations have a <tt>SharingClone</tt> that exchanges data with this <tt>SharingClone</tt>.
62 @details The stations that are assessed are those for which the <tt>CloneProtocol::IsActiveStation</tt> function returns <tt>true</tt>.
63 @details Note that if the paired <tt>SharingClone</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.
64 @return Returns <tt>true</tt> if all stations have a <tt>SharingClone</tt> that exchanges data with this <tt>SharingClone</tt>.
65 @see IsConnected
66 
67 */
68  bool IsConnectedWithAll() const;
69 
70 
71 public:
72 /*!
73 @cond PRIVATE
74 @brief Gets the receiver. (For debugging.)
75 */
76  u32 GetParticipantBmp() const
77  {
78  return m_ParticipantBmp;
79  }
80  //! @endcond
81 
82 /*!
83 @cond PRIVATE
84 @brief Gets the destination of the connection request. (For debugging.)
85 */
86  u32 GetRequestBmp() const
87  {
88  return m_RequestCommandToken.GetDestStationBitmap();
89  }
90  //! @endcond
91 
92 /*!
93 @cond PRIVATE
94 @brief Gets whether a connection is being requested. (For debugging.)
95 */
96  bool IsRequest() const
97  {
98  return m_RequestCommandToken.IsInList();
99  }
100  //! @endcond
101 
102  virtual void Trace(u64 flag) const;
103 
104  //! @cond PRIVATE
105 
106 protected:
107  virtual void OnStartup();
108  virtual void OnCleanup();
109  virtual void OnEnd();
110  virtual bool OnCheckEnd();
111 
112  virtual void OnExit(StationIndex stationId);
113  virtual void OnDisconnect(StationIndex stationId, bool isValid);
114  virtual void OnRegister();
115 
116  virtual void OnAddParticipant(StationIndex stationIndex)
117  {
118  NN_PIA_DUMMY_PARAM(stationIndex);
119  }
120 
121 public:
122  enum RequestResponse
123  {
124  REQUEST_RESPONSE_ACCEPT,
125  REQUEST_RESPONSE_REJECT,
126  REQUEST_RESPONSE_IGNORE
127  };
128  RequestResponse ReceiveRequest(StationIndex src, ClockValue clock, u8 count);
129  void ReceiveAccept(StationIndex src, ClockValue clock, u8 count);
130  virtual void ReceiveReject(StationIndex src, ClockValue clock);
131  virtual void ReceiveStop(StationIndex src);
132 
133 public:
134  virtual u32 GetDestBitmap() const;
135  virtual bool IsInRequest() const
136  {
137  return m_RequestCommandToken.IsInList();
138  }
139 
140  virtual u8 GetLocalRegisterCount() const
141  {
142  return m_LocalRegisterCount;
143  }
144  virtual u64 GetRegisterCountAll() const
145  {
146  return m_RegisterCountAll;
147  }
148  virtual bool IsMatchLocalRegisterCount(u64 registerCountAll) const;
149  void IncrementLocalRegisterCount();
150  void SetRegisterCountAll(StationIndex stationIndex, u8 count);
151 
152 protected:
153  bool IsSendingRequest(StationIndex stationIndex) const;
154 
155 public:
156  class RequestCommandToken : public ClockCommandToken
157  {
158  public:
159  explicit RequestCommandToken(SharingClone* pClone)
160  : ClockCommandToken(pClone), m_DestBitmap(0), m_Clock(INVALID_CLOCK)
161  {
162  }
163  virtual CommandType GetType() const
164  {
165  return COMMAND_REQUEST;
166  }
167  virtual u32 GetDestStationBitmap() const
168  {
169  return m_DestBitmap;
170  }
171  void SetDestBitmap(u32 destBitmap)
172  {
173  m_DestBitmap = destBitmap;
174  }
175  void Exit(StationIndex stationId)
176  {
177  m_DestBitmap &= ~(0x1 << stationId);
178  }
179  virtual ClockValue GetClock() const
180  {
181  return m_Clock;
182  }
183  void SetClock(ClockValue clock)
184  {
185  m_Clock = clock;
186  }
187 
188  private:
189  u32 m_DestBitmap;
190  ClockValue m_Clock;
191  };
192 
193 private:
194  u32 m_ParticipantBmp;
195 
196  RequestCommandToken m_RequestCommandToken;
197 
198  u8 m_LocalRegisterCount; // Register counter for the local station (2-bit).
199  u64 m_RegisterCountAll; // Register counters for all stations (each 2-bit).
200 
201 public:
202  template <int TEST_ID, typename Arg>
203  static void Test(const SharingClone& obj, Arg* pArg = NULL);
204 
205  //! @endcond
206 };
207 }
208 }
209 } // end of namespace nn::pia::clone
bool IsConnectedWithAll() const
Determines whether all stations have a SharingClone that exchanges data with this SharingClone...
u32 ClockValue
Defines a type that holds a clock value.
Definition: clone_definitions.h:44
This class is a derivative of CloneBase and provides functionality for bidirectional sending and rece...
Definition: clone_SharingClone.h:34
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
bool IsConnected(StationId stationId) const
Determines whether another station&#39;s SharingClone exchanges data with this SharingClone.
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
virtual ~SharingClone()
Destructor.