refactor: simplifying message queue
This commit is contained in:
@@ -118,9 +118,8 @@ class SPITObject {
|
||||
}
|
||||
};
|
||||
|
||||
void setID(const string &id);
|
||||
bool setConfirmed(bool p_Confirmed);
|
||||
void setCreatedByClient(bool p_CreatedByClient);
|
||||
void setCreatedByClient(bool p_CreatedByClient) { m_CreatedByClient = p_CreatedByClient; }
|
||||
bool setName(string p_Name);
|
||||
bool setRemark(string p_Remark);
|
||||
bool setServerParams(string p_ServerParams);
|
||||
|
||||
@@ -78,7 +78,6 @@ class SPITType {
|
||||
return m_ActionAssigned;
|
||||
}
|
||||
|
||||
void setID(const string &p_ID) { m_ID = p_ID; }
|
||||
bool setGroupName(const string &p_GroupName);
|
||||
bool setName(const string &p_Name);
|
||||
bool setServerRemote(bool p_BelongstoServer);
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -76,6 +76,17 @@ class SPIT_Message {
|
||||
public:
|
||||
Header *getHeader() const { return m_Header.get(); }
|
||||
int getBytesCount() const { return m_BytesCount; }
|
||||
void setServerInfoInHeader(string clientId, string serverId) {
|
||||
if (!m_Header)
|
||||
return;
|
||||
m_Header->setClientID(clientId);
|
||||
m_Header->setServerID(serverId);
|
||||
}
|
||||
void setMessageNumber(uint8_t no) {
|
||||
if (!m_Header)
|
||||
return;
|
||||
m_Header->setMessageNumber(no);
|
||||
}
|
||||
|
||||
const string getServerID() const {
|
||||
if (!m_Header) {
|
||||
@@ -131,7 +142,6 @@ class SPIT_Message {
|
||||
|
||||
// Members
|
||||
private:
|
||||
std::vector<char> m_MessageBytes{};
|
||||
unique_ptr<OPPart> m_OPPart{};
|
||||
|
||||
// Receive
|
||||
@@ -148,13 +158,11 @@ class SPIT_Message {
|
||||
const OPPart *getOPPart() const { return m_OPPart.get(); }
|
||||
|
||||
private:
|
||||
bool parse();
|
||||
bool parse(std::vector<char> message);
|
||||
|
||||
// Send
|
||||
public:
|
||||
SPIT_Message(unique_ptr<OPPart> p_OPPart);
|
||||
bool fillBytes();
|
||||
const std::vector<char> *getMessageBytes();
|
||||
static std::vector<char> createMessage(OPPart & p_OPPart);
|
||||
|
||||
//------------------------------ Connection ----------------------------------
|
||||
|
||||
@@ -387,15 +395,15 @@ class SPIT_Message {
|
||||
static constexpr int BYTESLENGTH = 168;
|
||||
|
||||
private:
|
||||
bool m_Confirmed {};
|
||||
string m_SPITTypeID {};
|
||||
bool m_Fixed {};
|
||||
bool m_ServerRemote {};
|
||||
bool m_ServerProjectIndepended {};
|
||||
string m_SPITTypeGroupName {};
|
||||
string m_SPITTypeName {};
|
||||
long long m_Delay {};
|
||||
long long m_Duration {};
|
||||
bool m_Confirmed{};
|
||||
string m_SPITTypeID{};
|
||||
bool m_Fixed{};
|
||||
bool m_ServerRemote{};
|
||||
bool m_ServerProjectIndepended{};
|
||||
string m_SPITTypeGroupName{};
|
||||
string m_SPITTypeName{};
|
||||
long long m_Delay{};
|
||||
long long m_Duration{};
|
||||
|
||||
public:
|
||||
ReportSPITType(const ReportSPITType &orig);
|
||||
@@ -528,7 +536,6 @@ class SPIT_Message {
|
||||
void setDuration(long long p_Duration);
|
||||
void setActionAssigned(bool p_ActionAssigned) { m_ActionAssigned = p_ActionAssigned; }
|
||||
bool fillBytes(std::vector<char> &message);
|
||||
|
||||
};
|
||||
|
||||
//----------- RemoveSPITObject -----------
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
template <typename T>
|
||||
class SpitRepo {
|
||||
public:
|
||||
bool hasEntry(const string &id) {
|
||||
return mEntries.contains(id);
|
||||
}
|
||||
|
||||
T *getEntry(const string &id) {
|
||||
auto i = mEntries.find(id);
|
||||
if (i == mEntries.end()) {
|
||||
|
||||
Reference in New Issue
Block a user