17 #include <pia/transport/transport_definitions.h> 19 #include <pia/transport/transport_Protocol.h> 20 #include <pia/common/common_Time.h> 29 class ProtocolMessageWriter;
30 class ProtocolMessageReader;
63 PIA_PROTOCOL_TYPE_INFO(PROTOCOL_TYPE_RELIABLE_BROADCAST);
118 virtual nn::Result Startup(
StationIndex myStationIndex);
126 virtual void Cleanup();
136 virtual nn::Result Dispatch();
151 virtual nn::Result UpdateProtocolEvent(
const transport::ProtocolEvent& event);
161 MODE_INVALID = 0x00000000,
162 MODE_WAIT = 0x01000000,
163 MODE_SEND = 0x02000000,
164 MODE_RECEIVE = 0x03000000
175 CONDITION_WAIT = 0x00010000,
176 CONDITION_IN_PROGRESS = 0x00020000,
177 CONDITION_SUCCESS = 0x00030000,
178 CONDITION_FAILURE = 0x00040000
190 return static_cast<Mode
>(m_State & 0xFF000000);
200 Condition GetCondition()
const 202 return static_cast<Condition
>(m_State & 0x00FF0000);
213 STATE_INVALID = MODE_INVALID | CONDITION_WAIT,
214 STATE_WAIT = MODE_WAIT | CONDITION_WAIT,
215 STATE_SENDING = MODE_SEND | CONDITION_IN_PROGRESS,
216 STATE_SEND_SUCCESS = MODE_SEND | CONDITION_SUCCESS,
217 STATE_SEND_FAILURE = MODE_SEND | CONDITION_FAILURE,
218 STATE_RECEIVING = MODE_RECEIVE | CONDITION_IN_PROGRESS,
219 STATE_RECEIVE_SUCCESS = MODE_RECEIVE | CONDITION_SUCCESS,
220 STATE_RECEIVE_FAILURE = MODE_RECEIVE | CONDITION_FAILURE,
224 STATE_SEND_CANCELING = STATE_SENDING | 0x1,
225 STATE_SEND_REJECTING = STATE_SENDING | 0x2,
226 STATE_SEND_ABANDONING = STATE_SENDING | 0x3,
227 STATE_SEND_COMPLETING = STATE_SENDING | 0x4,
228 STATE_SEND_CANCELED = STATE_SEND_FAILURE | 0x1,
229 STATE_SEND_REJECTED = STATE_SEND_FAILURE | 0x2,
230 STATE_SEND_ABANDONED = STATE_SEND_FAILURE | 0x3,
231 STATE_RECEIVE_READY = STATE_RECEIVING | 0x1,
232 STATE_RECEIVE_CANCELING = STATE_RECEIVING | 0x2,
233 STATE_RECEIVE_CANCELED_BEFORE_START = STATE_RECEIVE_FAILURE | 0x1,
234 STATE_RECEIVE_CANCELED = STATE_RECEIVE_FAILURE | 0x2,
235 STATE_RECEIVE_INTERRUPTED = STATE_RECEIVE_FAILURE | 0x3,
236 STATE_RECEIVE_MISMATCH = STATE_RECEIVE_FAILURE | 0x4
247 return static_cast<State>(m_State & 0xFFFF0000);
261 return (GetCondition() == CONDITION_IN_PROGRESS);
279 : m_Value(CURRENT_CONNECTION_SYNC.m_Value)
313 return IsFlagOn(FLAG_SEND_TO_NEWCOMER);
324 return IsFlagOn(FLAG_SYNCRONIZE_COMPLETION);
341 return IsFlagOn(FLAG_SEND_ENDLESS);
352 return IsFlagOn(FLAG_FAIL_IF_REJECTED);
371 return IsFlagOn(FLAG_MEDIATE_REQUEST);
385 SetFlag(FLAG_SEND_TO_NEWCOMER, isOn);
398 SetFlag(FLAG_SYNCRONIZE_COMPLETION, isOn);
411 SetFlag(FLAG_SEND_ENDLESS, isOn);
424 SetFlag(FLAG_FAIL_IF_REJECTED, isOn);
437 SetFlag(FLAG_MEDIATE_REQUEST, isOn);
500 FLAG_SEND_TO_NEWCOMER = 1 << 0,
501 FLAG_SYNCRONIZE_COMPLETION = 1 << 1,
502 FLAG_SEND_ENDLESS = 1 << 2,
503 FLAG_FAIL_IF_REJECTED = 1 << 3,
504 FLAG_MEDIATE_REQUEST = 1 << 4
507 bool IsFlagOn(Flag flag)
const 509 return ((m_Value & flag) == flag);
511 void SetFlag(Flag flag,
bool isOn)
580 size_t GetProgress()
const;
624 nn::Result StartSend(
const void* cpData,
size_t dataSize,
Configuration configuration, u32 userData = 0);
637 nn::Result FinishSendEndless();
666 nn::Result StartReceive(
void* pBuffer,
size_t bufferSize,
StationId sourceStationId);
673 nn::Result StartReceive(
void* pBuffer,
size_t bufferSize,
StationIndex sourceStationIndex);
761 nn::Result RejectRequest();
816 m_ThroughputLimit = throughputLimit;
829 return m_ThroughputLimit;
838 virtual void Trace(u64 flag)
const;
842 static const u16 cInvalidMessageIdx = 0xffff;
848 u32 GetCount()
const;
849 bool IsOn(u32 idx)
const;
850 bool IsAllOff()
const;
851 bool IsComplete()
const 853 return m_FirstOffIdx >= m_UnitNum;
857 static const u32 cFlagBlockNum = 4;
860 u32 m_Flag[cFlagBlockNum];
864 class ReceiverProgress :
public Progress
867 void Clear(u32 unitNum);
869 void Get(u32* pOffset, u64* pFlag)
const;
873 class SenderProgress :
public Progress
876 void Clear(u32 unitNum);
877 bool Update(u32 offset, u64 flag);
878 bool IsReceivable(u32 offset)
const;
879 void UpdateMessageIdx(u32 unitIdx, u16 messageIdx);
880 u32 GetFirstOffIdx()
const 882 return m_FirstOffIdx;
884 u32 GetUnitNum()
const 888 u16 GetSendMessageIdx(u32 unitIdx)
const;
891 static const u32 cDataSize = cFlagBlockNum * 32;
893 u16 m_SendMessageIdx[cDataSize];
906 eMTCommandAck = 0x28,
912 class MessageAccessor
919 bool IsSenderMessage()
const 921 return (m_Type & 0xf0) == 0x10;
923 bool IsReceiverMessage()
const 925 return (m_Type & 0xf0) == 0x20;
927 bool IsDataMessage()
const 929 return m_Type == eMTData;
932 u32 GetMessageSize()
const;
933 static bool Unpack(MessageAccessor* pAccessor,
const ProtocolMessageReader& reader, u32* pMessageIdx);
934 static bool Pack(ProtocolMessageWriter* pWriter,
const MessageAccessor& accessor, u32 messageIdx);
946 const void* m_cpPayload;
960 return (m_DataSize > 0);
1000 void HandleMessage(
const MessageAccessor& accessor);
1003 void ForceReserveReject()
1005 m_ReservedAckFlag |= eRAFReject;
1010 void ClearReceiverState()
1012 m_ReceiverState = eRSNothing;
1014 void StartReceive(u16 receiveId, u32 unitNum);
1016 bool IsConnected()
const 1022 return MyStationIndex();
1024 SenderState GetSenderState()
const 1026 return m_SenderState;
1028 ReceiverState GetReceiverState()
const 1030 return m_ReceiverState;
1032 const InnerTransferSetting& GetRequest()
const 1036 const SenderProgress* GetProgress()
const 1041 u16 GetReturnedMessageIdx()
const 1043 return m_ReturnedMessageIdx;
1045 u16 GetReceivedMessageIdx()
const 1047 return m_ReceivedMessageIdx;
1050 void HandleMessageIdx(u32 messageIdx);
1052 u32 GetNextSendUnitIndex(
bool isOnlyPrior, u32 dispatchCount)
const;
1054 bool IsNeedSendRequest()
const 1056 return (GetReceiverState() == eRSReceiving) && m_IsNeedSendRequest;
1059 void RecordSendData(u32 dispatchCount, u16 unitIdx, u16 messageIdx);
1062 void UpdateRequest(
const MessageAccessor& accessor);
1063 bool CheckRequest(
const MessageAccessor& accessor)
const;
1067 return m_Request.m_SourceStationIndex;
1071 return m_Request.m_SourceStationIndex;
1073 u16& SenderSequenceId()
1075 return m_Request.m_Id;
1077 u16 SenderSequenceId()
const 1079 return m_Request.m_Id;
1085 InnerTransferSetting m_Request;
1086 SenderState m_SenderState;
1088 enum ReservedAckFlag
1096 u32 m_ReservedAckFlag;
1098 SenderProgress m_Progress;
1100 ReceiverState m_ReceiverState;
1102 u16 m_ReturnedMessageIdx;
1103 u16 m_ReceivedMessageIdx;
1105 bool m_IsNeedSendRequest;
1107 u32 m_LastSentDataDispatchCount;
1113 return (stationId >=
STATION_INDEX_1) && (stationId < static_cast<StationIndex>(m_MaxConnections)) && (stationId != m_LocalStationIndex);
1119 PIA_ASSERT(IsValidStation(stationId));
1120 return &m_paStation[stationId < m_LocalStationIndex ? stationId : stationId - 1];
1124 const Station* GetStation(
StationIndex stationId)
const 1126 PIA_ASSERT(IsValidStation(stationId));
1127 return &m_paStation[stationId < m_LocalStationIndex ? stationId : stationId - 1];
1130 static u32 CalcProgress(
const InnerTransferSetting& transferSetting,
const Progress& progress);
1133 bool DispatchSendAck();
1134 bool DispatchSendCommand();
1135 bool DispatchSendData();
1136 void DispatchOnReceiveCanceling();
1138 void PushRequest(
const MessageAccessor& accessor,
const Station& sender);
1139 bool PushData(
const MessageAccessor& accessor,
const Station& sender);
1140 void PushComplete(
const MessageAccessor& accessor,
const Station& sender);
1141 void PushCancel(
const MessageAccessor& accessor,
const Station& sender);
1143 bool CreateMessage(
const MessageAccessor& accessor, Station* pDestinationStation);
1144 u32 IssueMessageIdx(
const Station* cpDestStation);
1146 static bool IsSameSetting(
const InnerTransferSetting& setting,
const MessageAccessor& accessor);
1149 u32 m_MaxConnections;
1154 InnerTransferSetting m_TransferSetting;
1156 void* m_pReceiveBuffer;
1157 ReceiverProgress m_ReceiveProgress;
1159 const void* m_cpSendBuffer;
1161 u32 m_NextSendCommandStationIndex;
1162 u32 m_NextSendDataStationIndex;
1163 bool m_IsFinishSendEndless;
1165 u32 m_NextSendAckStationIndex;
1167 u16 m_SentMessageIdx;
1169 u32 m_ThroughputLimit;
1170 u32 m_RestThroughputLimit;
1172 u32 m_DispatchCount;
1174 Station* m_paStation;
1178 static const u32 cDefaultPacketNumPerDispatch;
Configuration()
Instantiates the object with default parameters (default constructor). Initialized with the same valu...
Definition: transport_ReliableBroadcastProtocol.h:278
bool IsRunning() const
Gets whether asynchronous send and receive operations are currently executing.
Definition: transport_ReliableBroadcastProtocol.h:259
u32 GetThroughputLimit() const
Gets the maximum amount of data that this protocol can send per call to the common::Scheduler::Dispat...
Definition: transport_ReliableBroadcastProtocol.h:827
Stores data transfer settings.
Definition: transport_ReliableBroadcastProtocol.h:530
Represents methods used to transfer data.
Definition: transport_ReliableBroadcastProtocol.h:271
Class that represents time.
Definition: common_Time.h:39
StationIndex
Enumerates StationIndex values.
Definition: platformCtr.h:44
Definition of the StationId identifying the station within the session.
Definition: types.h:33
ID indicating Player 1.
Definition: platformCtr.h:46
bool IsFailIfRejected() const
Gets the setting for determining whether a send operation had failed or been abandoned when the recei...
Definition: transport_ReliableBroadcastProtocol.h:350
bool IsSynchronizeCompletion() const
Gets the setting that controls whether to synchronize the completion of receive operations.
Definition: transport_ReliableBroadcastProtocol.h:322
ID indicating a station that is not present in the session.
Definition: platformCtr.h:59
virtual void Trace(u64 flag) const
Prints information that is useful for debugging.
void Finalize(void)
Initializes the transport module. This function does nothing and returns if it is called before the I...
void SetThroughputLimit(u32 throughputLimit)
Sets the maximum amount of data that this protocol sends per call to the common::Scheduler::Dispatch ...
Definition: transport_ReliableBroadcastProtocol.h:814
Configuration m_Configuration
Specifies the method used to transfer data.
Definition: transport_ReliableBroadcastProtocol.h:535
Represents a protocol for sending a large volume of data to all stations.
Definition: transport_ReliableBroadcastProtocol.h:60
bool IsMediateRequest() const
Gets the setting for determining whether a send operation automatically fails on one station if two s...
Definition: transport_ReliableBroadcastProtocol.h:369
static const Configuration CURRENT_CONNECTION_SYNC
Represents the configuration for synchronized transfer of data to currently connected stations...
Definition: transport_ReliableBroadcastProtocol.h:452
State GetState() const
Gets the current operational state.
Definition: transport_ReliableBroadcastProtocol.h:245
static const Configuration SHARE_DATA_ASYNC
Represents the configuration for continuing to send data to stations that may join the session in add...
Definition: transport_ReliableBroadcastProtocol.h:494
Protocol base class.
Definition: transport_Protocol.h:44
void SetSendToNewcomer(bool isOn)
Sets whether to also send data to stations that join the session after the send operation begins...
Definition: transport_ReliableBroadcastProtocol.h:383
static const Configuration CURRENT_CONNECTION_ASYNC
Represents the configuration for asynchronously sending data to currently connected stations...
Definition: transport_ReliableBroadcastProtocol.h:465
bool IsSendEndless() const
Gets the setting for determining whether to maintain a state of STATE_SENDING even after data has bee...
Definition: transport_ReliableBroadcastProtocol.h:339
void SetSynchronizeCompletion(bool isOn)
Sets whether to synchronize completion of receive operations.
Definition: transport_ReliableBroadcastProtocol.h:396
StationIndex m_SourceStationIndex
The sender's StationIndex value.
Definition: transport_ReliableBroadcastProtocol.h:532
State
Enumerates the operational states.
Definition: transport_ReliableBroadcastProtocol.h:211
void SetSendEndless(bool isOn)
Sets whether the instance maintains a state of STATE_SENDING even after data has been successfully se...
Definition: transport_ReliableBroadcastProtocol.h:409
u32 m_UserData
Specifies the user information set by the sender.
Definition: transport_ReliableBroadcastProtocol.h:534
static const Configuration SHARE_DATA_SYNC
Represents the configuration for sending data to any stations that may join the session, in addition to currently connected stations, and waits for all stations to finish receiving data.
Definition: transport_ReliableBroadcastProtocol.h:480
nn::Result Initialize(void)
Initializes the transport module.
u32 m_DataSize
Specifies the size (in bytes) of the data being transferred.
Definition: transport_ReliableBroadcastProtocol.h:533
void SetFailIfRejected(bool isOn)
Sets whether to treat a send operation as a send failure and suspend sending data when a receiving st...
Definition: transport_ReliableBroadcastProtocol.h:422
bool IsSendToNewcomer() const
Gets whether to also send data to stations that join the session after the send operation begins...
Definition: transport_ReliableBroadcastProtocol.h:311
void SetMediateRequest(bool isOn)
Sets whether a send operation automatically fails on one station when two stations try to send data t...
Definition: transport_ReliableBroadcastProtocol.h:435