CTR Pia  4.11.3
Game Communication Engine
sync_SyncProtocol.h
1 /*---------------------------------------------------------------------------*
2  Project: Pia
3  File: sync_SyncProtocol.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 
18 #include <pia/transport/transport_Protocol.h>
19 
20 #include <pia/transport/transport_ProtocolEvent.h>
21 #if NN_PIA_TRANSPORT_V3
22 #include <pia/common/common_PacketDefine.h>
23 #else
24 #include <pia/common/common_ProtocolMessageOld.h>
25 #endif
26 #include <pia/transport/transport_definitions.h>
27 
28 
29 // Forward declaration.
30 namespace nn
31 {
32 namespace pia
33 {
34 namespace common
35 {
36 class ZlibCompressor;
37 class ZlibUncompressor;
38 }
39 }
40 }
41 
42 
43 namespace nn
44 {
45 namespace pia
46 {
47 namespace sync
48 {
49 
50 /*!
51 @brief This protocol is used for synchronized communication. <br/>
52 Full mesh is the only network topology type that is supported. Note that star and relay mesh types are not supported.
53 @date 2014-01-30 Added constants to specify the compression level of synchronization data, and made any other compression levels unsupported.
54 @date 2013-11-22 Changed internal processes and reduced the amount of synchronization data sent.
55 @date 2013-11-22 Enabled a skip feature when sending synchronized data on the same frame by default and removed the configuration parameter (<tt>Setting::m_SendSkipMax</tt>).
56 @date 2013-10-25 Added the <tt>EndAlone</tt> function for unilaterally ending synchronization.
57 @date 2013-10-25 Added a feature for compressing synchronized data.
58 @date 2013-10-25 Added a skip feature when sending synchronized data on the same frame.
59 @date 2013-08-30 Changed the message headers. This breaks backward compatibility.
60 @date 2013-08-26 Removed the <tt>Session::m_SendPeriod</tt> function. Set the same parameters by calling <tt>Start</tt>.
61 @date 2013-08-26 Removed <tt>Start(bit32 usingDataIdBitmap)</tt> and <tt>Start(bit32 usingDataIdBitmap, u32 delay)</tt>. Use <tt>Start(bit32 usingDataIdBitmap, u32 delay, u32 sendPeriod)</tt> when synchronized communication starts.
62 @date 2013-05-20 Promoted the feature to change delay during synchronization to the officially supported version.
63 @date 2013-04-12 Added a function to calculate the maximum data size that would fit into a single packet of synchronization data to be sent.
64 @date 2013-04-12 Added a feature to change the delay after initialization. (The feature to change the delay during synchronization is still in beta.)
65 @date 2013-04-12 Changed the type of the <tt>Setting</tt> member.
66 @date 2013-04-12 Changed the number of Data IDs that can be configured.
67 @date 2013-02-19 Renamed <tt>STATE_READY</tt> to <tt>STATE_WAITING</tt>.
68 @date 2013-02-15 Added a function to get the settings specified in the <tt>Initialize</tt> function.
69 @date 2013-02-15 Changed the type of the <tt>Setting</tt> member.
70 @date 2013-01-18 Greatly revised the state transitions, and changed the operations of each function.
71 @date 2013-01-18 It is now possible to send large files.
72 @date 2012-12-25 Initial version.
73 @if CTR_DOC
74 @date 2012-12-25 Renamed the existing <tt>SyncProtocol</tt> class to <tt>SyncProtocolOld</tt>.
75 @endif
76 
77 */
79 {
80 public:
81 /*!
82 @cond PRIVATE
83 @brief Instantiates the object with default parameters (default constructor).
84 @details Applications should not call this constructor directly.
85 Use the <tt>@ref transport::Transport::CreateProtocol</tt> function to create an instance.
86 
87 */
88  SyncProtocol(void);
89  //! @endcond
90 
91 
92 /*!
93 @cond PRIVATE
94 @brief Destructor.
95 @details Do not call this destructor directly from applications.
96 Use the <tt>@ref transport::Transport::DestroyProtocol</tt> function to free an instance.
97 
98 */
99  virtual ~SyncProtocol(void);
100  //! @endcond
101 
102 
103  PIA_PROTOCOL_TYPE_INFO(nn::pia::transport::PROTOCOL_TYPE_SYNC);
104 
105 
106  //! Defines the maximum input latency specified that can be specified for <tt>@ref Setting::m_MaxDelay</tt>, as a number of frames.
107  static const u8 FRAME_DELAY_MAX = 32;
108 
109  //! Defines the number of data IDs that can be set.
110  static const u32 DATA_ID_NUM = 16;
111 
112  //! Defines the reserved data ID.
113  static const u32 RESERVED_DATA_ID_NUM = 1;
114  static const u32 RESERVED_DATA_ID_CHANGE_DELAY = DATA_ID_NUM + 0;
115 
116  static const u32 SEND_SKIP_MAX = 2;
117  static const u32 DATA_FIRST_SEND_COUNT = 3;
118 
119  static const u32 COMPRESSION_LEVEL_NONE = 0; //!< Specifies the compression level (no compression) for the synchronization data specified in <tt>@ref Setting::m_DataCompressionLevel</tt>.
120  static const u32 COMPRESSION_LEVEL_LOW = 1; //!< Specifies the compression level (speed emphasized) for the synchronization data specified in <tt>@ref Setting::m_DataCompressionLevel</tt>.
121  static const u32 COMPRESSION_LEVEL_MIDDLE = 5; //!< Specifies the compression level for the synchronization data specified in <tt>@ref Setting::m_DataCompressionLevel</tt>.
122  static const u32 COMPRESSION_LEVEL_HIGH = 9; //!< Specifies the compression level (compression rate emphasized) for the synchronization data specified in <tt>@ref Setting::m_DataCompressionLevel</tt>.
123 
124 /*!
125 @brief Stores settings specified during initialization.
126 @details Specify the same values on stations using data synchronization.
127 */
128  struct Setting
129  {
130  public:
131 /*!
132 @brief Instantiates the object with default parameters (default constructor).
133 @details This function initializes the object using default values.
134 */
135  Setting();
136 
137 /*!
138 @brief Sets the size of the data to send for each data ID.
139 @details Specify <tt>0</tt> for unused data IDs.
140 You can use the <tt>@ref SyncProtocol::GetDataUnitSizeMax</tt> function to find out the largest size this value can be set to.
141 @see SyncProtocol::GetDataUnitSizeMax
142 */
143  size_t m_DataUnitSize[DATA_ID_NUM + RESERVED_DATA_ID_NUM];
144 
145 /*!
146 @brief Defines the maximum number of frames of input delay.
147 @details Specify a value between 1 and <tt>FRAME_DELAY_MAX</tt>.
148 @if CTR_DOC
149 @details <b>Note:</b> To set a value equivalent to the delays set in the <tt>HidSync</tt> and <tt>SyncProtocolOld</tt> classes, you must specify a value 1 greater than the values set in those classes.
150 @endif
151 */
153 
154 /*!
155 @brief Ends synchronization due to a timeout if packets cannot be received consecutively for the specified number of frames (number of calls to <tt>@ref SyncProtocol::Step</tt>).
156 @details If you specify 0, the object continues to wait for packets forever, and data synchronization never times out.
157 */
159 
160 /*!
161 @brief Enables or disables use of the change delay feature while communication is synchronized.
162 */
164 
165 /*!
166 @brief Sets the compression level for synchronized data.
167 @details Not compressed when <tt>@ref SyncProtocol::COMPRESSION_LEVEL_NONE</tt> is specified.
168 Specifying <tt>@ref SyncProtocol::COMPRESSION_LEVEL_LOW</tt> emphasizes speed; <tt>@ref SyncProtocol::COMPRESSION_LEVEL_HIGH</tt> emphasizes the compression rate.
169 Specifying <tt>@ref SyncProtocol::COMPRESSION_LEVEL_MIDDLE</tt> results in an intermediate level of compression between the other two.
170 The default value is <tt>@ref SyncProtocol::COMPRESSION_LEVEL_NONE</tt>.
171 Other values are not supported.
172 Execution time varies significantly based on the CPU performance of the platform.
173 */
175  };
176 
177 
178 /*!
179 @brief Gets the maximum number of bytes that can be sent in one data unit.
180 @details The value obtained depends on the parameter specified when initializing the <tt>transport::Transport</tt> instance.
181 @see Returns the maximum number of bytes that can be sent in one data unit.
182 @see Setting::m_DataUnitSize
183 
184 
185 
186 */
187  size_t GetDataUnitSizeMax() const;
188 
189 
190 /*!
191 @brief Initializes the instance. Make this call between the <tt>BeginSetup</tt> and <tt>EndSetup</tt> functions.
192 
193 @param[in] setting Specifies various settings.
194 Specify the same values on all stations using data synchronization. Operations are undefined when different values are specified.
195 
196 @return Returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt> if execution succeeds. You must make sure that the implementation of this function in your application does not return any errors.
197 @retval ResultAlreadyInitialized Indicates that the instance is already initialized. Programming error. Fix your program so that this error is not returned.
198 @retval ResultInvalidArgument Indicates that an argument is invalid. Programming error. Fix your program so that this error is not returned.
199 @see Finalize
200 
201 
202 */
203  nn::Result Initialize(const Setting& setting);
204 
205 
206 /*!
207 @brief Finalizes the instance.
208 @see Initialize
209 
210 */
211  void Finalize();
212 
213 
214 /*!
215 @brief Gets the size of data having the data ID specified to the <tt>Initialize</tt> function.
216 @param[in] dataId Specifies the data ID of the data being checked.
217 @return Returns the size of the specified data.
218 
219 
220 */
221  size_t GetDataSize(u32 dataId) const;
222 
223 
224 /*!
225 @brief Gets the maximum input delay specified to the <tt>Initialize</tt> function.
226 @return Returns the maximum number of frames to delay input.
227 
228 */
229  u32 GetMaxDelay() const
230  {
231  return static_cast<u32>(m_MaxDelay);
232  }
233 
234 /*!
235 @brief Gets the input delay actually specified.
236 @return Returns the number of input delay frames.
237 
238 */
239  u32 GetDelay() const
240  {
241  return static_cast<u32>(m_Delay);
242  }
243 
244 
245 /*!
246 @brief Gets the timeout setting specified in the <tt>Initialize</tt> function.
247 @return Returns the timeout setting.
248 
249 */
250  u32 GetTimeoutFrame() const
251  {
252  return static_cast<u32>(m_TimeoutFrame);
253  }
254 
255 
256 /*!
257 @brief Gets the send interval specified to the <tt>Start</tt> function.
258 @return Returns the send interval.
259 
260 */
261  u32 GetSendPeriod() const
262  {
263  return m_SendPeriod;
264  }
265 
266 /*!
267 @brief Sets the send interval.
268 @return Returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt> if execution succeeds.
269 @retval ResultInvalidArgument Indicates that an argument is invalid. Programming error. Fix your program so that this error is not returned.
270 
271 
272 */
273  nn::Result SetSendPeriod(u32 sendPeriod);
274 
275 
276 /*!
277 @brief Advances synchronization by one frame.
278 @details Call this function during each frame when the state is other than <tt>STATE_NOT_SYNCHRONIZED</tt>. Call this function at the beginning of each frame.
279 When <tt>@ref NeedSetData</tt> returns <tt>true</tt>, specify the data to send to the <tt>@ref SetData</tt> function before calling this function.
280 This function can also be called when the state is <tt>STATE_NOT_SYNCHRONIZED</tt>.
281 @ref EndAlone After being called successfully, this function fails when called during individual synchronization finalization processes. It must be called every frame to keep the internal processing going.
282 @return Returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt> if execution succeeds.
283 @retval ResultInvalidState Indicates that communication is not active. Programming error. Fix your program so that this error is not returned.
284 @retval ResultDataIsNotArrivedYet Indicates that the frame was not advanced because the data being synchronized has not arrived from other stations.
285 Try calling this function again after calling the <tt>common::Scheduler::Dispatch</tt> function. Handle appropriately in the application.
286 @retval ResultDataIsNotSet Indicates that the local station has not yet set the data to send. Programming error. Fix your program so that this error is not returned.
287 @retval ResultTemporaryUnavailable An individual synchronization finalization process is in progress.
288 @see SetData
289 
290 
291 
292 
293 
294 
295 */
296  nn::Result Step();
297 
298 
299 /*!
300 @brief Starts synchronization.
301 @details If this function is successfully called when the state is <tt>STATE_NOT_SYNCHRONIZED</tt>, the state transitions to <tt>STATE_WAITING</tt>.
302 If a network node starts synchronization after this function is called, the state transitions to <tt>STATE_STARTING</tt> and <tt>STATE_SYNCHRONIZED</tt>.
303 @param[in] usingDataIdBitmap Specifies a bit flag representing the data IDs (among those specified by <tt>Initialize</tt>) to send from this station during this round of synchronized communication.
304 Bits are ordered from low to high, with the lowest-order bit corresponding to data ID 0.
305 You can specify separate values for each station.
306 
307 @param[in] delay Specifies the delay requested by this station.
308 The largest delay value among stations that specify a delay is actually used.
309 This delay value must be less than or equal to the delay specified during initialization.
310 @param[in] sendPeriod Specifies the send/resend interval for the configured data.
311 Each time that <tt>SyncProtocol::Step</tt> is called the number of times specified by this parameter, send/resend is executed when <tt>common::Scheduler::Dispatch</tt> is called.
312 Specify a value of <tt>1</tt> or greater.
313 
314 @return Returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt> if execution succeeds. You must make sure that the implementation of this function in your application does not return any errors.
315 
316 @retval ResultInvalidState Indicates that this function cannot be called in the current <tt>@ref nn::pia::sync::SyncProtocol::State "State"</tt>. Alternatively, it indicates that stations are not communicating. Programming error. Fix your program so that this error is not returned.
317 @retval ResultInvalidArgument Indicates that an argument is invalid. Programming error. Fix your program so that this error is not returned.
318 @see End
319 
320 
321 
322 
323 */
324  nn::Result Start(bit32 usingDataIdBitmap, u32 delay, u32 sendPeriod);
325 
326 
327 /*!
328 @brief Ends synchronized communication.
329 @details If this function can be called when the state is <tt>STATE_WAITING</tt>, <tt>STATE_STARTING</tt>, or <tt>STATE_SYNCHRONIZED</tt>, and the function succeeds, the state transitions to <tt>STATE_ENDING</tt>.
330 When network nodes are subsequently notified that communication has ended, the state transitions to <tt>STATE_NOT_SYNCHRONIZED</tt>.
331 If you use this function to end synchronization, normally the reason for the end of communication is <tt>END_REASON_END</tt> for the local station and <tt>END_REASON_OTHER_STATION</tt> for other stations.
332 However, these are not necessarily the values if communication is simultaneously terminated by different nodes for different reasons.
333 Immediately after this function is called, you must call the <tt>Step</tt> function for several frames until <tt>STATE_NOT_SYNCHRONIZED</tt> results before calling the <tt>Start</tt> function again.
334 
335 @return Returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt> if execution succeeds. You must make sure that the implementation of this function in your application does not return any errors.
336 
337 @retval ResultInvalidState Indicates that this function cannot be called in the current <tt>@ref nn::pia::sync::SyncProtocol::State "State"</tt>. Alternatively, it indicates that stations are not communicating. Programming error. Fix your program so that this error is not returned.
338 @see Start
339 
340 
341 
342 
343 
344 */
345  nn::Result End();
346 
347 /*!
348 @brief Unilaterally ends synchronization for only the local station.
349 @details This function can be called while the state is <tt>STATE_SYNCHRONIZED</tt>.
350 <br/>
351 This function can get the synchronization data for each frame. If there is a notification that an individual synchronization finalization has been done on another station after this function has been called, however, the synchronization data that station sent cannot be obtained. This can lead to the data getting out of sync, so make sure to call this function after getting the received synchronization data.
352 The end frame is set to the last frame for which send data has already been set.
353 The peers are notified of the end frame and the local station transitions to the <tt>STATE_ENDED_ALONE</tt> state after confirming that all peers have reached the end frame.
354 After this function is called successfully, <tt>@ref Step</tt> fails while the state is <tt>STATE_SYNCHRONIZED</tt>. Note that the frame can no longer advance when this happens, so the local station never reaches the end frame.
355 Nonetheless, the <tt>@ref Step</tt> function must still be called in every frame to advance internal processes.
356 If you use this function to end synchronization, normally the reason for the end of communication is <tt>END_REASON_END_ALONE</tt> for the local station.
357 However, these are not necessarily the values if communication is simultaneously terminated by different nodes for different reasons.
358 Once synchronization ends with all peers while in the <tt>STATE_ENDED_ALONE</tt> state, the state transitions to <tt>STATE_NOT_SYNCHRONIZED</tt>.
359 Also, the other stations can maintain synchronization even if the local station leaves the session in the <tt>STATE_ENDED_ALONE</tt> state, or after transitioning to the subsequent <tt>STATE_NOT_SYNCHRONIZED</tt> state.
360 However, if the local station disconnects in the <tt>STATE_WAITING</tt> state because a new station connected after the transition to the <tt>STATE_ENDED_ALONE</tt> state and the other stations attempted synchronization again, the other stations end synchronization and transition to the <tt>STATE_NOT_SYNCHRONIZED</tt> state.
361 Also, stations that ended in the <tt>STATE_ENDED_ALONE</tt> state can restart synchronization after transitioning to the <tt>STATE_NOT_SYNCHRONIZED</tt> state, but if those stations restart synchronization or leave the session, the stations other than the local station cannot be synchronized.
362 @return Returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt> if execution succeeds. You must make sure that the implementation of this function in your application does not return any errors.
363 
364 @retval ResultInvalidState Indicates that this function cannot be called in the current <tt>@ref nn::pia::sync::SyncProtocol::State "State"</tt>. or that the end frame has already been set. Alternatively, it indicates that stations are not communicating. Programming error. Fix your program so that this error is not returned.
365 
366 
367 
368 
369 
370 
371 
372 
373 
374 
375 
376 
377 
378 
379 
380 
381 */
382  nn::Result EndAlone();
383 
384 /*!
385 @brief Gets the end frame for the specified station.
386 @details This function can be called when the state is something other than <tt>STATE_NOT_SYNCHRONIZED</tt> or <tt>STATE_WAITING</tt>.
387 If synchronization ends before the <tt>STATE_SYNCHRONIZED</tt> state is reached, <tt>endFrame</tt> becomes <tt>0</tt>, but note that synchronization actually ends before that.
388 Also note that the station ending synchronization may end before reaching this frame.
389 @return Returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt> if execution succeeds.
390 
391 @retval ResultInvalidArgument Indicates that an argument is invalid. Programming error. Fix your program so that this error is not returned.
392 @retval ResultInvalidState Indicates that this function cannot be called in the current <tt>@ref nn::pia::sync::SyncProtocol::State "State"</tt>. Programming error. Fix your program so that this error is not returned.
393 @retval ResultNoData Indicates that the end frame is not set. Handle appropriately in the application.
394 
395 
396 
397 */
398  nn::Result GetEndFrameNo(StationId stationId, u32* endFrameNo) const;
399 
400 /*!
401 @brief Represents the current state of synchronization.
402 */
403  enum State
404  {
405  STATE_NOT_SYNCHRONIZED = 0, //!< Synchronization is not active.
406  STATE_WAITING, //!< Start synchronization and wait for other stations to start synchronization.
407  STATE_STARTING, //!< Synchronization is starting. Although the data to send must be set, it cannot yet be retrieved.
408  STATE_SYNCHRONIZED, //!< Synchronization is active. The data to send must be set, and it can be retrieved.
409  STATE_ENDING, //!< Synchronization is ending.
410  STATE_ENDED_ALONE //!< The local station unilaterally ended synchronization.
411  };
412 
413 
414 /*!
415 @brief Gets the current state of synchronization.
416 @return Returns the current state of synchronization.
417 
418 */
419  State GetState() const
420  {
421  return m_State;
422  }
423 
424 
425 /*!
426 @brief Gets whether it is necessary to set the data to send.
427 @details You must set the data to send during <tt>STATE_STARTING</tt> and <tt>STATE_SYNCHRONIZED</tt>.
428 If the return value of a call to <tt>Step</tt> indicates that execution failed, there is no need to reconfigure send data before the next call to <tt>Step</tt> because the frame has not advanced.
429 @return Returns <tt>true</tt> if any of the required data IDs are not set.
430 Returns <tt>false</tt> if it is not necessary to set send data, or the data to send has already been set.
431 @see SetData
432 
433 
434 
435 
436 */
437  bool NeedSetData() const;
438 
439 
440 /*!
441 @brief Gets whether it is necessary to set the data to send for the specified data ID.
442 @details You must set the data to send during <tt>STATE_STARTING</tt> and <tt>STATE_SYNCHRONIZED</tt>.
443 When the return value of a call to <tt>Step</tt> indicates that execution failed, you do not need to reconfigure send data before the next call to <tt>Step</tt> because the frame has not advanced.
444 @param[in] dataId Specifies the data ID to check whether it is necessary to send data for.
445 @return Returns <tt>true</tt> when send data needs to be set for the specified data ID.
446 Returns <tt>false</tt> if it is not necessary to set send data, or the data to send has already been set.
447 @see SetData
448 
449 
450 
451 
452 
453 */
454  bool NeedSetData(u32 dataId) const;
455 
456 
457 /*!
458 @brief Gets whether received data can be retrieved.
459 @details Received data can be retrieved while the state is <tt>STATE_SYNCHRONIZED</tt>.
460 However, when you are using the feature to change the delay while communication is synchronized, use <tt>GetIsNoDataFrame</tt> to check whether data can be retrieved during the current frame. During some frames you cannot retrieve data even if this function returns <tt>true</tt>.
461 @return Returns <tt>true</tt> if received data can be retrieved.
462 @see GetData
463 
464 
465 
466 
467 */
468  bool CanGetData() const;
469 
470 
471 /*!
472 @brief Gets the number of frames since synchronization started.
473 @details While the state is <tt>STATE_SYNCHRONIZED</tt>, every successful call to the <tt>Step</tt> function advances one frame.
474 @return Returns the number of frames since synchronization started.
475 <b>Note:</b> This function returns <tt>0</tt> if synchronization is not active, and also returns <tt>0</tt> on the first frame when synchronization starts.
476 
477 
478 */
479  u32 GetFrameNo() const;
480 
481 
482 /*!
483 @brief Gets whether the specified station has joined synchronization.
484 @param[in] stationId Specifies the <tt>@ref StationId</tt> of the station being checked.
485 @return Returns <tt>true</tt> if the specified station has joined synchronization.
486 
487 
488 */
489  bool CheckEntry(StationId stationId) const;
490 
491 
492 /*!
493 @brief Gets a bit flag representing the list of data IDs that the specified station is sending.
494 @param[in] stationId Specifies the <tt>@ref StationId</tt> of the station being checked.
495 @return Returns a list of data IDs that the specified station is sending.
496 <tt>0</tt> is returned for stations not engaging in synchronization (stations for which <tt>@ref CheckEntry</tt> returns <tt>false</tt>).
497 
498 
499 */
500  bit32 GetUsingDataIdBitmap(StationId stationId) const;
501 
502 
503 /*!
504 @brief Represents the reason why synchronization was ended.
505 */
507  {
508  END_REASON_NOTHING = 0, //!< Synchronization has not ended.
509  END_REASON_END, //!< Communication ended because of a call to the <tt>@ref End</tt> function by the station.
510  END_REASON_OTHER_STATION, //!< Communication ended because another station ended synchronization.
511  END_REASON_CHANGE_CONNECTION, //!< Communication ended because there was a change in the stations in the session.
512  END_REASON_TIMEOUT, //!< Communication ended because no data was received for <tt>@ref Setting::m_TimeoutFrame</tt> frames.
513  END_REASON_END_ALONE //!< Communication ended because of a call to the <tt>@ref EndAlone</tt> function by the station.
514  };
515 
516 
517 /*!
518 @brief Gets the reason why synchronization was ended.
519 @details This value is reset if the <tt>@ref Start</tt> function is called to start synchronization again.
520 @return Returns the reason why synchronization ended.
521 
522 
523 */
524  EndReason GetLastEndReason() const;
525 
526 
527 /*!
528 @brief Sets data to send during synchronization.
529 @details If the <tt>NeedSetData</tt> function returns <tt>true</tt>, you must set data before calling the <tt>Step</tt> function.
530 
531 @param[in] dataId Specifies the data ID of data being set.
532 @param[in] cpData Specifies the data being set. The size is specified in the call to the <tt>Initialize</tt> function.
533 @return Returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt> if execution succeeds. You must make sure that the implementation of this function in your application does not return any errors.
534 
535 @retval ResultInvalidState Indicates that this function cannot be called in the current <tt>@ref nn::pia::sync::SyncProtocol::State "State"</tt>. Alternatively, it indicates that stations are not communicating. Programming error. Fix your program so that this error is not returned.
536 @retval ResultInvalidArgument Indicates that an argument is invalid. Programming error. Fix your program so that this error is not returned.
537 @retval ResultAlreadyExists Indicates that the data has already been set. Programming error. Fix your program so that this error is not returned.
538 @see NeedSetData, Step
539 
540 
541 
542 */
543  nn::Result SetData(u32 dataId, const void* cpData);
544 
545 
546 /*!
547 @brief Gets the data received during synchronization.
548 @details If the <tt>CanGetData</tt> and <tt>CheckEntry</tt> functions return <tt>true</tt> for a station, it can retrieve data for data IDs that have bits set in the bitmap returned from the <tt>GetUsingDataIdBitmap</tt> function.
549 If you use the feature to change the delay while communication is synchronized, data cannot be retrieved in some frames. The function returns <tt>ResultInvalidState</tt> in these frames.
550 Use the <tt>@ref GetIsNoDataFrame</tt> function to determine whether data can be retrieved in this frame.
551 
552 @param[in] stationId Specifies the <tt>@ref StationId</tt> of the station that is sending the data to retrieve.
553 @param[in] dataId Specifies the data ID of the data to retrieve.
554 @param[out] pBuffer Specifies a pointer to a buffer to store the data. It must be the size specified in the <tt>Initialize</tt> function.
555 @return Returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt> if execution succeeds. You must make sure that the implementation of this function in your application does not return any errors.
556 
557 @retval ResultInvalidState Indicates that this function cannot be called in the current <tt>@ref nn::pia::sync::SyncProtocol::State "State"</tt>. Alternatively, it could indicate that data cannot be retrieved in this frame. Alternatively, it indicates that stations are not communicating. Programming error. Fix your program so that this error is not returned.
558 @retval ResultInvalidArgument Indicates that an argument is invalid. Programming error. Fix your program so that this error is not returned.
559 
560 
561 */
562  nn::Result GetData(StationId stationId, u32 dataId, void* pBuffer) const
563  {
564  return this->GetData(stationId, dataId, pBuffer, 0);
565  }
566 
567 
568 /*!
569 @cond PRIVATE
570 @brief Gets data for a future frame received via synchronized communication.
571 @details If the <tt>CanGetData</tt> and <tt>CheckEntry</tt> functions return <tt>true</tt> for a station, it can retrieve data for data IDs that have bits set in the bitmap returned from the <tt>GetUsingDataIdBitmap</tt> function.
572 You can specify a frame offset. This is the offset from the current frame to the frame for which you want to retrieve synchronization data.
573 If you use the feature to change the delay while communication is synchronized, data cannot be retrieved in some frames. The function returns <tt>ResultInvalidState</tt> in these frames.
574 Use the <tt>@ref GetIsNoDataFrame</tt> function to determine whether data can be retrieved in this frame.
575 The function returns <tt>ResultNoData</tt> if no data has been received for the specified future frame.
576 
577 @param[in] stationId Specifies the <tt>@ref StationId</tt> of the station that is sending the data to retrieve.
578 @param[in] dataId Specifies the data ID of the data to retrieve.
579 @param[out] pBuffer Specifies a pointer to a buffer to store the data. It must be the size specified in the <tt>Initialize</tt> function.
580 @param[in] frameOffset Specifies the offset from the current frame to the frame you want to retrieve synchronization data for.
581 @return Returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt> if execution succeeds.
582 
583 @retval ResultInvalidState Indicates that this function cannot be called in the current <tt>@ref nn::pia::sync::SyncProtocol::State "State"</tt>. Alternatively, it could indicate that data cannot be retrieved in this frame. Or, it indicates that stations are not communicating. Programming error. Fix your program so that this error is not returned.
584 @retval ResultInvalidArgument Indicates that an argument is invalid. Programming error. Fix your program so that this error is not returned.
585 @retval ResultNoData Indicates that there is no data. Handle appropriately in the application.
586 
587 
588 */
589  nn::Result GetData(StationId stationId, u32 dataId, void* pBuffer, u32 frameOffset) const;
590  //! @endcond
591 
592 
593 /*!
594 @brief Gets a pointer to the data received during synchronization.
595 @details If the <tt>CanGetData</tt> and <tt>CheckEntry</tt> functions return <tt>true</tt> for a station, it can retrieve data for data IDs that have bits set in the bitmap returned from the <tt>GetUsingDataIdBitmap</tt> function.
596 The retrieved pointer is valid until the next call to the <tt> Step</tt> function.
597 It has the size specified in the <tt>Initialize</tt> function.
598 
599 @param[in] stationId Specifies the <tt>@ref StationId</tt> of the station that is sending the data to retrieve.
600 @param[in] dataId Specifies the data ID of the data to retrieve.
601 @return Returns a pointer to data received during synchronization.
602 This function returns <tt>NULL</tt> if there is no available data.
603 
604 
605 */
606  const void* GetDataPtr(StationId stationId, u32 dataId) const;
607 
608 
609 /*!
610 @cond PRIVATE
611 @brief Gets the number of frames from the current frame for which the local station has received synchronization data from the specified station.
612 @details The number for the available frames that have received data does not include the current frame.
613 If you specify the ID of the local station in <tt>stationId</tt>, this function returns the value <tt>configured delay - 1</tt>.
614 The function returns zero if the <tt>stationId</tt> value is invalid, or if the <tt>GetUsingDataIdBitmap</tt> function returns zero for that station.
615 
616 @param[in] stationId Specifies the <tt>@ref StationId</tt> of the station that sent the received data.
617 @return Returns the amount of synchronization data for future frames received from the specified station.
618 
619 
620 */
621  u32 GetReceivedDataNum(StationId stationId) const;
622  //! @endcond
623 
624 /*!
625 @cond PRIVATE
626 @brief Gets the number of frames that the local station is ahead from the perspective of the specified station.
627 @details Estimates the number of frames that the local station is ahead from the perspective of the specified station. The function bases its estimate on the number of frames of data received, and the RTT.
628 If the local station is ahead, the function returns a positive value. It returns a negative value if the local station is behind.
629 The actual number of frames that the local station is ahead or behind may be different from this value, for example if some data was not received due to packet loss.
630 Additionally, the numbers of frames ahead estimated by each station do not necessarily match up.
631 @param[in] stationId Specifies the <tt>@ref StationId</tt> of the station with which to compare frame counts.
632 @param[in] frameRate Specifies the frame rate of the application.
633 @return Returns the number of frames that the local station is ahead from the perspective of the specified station.
634 
635 
636 
637 */
638  s32 EstimateLeadingFrameNum(StationId stationId, u32 frameRate) const;
639  //! @endcond
640 
641 /*!
642 @brief Sets a change delay request as synchronization data.
643 @details The requested delay must be no larger than the delay specified at initialization.
644 If you request a delay of zero, the library assumes that you have not requested a change.
645 Even if this function succeeds, the delay is not guaranteed to change to the requested value.
646 If more than one request is received in the same frame, the largest requested delay value gets precedence.
647 If the delay is already being changed in response to a request when another delay-change request arrives as synchronization data, the newly arrived request is ignored.
648 @param[in] newDelay Specifies the requested delay value.
649 @return Returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt> if execution succeeds.
650 @retval ResultInvalidState Indicates that the function was called in an invalid state. Alternatively, it indicates that stations are not communicating. Programming error. Fix your program so that this error is not returned.
651 @retval ResultInvalidArgument Indicates that an argument is invalid. Programming error. Fix your program so that this error is not returned.
652 @retval ResultAlreadyExists Indicates that the data has already been set. Programming error. Fix your program so that this error is not returned.
653 
654 
655 
656 
657 */
658  nn::Result RequestToChangeDelay(u32 newDelay);
659 
660 /*!
661 @brief Gets whether synchronization data cannot be retrieved for this frame.
662 @details If you are using the feature to change the delay while communication is synchronized, use this function to check whether data can be retrieved in the current frame. Data cannot be retrieved for some frames when you use this feature.
663 You are not required to use this function if you are not using the function for changing the delay while communication is synchronized.
664 @param[out] isNoDataFrame Specifies whether synchronization data is available in this frame.
665 @return Returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt> if execution succeeds.
666 @retval ResultInvalidState Indicates that the function was called in an invalid state. Programming error. Fix your program so that this error is not returned.
667 @retval ResultInvalidArgument Indicates that an argument is invalid. Programming error. Fix your program so that this error is not returned.
668 
669 
670 
671 
672 */
673  nn::Result GetIsNoDataFrame(bool* isNoDataFrame) const
674  {
675  return this->GetIsNoDataFrame(isNoDataFrame, 0);
676  }
677 
678 /*!
679 @cond PRIVATE
680 @brief Gets whether synchronization data cannot be retrieved for this frame.
681 @details If you are using the feature to change the delay while communication is synchronized, use this function to check whether data can be retrieved in the current frame. Data cannot be retrieved for some frames when you use this feature.
682 You are not required to use this function if you are not using the function for changing the delay while communication is synchronized.
683 @param[out] isNoDataFrame Specifies whether synchronization data is available in this frame.
684 @param[in] frameOffset Specifies the offset from the current frame.
685 @return Returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt> if execution succeeds.
686 @retval ResultInvalidState Indicates that the function was called in an invalid state. Programming error. Fix your program so that this error is not returned.
687 @retval ResultInvalidArgument Indicates that an argument is invalid. Programming error. Fix your program so that this error is not returned.
688 
689 
690 
691 
692 */
693  nn::Result GetIsNoDataFrame(bool* isNoDataFrame, u32 frameOffset) const;
694  //! @endcond
695 
696 /*!
697 @cond PRIVATE
698 @brief Gets the preconfigured maximum frame offset beyond which synchronization data cannot be retrieved.
699 @details There is a predetermined limit to the number of frames after the current one for which synchronization data can be retrieved. This function returns that value as an offset from the current frame.
700 @return Returns the preconfigured maximum frame offset beyond which synchronization data cannot be retrieved.
701 
702 
703 */
704  u32 GetMaxFrameOffsetDecidedIfNoDataFrameOrNot() const;
705  //! @endcond
706 
707 /*!
708 @brief Calculates the maximum total size of data that can be sent as a single packet of synchronization data, given the specified number of data IDs.
709 @details This function calculates the maximum amount of synchronization data that can be sent. This maximum amount of data is the value to use when you need to send (delay * 2) frames of synchronization data.
710 @param[in] delay Specifies the delay value.
711 @param[in] dataIdNum Specifies the number of data IDs that you are using.
712 @return Returns the maximum total size of data that can be sent as a single packet of synchronization data, given the specified number of data IDs.
713 
714 
715 
716 */
717  size_t CalcMaxSyncDataSizeSentInOnePacket(u32 delay, u32 dataIdNum);
718 
719 
720 /*!
721 @cond PRIVATE
722 @brief Advances to the next frame without setting data to send when a frame is dropped.
723 @details When a frame is dropped, call this function instead of the <tt>SyncProtocol::Step</tt> function. On success, you can advance one frame without setting data to send. The function also decrements by 1 the offset of the frame for which data being sent is set. Execution fails if this function is called in any state other than <tt>STATE_SYNCHRONIZED</tt>. This cannot be used at the same time as the feature for changing the delay during synchronization.
724 @return Returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt> if execution succeeds.
725 On failure, returns the same <tt>Result</tt> value as the <tt>SyncProtocol::Step</tt> function, or <tt>ResultInvalidState</tt>.
726 @retval ResultInvalidState Indicates that the frame offset for the input delay frame count plus the data being sent is less than <tt>1</tt>, or that this function was not called in a <tt>@ref nn::pia::sync::SyncProtocol::State</tt> state. Programming error. Fix your program so that this error is not returned.
727 
728 
729 
730 */
731  nn::Result StepWithoutSetData();
732  //! @endcond
733 
734 
735 /*!
736 @cond PRIVATE
737 @brief Adjusts the frame offset for setting send data.
738 @details Call this after setting the data to send when skipping a frame or when processing slows. On success, increments by 1 the offset of the frame for which to set send data. Execution fails if this function is called in any state other than <tt>STATE_SYNCHRONIZED</tt>. This cannot be used at the same time as the feature for changing the delay during synchronization.
739 @return Returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt> if execution succeeds.
740 @retval ResultInvalidState Indicates that the frame offset for the input delay frame count plus the data being sent is greater than the maximum input frame delay, or that this function was not called in a <tt>@ref nn::pia::sync::SyncProtocol::State</tt> state. Programming error. Fix your program so that this error is not returned.
741 @retval ResultDataIsNotSet Indicates that the local station has not yet set the data to send. Programming error. Fix your program so that this error is not returned.
742 
743 
744 
745 */
746  nn::Result EndSetDataInNoProcessFrame();
747  //! @endcond
748 
749 
750 /*!
751 @cond PRIVATE
752 @brief Indicates the offset of the frame for which to set send data.
753 */
754  s32 GetSetDataOffset()
755  {
756  return m_SetDataOffset;
757  }
758  //! @endcond
759 
760 
761 /*!
762 @cond PRIVATE
763 @brief Specifies whether to use the feature for checking if data is already received and suppressing resends.
764 */
765  void SetIsUsingReceivedDataCheck(bool isUsingReceivedDataCheck);
766  //! @endcond
767 
768 
769 /*!
770 @cond PRIVATE
771 @brief Starts communication.
772 @param[in] myStationIndex The <tt>StationIndex</tt> value of the local station. Specify a value in the range from <tt>STATION_INDEX_1</tt> to <span class="argument">maxConnections</span>.
773 @return Returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt> if execution succeeds.
774 @retval ResultNotInitialized Indicates that the instance is not initialized.
775 @retval ResultInvalidState Indicates that stations are already communicating.
776 @retval ResultInvalidArgument Indicates that an argument is invalid.
777 
778 
779 
780 */
781  virtual nn::Result Startup(StationIndex myStationIndex);
782  //! @endcond
783 
784 
785 /*!
786 @cond PRIVATE
787 @brief Ends communication.
788 */
789  virtual void Cleanup();
790  //! @endcond
791 
792 
793 /*!
794 @cond PRIVATE
795 @brief The main process.
796 @return Returns <tt>nn::ResultSuccess</tt>.
797 
798 */
799  virtual nn::Result Dispatch();
800  //! @endcond
801 
802 
803 /*!
804 @cond PRIVATE
805 @brief Switches the connection status.
806 @param[in] event Specifies the event representing the operation.
807 @return Returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt> if execution succeeds.
808 @retval ResultInvalidState Indicates that the function was called in an invalid state.
809 @retval ResultInvalidArgument Indicates that an argument is invalid.
810 
811 
812 
813 */
814  virtual nn::Result UpdateProtocolEvent(const transport::ProtocolEvent& event);
815  //! @endcond
816 
817 
818 /*!
819 @brief Prints information that is useful for debugging.
820 @param[in] flag Specifies the bitwise OR of trace flags. For more information, see the <tt>@ref TraceFlag</tt> type.
821 
822 */
823  virtual void Trace(u64 flag) const;
824 
825 
826 private:
827  struct StationInfo
828  {
829  public:
830  void Clear();
831 
832  public:
833  bool m_IsConnect;
834  bool m_IsSync;
835 
836  u16 m_SyncId;
837  u32 m_UsingDataIdBitmap;
838 
839  u32 m_PreparedFrameNo;
840  bit32 m_ReceivedDataBitmap;
841 
842  u32 m_LastReceiveStepCount;
843 
844  bool m_IsEndAlone;
845  u32 m_EndFrameNo;
846  bool m_IsEndAloneInCurrentSession;
847  };
848 
849  bool IsInitialized() const
850  {
851  return (m_StationNum > 0);
852  }
853  bool IsInCommunication() const
854  {
855  return (m_LocalStationIndex != STATION_INDEX_INVALID);
856  }
857 
858  void CheckTimeout();
859 
860  void DispatchReceive();
861  void ReceiveStartMessage(StationIndex stationIndex, u16 syncId, u32 usingDataIdBitmap, s32 delay, bit16 connectedStationBitmap);
862  void ReceiveEndMessage(StationIndex stationIndex, u16 syncId);
863  void ReceiveStartEndMessage(StationIndex stationIndex, u16 syncId);
864  void ReceiveEndAloneMessage(StationIndex stationIndex, u16 syncId, u32 endFrameNo);
865  void ReceiveStartAckMessage(StationIndex stationIndex, u16 syncId);
866  void ReceiveEndAckMessage(StationIndex stationIndex, u16 syncId);
867  void ReceiveEndAloneAckMessage(StationIndex stationIndex, u16 syncId);
868  void ReceiveDataMessage(StationIndex stationIndex, u16 syncId, const void* cpMessage, size_t size, bool isCompressedData);
869 
870  void DispatchSend();
871  bool SendCommand(StationIndex stationIndex, int type, u16 syncId = 0);
872  bool SendCommandMulti(u32 destBmp, int type);
873  void SendData();
874  void ResetSendDataFrameNo();
875  bool CreateDataChunk(size_t* pSize, bool forceDisableDataCompression = false);
876 
877  void UpdatePreparedFrameNo();
878  void UpdateReceivedDataBitmap();
879  bool IsAllReceivedData(u32 sendDataFrameNo);
880 
881  u64 MakeSendFrameBitmap(u32 dataFirstSendCount) const;
882  bool IsSendFrameNo(u32 sendDataFrameNo);
883  u32* GetSendProcessCountPtr(u32 frameNo)
884  {
885  return &m_paSendProcessCnt[GetDataBufferIdx(m_LocalStationIndex, frameNo)];
886  }
887 
888  StationInfo* GetStationInfo(StationIndex stationIndex);
889  const StationInfo* GetStationInfo(StationIndex stationIndex) const
890  {
891  return const_cast<SyncProtocol*>(this)->GetStationInfo(stationIndex);
892  }
893 
894  int GetDataBufferIdx(StationIndex stationIndex, u32 frameNo) const;
895 
896  u32* GetValidDataFlag(StationIndex stationIndex, u32 frameNo)
897  {
898  return &m_paValidDataFlag[stationIndex * m_BufferFrameNum + GetDataBufferIdx(stationIndex, frameNo)];
899  }
900  const u32* GetValidDataFlag(StationIndex stationIndex, u32 frameNo) const
901  {
902  return const_cast<SyncProtocol*>(this)->GetValidDataFlag(stationIndex, frameNo);
903  }
904 
905  u32* GetNoDataFrameFlag(u32 frameNo)
906  {
907  return &m_paNoDataFrameFlag[GetDataBufferIdx(m_LocalStationIndex, frameNo)];
908  }
909  const u32* GetNoDataFrameFlag(u32 frameNo) const
910  {
911  return const_cast<SyncProtocol*>(this)->GetNoDataFrameFlag(frameNo);
912  }
913 
914  void* GetDataBuffer(StationIndex stationIndex, u32 frameNo, u32 dataId)
915  {
916  PIA_ASSERT(dataId < DATA_ID_NUM + RESERVED_DATA_ID_NUM);
917  return &m_pDataBuffer[(stationIndex * m_BufferFrameNum + GetDataBufferIdx(stationIndex, frameNo)) * m_TotalDataSize + m_DataInfo[dataId].m_Offset];
918  }
919  const void* GetDataBuffer(StationIndex stationIndex, u32 frameNo, u32 dataId) const
920  {
921  return const_cast<SyncProtocol*>(this)->GetDataBuffer(stationIndex, frameNo, dataId);
922  }
923 
924  // Dynamically change the delay.
925  nn::Result ChangeDelay(u32 newDelay);
926  bool IsUsingChangeDelay() const
927  {
928  return m_DataInfo[RESERVED_DATA_ID_CHANGE_DELAY].m_Size != 0;
929  }
930 
931  bool EndImpl(EndReason reason);
932 
933  void CheckEndedAlone();
934 
935  bit16 CalcConnectedStationBitmap() const;
936 
937  // For the <tt>StationIndex</tt>.
938  bool CheckEntry(StationIndex stationIndex) const;
939  nn::Result GetData(StationIndex stationIndex, u32 dataId, void* pBuffer) const
940  {
941  return this->GetData(stationIndex, dataId, pBuffer, 0);
942  }
943  nn::Result GetData(StationIndex stationIndex, u32 dataId, void* pBuffer, u32 frameOffset) const;
944  bit32 GetUsingDataIdBitmap(StationIndex stationIndex) const;
945 
946 private:
947  u32 m_StationNum;
948  StationIndex m_LocalStationIndex;
949 
950  State m_State;
951 
952 #if NN_PIA_TRANSPORT_V3
953  static const u32 cMessageBufferSize = common::PROTOCOL_MESSGAE_PAYLOAD_SIZE_MAX / sizeof(u32) * sizeof(u32);
954 #else
955  static const u32 cMessageBufferSize = common::ProtocolMessageOld::MESSAGE_SIZE_MAX / sizeof(u32) * sizeof(u32);
956 #endif
957  u32 m_MessageBuffer[cMessageBufferSize / sizeof(u32)];
958  u32* m_pCompressedMessageBuffer;
959 
960  StationInfo* m_paStationInfo;
961  u32* m_paValidDataFlag;
962  u32* m_paNoDataFrameFlag;
963  u8* m_pDataBuffer;
964  s32* m_pDelayBuffer;
965 
966  struct
967  {
968  u32 m_Offset;
969  u32 m_Size;
970  } m_DataInfo[DATA_ID_NUM + RESERVED_DATA_ID_NUM];
971 
972  u32 m_TotalDataSize;
973 
974  s32 m_Delay;
975  s32 m_MaxDelay;
976  s32 m_BufferFrameNum;
977  u32 m_SendPeriod;
978  s32 m_TimeoutFrame;
979 
980  u32 m_CurrentFrameNo;
981  u32 m_PreparedFrameNo;
982  bit32 m_ReceivedDataBitmap; // In the frames after <span class="argument">m_PreparedFrameNo</span> + 1, data has already been received from all stations for this frame.
983  bool m_IsUsingReceivedDataCheck;
984 
985  s32 m_CurrentDataBufferIdx;
986 
987  EndReason m_LastEndReason;
988 
989  u32 m_StepCount;
990  u32 m_StepCountOffset;
991  bool m_IsSendStart;
992  bool m_IsSendEnd;
993  bool m_IsSendEndAlone;
994  u32 m_ParticipantBmp;
995  u32 m_SendStartDestBmp;
996  u32 m_SendEndDestBmp;
997  u32 m_SendEndAloneDestBmp;
998  u32 m_SendDataFrameNo;
999  u32 m_SendDataId;
1000  bool m_IsResetSendData;
1001 
1002  // For dynamically changing the delay.
1003  s32 m_NewDelay;
1004  u32 m_ChangeDelayRequestFrameNo;
1005 
1006  // Offset of the frame for which to set send data.
1007  s32 m_SetDataOffset;
1008 
1009  // Flag for stepping without checking whether data to send has been set.
1010  bool m_IsStepWithoutSetData;
1011 
1012  // To compress and uncompress data:
1013  bool m_IsEnableDataCompression;
1014  u32 m_DataCompressionLevel;
1015  static const u32 cZlibCompressorWindowBits = 12;
1016  static const u32 cZlibCompressorMemLevel = 5;
1017  static const u32 cZlibCompressorWorkMemorySize = 38596;
1018  common::ZlibCompressor* m_pZlibCompressor;
1019  u32* m_paZlibCompressorMemory;
1020  common::ZlibUncompressor* m_pZlibUncompressor;
1021  u32* m_paZlibUncompressorMemory;
1022 
1023  // To skip sending the same data:
1024  u32 m_SendSkipMax;
1025  u32 m_SendSkip;
1026  u32 m_SameDataCount;
1027  u32 m_PreSendFrameNoMin;
1028  u32 m_PreSendFrameNoMax;
1029 
1030  // Determines whether to send synchronization data.
1031  u32* m_paSendProcessCnt; // Buffer for counting the number of times sending all frames was attempted.
1032  u32 m_SendProcessFrameNoMin; // The smallest value of the frame numbers for which a send attempt was made.
1033  u32 m_SendProcessFrameNoMax; // The largest value of the frame numbers for which a send attempt was made.
1034  u32 m_DataFirstSendCount; // The first send count setting for synchronization data.
1035  u64 m_SendFrameBitmap; // Bitmap for send determinations.
1036 
1037  // For <tt>MonitoringData</tt>.
1038  u8 m_MonitoringMinDelay; // The minimum input delay value during game communication.
1039  u8 m_MonitoringMaxDelay; // The maximum input delay value during game communication.
1040  u8 m_MonitoringMinSendPeriod; // The minimum value for the sending frequency.
1041  u8 m_MonitoringMaxSendPeriod; // The maximum value for the sending frequency.
1042  u32 m_MonitoringStepCount; // Number of times <tt>Step</tt> has been called.
1043  u32 m_MonitoringPreSendFrameNoMaxBuf; // For saving the largest frame number sent last time.
1044  u32 m_MonitoringResendCountedFrameNoMax; // The largest frame number counted as a resent frame.
1045  u8 m_MonitoringResendFrameCnt; // For counting the number of frames resent.
1046  u8 m_MonitoringMaxResendFrameNum; // The maximum value of the number of frames resent.
1047 };
1048 }
1049 }
1050 } // end of namespace nn::pia::sync
void Finalize(void)
Finalizes the common module.
Communication ended because no data was received for Setting::m_TimeoutFrame frames.
Definition: sync_SyncProtocol.h:512
StationIndex
Enumerates StationIndex values.
Definition: platformCtr.h:44
Definition of the StationId identifying the station within the session.
Definition: types.h:33
u32 m_TimeoutFrame
Ends synchronization due to a timeout if packets cannot be received consecutively for the specified n...
Definition: sync_SyncProtocol.h:158
Definition: assert.h:115
Synchronization is starting. Although the data to send must be set, it cannot yet be retrieved...
Definition: sync_SyncProtocol.h:407
ID indicating a station that is not present in the session.
Definition: platformCtr.h:59
EndReason
Represents the reason why synchronization was ended.
Definition: sync_SyncProtocol.h:506
Stores settings specified during initialization.
Definition: sync_SyncProtocol.h:128
bool IsInitialized(void)
Indicates whether the common module is initialized.
nn::Result GetIsNoDataFrame(bool *isNoDataFrame) const
Gets whether synchronization data cannot be retrieved for this frame.
Definition: sync_SyncProtocol.h:673
u32 m_MaxDelay
Defines the maximum number of frames of input delay.
Definition: sync_SyncProtocol.h:152
State
Represents the current state of synchronization.
Definition: sync_SyncProtocol.h:403
u32 m_DataCompressionLevel
Sets the compression level for synchronized data.
Definition: sync_SyncProtocol.h:174
This protocol is used for synchronized communication. Full mesh is the only network topology type t...
Definition: sync_SyncProtocol.h:78
nn::Result Initialize(void *pMem, u32 size)
Initializes the common module.
u32 GetSendPeriod() const
Gets the send interval specified to the Start function.
Definition: sync_SyncProtocol.h:261
State GetState() const
Gets the current state of synchronization.
Definition: sync_SyncProtocol.h:419
Protocol base class.
Definition: transport_Protocol.h:44
bool m_IsUsingChangeDelay
Enables or disables use of the change delay feature while communication is synchronized.
Definition: sync_SyncProtocol.h:163
Start synchronization and wait for other stations to start synchronization.
Definition: sync_SyncProtocol.h:406
Communication ended because of a call to the End function by the station.
Definition: sync_SyncProtocol.h:509
Communication ended because there was a change in the stations in the session.
Definition: sync_SyncProtocol.h:511
nn::Result GetData(StationId stationId, u32 dataId, void *pBuffer) const
Gets the data received during synchronization.
Definition: sync_SyncProtocol.h:562
u32 GetTimeoutFrame() const
Gets the timeout setting specified in the Initialize function.
Definition: sync_SyncProtocol.h:250
Synchronization is ending.
Definition: sync_SyncProtocol.h:409
u32 GetMaxDelay() const
Gets the maximum input delay specified to the Initialize function.
Definition: sync_SyncProtocol.h:229
Synchronization is active. The data to send must be set, and it can be retrieved. ...
Definition: sync_SyncProtocol.h:408
u32 GetDelay() const
Gets the input delay actually specified.
Definition: sync_SyncProtocol.h:239
Communication ended because another station ended synchronization.
Definition: sync_SyncProtocol.h:510