refactor: simplifying message queue
This commit is contained in:
@@ -33,10 +33,10 @@ class SPIT_Client : I_SAD_Client {
|
||||
static const int MAXSPITMESSAGEBYTECOUNT = 512;
|
||||
|
||||
enum class ProjUpdate {
|
||||
ServerLoaded,
|
||||
StartTransfer,
|
||||
EndTransfer,
|
||||
ServerClosed,
|
||||
ServerLoaded,
|
||||
StartTransfer,
|
||||
EndTransfer,
|
||||
ServerClosed,
|
||||
};
|
||||
enum class ServerEvent {
|
||||
Detect,
|
||||
@@ -48,10 +48,17 @@ class SPIT_Client : I_SAD_Client {
|
||||
Changed,
|
||||
Deleted
|
||||
};
|
||||
enum class Connection {
|
||||
None = 0, // No Connection established.<br>Either no connect tried or disconnected
|
||||
NoneServer = 1, // Server has disconnected
|
||||
Lost = 2, // The connection is lost<br>Either because of a network crash or because the server no longer responds.
|
||||
Ok = 3, // Connection to the serv er is established.
|
||||
TryConnection = 4, // A connection to the server is tried.
|
||||
};
|
||||
|
||||
struct Callbacks {
|
||||
void (*onServerEvent)(ServerEvent event, const SAD_DetectedServer &p_DetectedServer){};
|
||||
void (*onConnectionStatus)(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime, int p_ConnectionStatus, int p_OldConnectionStatus){};
|
||||
void (*onConnectionStatus)(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime, Connection p_ConnectionStatus, Connection p_OldConnectionStatus){};
|
||||
void (*onProjectUpdate)(ProjUpdate state, string projectId){};
|
||||
void (*onSpitType)(ObjectEvent event, bool isRemote, const SPITType &p_SPITType){};
|
||||
void (*onSpitObject)(ObjectEvent event, bool isRemote, const SPITType &p_SPITType, const SPITObject &p_SPITObject){};
|
||||
@@ -63,19 +70,6 @@ class SPIT_Client : I_SAD_Client {
|
||||
bool (*onCheckSpitObjectVeto)(SPIT_Message::ReportSPITObject *p_ReportSPITObject){};
|
||||
};
|
||||
|
||||
//----- Connection Status -----
|
||||
public:
|
||||
/** No Connection established.<br>Either no connect tried or disconnected*/
|
||||
static constexpr int CONNECTION_NONE = 0;
|
||||
/** Server has disconnected*/
|
||||
static constexpr int CONNECTION_NONESERVER = 1;
|
||||
/** The connection is lost<br>Either because of a network crash or because the server no longer responds.*/
|
||||
static constexpr int CONNECTION_LOST = 2;
|
||||
/** Connection to the serv er is established.*/
|
||||
static constexpr int CONNECTION_OK = 3;
|
||||
/** A connection to the server is tried.*/
|
||||
static constexpr int CONNECTION_TRYCONNECTION = 4;
|
||||
|
||||
//------ PlayerType ------
|
||||
public:
|
||||
/** continous main player, time value can be used like a timecode.<br>The time value is the position in server's project.<br>A server should use only one main player.*/
|
||||
@@ -107,7 +101,7 @@ class SPIT_Client : I_SAD_Client {
|
||||
fos::TaskT<SPIT_Client &> *m_ThreadReceive{};
|
||||
bool m_StopReceiveSPITMessages{};
|
||||
|
||||
int m_ConnectionStatus;
|
||||
Connection m_ConnectionStatus{Connection::None};
|
||||
bool m_DisconnectedByServer{}; // flag true = when server disconnects
|
||||
string m_ID;
|
||||
string m_Name;
|
||||
@@ -116,8 +110,8 @@ class SPIT_Client : I_SAD_Client {
|
||||
|
||||
string m_ClientProjectName;
|
||||
|
||||
unsigned char m_MessageNumber_Send;
|
||||
int m_MessageNumber_Received;
|
||||
uint8_t m_MessageNumber_Send{1};
|
||||
int m_MessageNumber_Received{-1}; // set to -1 because the first received message will set the number (1..255)
|
||||
vector<unique_ptr<SPIT_Message>> m_OvertakingSPIT_Messages;
|
||||
|
||||
// Server's info filled by parseConnectAnswer
|
||||
@@ -179,8 +173,7 @@ class SPIT_Client : I_SAD_Client {
|
||||
// Reconnect to the server when connection is lost see eventConnectionStatus and eventServerDetected
|
||||
bool _doReconnect{}; // true = on eventServerDetected connect to the server identified by m_ServerID
|
||||
public:
|
||||
void fillHeader(SPIT_Message::Header *p_Header);
|
||||
int sendSPITMessage(unique_ptr<SPIT_Message::OPPart> spitMessageOPPart);
|
||||
int sendSPITMessage(SPIT_Message::OPPart & spitMessageOPPart);
|
||||
|
||||
//--------------- ServerAutoDetection SAD ---------------
|
||||
public:
|
||||
@@ -214,7 +207,7 @@ class SPIT_Client : I_SAD_Client {
|
||||
void disconnect();
|
||||
|
||||
private:
|
||||
void disconnectInternal(int p_Cause);
|
||||
void disconnectInternal(Connection p_Cause);
|
||||
void resetMessageNumberReceived();
|
||||
void parseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage);
|
||||
void checkParseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage);
|
||||
@@ -339,7 +332,7 @@ class SPIT_Client : I_SAD_Client {
|
||||
private:
|
||||
static void processSocketTask(SPIT_Client &instance);
|
||||
fos::TaskT<SPIT_Client &> *sThread{};
|
||||
bool abortSearch{};
|
||||
bool mAbortSearch{};
|
||||
bool sAnswered{};
|
||||
static fos::Semaphore sStartSad;
|
||||
SPITSocket *mSPITSocket;
|
||||
@@ -351,7 +344,6 @@ class SPIT_Client : I_SAD_Client {
|
||||
SpitRepo<SPITObject> mRemoteSpitObjects;
|
||||
SpitRepo<SPITType> mSpitTypes;
|
||||
SpitRepo<SPITType> mRemoteSpitTypes;
|
||||
|
||||
};
|
||||
|
||||
#endif /* SPIT_CLIENT_H */
|
||||
|
||||
Reference in New Issue
Block a user