feat: Migrating features from newer implementation
This commit is contained in:
@@ -20,7 +20,7 @@ public:
|
||||
* @param p_Addition sometimes server may have additional informations
|
||||
* @param p_IsIP4 the server ip is a ip4 address
|
||||
*/
|
||||
virtual void eventServerDetected(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_CLientIP, bool p_IsIP4) = 0;
|
||||
virtual void eventServerDetected(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ProjectName, string p_ClientIP, bool p_IsIP4) = 0;
|
||||
/**
|
||||
* If a SPITServer is not more found, this function is called.
|
||||
* To do so the SAD_Client ServerAutoDetect has to be startet - see SAD_Client::startServerAutoDetect.<br>
|
||||
@@ -32,5 +32,6 @@ public:
|
||||
* @param p_Addition sometimes server may have additional informations
|
||||
* @param p_IsIP4 the server ip is a ip4 address
|
||||
*/
|
||||
virtual void eventServerLost(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_CLientIP, bool p_IsIP4) = 0;
|
||||
virtual void eventServerLost(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ProjectName, string p_ClientIP, bool p_IsIP4) = 0;
|
||||
virtual void eventServerChanged(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ProjectName, string p_ClientIP, bool p_IsIP4) = 0;
|
||||
};
|
||||
|
||||
@@ -43,12 +43,8 @@ class MyApp {
|
||||
// All times are given in frames,
|
||||
|
||||
public:
|
||||
//----- ServerAutoDetection -----
|
||||
static void onServerDetected(const SAD_DetectedServer &p_DetectedServer); // a SPITServer is detected
|
||||
static void onServerLost(const SAD_DetectedServer &p_DetectedServer); // a prior detected SPITServer is lost
|
||||
|
||||
//----- Connection -----
|
||||
void eventConnectionStatus(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime, int p_ConnectionStatus, int p_OldConnectionStatus);
|
||||
static void onServerEvent(SPIT_Client::ServerEvent event, const SAD_DetectedServer &p_DetectedServer);
|
||||
static void onConnectionStatus(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime, int p_ConnectionStatus, int p_OldConnectionStatus);
|
||||
|
||||
//----- Project -----
|
||||
static void onStartProjectTransfer();
|
||||
@@ -57,12 +53,14 @@ class MyApp {
|
||||
static void onProjectClosed(string p_ProjectID);
|
||||
|
||||
//----- SPITType -----
|
||||
static bool onCheckSpitTypeVeto(SPIT_Message::ReportSPITType* p_ReportSPITType);
|
||||
static void onSpitType(bool p_New, const SPITType &p_SPITType);
|
||||
static void onSpitTypeRemote(bool p_New, const SPITType &p_SPITType);
|
||||
static void onSpitTypeRemoved(const SPITType &p_SPITType);
|
||||
static void onSpitTypeRemoteRemoved(const SPITType &p_SPITType);
|
||||
|
||||
//----- SPITObject -----
|
||||
static bool onCheckSpitObjectVeto(SPIT_Message::ReportSPITObject* p_ReportSPITObject);
|
||||
static void onSpitObject(bool p_New, const SPITType &p_SPITType, const SPITObject &p_SPITObject);
|
||||
static void onSpitObjectRemote(bool p_New, const SPITType &p_SPITType, const SPITObject &p_SPITObject);
|
||||
static void onSpitObjectRemoved(const SPITType &p_SPITType, const SPITObject &p_SPITObject);
|
||||
@@ -70,7 +68,7 @@ class MyApp {
|
||||
|
||||
//----- Play SPITObjects -----
|
||||
static void onPlay(string p_PlayerID, string p_PlayerName, char p_PlayerType, bool p_PlayerIsRunning, long long p_TimeFrames);
|
||||
static void onPlayObject(string p_PlayerID, bool p_Started, bool p_Stopped, const SPITType &p_SPITType, const SPITObject &p_SPITObject, const SPITPlayer::PlayObject &p_PlayObject);
|
||||
static void onPlaySpitType(string p_PlayerID, string p_SPITTypeID, bool p_PlayerIsRunning, bool p_Started, bool p_Ended, double p_Value);
|
||||
|
||||
//----- Server changes status of one of his REMOTE SPITObjects -----
|
||||
// REMOTE only Server->Client RemoteObject's play status
|
||||
|
||||
@@ -32,6 +32,7 @@ public:
|
||||
string m_ClientIP;
|
||||
string m_Port;
|
||||
string m_Additions;
|
||||
string m_ServerProjectName;
|
||||
bool m_New;
|
||||
bool m_Changed;
|
||||
bool m_FoundAgain;
|
||||
@@ -45,6 +46,7 @@ public:
|
||||
string getPort() const { return m_Port; }
|
||||
string getClientIP() const { return m_ClientIP; }
|
||||
string getAdditions() const { return m_Additions; }
|
||||
string getProjectName() const {return m_ServerProjectName;}
|
||||
private:
|
||||
void setID(string p_ID) { m_ID = p_ID; }
|
||||
void setName(string p_Name) { m_Name = p_Name; }
|
||||
@@ -53,6 +55,7 @@ private:
|
||||
void setClientIP(string p_IP) { m_ClientIP = p_IP; }
|
||||
void setPort(string p_Port) { m_Port = p_Port; }
|
||||
void setAdditions(string p_Additions) { m_Additions = p_Additions;}
|
||||
void setProjectName(string p_ServerProjectName);
|
||||
|
||||
void setIPIsIP4(bool p_IsIP4) { m_IPIsIP4 = p_IsIP4; }
|
||||
bool getNew() const { return m_New; }
|
||||
@@ -67,6 +70,7 @@ private:
|
||||
m_IPIsIP4 = false;
|
||||
m_Changed = false;
|
||||
m_FoundAgain = false;
|
||||
m_New = false;
|
||||
}
|
||||
//SAD_Client m_Thread_Send has paused in the meantime m_ThreadReceive may received messages from servers
|
||||
void endCycleSAD() { }
|
||||
@@ -81,7 +85,8 @@ public:
|
||||
static const int PARAMINDEX_PORT = 5;
|
||||
static const int PARAMINDEX_CLIENTIP = 6;
|
||||
static const int PARAMINDEX_ADDITIONS = 7;
|
||||
static const int PARAMINDEX_IP = 8;
|
||||
static const int PARAMINDEX_SERVERPROJECTNAME = 8;
|
||||
static const int PARAMINDEX_IP = 9;
|
||||
/**
|
||||
* Used by SAD_Client to add a found SPITServer - don't use this manually
|
||||
* @param p_IsIP4 true = the server is reached via a IP4 address<br>false = the server is reahed via a IP6 address
|
||||
|
||||
@@ -33,21 +33,26 @@ public:
|
||||
static const SPITObject& getSPITObjectRef(string p_ID);
|
||||
static bool addSPITObject(SPITObject* p_ptrSpitObject);
|
||||
static bool removeSPITObject(SPITObject* p_ptrSpitObject);
|
||||
static bool removeSPITObject(string p_SpitObjectID);
|
||||
static int getSPITObjectCount();
|
||||
static SPITObject* getSPITObject(int p_Index);
|
||||
static const SPITObject& getSPITObjectRef(int p_Index);
|
||||
static void clearSPITObjects();
|
||||
static void clearUnconfirmedSPITObjects();
|
||||
static void setConfirmedFalse();
|
||||
|
||||
static SPITObject* getSPITObjectRemote(string p_ID);
|
||||
static const SPITObject& getSPITObjectRemoteRef(string p_ID);
|
||||
static bool addSPITObjectRemote(SPITObject* p_ptrSpitObject);
|
||||
static bool removeSPITObjectRemote(SPITObject* p_ptrSpitObject);
|
||||
static bool removeSPITObjectRemote(string p_SpitObjectID);
|
||||
static int getSPITObjectRemoteCount();
|
||||
static SPITObject* getSPITObjectRemote(int p_Index);
|
||||
static const SPITObject& getSPITObjectRemoteRef(int p_Index);
|
||||
static void clearSPITObjectsRemote();
|
||||
|
||||
static void eventProjectClosed();
|
||||
|
||||
SPITObject();
|
||||
// SPITObject(const SPITObject& orig);
|
||||
~SPITObject();
|
||||
@@ -59,6 +64,7 @@ private:
|
||||
string m_Remark;
|
||||
bool m_Confirmed;
|
||||
bool m_Fixed;
|
||||
bool m_CreatedByClient;
|
||||
bool m_ServerRemote;
|
||||
bool m_ActionAssigned;
|
||||
bool m_ActionAssignedType; //Virtual construct
|
||||
@@ -80,90 +86,68 @@ private:
|
||||
|
||||
void initMembers();
|
||||
public:
|
||||
string getID() const {
|
||||
return m_ID;
|
||||
}
|
||||
string getName() const {
|
||||
return m_Name;
|
||||
}
|
||||
string getRemark() const {
|
||||
return m_Remark;
|
||||
}
|
||||
string getSPITTypeID() const {
|
||||
return m_SPITTypeID;
|
||||
}
|
||||
string getServerParams() const {
|
||||
return m_ServerParams;
|
||||
}
|
||||
string getID() const { return m_ID; }
|
||||
string getName() const { return m_Name; }
|
||||
string getRemark() const { return m_Remark; }
|
||||
string getSPITTypeID() const { return m_SPITTypeID; }
|
||||
string getServerParams() const { return m_ServerParams; }
|
||||
|
||||
/**
|
||||
* Returns if the SPITType triggers an action on the Server or on the client.
|
||||
* @return false = the action is triggered on the client The client waits for the server to play objects of this SPITType<br>
|
||||
* true = the action is triggered on the server. The server waits for the client to play objects of this SPITType.
|
||||
*/
|
||||
bool getServerRemote() const {
|
||||
return m_ServerRemote;
|
||||
}
|
||||
bool getServerRemote() const { return m_ServerRemote; }
|
||||
|
||||
/**
|
||||
* This is used by the server and client to tell if the other side has registered the changes.
|
||||
* @return true = other side has registered the changes.
|
||||
*/
|
||||
bool getConfirmed() const {
|
||||
return m_Confirmed;
|
||||
}
|
||||
bool getFixed() const {
|
||||
return m_Fixed;
|
||||
}
|
||||
bool getConfirmed() const { return m_Confirmed; }
|
||||
bool getFixed() const { return m_Fixed; }
|
||||
bool getCreatedByClient() { return m_CreatedByClient; }
|
||||
/**
|
||||
* This is a virtual construct - ActionAssignedType is not implemented in the SPITProtocol.<br>
|
||||
* This is used when an action is associated with a SPITType. <br>
|
||||
* Then this action is done for every SPITObject with the SPITType.
|
||||
* @return true = an action is assigned for the SPITType.
|
||||
*/
|
||||
bool getActionAssignedType() const {
|
||||
return m_ActionAssignedType;
|
||||
}
|
||||
bool getActionAssignedType() const { return m_ActionAssignedType; }
|
||||
/** Returns if this SPITObject has an associated action or not.<br>
|
||||
* @return true = the user has asscociated an action with this SPITObject or <br>
|
||||
* the user has asscociated an action with the SPITType of this SPITObject
|
||||
*/
|
||||
bool getActionAssigned() const {
|
||||
return m_ActionAssigned || m_ActionAssignedType;
|
||||
}
|
||||
bool getActionAssigned() const { return m_ActionAssigned || m_ActionAssignedType; }
|
||||
|
||||
long long getFrameStart() const {
|
||||
return m_FrameStart;
|
||||
}
|
||||
long long getFrameLength() const {
|
||||
return m_FrameLength;
|
||||
}
|
||||
long long getFrameFadeInLength() const {
|
||||
return m_FrameFadeInLength;
|
||||
}
|
||||
long long getFrameFadeOutLength() const {
|
||||
return m_FrameFadeOutLength;
|
||||
}
|
||||
char getValueUse() const {
|
||||
return m_ValueUse;
|
||||
}
|
||||
int getValueFactor() const {
|
||||
return m_ValueFactor;
|
||||
}
|
||||
int getTrack() const {
|
||||
return m_Track;
|
||||
}
|
||||
long long getFrameStart() const { return m_FrameStart; }
|
||||
// contains the length of the SPITObject
|
||||
long long getFrameLength() const { return m_FrameLength; }
|
||||
long long getFrameFadeInLength() const { return m_FrameFadeInLength; }
|
||||
long long getFrameFadeOutLength() const { return m_FrameFadeOutLength; }
|
||||
char getValueUse() const { return m_ValueUse; }
|
||||
int getValueFactor() const { return m_ValueFactor; }
|
||||
int getTrack() const { return m_Track; }
|
||||
|
||||
long long getDelay() const {
|
||||
return m_Delay;
|
||||
}
|
||||
long long getDuration() const {
|
||||
return m_Duration;
|
||||
}
|
||||
long long getDelay() const { return m_Delay; }
|
||||
long long getDuration() const { return m_Duration; }
|
||||
|
||||
bool getProjectIndepended() const {
|
||||
SPITType* ptrSPITType;
|
||||
if (m_ServerRemote == false) {
|
||||
ptrSPITType = SPITType::getSPITType(m_SPITTypeID);
|
||||
if (ptrSPITType == NULL) return true;
|
||||
return ptrSPITType->getProjectIndepended();
|
||||
}
|
||||
else {
|
||||
ptrSPITType = SPITType::getSPITTypeRemote(m_SPITTypeID);
|
||||
if (ptrSPITType == NULL) return true;
|
||||
return ptrSPITType->getProjectIndepended();
|
||||
}
|
||||
};
|
||||
|
||||
void setID(string p_ID);
|
||||
bool setConfirmed(bool p_Confirmed);
|
||||
void setCreatedByClient(bool p_CreatedByClient);
|
||||
bool setName(string p_Name);
|
||||
bool setRemark(string p_Remark);
|
||||
bool setServerParams(string p_ServerParams);
|
||||
@@ -182,7 +166,7 @@ public:
|
||||
bool setDelay(long long p_Delay);
|
||||
bool setDuration(long long p_Duration);
|
||||
|
||||
void setMessageOP(SPIT_Message::ReportSPITObject* p_ReportSPITObject);
|
||||
bool setMessageOP(SPIT_Message::ReportSPITObject* p_ReportSPITObject);
|
||||
void fillMessageOP(SPIT_Message::ReportSPITObject* p_ReportSPITObject);
|
||||
void fillMessageOP(SPIT_Message::RemoveSPITObject* p_RemoveSPITObject);
|
||||
};
|
||||
|
||||
@@ -21,102 +21,39 @@ class SPITPlayer {
|
||||
|
||||
//----- PlayObject used in PlaySequences: PlaySPITStart, PlaySPITObject,..., PlaySPITEnd ------
|
||||
public:
|
||||
class PlayObject {
|
||||
class PlaySPITType {
|
||||
public:
|
||||
PlayObject();
|
||||
PlayObject(SPITPlayer* p_SPITPlayer, string p_SPITObjectID);
|
||||
PlayObject(const PlayObject& orig);
|
||||
PlaySPITType();
|
||||
PlaySPITType(SPITPlayer* p_SPITPlayer, string p_SPITObjectID);
|
||||
PlaySPITType(const PlaySPITType& orig);
|
||||
|
||||
string getSPITObjectID() const {
|
||||
return m_SPITObjectID;
|
||||
string getSPITTypeID() const {
|
||||
return m_SPITTypeID;
|
||||
}
|
||||
|
||||
void startPlaySequence();
|
||||
bool getIsNew() const {
|
||||
return m_IsNew;
|
||||
}
|
||||
void setIsNew(bool p_IsNew) {
|
||||
m_IsNew = p_IsNew;
|
||||
}
|
||||
bool getIsPlayed() const {
|
||||
return m_IsPlayed;
|
||||
}
|
||||
void setIsPlayed(bool p_IsFound) {
|
||||
m_IsPlayed = p_IsFound;
|
||||
}
|
||||
|
||||
|
||||
string getPlayerID() const {
|
||||
return m_PlayerID;
|
||||
}
|
||||
string getPlayerName() const {
|
||||
return m_PlayerName;
|
||||
}
|
||||
bool getPlayerIsRunning() const {
|
||||
return m_PlayerRuns;
|
||||
}
|
||||
void setPlayerIsRunning(bool p_PlayerRuns) {
|
||||
m_PlayerRuns = p_PlayerRuns;
|
||||
}
|
||||
|
||||
void setValue(int p_Value, bool p_PlayPrePosition) {
|
||||
if (p_PlayPrePosition) m_ValuePrePosition = p_Value;
|
||||
else m_Value = p_Value;
|
||||
}
|
||||
|
||||
int getValue() const {
|
||||
return m_ValuePrePosition + m_Value;
|
||||
}
|
||||
int getValueFadePrePosition() const {
|
||||
return m_ValuePrePosition;
|
||||
}
|
||||
int getValueFade() const {
|
||||
return m_Value;
|
||||
}
|
||||
void setValueFactor(int p_ValueFactor) {
|
||||
m_ValueFactor = p_ValueFactor;
|
||||
}
|
||||
void setValueFlag(char p_ValueFlag) {
|
||||
m_ValueFlag = p_ValueFlag;
|
||||
}
|
||||
int getValueFactor() const {
|
||||
return m_ValueFactor;
|
||||
}
|
||||
char getValueFlag() const {
|
||||
return m_ValueFlag;
|
||||
}
|
||||
void setFrameInside(long long p_FrameInside, bool p_PlayPrePosition) {
|
||||
if (p_PlayPrePosition) m_FrameInsidePrePosition = p_FrameInside;
|
||||
else m_FrameInside = p_FrameInside;
|
||||
}
|
||||
long long getFrameInside() const {
|
||||
return m_FrameInside;
|
||||
}
|
||||
long long getFrameInsidePrePosition() const {
|
||||
return m_FrameInsidePrePosition;
|
||||
}
|
||||
|
||||
bool getIsNew() const { return m_IsNew; }
|
||||
void setIsNew(bool p_IsNew) { m_IsNew = p_IsNew; }
|
||||
bool getIsPlayed() const { return m_IsPlayed; }
|
||||
void setIsPlayed(bool p_IsFound) { m_IsPlayed = p_IsFound; }
|
||||
string getPlayerID() const { return m_PlayerID; }
|
||||
string getPlayerName() const { return m_PlayerName; }
|
||||
bool getPlayerIsRunning() const { return m_PlayerRuns; }
|
||||
void setPlayerIsRunning(bool p_PlayerRuns) { m_PlayerRuns = p_PlayerRuns; }
|
||||
void setValue(double p_Value) { m_Value = p_Value; }
|
||||
void addValue(double p_Value, double p_ValueFactor) { m_Value += (p_Value * p_ValueFactor); }
|
||||
double getValue() const { return m_Value; }
|
||||
|
||||
private:
|
||||
string m_PlayerID;
|
||||
string m_PlayerName;
|
||||
bool m_PlayerRuns;
|
||||
string m_SPITObjectID;
|
||||
string m_SPITTypeID;
|
||||
bool m_IsPlayed;
|
||||
bool m_IsNew;
|
||||
|
||||
int m_Value;
|
||||
int m_ValuePrePosition;
|
||||
int m_ValueFactor;
|
||||
char m_ValueFlag;
|
||||
long long m_FrameInsidePrePosition;
|
||||
long long m_FrameInside;
|
||||
|
||||
|
||||
double m_Value;
|
||||
};
|
||||
|
||||
|
||||
|
||||
//----- SPITPlayer ------
|
||||
public:
|
||||
//list the SPITPlayers
|
||||
@@ -124,46 +61,33 @@ public:
|
||||
static SPITPlayer* getSPITPlayer(string p_PlayerID); //if a player does not exist creates a new one
|
||||
static void clearPlayers();
|
||||
|
||||
|
||||
|
||||
SPITPlayer(string p_PlayerID);
|
||||
virtual ~SPITPlayer();
|
||||
|
||||
|
||||
void startPlaySequence(); //called by SPIT_Client::parsePlaySPITStart
|
||||
PlayObject* addSPITObject_Playing (string p_SPITObjectID); //called by SPIT_Client::parsePlaySPITStart
|
||||
PlaySPITType* addSPITType_Playing (string p_SPITTypeID); //called by SPIT_Client::parsePlaySPITStart
|
||||
void endPlaySequence(); //called by SPIT_Client::parsePlaySPITEnd
|
||||
|
||||
string getID() {
|
||||
return m_ID;
|
||||
}
|
||||
|
||||
unordered_map<string, PlayObject*>* getPlayObjects();
|
||||
|
||||
unordered_map<string, PlaySPITType*>* getPlaySPITTypes();
|
||||
void setIsRunning(bool p_IsRunning);
|
||||
bool getIsRunning() {
|
||||
return m_IsRunning;
|
||||
}
|
||||
bool getIsRunning() { return m_IsRunning; }
|
||||
void setName(string p_Name);
|
||||
string getName() {
|
||||
return m_Name;
|
||||
}
|
||||
string getName() { return m_Name; }
|
||||
void setType(char p_Type);
|
||||
char getType() {
|
||||
return m_Type;
|
||||
}
|
||||
char getType() { return m_Type; }
|
||||
void setTime(long long p_Frames);
|
||||
long long getTime() {
|
||||
return m_TimeFrames;
|
||||
}
|
||||
|
||||
PlayObject* getPlayObject(string p_SPITObjectID);
|
||||
long long getTime() { return m_TimeFrames; }
|
||||
|
||||
private:
|
||||
string m_ID;
|
||||
string m_Name;
|
||||
char m_Type;
|
||||
unordered_map<string, PlayObject*> m_PlayObjects;
|
||||
unordered_map<string, PlaySPITType*> m_PlaySPITTypes;
|
||||
bool m_IsRunning;
|
||||
long long m_TimeFrames;
|
||||
};
|
||||
|
||||
@@ -145,7 +145,7 @@ public:
|
||||
|
||||
int receiveMessage(int p_InetFamily, char* p_Buffer, int p_BufferLength, string* p_ServerIP);
|
||||
int setBroadcast(bool p_Broadcast);
|
||||
int bindSocket(string p_ClientIP, string p_ClientPort);
|
||||
int bindSocket(string p_ServerIP, string p_ClientIP, string p_ClientPort);
|
||||
|
||||
// * Internal usage - don't use this manually
|
||||
// * Use sendMessage instead
|
||||
|
||||
@@ -48,6 +48,7 @@ public:
|
||||
static const SPITType& getSPITTypeRemoteRef(int p_Index);
|
||||
static void clearSPITTypesRemote();
|
||||
|
||||
static void eventProjectClosed();
|
||||
|
||||
SPITType();
|
||||
SPITType(string p_ID, string p_GroupName, string p_Name, bool p_Fixed, bool p_ProjectIndepended,long long p_DefaultDelay, long long p_DefaultDuration);
|
||||
@@ -138,6 +139,4 @@ public:
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* SPITTYPE_H */
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "SPITObject.h"
|
||||
#include "SPITPlayer.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -30,9 +31,15 @@ public:
|
||||
/** Maximal length of a SPITMessage*/
|
||||
static const int MAXSPITMESSAGEBYTECOUNT = 512;
|
||||
|
||||
enum ServerEvent {
|
||||
Detect,
|
||||
Lost,
|
||||
Changed,
|
||||
};
|
||||
|
||||
struct Callbacks {
|
||||
void(*onServerDetect)(const SAD_DetectedServer &p_DetectedServer);
|
||||
void(*onServerLost)(const SAD_DetectedServer &p_DetectedServer);
|
||||
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(*onStartProjectTransfer)();
|
||||
void(*onEndProjectTransfer)();
|
||||
void(*onProjectClosed)(string);
|
||||
@@ -46,8 +53,10 @@ public:
|
||||
void(*onSpitObjectRemoved)(const SPITType &p_SPITType, const SPITObject &p_SPITObject);
|
||||
void(*onSpitObjectRemoteRemoved)(const SPITType &p_SPITType, const SPITObject &p_SPITObject);
|
||||
void(*onPlay)(string p_PlayerID, string p_PlayerName, char p_PlayerType, bool p_PlayerIsRunning, long long p_TimeFrames);
|
||||
void(*onPlayObject)(string p_PlayerID, bool p_Started, bool p_Stopped, const SPITType &p_SPITType, const SPITObject &p_SPITObject, const SPITPlayer::PlayObject &p_PlayObject);
|
||||
void(*onPlaySpitType)(string p_PlayerID, string p_SPITTypeID, bool p_PlayerIsRunning, bool p_Started, bool p_Ended, double p_Value);
|
||||
void(*onPlayRemoteObjectStatus)(const SPITType &p_SPITType, const SPITObject &p_SPITObject, long long p_FrameInsideObject, int p_Value);
|
||||
bool(*onCheckSpitTypeVeto)(SPIT_Message::ReportSPITType* p_ReportSPITType);
|
||||
bool(*onCheckSpitObjectVeto)(SPIT_Message::ReportSPITObject* p_ReportSPITObject);
|
||||
};
|
||||
|
||||
//----- Connection Status -----
|
||||
@@ -86,6 +95,7 @@ public:
|
||||
public:
|
||||
SPIT_Client(string name, string projName, Callbacks calls);
|
||||
virtual ~SPIT_Client();
|
||||
static int s_MAX_OVERTAKING_SPIT_MESSAGES;
|
||||
private:
|
||||
Callbacks mCallbacks;
|
||||
|
||||
@@ -99,15 +109,18 @@ private:
|
||||
string m_ProjName;
|
||||
string m_ComputerName;
|
||||
|
||||
string m_ClientProjectName;
|
||||
|
||||
unsigned char m_MessageNumber_Send;
|
||||
int m_MessageNumber_Received;
|
||||
vector<SPIT_Message*> m_OvertakingSPIT_Messages;
|
||||
|
||||
//Server's info filled by parseConnectAnswer
|
||||
string m_ServerID{};
|
||||
string m_ServerName{};
|
||||
string m_ServerComputerName{};
|
||||
int m_ServerStepTime{-1};
|
||||
|
||||
unsigned char m_MessageNumber_Send;
|
||||
int m_MessageNumber_Received;
|
||||
|
||||
//--- Server Project ---
|
||||
string m_ServerProjectID;
|
||||
string m_ServerProjectName;
|
||||
@@ -115,25 +128,28 @@ private:
|
||||
|
||||
public:
|
||||
/** The ID of the client.<br>Every client instance should set an unique id*/
|
||||
string getID();
|
||||
string getID() { return m_ID; }
|
||||
/** The name of the client, should be set by the user app*/
|
||||
string getName();
|
||||
string getName() { return m_Name; }
|
||||
//----- Computer Params -----
|
||||
/** The name of the client's host computer*/
|
||||
string getComputerName();
|
||||
string getComputerName() { return m_ComputerName; }
|
||||
void setClientProjectName(string p_ClientProjectName) { m_ClientProjectName = p_ClientProjectName; }
|
||||
string getClientProjectName() { return m_ClientProjectName; }
|
||||
|
||||
//connected Server Infos
|
||||
/** The ID of the connected SPITServer*/
|
||||
string getServerID();
|
||||
string getServerID() { return m_ServerID; }
|
||||
/** The host computername of the connected SPITServer*/
|
||||
string getServerComputerName();
|
||||
string getServerComputerName() { return m_ServerComputerName; }
|
||||
/** The name of the connected SPITServer*/
|
||||
string getServerName();
|
||||
string getServerName() { return m_ServerName; }
|
||||
|
||||
/** Expected Refreah Rate of the connectd SPITServer.<br>
|
||||
* When the server plays objects, it will do so at discrete time steps.<br>
|
||||
* Play events will take place in these time steps..
|
||||
*/
|
||||
int getServerStepTime();
|
||||
int getServerStepTime() { return m_ServerStepTime; }
|
||||
|
||||
/** Should be called when the client wants to close his project*/
|
||||
void clientProjectClose();
|
||||
@@ -155,11 +171,11 @@ private:
|
||||
bool startReceiveSPITMessages();
|
||||
void stopReceiveSPITMessages();
|
||||
static void receiveSPITMessage(SPIT_Client& rM);
|
||||
int sendSPITMessage(SPIT_Message::OPPart& p_SPITMessageOPPart);
|
||||
void fillHeader(SPIT_Message::Header* p_Header);
|
||||
|
||||
// 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(SPIT_Message::OPPart& p_SPITMessageOPPart);
|
||||
|
||||
//--------------- ServerAutoDetection SAD ---------------
|
||||
public:
|
||||
@@ -168,10 +184,10 @@ public:
|
||||
/** Stops the autodetection of SPITServers in the local network*/
|
||||
void stopServerAutoDetect();
|
||||
/** Called every time a new SPITServer is detetced in the local network */
|
||||
void eventServerDetected(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ClientIP, bool p_IsIP4);
|
||||
void eventServerDetected(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ProjectName, string p_ClientIP, bool p_IsIP4);
|
||||
/** Called every time a prior detected SPITServer is is no longer found.*/
|
||||
void eventServerLost(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ClientIP, bool p_IsIP4);
|
||||
|
||||
void eventServerLost(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ProjectName, string p_ClientIP, bool p_IsIP4);
|
||||
void eventServerChanged(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ProjectName, string p_ClientIP, bool p_IsIP4);
|
||||
|
||||
//--------------- Connection ---------------
|
||||
public:
|
||||
@@ -194,7 +210,10 @@ public:
|
||||
|
||||
private:
|
||||
void disconnectInternal(int p_Cause);
|
||||
void resetMessageNumberReceived();
|
||||
void parseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage);
|
||||
void checkParseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage);
|
||||
void addOvertakingSPIT_Message(SPIT_Message* p_SPIT_Message);
|
||||
void parseConnectAnswer(SPIT_Message::ConnectAnswer* p_ConnectAnswer);
|
||||
void parseDisconnect(SPIT_Message::Disconnect* p_Disconnect);
|
||||
void parseWatchdog(SPIT_Message::Watchdog* p_Watchdog);
|
||||
@@ -220,7 +239,8 @@ private:
|
||||
void parseRequestProjectTransfer(SPIT_Message::RequestProjectTransfer* p_RequestProjectTransfer);
|
||||
void parseStartProjectTransfer(SPIT_Message::StartProjectTransfer* p_StartProjectTransfer);
|
||||
void parseEndProjectTransfer(SPIT_Message::EndProjectTransfer* p_EndProjectTransfer);
|
||||
|
||||
public:
|
||||
static void sendProject(SPIT_Client* p_PtrSPIT_Client);
|
||||
|
||||
// --------------- SPIT Types ---------------
|
||||
public:
|
||||
|
||||
@@ -12,8 +12,8 @@ MyApp::MyApp() :
|
||||
_SpitClient (
|
||||
s_ClientName, s_ProjectName,
|
||||
{
|
||||
.onServerDetect = onServerDetected,
|
||||
.onServerLost = onServerLost,
|
||||
.onServerEvent = onServerEvent,
|
||||
.onConnectionStatus = onConnectionStatus,
|
||||
.onStartProjectTransfer = onStartProjectTransfer,
|
||||
.onEndProjectTransfer = onEndProjectTransfer,
|
||||
.onProjectClosed = onProjectClosed,
|
||||
@@ -27,10 +27,11 @@ MyApp::MyApp() :
|
||||
.onSpitObjectRemoved = onSpitObjectRemoved,
|
||||
.onSpitObjectRemoteRemoved = onSpitObjectRemoteRemoved,
|
||||
.onPlay = onPlay,
|
||||
.onPlayObject = onPlayObject,
|
||||
.onPlaySpitType = onPlaySpitType,
|
||||
.onPlayRemoteObjectStatus = onPlayRemoteObjectStatus,
|
||||
.onCheckSpitTypeVeto = onCheckSpitTypeVeto,
|
||||
.onCheckSpitObjectVeto = onCheckSpitObjectVeto,
|
||||
}) {
|
||||
|
||||
}
|
||||
|
||||
string MyApp::m_ServerProjectID{};
|
||||
@@ -38,10 +39,8 @@ string MyApp::m_ServerProjectName{};
|
||||
int MyApp::m_ServerFramesPerSecond{44100}; // set when the server reports his project, see eventProjectReport
|
||||
|
||||
void MyApp::init() {
|
||||
SPITType *ptrSPITType1Fix;
|
||||
ptrSPITType1Fix = _SpitClient.createSPITTypeFixed("MySPITAPP_Action1ID", "ActionGroupName", "Action1Name", 0, 0);
|
||||
SPITType *ptrSPITType2Fix;
|
||||
ptrSPITType2Fix = _SpitClient.createSPITTypeFixed("MySPITAPP_Action2ID", "ActionGroupName", "Action2Name", 0, 0);
|
||||
SPITType *ptrSPITType1Fix = _SpitClient.createSPITTypeFixed("MySPITAPP_Action1ID", "ActionGroupName", "Action1Name", 0, 0);
|
||||
SPITType *ptrSPITType2Fix = _SpitClient.createSPITTypeFixed("MySPITAPP_Action2ID", "ActionGroupName", "Action2Name", 0, 0);
|
||||
|
||||
// When an action exist which should be done whenever a SPITObject with this SPITType is played,
|
||||
// then you should 'setAssignedActionType' to true
|
||||
@@ -51,24 +50,37 @@ void MyApp::init() {
|
||||
_SpitClient.startServerAutoDetect();
|
||||
}
|
||||
|
||||
void MyApp::onServerDetected(const SAD_DetectedServer &p_DetectedServer) {
|
||||
void MyApp::onServerEvent(SPIT_Client::ServerEvent event, const SAD_DetectedServer &p_DetectedServer) {
|
||||
switch (event)
|
||||
{
|
||||
case SPIT_Client::ServerEvent::Detect:
|
||||
ESP_LOGI(TAG, "SERVER DETECTED");
|
||||
ESP_LOGD(TAG, " Name: %s", p_DetectedServer.getName().data());
|
||||
ESP_LOGD(TAG, " ID: %s", p_DetectedServer.getID().data());
|
||||
ESP_LOGD(TAG, " Computer: %s", p_DetectedServer.getComputerName().data());
|
||||
ESP_LOGD(TAG, " IP: %s", p_DetectedServer.getIP().data());
|
||||
ESP_LOGD(TAG, " Port: %s", p_DetectedServer.getPort().data());
|
||||
ESP_LOGD(TAG, " Addition: %s", p_DetectedServer.getAdditions().data());
|
||||
ESP_LOGD(TAG, " ClientIP: %s", p_DetectedServer.getClientIP().data());
|
||||
}
|
||||
void MyApp::onServerLost(const SAD_DetectedServer &p_DetectedServer) {
|
||||
ESP_LOGI(TAG, " Name: %s", p_DetectedServer.getName().data());
|
||||
ESP_LOGI(TAG, " ID: %s", p_DetectedServer.getID().data());
|
||||
ESP_LOGI(TAG, " Computer: %s", p_DetectedServer.getComputerName().data());
|
||||
ESP_LOGI(TAG, " IP: %s", p_DetectedServer.getIP().data());
|
||||
ESP_LOGI(TAG, " Port: %s", p_DetectedServer.getPort().data());
|
||||
ESP_LOGI(TAG, " Addition: %s", p_DetectedServer.getAdditions().data());
|
||||
ESP_LOGI(TAG, " ClientIP: %s", p_DetectedServer.getClientIP().data());
|
||||
break;
|
||||
case SPIT_Client::ServerEvent::Lost:
|
||||
ESP_LOGW(TAG, "Server lost Name: %s IP: %s", p_DetectedServer.getName().data(), p_DetectedServer.getIP().data());
|
||||
|
||||
break;
|
||||
case SPIT_Client::ServerEvent::Changed:
|
||||
ESP_LOGW(TAG, "Server lost Name: %s IP: %s", p_DetectedServer.getName().data(), p_DetectedServer.getIP().data());
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------
|
||||
//---------- Connecting event ----------
|
||||
|
||||
void MyApp::eventConnectionStatus(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime, int p_ConnectionStatus, int p_OldConnectionStatus) {
|
||||
void MyApp::onConnectionStatus(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime, int p_ConnectionStatus, int p_OldConnectionStatus) {
|
||||
ESP_LOGI(TAG, "MySPITApp: eventConnectionStatus %d ", p_ConnectionStatus);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------
|
||||
@@ -117,6 +129,41 @@ void MyApp::onEndProjectTransfer() {
|
||||
//----------------------------------------------------
|
||||
//--------- SPITType events ----------
|
||||
|
||||
|
||||
/**
|
||||
* The SPITCLientInterface (implemented by this) will be asked to veto the SPITType while SPIT_Client.parseReportSPITType.<br>
|
||||
* @param p_ReportSPITType
|
||||
* @return false = the SPITType is denied, true = the SPITType is accepted
|
||||
*/
|
||||
bool MyApp::onCheckSpitTypeVeto(SPIT_Message::ReportSPITType* p_ReportSPITType) {
|
||||
if (p_ReportSPITType == NULL) return true;
|
||||
SPITType* ptrSPITType;
|
||||
ptrSPITType = SPITType::getSPITType(p_ReportSPITType->getID());
|
||||
|
||||
//Don't allow foreign SPITTypes
|
||||
if (ptrSPITType == NULL) return false;
|
||||
if (ptrSPITType->getCreatedByClient() == false) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MyApp::onCheckSpitObjectVeto(SPIT_Message::ReportSPITObject* p_ReportSPITObject) {
|
||||
if (p_ReportSPITObject == NULL) return true;
|
||||
SPITType* ptrSPITType;
|
||||
ptrSPITType = SPITType::getSPITType(p_ReportSPITObject->getSPITTypeID());
|
||||
if (ptrSPITType == NULL) return false;
|
||||
|
||||
//Don't allow SPITObjects which refers to a SPITType which is not created by this client - other SPITTypes cannot be handled here
|
||||
//if (ptrSPITType->getCreatedByClient() == false) return false;
|
||||
|
||||
// SPITObject* ptrSPITObject;
|
||||
// ptrSPITObject = SPITObject::getSPITObject(p_ReportSPITOnject->getID());
|
||||
//Don't allow foreign SPITTypes
|
||||
// if (ptrSPITObject == NULL) return false;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the server has created, loaded or changed a SPITType.
|
||||
* May also occur when the server confirms a SPITType created or changed by the client.
|
||||
@@ -336,45 +383,29 @@ void MyApp::onPlay(string p_PlayerID, string p_PlayerName, char p_PlayerType, bo
|
||||
* whether the player is running or not
|
||||
* the actual value of the SPITObject (in liveSHOWsoftware objects ma faded in or out or the main value is decreased, ..
|
||||
*/
|
||||
void MyApp::onPlayObject(string p_PlayerID, bool p_Started, bool p_Ended, const SPITType &p_SPITType, const SPITObject &p_SPITObject, const SPITPlayer::PlayObject &p_PlayObject) {
|
||||
// p_PlayObject.getValue() contain the value in ppm (we can calculate value between 0.0 and 1.0)
|
||||
// p_SPITObject.getValueFactor() or redundand p_PlayObject.getValueFactor()
|
||||
// contains the factor the above value should be multiplicated to get the end value.
|
||||
double doubleValue = ((double)p_PlayObject.getValue() / 1000000) * ((double)p_PlayObject.getValueFactor() / 1000000);
|
||||
void MyApp::onPlaySpitType(string p_PlayerID, string p_SPITTypeID, bool p_PlayerIsRunning, bool p_Started, bool p_Ended, double p_Value) {
|
||||
// double doubleValue = ((double)p_PlayObject.getValue() / 1000000) * ((double)p_PlayObject.getValueFactor() / 1000000);
|
||||
|
||||
// Other factors besides value may be of interest
|
||||
// p_PlayObject.getFrameInside() contains the play position inside the SPITObject
|
||||
// p_SPITObject.getFrameLength() contains the length of the SPITObject
|
||||
//-> we can calculate the position 0.0 to 1.0 where the Object is played
|
||||
ESP_LOGD(TAG, "eventPlayObject Player: %s is running: %d Object Started: %d Stopped: %d", p_PlayerID.data(), p_PlayerIsRunning, p_Started, p_Ended);
|
||||
// ESP_LOGD(TAG, " SPITType: %s SPITObject: %s Position: %lld Value: %f\n", p_SPITTypeID.data(), p_SPITObject.getName().data(), p_PlayObject.getFrameInside(), doubleValue);
|
||||
ESP_LOGD(TAG, " SPITType: %s Value: %f\n", p_SPITTypeID.data(), p_Value);
|
||||
|
||||
// in liveSHOWsoftware the player may play two different position in the SPITObject to mix them down, e.g. a SceneBridge is played
|
||||
// We can get the second (pre played) position: p_PlayObject.getFrameInsidePrePosition();
|
||||
|
||||
ESP_LOGD(TAG, "eventPlayObject Player: %s is running: %d Object Started: %d Stopped: %d", p_PlayObject.getPlayerName().data(), p_PlayObject.getPlayerIsRunning(), p_Started, p_Ended);
|
||||
ESP_LOGD(TAG, " SPITType: %s SPITObject: %s Position: %lld Value: %f\n", p_SPITType.getName().data(), p_SPITObject.getName().data(), p_PlayObject.getFrameInside(), doubleValue);
|
||||
|
||||
// check for your actions to do
|
||||
|
||||
// In our little excample decribed in loadClientProject:
|
||||
// We want to react to SPIT types, no matter which SPIT object is currently being played.
|
||||
//-> check not the SPITObject itself but the associated SPITType
|
||||
bool boolPLayerIsRunning = p_PlayObject.getPlayerIsRunning();
|
||||
if (p_SPITType.getID() == "MySPITAPP_Action1ID") { // do Action 1
|
||||
if (p_SPITTypeID == "MySPITAPP_Action1ID") { // do Action 1
|
||||
// we can get some information about the play status
|
||||
if (p_Started == true) {
|
||||
ESP_LOGI(TAG, "MyApp AKTION 1 started Value: %f and running: %d", doubleValue, boolPLayerIsRunning);
|
||||
ESP_LOGI(TAG, "MyApp AKTION 1 started Value: %f and running: %d", p_Value, p_PlayerIsRunning);
|
||||
} else if (p_Ended == true) {
|
||||
ESP_LOGI(TAG, "MyApp AKTION 1 ended"); // p_PlayObject.getFrameInside() is -1
|
||||
} else {
|
||||
ESP_LOGD(TAG, "MyApp AKTION 1 is played Value: %f and running: %d", doubleValue, boolPLayerIsRunning);
|
||||
ESP_LOGD(TAG, "MyApp AKTION 1 is played Value: %f and running: %d", p_Value, p_PlayerIsRunning);
|
||||
}
|
||||
} else if (p_SPITType.getID() == "MySPITAPP_Action2ID") { // do Action 2
|
||||
} else if (p_SPITTypeID == "MySPITAPP_Action2ID") { // do Action 2
|
||||
if (p_Started == true) {
|
||||
ESP_LOGI(TAG, "AKTION 2 started Value: %f and running: %d", doubleValue, boolPLayerIsRunning);
|
||||
ESP_LOGI(TAG, "AKTION 2 started Value: %f and running: %d", p_Value, p_PlayerIsRunning);
|
||||
} else if (p_Ended == true) {
|
||||
ESP_LOGI(TAG, "AKTION 2 ended"); // p_PlayObject.getFrameInside() is -1
|
||||
} else {
|
||||
ESP_LOGD(TAG, "AKTION 2 is played Value: %f and running: %d", doubleValue, boolPLayerIsRunning);
|
||||
ESP_LOGD(TAG, "AKTION 2 is played Value: %f and running: %d", p_Value, p_PlayerIsRunning);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,14 +32,24 @@ SAD_DetectedServer::SAD_DetectedServer() {
|
||||
m_IPIsIP4 = false;
|
||||
}
|
||||
|
||||
void SAD_DetectedServer::setProjectName(string p_ServerProjectName) {
|
||||
if (m_ServerProjectName.compare(p_ServerProjectName) != 0) {
|
||||
if (m_New == false) {
|
||||
m_Changed = true;
|
||||
}
|
||||
}
|
||||
m_ServerProjectName = p_ServerProjectName;
|
||||
}
|
||||
|
||||
void SAD_DetectedServer::cycleStart() {
|
||||
for (auto i = s_DetectedServers.begin(); i != s_DetectedServers.end(); i++) {
|
||||
i->second->startCycleSAD();
|
||||
}
|
||||
}
|
||||
void SAD_DetectedServer::cycleEnd(I_SAD_Client& sADClientInterface) {
|
||||
void SAD_DetectedServer::cycleEnd(I_SAD_Client& sadClient) {
|
||||
list<SAD_DetectedServer*> o_LostServers;
|
||||
list<SAD_DetectedServer*> o_NewServers;
|
||||
list<SAD_DetectedServer*> o_ChangedServers;
|
||||
SAD_DetectedServer* ptrDetectedServer;
|
||||
{
|
||||
for (auto i = s_DetectedServers.begin(); i != s_DetectedServers.end(); i++) {
|
||||
@@ -54,6 +64,7 @@ void SAD_DetectedServer::cycleEnd(I_SAD_Client& sADClientInterface) {
|
||||
ptrDetectedServer->endCycleSAD();
|
||||
}
|
||||
else if (ptrDetectedServer->getChanged()) {
|
||||
o_ChangedServers.push_back(ptrDetectedServer);
|
||||
ptrDetectedServer->endCycleSAD();
|
||||
}
|
||||
else {
|
||||
@@ -64,8 +75,8 @@ void SAD_DetectedServer::cycleEnd(I_SAD_Client& sADClientInterface) {
|
||||
//Notify client interface about lost servers
|
||||
for (auto i = o_LostServers.begin(); i != o_LostServers.end(); i++) {
|
||||
ptrDetectedServer = *i;
|
||||
sADClientInterface.eventServerLost(ptrDetectedServer->getID(), ptrDetectedServer->getName(),
|
||||
ptrDetectedServer->getComputerName(), ptrDetectedServer->getIP(), ptrDetectedServer->getPort(), ptrDetectedServer->getAdditions(),
|
||||
sadClient.eventServerLost(ptrDetectedServer->getID(), ptrDetectedServer->getName(),
|
||||
ptrDetectedServer->getComputerName(), ptrDetectedServer->getIP(), ptrDetectedServer->getPort(), ptrDetectedServer->getAdditions(),ptrDetectedServer->getProjectName(),
|
||||
ptrDetectedServer->getClientIP(),
|
||||
ptrDetectedServer->getIpIsIP4());
|
||||
}
|
||||
@@ -78,13 +89,20 @@ void SAD_DetectedServer::cycleEnd(I_SAD_Client& sADClientInterface) {
|
||||
|
||||
for (auto i = o_NewServers.begin(); i != o_NewServers.end(); i++) {
|
||||
ptrDetectedServer = *i;
|
||||
sADClientInterface.eventServerDetected(ptrDetectedServer->getID(), ptrDetectedServer->getName(),
|
||||
ptrDetectedServer->getComputerName(), ptrDetectedServer->getIP(), ptrDetectedServer->getPort(), ptrDetectedServer->getAdditions(),
|
||||
sadClient.eventServerDetected(ptrDetectedServer->getID(), ptrDetectedServer->getName(),
|
||||
ptrDetectedServer->getComputerName(), ptrDetectedServer->getIP(), ptrDetectedServer->getPort(), ptrDetectedServer->getAdditions(),ptrDetectedServer->getProjectName(),
|
||||
ptrDetectedServer->getClientIP(),
|
||||
ptrDetectedServer->getIpIsIP4());
|
||||
}
|
||||
o_NewServers.clear();
|
||||
|
||||
for (auto i = o_ChangedServers.begin(); i != o_ChangedServers.end(); i++) {
|
||||
ptrDetectedServer = *i;
|
||||
sadClient.eventServerChanged(ptrDetectedServer->getID(), ptrDetectedServer->getName(),
|
||||
ptrDetectedServer->getComputerName(), ptrDetectedServer->getIP(), ptrDetectedServer->getPort(), ptrDetectedServer->getAdditions(),ptrDetectedServer->getProjectName(),
|
||||
ptrDetectedServer->getClientIP(),
|
||||
ptrDetectedServer->getIpIsIP4());
|
||||
}
|
||||
o_ChangedServers.clear();
|
||||
}
|
||||
/**
|
||||
* Used by SAD_Client to add a found SPITServer - don't use this manually
|
||||
@@ -120,6 +138,7 @@ void SAD_DetectedServer::addDetectedServer(bool p_IsIP4, string p_ServerID, stri
|
||||
ptrDetectedServer->setComputerName(p_ServerParams[PARAMINDEX_COMPUTERNAME]);
|
||||
ptrDetectedServer->setPort(p_ServerParams[PARAMINDEX_PORT]);
|
||||
ptrDetectedServer->setAdditions(p_ServerParams[PARAMINDEX_ADDITIONS]);
|
||||
ptrDetectedServer->setProjectName(p_ServerParams[PARAMINDEX_SERVERPROJECTNAME]);
|
||||
|
||||
s_DetectedServers[ptrDetectedServer->getID()] = ptrDetectedServer;
|
||||
}
|
||||
|
||||
@@ -84,8 +84,11 @@
|
||||
}
|
||||
bool SPITObject::removeSPITObject(SPITObject* p_ptrSPITObject) {
|
||||
if (p_ptrSPITObject == NULL) return false;
|
||||
return removeSPITObject(p_ptrSPITObject->getID());
|
||||
}
|
||||
bool SPITObject::removeSPITObject(string p_SPITObjectID) {
|
||||
{
|
||||
auto i = s_SPITObjects.find(p_ptrSPITObject->getID());
|
||||
auto i = s_SPITObjects.find(p_SPITObjectID);
|
||||
if (i == s_SPITObjects.end()) {
|
||||
return false;
|
||||
}
|
||||
@@ -95,8 +98,11 @@
|
||||
}
|
||||
bool SPITObject::removeSPITObjectRemote(SPITObject* p_ptrSPITObject) {
|
||||
if (p_ptrSPITObject == NULL) return false;
|
||||
return removeSPITObjectRemote(p_ptrSPITObject->getID());
|
||||
}
|
||||
bool SPITObject::removeSPITObjectRemote(string p_ptrSPITObject) {
|
||||
{
|
||||
auto i = s_SPITObjectsRemote.find(p_ptrSPITObject->getID());
|
||||
auto i = s_SPITObjectsRemote.find(p_ptrSPITObject);
|
||||
if (i == s_SPITObjectsRemote.end()) {
|
||||
return false;
|
||||
}
|
||||
@@ -203,8 +209,44 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* clears all unconfirmed SPITObjects not created by this SPIT_Client.
|
||||
*/
|
||||
void SPITObject::clearUnconfirmedSPITObjects() {
|
||||
for (auto i = s_SPITObjects.begin(); i != s_SPITObjects.end(); i++) {
|
||||
SPITObject* ptrSPITObject = i->second;
|
||||
if (ptrSPITObject->getCreatedByClient() == false && ptrSPITObject->getConfirmed() == false) {
|
||||
i = s_SPITObjects.erase(i);
|
||||
delete ptrSPITObject;
|
||||
}
|
||||
if (i == s_SPITObjects.end()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SPITObject::eventProjectClosed() {
|
||||
for (auto i = s_SPITObjects.begin(); i != s_SPITObjects.end(); i++) {
|
||||
SPITObject* ptrSPITObject = i->second;
|
||||
if (ptrSPITObject->getCreatedByClient() == true) {
|
||||
continue;
|
||||
}
|
||||
i = s_SPITObjects.erase(i);
|
||||
delete ptrSPITObject;
|
||||
if (i == s_SPITObjects.end()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
//Remote
|
||||
for (auto i = s_SPITObjectsRemote.begin(); i != s_SPITObjectsRemote.end(); i++) {
|
||||
SPITObject* ptrSPITObject = i->second;
|
||||
i = s_SPITObjectsRemote.erase(i);
|
||||
delete ptrSPITObject;
|
||||
if (i == s_SPITObjectsRemote.end()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* sets confirmed = false for all SPITObjects.<br>
|
||||
* This should be called when the client has loaded a project.<br>
|
||||
@@ -231,6 +273,7 @@ void SPITObject::initMembers() {
|
||||
m_Delay = 0;
|
||||
m_Duration = 0;
|
||||
m_Fixed = false;
|
||||
m_CreatedByClient = false;
|
||||
m_FrameFadeInLength = 0;
|
||||
m_FrameFadeOutLength = 0;
|
||||
m_FrameLength = 0;
|
||||
@@ -245,51 +288,112 @@ void SPITObject::initMembers() {
|
||||
m_ValueFactor = 1000000; //Values are given in ppm -> 1000000 = 1/1;
|
||||
m_ValueUse = 0x01;
|
||||
}
|
||||
/*
|
||||
SPITObject::SPITObject(const SPITObject& orig) {
|
||||
m_ActionAssigned = orig.getActionAssigned();
|
||||
m_Confirmed = orig.getConfirmed();
|
||||
m_Delay = orig.getDelay();
|
||||
m_Duration = orig.getDuration();
|
||||
m_Fixed = orig.getFixed();
|
||||
m_FrameFadeInLength = orig.getFrameFadeInLength();
|
||||
m_FrameFadeOutLength = orig.getFrameFadeOutLength();
|
||||
m_FrameLength = orig.getFrameLength();
|
||||
m_FrameStart = orig.getFrameStart();
|
||||
m_Remark = orig.getRemark();
|
||||
m_ID = orig.getID();
|
||||
m_Name = orig.getName();
|
||||
m_SPITTypeID = orig.getSPITTypeID();
|
||||
m_ServerParams = orig.getServerParams();
|
||||
m_ServerRemote = orig.getServerRemote();
|
||||
m_Track = orig.getTrack();
|
||||
m_ValueFactor = orig.getValueFactor();
|
||||
m_ValueUse = orig.getValueUse();
|
||||
}
|
||||
*/
|
||||
SPITObject::~SPITObject() {
|
||||
}
|
||||
|
||||
SPITObject::~SPITObject() { }
|
||||
|
||||
|
||||
void SPITObject::setMessageOP(SPIT_Message::ReportSPITObject* p_ReportSPITObject) {
|
||||
//m_ActionAssigned = p_ReportSPITObject->getActionAssigned(); //Should only be set by the client
|
||||
bool SPITObject::setMessageOP(SPIT_Message::ReportSPITObject* p_ReportSPITObject) {
|
||||
bool boolChangeAllowed;
|
||||
bool boolChanged = false;
|
||||
|
||||
if (m_CreatedByClient == true && m_Fixed == true) {
|
||||
boolChangeAllowed = false;
|
||||
}
|
||||
else {
|
||||
boolChangeAllowed = true;
|
||||
}
|
||||
|
||||
//Confirmation should be changable
|
||||
if (m_CreatedByClient) {
|
||||
//Server reports a client created SPITType -> the type is confirmed
|
||||
m_Confirmed = true;
|
||||
}
|
||||
else {
|
||||
//type is NOT client created -> the client has to confirm the SPITtype
|
||||
m_Confirmed = p_ReportSPITObject->getConfirmed();
|
||||
}
|
||||
|
||||
if (m_Delay != p_ReportSPITObject->getDelay()) {
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_Delay = p_ReportSPITObject->getDelay();
|
||||
boolChanged = true;
|
||||
}
|
||||
if (m_Duration != p_ReportSPITObject->getDuration()) {
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_Duration = p_ReportSPITObject->getDuration();
|
||||
boolChanged = true;
|
||||
}
|
||||
if (m_Fixed != p_ReportSPITObject->getFixed()) {
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_Fixed = p_ReportSPITObject->getFixed();
|
||||
boolChanged = true;
|
||||
}
|
||||
if (m_FrameFadeInLength != p_ReportSPITObject->getFrameFadeInLength()) {
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_FrameFadeInLength = p_ReportSPITObject->getFrameFadeInLength();
|
||||
boolChanged= true;
|
||||
}
|
||||
if (m_FrameFadeOutLength != p_ReportSPITObject->getFrameFadeOutLength()) {
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_FrameFadeOutLength = p_ReportSPITObject->getFrameFadeOutLength();
|
||||
boolChanged = true;
|
||||
}
|
||||
if (m_FrameLength != p_ReportSPITObject->getFrameLength()) {
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_FrameLength = p_ReportSPITObject->getFrameLength();
|
||||
boolChanged = true;
|
||||
}
|
||||
if (m_FrameStart != p_ReportSPITObject->getFrameStart()) {
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_FrameStart = p_ReportSPITObject->getFrameStart();
|
||||
boolChanged = true;
|
||||
}
|
||||
if (m_Remark != p_ReportSPITObject->getRemark()) {
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_Remark = p_ReportSPITObject->getRemark();
|
||||
boolChanged = true;
|
||||
}
|
||||
if (m_ID != p_ReportSPITObject->getID()) {
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_ID = p_ReportSPITObject->getID();
|
||||
boolChanged = true;
|
||||
}
|
||||
if (m_Name != p_ReportSPITObject->getName()) {
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_Name = p_ReportSPITObject->getName();
|
||||
boolChanged = true;
|
||||
}
|
||||
if (m_SPITTypeID != p_ReportSPITObject->getSPITTypeID()) {
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_SPITTypeID = p_ReportSPITObject->getSPITTypeID();
|
||||
boolChanged = true;
|
||||
}
|
||||
if (m_ServerParams != p_ReportSPITObject->getServerParams()) {
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_ServerParams = p_ReportSPITObject->getServerParams();
|
||||
boolChanged = true;
|
||||
}
|
||||
if (m_ServerRemote != p_ReportSPITObject->getServerRemote()) {
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_ServerRemote = p_ReportSPITObject->getServerRemote();
|
||||
boolChanged = true;
|
||||
}
|
||||
if (m_Track != p_ReportSPITObject->getTrack()) {
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_Track = p_ReportSPITObject->getTrack();
|
||||
boolChanged = true;
|
||||
}
|
||||
if (m_ValueFactor != p_ReportSPITObject->getValueFactor()) {
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_ValueFactor = p_ReportSPITObject->getValueFactor();
|
||||
boolChanged = true;
|
||||
}
|
||||
if (m_ValueUse != p_ReportSPITObject->getValueUse()) {
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_ValueUse = p_ReportSPITObject->getValueUse();
|
||||
boolChanged = true;
|
||||
}
|
||||
return boolChanged;
|
||||
}
|
||||
|
||||
void SPITObject::fillMessageOP(SPIT_Message::ReportSPITObject* p_ReportSPITObject) {
|
||||
@@ -319,6 +423,9 @@ void SPITObject::fillMessageOP(SPIT_Message::RemoveSPITObject* p_RemoveSPITObjec
|
||||
void SPITObject::setID(string p_ID) {
|
||||
m_ID = p_ID;
|
||||
}
|
||||
void SPITObject::setCreatedByClient(bool p_CreatedByClient) {
|
||||
m_CreatedByClient = p_CreatedByClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used by the server and client to tell if the other side has registered the changes.
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
*/
|
||||
|
||||
#include "SPITPlayer.h"
|
||||
#include <vector>
|
||||
|
||||
unordered_map<string, SPITPlayer*> SPITPlayer::s_SPITPlayers;
|
||||
|
||||
@@ -29,18 +30,17 @@ SPITPlayer* SPITPlayer::getSPITPlayer(string p_PlayerID) {
|
||||
}
|
||||
|
||||
void SPITPlayer::clearPlayers() {
|
||||
SPITPlayer* ptrSPITPlayer;
|
||||
{
|
||||
;
|
||||
vector<SPITPlayer*> o_SPITPlayers;
|
||||
for (auto i = s_SPITPlayers.begin(); i != s_SPITPlayers.end(); i++) {
|
||||
ptrSPITPlayer = i->second;
|
||||
i = s_SPITPlayers.erase(i);
|
||||
SPITPlayer* ptrSPITPlayer = i->second;
|
||||
o_SPITPlayers.push_back(ptrSPITPlayer);
|
||||
}
|
||||
for (auto i = o_SPITPlayers.begin(); i != o_SPITPlayers.end(); i++) {
|
||||
SPITPlayer* ptrSPITPlayer = *i;
|
||||
delete ptrSPITPlayer;
|
||||
if (i == s_SPITPlayers.end()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
o_SPITPlayers.clear();
|
||||
}
|
||||
|
||||
SPITPlayer::SPITPlayer(string p_PlayerID) {
|
||||
@@ -48,19 +48,17 @@ SPITPlayer::SPITPlayer(string p_PlayerID) {
|
||||
s_SPITPlayers[p_PlayerID] = this;
|
||||
}
|
||||
|
||||
|
||||
SPITPlayer::~SPITPlayer() {
|
||||
{
|
||||
PlayObject* ptrPlayObject;
|
||||
for (auto i = m_PlayObjects.begin(); i != m_PlayObjects.end(); i++) {
|
||||
ptrPlayObject = i->second;
|
||||
i = m_PlayObjects.erase(i);
|
||||
delete ptrPlayObject;
|
||||
if (i == m_PlayObjects.end()) {
|
||||
PlaySPITType* ptrPlaySPITType;
|
||||
for (auto i = m_PlaySPITTypes.begin(); i != m_PlaySPITTypes.end(); i++) {
|
||||
ptrPlaySPITType = i->second;
|
||||
i = m_PlaySPITTypes.erase(i);
|
||||
delete ptrPlaySPITType;
|
||||
if (i == m_PlaySPITTypes.end()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SPITPlayer::setIsRunning(bool p_IsRunning) {
|
||||
@@ -76,8 +74,8 @@ void SPITPlayer::setTime(long long p_Frames) {
|
||||
m_TimeFrames = p_Frames;
|
||||
}
|
||||
|
||||
unordered_map<string, SPITPlayer::PlayObject*>* SPITPlayer::getPlayObjects() {
|
||||
return &m_PlayObjects;
|
||||
unordered_map<string, SPITPlayer::PlaySPITType*>* SPITPlayer::getPlaySPITTypes() {
|
||||
return &m_PlaySPITTypes;
|
||||
}
|
||||
/**
|
||||
*
|
||||
@@ -85,72 +83,59 @@ unordered_map<string, SPITPlayer::PlayObject*>* SPITPlayer::getPlayObjects() {
|
||||
* @return true = new PlayObject added<br>
|
||||
* false = PlayObject exists
|
||||
*/
|
||||
SPITPlayer::PlayObject* SPITPlayer::addSPITObject_Playing (string p_SPITObjectID) {
|
||||
PlayObject* ptrPlayObject;
|
||||
{
|
||||
auto i = m_PlayObjects.find(p_SPITObjectID);
|
||||
if (i == m_PlayObjects.end()) {
|
||||
ptrPlayObject = new PlayObject(this, p_SPITObjectID);
|
||||
ptrPlayObject->setIsPlayed(true);
|
||||
ptrPlayObject->setIsNew(true);
|
||||
m_PlayObjects[p_SPITObjectID] = ptrPlayObject;
|
||||
SPITPlayer::PlaySPITType* SPITPlayer::addSPITType_Playing (string p_SPITTypeID) {
|
||||
PlaySPITType* ptrPlaySPITType;
|
||||
|
||||
auto i = m_PlaySPITTypes.find(p_SPITTypeID);
|
||||
if (i == m_PlaySPITTypes.end()) {
|
||||
ptrPlaySPITType = new PlaySPITType(this, p_SPITTypeID);
|
||||
ptrPlaySPITType->setIsPlayed(true);
|
||||
ptrPlaySPITType->setIsNew(true);
|
||||
m_PlaySPITTypes[p_SPITTypeID] = ptrPlaySPITType;
|
||||
}
|
||||
else {
|
||||
ptrPlayObject = i->second;
|
||||
ptrPlayObject->setIsPlayed(true);
|
||||
}
|
||||
return ptrPlayObject;
|
||||
ptrPlaySPITType = i->second;
|
||||
ptrPlaySPITType->setIsPlayed(true);
|
||||
}
|
||||
return ptrPlaySPITType;
|
||||
|
||||
}
|
||||
|
||||
void SPITPlayer::startPlaySequence() {
|
||||
PlayObject* ptrPlayObject;
|
||||
{
|
||||
for (auto i = m_PlayObjects.begin(); i != m_PlayObjects.end(); i++) {
|
||||
ptrPlayObject = i->second;
|
||||
ptrPlayObject->startPlaySequence();
|
||||
}
|
||||
PlaySPITType* ptrPlaySPITType;
|
||||
for (auto i = m_PlaySPITTypes.begin(); i != m_PlaySPITTypes.end(); i++) {
|
||||
ptrPlaySPITType = i->second;
|
||||
ptrPlaySPITType->startPlaySequence();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
SPITPlayer::PlayObject* SPITPlayer::getPlayObject(string p_SPITObjectID) {
|
||||
auto i = m_SPITObjectsPlaying.find(p_SPITObjectID);
|
||||
if (i == m_SPITObjectsPlaying.end()) {
|
||||
return NULL;
|
||||
}
|
||||
return i->second;
|
||||
}
|
||||
*/
|
||||
void SPITPlayer::endPlaySequence() {
|
||||
PlayObject* ptrPlayObject;
|
||||
{
|
||||
for (auto i = m_PlayObjects.begin(); i != m_PlayObjects.end(); i++) {
|
||||
ptrPlayObject = i->second;
|
||||
if (ptrPlayObject->getIsPlayed() == false) {
|
||||
i = m_PlayObjects.erase(i);
|
||||
delete ptrPlayObject;
|
||||
if (i == m_PlayObjects.end()) {
|
||||
PlaySPITType* ptrPlaySPITType;
|
||||
|
||||
for (auto i = m_PlaySPITTypes.begin(); i != m_PlaySPITTypes.end(); i++) {
|
||||
ptrPlaySPITType = i->second;
|
||||
if (ptrPlaySPITType->getIsPlayed() == false) {
|
||||
i = m_PlaySPITTypes.erase(i);
|
||||
delete ptrPlaySPITType;
|
||||
if (i == m_PlaySPITTypes.end()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
SPITPlayer::PlayObject::PlayObject() {
|
||||
SPITPlayer::PlaySPITType::PlaySPITType() {
|
||||
}
|
||||
SPITPlayer::PlayObject::PlayObject(SPITPlayer* p_SPITPlayer, string p_SPITObjectID) {
|
||||
m_SPITObjectID = p_SPITObjectID;
|
||||
SPITPlayer::PlaySPITType::PlaySPITType(SPITPlayer* p_SPITPlayer, string p_SPITTypeID) {
|
||||
m_SPITTypeID = p_SPITTypeID;
|
||||
m_PlayerID = p_SPITPlayer->getID();
|
||||
m_PlayerName = p_SPITPlayer->getName();
|
||||
startPlaySequence();
|
||||
m_IsNew = true;
|
||||
}
|
||||
SPITPlayer::PlayObject::PlayObject(const PlayObject& orig) {
|
||||
m_SPITObjectID = orig.getSPITObjectID();
|
||||
SPITPlayer::PlaySPITType::PlaySPITType(const PlaySPITType& orig) {
|
||||
m_SPITTypeID = orig.getSPITTypeID();
|
||||
m_IsPlayed = orig.getIsPlayed();
|
||||
m_IsNew = orig.getIsNew();
|
||||
|
||||
@@ -158,21 +143,11 @@ SPITPlayer::PlayObject::PlayObject(const PlayObject& orig) {
|
||||
m_PlayerName = orig.getPlayerName();
|
||||
m_PlayerRuns = orig.getPlayerIsRunning();
|
||||
|
||||
m_Value = orig.getValueFade();
|
||||
m_ValuePrePosition = getValueFadePrePosition();
|
||||
m_ValueFactor = orig.getValueFactor();
|
||||
m_ValueFlag = orig.getValueFlag();
|
||||
m_FrameInsidePrePosition = orig.getFrameInsidePrePosition();
|
||||
m_FrameInside = orig.getFrameInside();
|
||||
m_Value = orig.getValue();
|
||||
}
|
||||
void SPITPlayer::PlayObject::startPlaySequence() {
|
||||
void SPITPlayer::PlaySPITType::startPlaySequence() {
|
||||
m_IsPlayed = false;
|
||||
m_IsNew = false;
|
||||
|
||||
m_FrameInside = -1;
|
||||
m_FrameInsidePrePosition = -1;
|
||||
m_Value = 0;
|
||||
m_ValuePrePosition = 0;
|
||||
m_ValueFlag = 0x00;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,23 +43,26 @@ bool SPITSocket::createSocket_UDP() {
|
||||
} else {
|
||||
intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_REUSEADDR, (void *)&intOptionValue4, sizeof(intOptionValue4));
|
||||
}
|
||||
if (intResult < 0) {
|
||||
boolSuccess = false;
|
||||
}
|
||||
|
||||
// // set the m_UDPSocketIP4 in NON BLOCKING mode because
|
||||
// // if the UDPSockets are in blocking mode the receiveMessage does not return in every constellation
|
||||
if (boolSuccess == true) {
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 1; // seconds
|
||||
tv.tv_usec = 0; // microseconds (0.0 sec)
|
||||
// This sets the receive timeout
|
||||
setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
|
||||
|
||||
// set the m_UDPSocketIP4 in NON BLOCKING mode because
|
||||
// if the UDPSockets are in blocking mode the receiveMessage does not return in every constellation
|
||||
// int intFlags;
|
||||
// intFlags = fcntl(m_UDPSocketIP4, F_GETFL);
|
||||
// fcntl(m_UDPSocketIP4, F_SETFL, intFlags | O_NONBLOCK);
|
||||
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 1; // seconds
|
||||
tv.tv_usec = 0; // microseconds (0.0 sec)
|
||||
|
||||
// This sets the receive timeout
|
||||
setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
|
||||
|
||||
|
||||
if (intResult < 0) {
|
||||
boolSuccess = false;
|
||||
// int intBufferSize = 2046 * 512;
|
||||
// intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_RCVBUF, (void*)&intBufferSize, sizeof(intBufferSize));
|
||||
// intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_SNDBUF, (void*)&intBufferSize, sizeof(intBufferSize));
|
||||
}
|
||||
return boolSuccess;
|
||||
}
|
||||
@@ -72,7 +75,7 @@ bool SPITSocket::createSocket_UDP() {
|
||||
* @return -1 id bind fails, o if bind is ok
|
||||
*
|
||||
*/
|
||||
int SPITSocket::bindSocket(string p_ClientIP, string p_ClientPort) {
|
||||
int SPITSocket::bindSocket(string p_ServerIP, string p_ClientIP, string p_ClientPort) {
|
||||
addrinfo *clientAI;
|
||||
struct sockaddr_in *ptrIP4SocketAddress;
|
||||
struct sockaddr_in o_IP4SocketAddress;
|
||||
@@ -193,7 +196,7 @@ int SPITSocket::sendMessageTo(int p_InetFamily, string p_ServerIP, string p_Serv
|
||||
intResult = -1;
|
||||
}
|
||||
|
||||
if (intResult == -1) {
|
||||
if (intResult < 0) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -200,6 +200,30 @@ static const char * TAG = "SPIT";
|
||||
}
|
||||
}
|
||||
|
||||
void SPITType::eventProjectClosed() {
|
||||
SPITType* ptrSPITType;
|
||||
for (auto i = s_SPITTypes.begin(); i != s_SPITTypes.end(); i++) {
|
||||
ptrSPITType = i->second;
|
||||
if (ptrSPITType->getCreatedByClient() == true) {
|
||||
continue;
|
||||
}
|
||||
i = s_SPITTypes.erase(i);
|
||||
delete ptrSPITType;
|
||||
if (i == s_SPITTypes.end()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
//Remote
|
||||
for (auto i = s_SPITTypesRemote.begin(); i != s_SPITTypesRemote.end(); i++) {
|
||||
ptrSPITType = i->second;
|
||||
i = s_SPITTypesRemote.erase(i);
|
||||
delete ptrSPITType;
|
||||
if (i == s_SPITTypesRemote.end()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets confirmed = false for all SPITTypes.<br>
|
||||
* This should be called when the client has loaded a project.<br>
|
||||
@@ -349,6 +373,7 @@ void SPITType::setCreatedByClient(bool p_CreatedByClient) {
|
||||
*/
|
||||
bool SPITType::setMessageOP(SPIT_Message::ReportSPITType* p_ReportSPITType) {
|
||||
bool boolChangeAllowed;
|
||||
bool boolChanged = false;
|
||||
|
||||
if (m_CreatedByClient == true && m_Fixed == true) {
|
||||
boolChangeAllowed = false;
|
||||
@@ -367,38 +392,46 @@ void SPITType::setCreatedByClient(bool p_CreatedByClient) {
|
||||
m_Confirmed = p_ReportSPITType->getConfirmed();
|
||||
}
|
||||
if (m_DefaultDelay != p_ReportSPITType->getDelay()) {
|
||||
if (boolChangeAllowed == false) return false;
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_DefaultDelay = p_ReportSPITType->getDelay();
|
||||
boolChanged = true;
|
||||
}
|
||||
if (m_DefaultDuration != p_ReportSPITType->getDuration()) {
|
||||
if (boolChangeAllowed == false) return false;
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_DefaultDuration = p_ReportSPITType->getDuration();
|
||||
boolChanged = true;
|
||||
}
|
||||
if (m_Fixed != p_ReportSPITType->getFixed()) {
|
||||
if (boolChangeAllowed == false) return false;
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_Fixed = p_ReportSPITType->getFixed();
|
||||
boolChanged = true;
|
||||
}
|
||||
if (m_GroupName != p_ReportSPITType->getGroupName()) {
|
||||
if (boolChangeAllowed == false) return false;
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_GroupName = p_ReportSPITType->getGroupName();
|
||||
boolChanged = true;
|
||||
}
|
||||
if (m_ID != p_ReportSPITType->getID()) {
|
||||
if (boolChangeAllowed == false) return false;
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_ID = p_ReportSPITType->getID();
|
||||
boolChanged = true;
|
||||
}
|
||||
if (m_Name != p_ReportSPITType->getName()) {
|
||||
if (boolChangeAllowed == false) return false;
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_Name = p_ReportSPITType->getName();
|
||||
boolChanged = true;
|
||||
}
|
||||
if (m_ServerProjectIndepended != p_ReportSPITType->getServerProjectIndepended()) {
|
||||
if (boolChangeAllowed == false) return false;
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_ServerProjectIndepended = p_ReportSPITType->getServerProjectIndepended();
|
||||
boolChanged = true;
|
||||
}
|
||||
if (m_ServerRemote != p_ReportSPITType->getServerRemote()) {
|
||||
if (boolChangeAllowed == false) return false;
|
||||
if (boolChangeAllowed == false) throw new exception();
|
||||
m_ServerRemote = p_ReportSPITType->getServerRemote();
|
||||
boolChanged = true;
|
||||
}
|
||||
return true;
|
||||
return boolChanged;
|
||||
}
|
||||
|
||||
void SPITType::fillMessageOP(SPIT_Message::ReportSPITType* ptrSMReportSPITType) {
|
||||
|
||||
+452
-107
@@ -42,37 +42,10 @@ SPIT_Client::~SPIT_Client() {
|
||||
}
|
||||
|
||||
|
||||
/** The ID of the client. Every client instance should set an unique id.*/
|
||||
string SPIT_Client::getID() { return m_ID; }
|
||||
/** The name of the client's host computer*/
|
||||
string SPIT_Client::getComputerName() { return m_ComputerName; }
|
||||
|
||||
/**
|
||||
* Sets the name of the client. This should be done by the user app.
|
||||
* @param p_Name the anme of the user's app
|
||||
*/
|
||||
/** The name of the client, as set by the user's app*/
|
||||
string SPIT_Client::getName() { return m_Name; }
|
||||
|
||||
//connected Server Infos
|
||||
/**If a connection is established. THis returns the SPITServer's ID*/
|
||||
string SPIT_Client::getServerID() { return m_ServerID; }
|
||||
/**If a connection is established. THis returns the SPITServer's computer/host name*/
|
||||
string SPIT_Client::getServerComputerName() { return m_ServerComputerName; }
|
||||
/**If a connection is established. THis returns the SPITServer's name*/
|
||||
string SPIT_Client::getServerName() { return m_ServerName; }
|
||||
|
||||
/** Expected Refreah Rate of the connectd SPITServer.<br>
|
||||
* When the server plays objects, it will do so at discrete time steps.<br>
|
||||
* Play events will take place in these time steps..
|
||||
*/
|
||||
int SPIT_Client::getServerStepTime() { return m_ServerStepTime; }
|
||||
|
||||
void SPIT_Client::clientProjectClose() {
|
||||
if (m_ConnectionStatus == CONNECTION_OK) {
|
||||
ESP_LOGI(TAG, " ... tidy up ressources");
|
||||
SPIT_Message::CloseSPITProject sMCloseSPITProject;
|
||||
fillHeader(sMCloseSPITProject.getHeader());
|
||||
sMCloseSPITProject.setProjectID(m_ProjName);
|
||||
if (sendSPITMessage(sMCloseSPITProject) < 0) {
|
||||
ESP_LOGD(TAG, "SPIT_Client could not send Client's ReportSPITProject");
|
||||
@@ -88,7 +61,6 @@ void SPIT_Client::clientProjectLoaded() {
|
||||
if (m_ConnectionStatus == CONNECTION_OK) {
|
||||
//send ReportSPITProject to the server
|
||||
SPIT_Message::ReportSPITProject sMReportSPITProject;
|
||||
fillHeader(sMReportSPITProject.getHeader());
|
||||
sMReportSPITProject.setProjectID(m_ProjName);
|
||||
sMReportSPITProject.setProjectName(m_ProjName);
|
||||
sMReportSPITProject.setFramesPerSecond(0);
|
||||
@@ -98,7 +70,6 @@ void SPIT_Client::clientProjectLoaded() {
|
||||
|
||||
//send RequestProjectTransfer
|
||||
SPIT_Message::RequestProjectTransfer sMRequestProjectTransfer;
|
||||
fillHeader(sMRequestProjectTransfer.getHeader());
|
||||
if (sendSPITMessage(sMRequestProjectTransfer) < 0) {
|
||||
ESP_LOGD(TAG, "SPIT_CLient::clientProjectLoaded could not send RequestProjectTransfer");
|
||||
}
|
||||
@@ -125,7 +96,7 @@ void SPIT_Client::setActionSPITType(string p_SPITTypeID, bool p_ActionAssigned)
|
||||
|
||||
for (int i = 0; i < SPITObject::getSPITObjectCount(); i++) {
|
||||
ptrSPITObject = SPITObject::getSPITObject(i);
|
||||
if (ptrSPITObject == NULL) break;
|
||||
if (ptrSPITObject == NULL) continue;
|
||||
if (ptrSPITObject->getSPITTypeID() == ptrSPITType->getID()) {
|
||||
if (ptrSPITObject->setActionAssignedType(p_ActionAssigned) == true) {
|
||||
sendSPITObjectInternal(ptrSPITObject);
|
||||
@@ -165,7 +136,7 @@ void SPIT_Client::startServerAutoDetect() {
|
||||
|
||||
SAD_DetectedServer::clearDetectedServers();
|
||||
if (!sThread) {
|
||||
sThread = new fos::TaskT<SPIT_Client &>(SPIT_Client::processSocketTask, *this, "spitSock");
|
||||
sThread = new fos::TaskT<SPIT_Client &>(SPIT_Client::processSocketTask, *this, "spitSock", fos::Task::DefaultStackSize*2 );
|
||||
}
|
||||
abortSearch = false;
|
||||
sStartSad.give();
|
||||
@@ -193,10 +164,10 @@ void SPIT_Client::stopServerAutoDetect() {
|
||||
* @param p_Addition sometimes server may have additional informations
|
||||
* @param p_IsIP4 the server ip is a ip4 address
|
||||
*/
|
||||
void SPIT_Client::eventServerDetected(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ClientIP, bool p_IsIP4) {
|
||||
void SPIT_Client::eventServerDetected(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ProjectName, string p_ClientIP, bool p_IsIP4) {
|
||||
try {
|
||||
SAD_DetectedServer o_RefDetectedServer = SAD_DetectedServer::getRefDetectedServer(p_ID);
|
||||
mCallbacks.onServerDetect(o_RefDetectedServer);
|
||||
mCallbacks.onServerEvent(ServerEvent::Detect, o_RefDetectedServer);
|
||||
|
||||
// If a connection has been established and the connection is lost -> reconnect
|
||||
if (_doReconnect) {
|
||||
@@ -235,16 +206,77 @@ void SPIT_Client::eventServerDetected(string p_ID, string p_Name, string p_Compu
|
||||
* @param p_Addition sometimes server may have additional informations
|
||||
* @param p_IsIP4 the server ip is a ip4 address
|
||||
*/
|
||||
void SPIT_Client::eventServerLost(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ClientIP, bool p_IsIP4) {
|
||||
void SPIT_Client::eventServerLost(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ProjectName, string p_ClientIP, bool p_IsIP4) {
|
||||
try {
|
||||
SAD_DetectedServer o_RefDetectedServer = SAD_DetectedServer::getRefDetectedServer(p_ID);
|
||||
mCallbacks.onServerLost(o_RefDetectedServer);
|
||||
mCallbacks.onServerEvent(ServerEvent::Lost, o_RefDetectedServer);
|
||||
}
|
||||
catch (...) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void SPIT_Client::eventServerChanged(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ProjectName, string p_ClientIP, bool p_IsIP4) {
|
||||
try {
|
||||
SAD_DetectedServer o_RefDetectedServer = SAD_DetectedServer::getRefDetectedServer(p_ID);
|
||||
mCallbacks.onServerEvent(ServerEvent::Changed, o_RefDetectedServer);
|
||||
// tryConnection(p_DetectedServer);
|
||||
}
|
||||
catch (...) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// void MyApp::tryConnection(const SAD_DetectedServer& p_DetectedServer) {
|
||||
// //fetch the infoemations from the p_DetectedServer
|
||||
// bool boolPossibleConnect;
|
||||
// bool boolSuccess;
|
||||
|
||||
// boolPossibleConnect = checkPossibleConnection(p_DetectedServer);
|
||||
|
||||
// if (boolPossibleConnect == false) return;
|
||||
|
||||
// // --------------------------------------
|
||||
// // You have three Options to use the detected server
|
||||
// // OPTION 1 Use the first server found
|
||||
// // OPTION 2 Use the first server found that fulfills specific conditions
|
||||
// // OPTION 3 take a copy of the p_DetectedServer and do connection later
|
||||
// // SAD_DetectedServer o_DetectedServer = p_DetectedServer; //this will call the copy constructor
|
||||
// // ---------------------------------------
|
||||
|
||||
// //Excample use the first detected LOOPBACK server, means the server runs on the same computer as this client
|
||||
// //if (p_DetectedServer.getIpIsLoopback() == true) { //omit the if condition if you want to use the first server found
|
||||
|
||||
// boolSuccess = false;
|
||||
// //Stop auto detection because a suitable server was found
|
||||
// stopServerAutoDetect();
|
||||
// if (m_SPIT_Client != NULL) {
|
||||
// m_ServerProjectName = p_DetectedServer.getProjectName();
|
||||
// m_ServerIP = p_DetectedServer.getIP();
|
||||
|
||||
// #if defined(DEBUGOUTPUT)
|
||||
// printf("MySPITApp: connect to %s ", p_DetectedServer.getIP().data());
|
||||
// #endif
|
||||
// //Use the m_BoardNumber as login name
|
||||
// string stringLoginName = "";
|
||||
// string stringLoginPassword = "";
|
||||
// boolSuccess = m_SPIT_Client->connect(p_DetectedServer.getIP(), p_DetectedServer.getPort(), p_DetectedServer.getClientIP(), stringLoginName, stringLoginPassword); //ClientPort = "0" meeans use any port
|
||||
// }
|
||||
// if (boolSuccess == false) {
|
||||
// //connection message could not be sent
|
||||
// //perhaps restart AutoDetection
|
||||
// startServerAutoDetect();
|
||||
// }
|
||||
// else {
|
||||
// //WAITING FOR CONNECTION ANSWER
|
||||
// //If the Server is closed in the meantime no answer will return
|
||||
// //-> connect(..) has started the watchdog
|
||||
// }
|
||||
|
||||
// // } //Excample
|
||||
// }
|
||||
|
||||
void SPIT_Client::fillHeader(SPIT_Message::Header* p_Header) {
|
||||
if (p_Header == NULL) return;
|
||||
@@ -257,6 +289,8 @@ int SPIT_Client::sendSPITMessage(SPIT_Message::OPPart& spitMessageOPPart) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
fillHeader(spitMessageOPPart.getHeader());
|
||||
|
||||
if (m_MessageNumber_Send == 255) m_MessageNumber_Send = 1;
|
||||
else m_MessageNumber_Send++;
|
||||
spitMessageOPPart.getHeader()->setMessageNumber(m_MessageNumber_Send);
|
||||
@@ -312,11 +346,114 @@ void SPIT_Client::receiveSPITMessage(SPIT_Client& rM) {
|
||||
continue;
|
||||
}
|
||||
auto ptrSPIT_Message = make_unique<SPIT_Message>(buffer, intResult);
|
||||
unsigned int intActualMessageNumber = (int)(ptrSPIT_Message->getHeader()->getMessageNumber() & 0xFF);
|
||||
rM.parseSPIT_Message(move(ptrSPIT_Message));
|
||||
// rM.checkParseSPIT_Message(move(ptrSPIT_Message));
|
||||
}
|
||||
}
|
||||
|
||||
void SPIT_Client::resetMessageNumberReceived() {
|
||||
SPIT_Message* ptrOvertakingSPIT_Message;
|
||||
|
||||
m_MessageNumber_Received = -1;
|
||||
for (auto it = m_OvertakingSPIT_Messages.begin(); it != m_OvertakingSPIT_Messages.end(); it++) {
|
||||
ptrOvertakingSPIT_Message = *it;
|
||||
delete ptrOvertakingSPIT_Message;
|
||||
// m_OvertakingSPIT_Messages.erase(it);
|
||||
}
|
||||
m_OvertakingSPIT_Messages.clear();
|
||||
}
|
||||
|
||||
void SPIT_Client::checkParseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage) {
|
||||
answerWatchdog();
|
||||
if (p_SPITMessage == NULL) {
|
||||
ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message Parameter == NULL\n");
|
||||
return;
|
||||
}
|
||||
if (p_SPITMessage->getHeader() == NULL) {
|
||||
ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message no Header\n");
|
||||
return;
|
||||
}
|
||||
if (p_SPITMessage->getOPPart() == NULL) {
|
||||
ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message no OPPart\n");
|
||||
return;
|
||||
}
|
||||
|
||||
int intActualMessageNumber;
|
||||
int intNextMessageNumber;
|
||||
SPIT_Message* ptrOvertakingSPIT_Message;
|
||||
|
||||
intActualMessageNumber = (int)(p_SPITMessage->getHeader()->getMessageNumber() & 0xFF);
|
||||
|
||||
if (intActualMessageNumber == 0) {
|
||||
parseSPIT_Message(std::move(p_SPITMessage));
|
||||
return;
|
||||
}
|
||||
if (m_MessageNumber_Received < 0) {
|
||||
m_MessageNumber_Received = intActualMessageNumber;
|
||||
parseSPIT_Message(std::move(p_SPITMessage));
|
||||
return;
|
||||
}
|
||||
|
||||
intNextMessageNumber = m_MessageNumber_Received +1;
|
||||
if (intNextMessageNumber > 255 || intNextMessageNumber < 1) intNextMessageNumber = 1;
|
||||
|
||||
if (intActualMessageNumber == intNextMessageNumber) {
|
||||
m_MessageNumber_Received = intActualMessageNumber;
|
||||
parseSPIT_Message(std::move(p_SPITMessage));
|
||||
|
||||
//check overtaking messages
|
||||
auto it = m_OvertakingSPIT_Messages.begin();
|
||||
while (m_OvertakingSPIT_Messages.size() > 0) {
|
||||
|
||||
intNextMessageNumber = m_MessageNumber_Received +1;
|
||||
if (intNextMessageNumber > 255 || intNextMessageNumber < 1) intNextMessageNumber = 1;
|
||||
|
||||
ptrOvertakingSPIT_Message = *it;
|
||||
intActualMessageNumber = (int)(ptrOvertakingSPIT_Message->getHeader()->getMessageNumber() & 0xFF);
|
||||
|
||||
if (intActualMessageNumber == intNextMessageNumber) {
|
||||
m_MessageNumber_Received = intActualMessageNumber;
|
||||
// parseSPIT_Message(ptrOvertakingSPIT_Message);
|
||||
m_OvertakingSPIT_Messages.erase(it);
|
||||
|
||||
it = m_OvertakingSPIT_Messages.begin();
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
//p_SPITMessage has overtaken another message
|
||||
addOvertakingSPIT_Message(p_SPITMessage.get());
|
||||
}
|
||||
}
|
||||
|
||||
int SPIT_Client::s_MAX_OVERTAKING_SPIT_MESSAGES = 10;
|
||||
|
||||
void SPIT_Client::addOvertakingSPIT_Message(SPIT_Message* p_SPIT_Message) {
|
||||
if (p_SPIT_Message == nullptr) return;
|
||||
int intMessageNumber;
|
||||
SPIT_Message* ptrOvertakingSPIT_Message;
|
||||
int intOvertakingMessageNumber;
|
||||
|
||||
if (m_OvertakingSPIT_Messages.size() > s_MAX_OVERTAKING_SPIT_MESSAGES) {
|
||||
printf("SPIT_Client receiveing: perhaps message lost !!!!!");
|
||||
}
|
||||
|
||||
intMessageNumber = (int)(p_SPIT_Message->getHeader()->getMessageNumber() & 0xFF);
|
||||
for (auto it = m_OvertakingSPIT_Messages.begin(); it != m_OvertakingSPIT_Messages.end(); it++) {
|
||||
ptrOvertakingSPIT_Message = *it;
|
||||
intOvertakingMessageNumber = (int)(ptrOvertakingSPIT_Message->getHeader()->getMessageNumber() & 0xFF);
|
||||
if (intMessageNumber < intOvertakingMessageNumber) {
|
||||
m_OvertakingSPIT_Messages.insert(it, p_SPIT_Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_OvertakingSPIT_Messages.push_back(p_SPIT_Message);
|
||||
}
|
||||
|
||||
void SPIT_Client::parseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage) {
|
||||
answerWatchdog();
|
||||
@@ -431,14 +568,13 @@ bool SPIT_Client::connect(string p_ServerIP, string p_ServerPort, string p_Clien
|
||||
disconnect();
|
||||
{
|
||||
mSPITSocket->setConnectionParams(p_ServerIP, p_ServerPort, p_ClientIP, p_ClientPort);
|
||||
intResult = mSPITSocket->bindSocket(p_ClientIP, p_ClientPort);
|
||||
intResult = mSPITSocket->bindSocket(p_ServerIP, p_ClientIP, p_ClientPort);
|
||||
if (intResult < 0) {
|
||||
m_StopReceiveSPITMessages = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
SPIT_Message::Connect sMConnect;
|
||||
fillHeader(sMConnect.getHeader());
|
||||
sMConnect.setClientComputerName(m_ComputerName);
|
||||
sMConnect.setClientName(m_Name);
|
||||
sMConnect.setLoginName(p_LoginName);
|
||||
@@ -455,7 +591,12 @@ bool SPIT_Client::connect(string p_ServerIP, string p_ServerPort, string p_Clien
|
||||
m_StopReceiveSPITMessages = true;
|
||||
return false;
|
||||
}
|
||||
resetMessageNumberReceived();
|
||||
int intOldConnectionStatus = m_ConnectionStatus;
|
||||
|
||||
m_ConnectionStatus = CONNECTION_TRYCONNECTION;
|
||||
mCallbacks.onConnectionStatus(m_ServerID, m_ServerComputerName, m_ServerName, m_ServerStepTime,
|
||||
m_ConnectionStatus, intOldConnectionStatus);
|
||||
|
||||
//sleep a little to make sure that the reception of the messages is started
|
||||
fos::Task::delayMs(500);
|
||||
@@ -485,7 +626,6 @@ void SPIT_Client::disconnectInternal(int p_Cause) {
|
||||
case CONNECTION_NONE:
|
||||
{
|
||||
SPIT_Message::Disconnect sMDisconnect;
|
||||
fillHeader(sMDisconnect.getHeader());
|
||||
intResult = sendSPITMessage(sMDisconnect);
|
||||
if (intResult < 0) {
|
||||
}
|
||||
@@ -495,6 +635,8 @@ void SPIT_Client::disconnectInternal(int p_Cause) {
|
||||
break;
|
||||
}
|
||||
stopReceiveSPITMessages();
|
||||
mCallbacks.onConnectionStatus(m_ServerID, m_ServerComputerName, m_ServerName, m_ServerStepTime,
|
||||
m_ConnectionStatus, intOldConnectionStatus);
|
||||
|
||||
if (intOldConnectionStatus != CONNECTION_NONE && intOldConnectionStatus != CONNECTION_NONESERVER) {
|
||||
ESP_LOGI(TAG, "eventConnectionStatus %d ", m_ConnectionStatus);
|
||||
@@ -577,9 +719,8 @@ void SPIT_Client::parseDisconnect(SPIT_Message::Disconnect* p_Disconnect) {
|
||||
void SPIT_Client::parseWatchdog(SPIT_Message::Watchdog* p_Watchdog) {
|
||||
// printf("parse Watchdog \n");
|
||||
SPIT_Message::WatchdogAnswer o_WatchdogAnswer;
|
||||
fillHeader(o_WatchdogAnswer.getHeader());
|
||||
int intResult;
|
||||
intResult = sendSPITMessage(o_WatchdogAnswer);
|
||||
;
|
||||
int intResult = sendSPITMessage(o_WatchdogAnswer);
|
||||
if (intResult < 0) {
|
||||
}
|
||||
}
|
||||
@@ -595,19 +736,24 @@ void SPIT_Client::parseWatchdogAnswer(SPIT_Message::WatchdogAnswer* p_WatchdogAn
|
||||
void SPIT_Client::sendWatchdog() {
|
||||
int intResult;
|
||||
SPIT_Message::Watchdog sMWatchdog;
|
||||
fillHeader(sMWatchdog.getHeader());
|
||||
intResult = sendSPITMessage(sMWatchdog);
|
||||
if (intResult < 0) {
|
||||
ESP_LOGW("WDT", "Failed to send Watchdog msg");
|
||||
}
|
||||
}
|
||||
void SPIT_Client::eventWatchdogLost() {
|
||||
if (m_ConnectionStatus == CONNECTION_TRYCONNECTION) {
|
||||
disconnectInternal(CONNECTION_NONESERVER);
|
||||
}
|
||||
else {
|
||||
disconnectInternal(CONNECTION_LOST);
|
||||
}
|
||||
}
|
||||
|
||||
//----- SPIT Project ------
|
||||
void SPIT_Client::parseReportSPITProject(SPIT_Message::ReportSPITProject* p_ReportSPITProject) {
|
||||
// printf("parse ReportSPITProject \n");
|
||||
if (p_ReportSPITProject == NULL) return;
|
||||
m_ServerProjectID = p_ReportSPITProject->getProjectID();
|
||||
m_ServerProjectName = p_ReportSPITProject->getProjectName();
|
||||
m_ServerFramesPerSecond = p_ReportSPITProject->getFramesPerSecond();
|
||||
@@ -620,24 +766,24 @@ void SPIT_Client::parseReportSPITProject(SPIT_Message::ReportSPITProject* p_Repo
|
||||
|
||||
//Send RequestProjectTransfer
|
||||
SPIT_Message::RequestProjectTransfer sMRequestProjectTransfer;
|
||||
fillHeader(sMRequestProjectTransfer.getHeader());
|
||||
if (sendSPITMessage(sMRequestProjectTransfer) < 0) {
|
||||
printf("SPIT_Client::parseReportSPITProject could not send RequestProjectTransfer\n");
|
||||
}
|
||||
|
||||
// todo Don't send the ReportSPITProject here it should be sended after parseEndProjectTransfer
|
||||
//Send client's ReportSPITProject
|
||||
SPIT_Message::ReportSPITProject sMReportSPITProject;
|
||||
fillHeader(sMReportSPITProject.getHeader());
|
||||
sMReportSPITProject.setProjectID(m_ProjName);
|
||||
sMReportSPITProject.setProjectName(m_ProjName);
|
||||
sMReportSPITProject.setFramesPerSecond(0);
|
||||
if (sendSPITMessage(sMReportSPITProject) < 0) {
|
||||
printf("SPIT_Client::parseReportSPITProject could not send Client's ReportSPITProject");
|
||||
}
|
||||
|
||||
}
|
||||
void SPIT_Client::parseCloseSPITProject(SPIT_Message::CloseSPITProject* p_CloseSPITProject) {
|
||||
// printf("parse CloseSPITProject \n");
|
||||
if (p_CloseSPITProject == NULL) return;
|
||||
string stringProjectID;
|
||||
mCallbacks.onProjectClosed(p_CloseSPITProject->getProjectID());
|
||||
}
|
||||
|
||||
@@ -648,24 +794,19 @@ int SPIT_Client::getServerFramesPerSecond() { return m_ServerFramesPerSecond; }
|
||||
|
||||
void SPIT_Client::parseRequestProjectTransfer(SPIT_Message::RequestProjectTransfer* p_RequestProjectTransfer) {
|
||||
// printf("parse RequestProjectTransfer \n");
|
||||
int intResult;
|
||||
int intCount;
|
||||
SPITType* ptrSPITType;
|
||||
SPITObject* ptrSPITObject;
|
||||
|
||||
//StartProjectTransfer
|
||||
SPIT_Message::StartProjectTransfer sMStartProjectTransfer;
|
||||
fillHeader(sMStartProjectTransfer.getHeader());
|
||||
intResult = sendSPITMessage(sMStartProjectTransfer);
|
||||
int intResult = sendSPITMessage(sMStartProjectTransfer);
|
||||
if (intResult < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
//send all listes SPITTypes
|
||||
intCount = SPITType::getSPITTypeCount();
|
||||
int intCount = SPITType::getSPITTypeCount();
|
||||
for (int i = 0; i < intCount; i++) {
|
||||
ptrSPITType = SPITType::getSPITType(i);
|
||||
SPITType* ptrSPITType = SPITType::getSPITType(i);
|
||||
if (ptrSPITType == NULL) break;
|
||||
sendSPITTypeInternal(ptrSPITType);
|
||||
fos::Task::delayMs(10);
|
||||
@@ -673,9 +814,9 @@ void SPIT_Client::parseRequestProjectTransfer(SPIT_Message::RequestProjectTransf
|
||||
}
|
||||
|
||||
{
|
||||
intCount = SPITObject::getSPITObjectCount();
|
||||
int intCount = SPITObject::getSPITObjectCount();
|
||||
for (int i = 0; i < intCount; i++) {
|
||||
ptrSPITObject = SPITObject::getSPITObject(i);
|
||||
SPITObject* ptrSPITObject = SPITObject::getSPITObject(i);
|
||||
if (ptrSPITObject == NULL) break;
|
||||
sendSPITObjectInternal(ptrSPITObject);
|
||||
fos::Task::delayMs(10);
|
||||
@@ -688,13 +829,151 @@ void SPIT_Client::parseRequestProjectTransfer(SPIT_Message::RequestProjectTransf
|
||||
intResult = sendSPITMessage(sMEndProjectTransfer);
|
||||
if (intResult < 0) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* NEW IMPLEMENTATION
|
||||
|
||||
void SPIT_Client::parseRequestProjectTransfer(SPIT_Message::RequestProjectTransfer* p_RequestProjectTransfer) {
|
||||
// printf("parse RequestProjectTransfer \n");
|
||||
thread* o_ThreadSend;
|
||||
o_ThreadSend = new thread(&this->sendProject, this);
|
||||
// int intResult;
|
||||
// SPIT_Message::StartProjectTransfer* ptrSMStartProjectTransfer;
|
||||
// SPIT_Message::EndProjectTransfer* ptrSMEndProjectTransfer;
|
||||
// int intCount;
|
||||
// SPITType* ptrSPITType;
|
||||
// SPITObject* ptrSPITObject;
|
||||
|
||||
|
||||
// //StartProjectTransfer
|
||||
// NotifyStartProjectTransfer_Client* o_RunnableStart = new NotifyStartProjectTransfer_Client(m_SPITClientInterface);
|
||||
// SPIT_Handler::addRunnable(o_RunnableStart);
|
||||
|
||||
// ptrSMStartProjectTransfer = new SPIT_Message::StartProjectTransfer();
|
||||
// intResult = sendSPITMessage(ptrSMStartProjectTransfer);
|
||||
// if (intResult < 0) {
|
||||
// return;
|
||||
// }
|
||||
// m_Watchdog->answerWatchdog();
|
||||
// {
|
||||
// //send all listes SPITTypes
|
||||
// unique_lock<recursive_mutex> o_LockType(*SPITType::getMutex());
|
||||
// intCount = SPITType::getSPITTypeCount();
|
||||
// for (int i = 0; i < intCount; i++) {
|
||||
// ptrSPITType = SPITType::getSPITType(i);
|
||||
// if (ptrSPITType == NULL) continue;
|
||||
// intResult = sendSPITTypeInternal(ptrSPITType);
|
||||
// if (intResult < 0) return;
|
||||
// m_Watchdog->answerWatchdog();
|
||||
// this_thread::sleep_for(chrono::milliseconds(7));
|
||||
// }
|
||||
// }
|
||||
|
||||
// {
|
||||
// unique_lock<recursive_mutex> o_LockObject(*SPITObject::getMutex());
|
||||
// intCount = SPITObject::getSPITObjectCount();
|
||||
// for (int i = 0; i < intCount; i++) {
|
||||
// ptrSPITObject = SPITObject::getSPITObject(i);
|
||||
// if (ptrSPITObject == NULL) continue;
|
||||
// intResult = sendSPITObjectInternal(ptrSPITObject);
|
||||
// if (intResult < 0) return;
|
||||
// m_Watchdog->answerWatchdog();
|
||||
// this_thread::sleep_for(chrono::milliseconds(7));
|
||||
// }
|
||||
// }
|
||||
|
||||
// //EndProjectTransfer
|
||||
// ptrSMEndProjectTransfer = new SPIT_Message::EndProjectTransfer();
|
||||
// intResult = sendSPITMessage(ptrSMEndProjectTransfer);
|
||||
// if (intResult < 0) {
|
||||
// return;
|
||||
// }
|
||||
// m_Watchdog->answerWatchdog();
|
||||
// NotifyEndProjectTransfer_Client* o_RunnableEnd = new NotifyEndProjectTransfer_Client(m_SPITClientInterface);
|
||||
// SPIT_Handler::addRunnable(o_RunnableEnd);
|
||||
|
||||
// //Send act
|
||||
}
|
||||
*/
|
||||
|
||||
void SPIT_Client::sendProject(SPIT_Client* p_PtrSPIT_Client) {
|
||||
// int intResult;
|
||||
// SPIT_Message::StartProjectTransfer* ptrSMStartProjectTransfer;
|
||||
// SPIT_Message::EndProjectTransfer* ptrSMEndProjectTransfer;
|
||||
// int intCount;
|
||||
// SPITType* ptrSPITType;
|
||||
// SPITObject* ptrSPITObject;
|
||||
|
||||
// //StartProjectTransfer
|
||||
// NotifyStartProjectTransfer_Client* o_RunnableStart = new NotifyStartProjectTransfer_Client(p_PtrSPIT_Client->getSPITClientInterface());
|
||||
// SPIT_Handler::addRunnable(o_RunnableStart);
|
||||
|
||||
// ptrSMStartProjectTransfer = new SPIT_Message::StartProjectTransfer();
|
||||
// intResult = p_PtrSPIT_Client->sendSPITMessage(ptrSMStartProjectTransfer);
|
||||
// if (intResult < 0) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// // m_Watchdog->answerWatchdog();
|
||||
// // {
|
||||
// //send all listes SPITTypes
|
||||
// // unique_lock<recursive_mutex> o_LockType(*SPITType::getMutex());
|
||||
// intCount = SPITType::getSPITTypeCount();
|
||||
// for (int i = 0; i < intCount; i++) {
|
||||
// ptrSPITType = SPITType::getSPITType(i);
|
||||
// if (ptrSPITType == NULL) continue;
|
||||
// if (ptrSPITType->getCreatedByClient() == false) continue;
|
||||
// intResult = p_PtrSPIT_Client->sendSPITTypeInternal(ptrSPITType);
|
||||
// if (intResult < 0) return;
|
||||
// // m_Watchdog->answerWatchdog();
|
||||
// this_thread::sleep_for(chrono::milliseconds(7));
|
||||
// }
|
||||
// // }
|
||||
|
||||
// // {
|
||||
// // unique_lock<recursive_mutex> o_LockObject(*SPITObject::getMutex());
|
||||
// intCount = SPITObject::getSPITObjectCount();
|
||||
// for (int i = 0; i < intCount; i++) {
|
||||
// ptrSPITObject = SPITObject::getSPITObject(i);
|
||||
// if (ptrSPITObject == NULL) continue;
|
||||
// if (ptrSPITObject->getCreatedByClient() == false) continue;
|
||||
// intResult = p_PtrSPIT_Client->sendSPITObjectInternal(ptrSPITObject);
|
||||
// if (intResult < 0) return;
|
||||
// // m_Watchdog->answerWatchdog();
|
||||
// this_thread::sleep_for(chrono::milliseconds(7));
|
||||
// }
|
||||
// // }
|
||||
|
||||
// //EndProjectTransfer
|
||||
// ptrSMEndProjectTransfer = new SPIT_Message::EndProjectTransfer();
|
||||
// intResult = p_PtrSPIT_Client->sendSPITMessage(ptrSMEndProjectTransfer);
|
||||
// if (intResult < 0) {
|
||||
// return;
|
||||
// }
|
||||
// // m_Watchdog->answerWatchdog();
|
||||
// NotifyEndProjectTransfer_Client* o_RunnableEnd = new NotifyEndProjectTransfer_Client(p_PtrSPIT_Client->getSPITClientInterface());
|
||||
// SPIT_Handler::addRunnable(o_RunnableEnd);
|
||||
|
||||
// //Send act
|
||||
}
|
||||
|
||||
|
||||
void SPIT_Client::parseStartProjectTransfer(SPIT_Message::StartProjectTransfer* p_StartProjectTransfer) {
|
||||
mCallbacks.onStartProjectTransfer();
|
||||
}
|
||||
void SPIT_Client::parseEndProjectTransfer(SPIT_Message::EndProjectTransfer* p_EndProjectTransfer) {
|
||||
SPITObject::clearUnconfirmedSPITObjects();
|
||||
mCallbacks.onEndProjectTransfer();
|
||||
|
||||
//Send SPIT_Message::ReportSPITProject after the m_SPITClientInterface is notfied of EndProjectTransfer
|
||||
SPIT_Message::ReportSPITProject ptrSMReportSPITProject;
|
||||
ptrSMReportSPITProject.setProjectID(m_ProjName);
|
||||
ptrSMReportSPITProject.setProjectName(m_ProjName);
|
||||
ptrSMReportSPITProject.setFramesPerSecond(0);
|
||||
if (sendSPITMessage(ptrSMReportSPITProject) < 0) {
|
||||
printf("SPIT_Client::parseReportSPITProject could not send Client's ReportSPITProject");
|
||||
}
|
||||
}
|
||||
|
||||
//----- SPIT Types ------
|
||||
@@ -703,11 +982,15 @@ void SPIT_Client::parseReportSPITType(SPIT_Message::ReportSPITType* p_ReportSPIT
|
||||
if (p_ReportSPITType == NULL) return;
|
||||
SPITType* ptrSPITType;
|
||||
bool boolNew = false;
|
||||
|
||||
bool boolChanged = false;
|
||||
{
|
||||
if (p_ReportSPITType->getServerRemote() == false) {
|
||||
ptrSPITType = SPITType::getSPITType(p_ReportSPITType->getID());
|
||||
if (ptrSPITType == NULL) {
|
||||
//The user's app my veto the SPITType
|
||||
if (mCallbacks.onCheckSpitTypeVeto(p_ReportSPITType) == false) {
|
||||
return;
|
||||
}
|
||||
ptrSPITType = new SPITType();
|
||||
boolNew = true;
|
||||
}
|
||||
@@ -719,7 +1002,10 @@ void SPIT_Client::parseReportSPITType(SPIT_Message::ReportSPITType* p_ReportSPIT
|
||||
boolNew = true;
|
||||
}
|
||||
}
|
||||
if (ptrSPITType->setMessageOP(p_ReportSPITType) == false) {
|
||||
try {
|
||||
boolChanged = ptrSPITType->setMessageOP(p_ReportSPITType);
|
||||
}
|
||||
catch (...) {
|
||||
//SPITType is not changable -> send back to the server
|
||||
sendSPITTypeInternal(ptrSPITType);
|
||||
return;
|
||||
@@ -736,7 +1022,7 @@ void SPIT_Client::parseReportSPITType(SPIT_Message::ReportSPITType* p_ReportSPIT
|
||||
}
|
||||
|
||||
if (ptrSPITType != NULL) {
|
||||
if (ptrSPITType->setConfirmed(true) == true) {
|
||||
if (ptrSPITType->setConfirmed(true) == true || boolChanged == true) {
|
||||
sendSPITTypeInternal(ptrSPITType);
|
||||
}
|
||||
}
|
||||
@@ -796,7 +1082,6 @@ int SPIT_Client::sendSPITTypeInternal(SPITType* p_SPITType) {
|
||||
if (p_SPITType == NULL) return -1;
|
||||
SPIT_Message::ReportSPITType ptrSMReportSPITType;
|
||||
p_SPITType->fillMessageOP(&ptrSMReportSPITType);
|
||||
fillHeader(ptrSMReportSPITType.getHeader());
|
||||
return sendSPITMessage(ptrSMReportSPITType);
|
||||
}
|
||||
|
||||
@@ -841,7 +1126,6 @@ int SPIT_Client::removeSPITType(string p_SPITTypeID) {
|
||||
if (ptrSPITType == NULL) return -1;
|
||||
SPIT_Message::RemoveSPITType sMRemoveSPITType;
|
||||
ptrSPITType->fillMessageOP(&sMRemoveSPITType);
|
||||
fillHeader(sMRemoveSPITType.getHeader());
|
||||
mCallbacks.onSpitTypeRemoved(*ptrSPITType);
|
||||
SPITType::removeSPITType(ptrSPITType);
|
||||
delete ptrSPITType;
|
||||
@@ -891,18 +1175,47 @@ void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject* p_Report
|
||||
SPITType* ptrSPITType;
|
||||
bool boolNew = false;
|
||||
bool boolRemote = false;
|
||||
bool boolChanged = false;
|
||||
{
|
||||
if (p_ReportSPITObject->getServerRemote() == false) {
|
||||
boolRemote = false;
|
||||
ptrSPITObject = SPITObject::getSPITObject(p_ReportSPITObject->getID());
|
||||
ptrSPITType = SPITType::getSPITType(p_ReportSPITObject->getSPITTypeID());
|
||||
|
||||
|
||||
if (ptrSPITType == NULL) {
|
||||
//No associated SPITType found
|
||||
if (ptrSPITObject != NULL) {
|
||||
//SpitObject exists but has no corresponding SPITType -> remove the SPITObject without sending a message
|
||||
//Maybe the SPITObject has changed the SPITTypeID to a SPITTypeID of another board
|
||||
SPITObject::removeSPITObject(ptrSPITObject);
|
||||
delete ptrSPITObject;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (ptrSPITObject == NULL) {
|
||||
//The user's app my veto the SPITType
|
||||
if (mCallbacks.onCheckSpitObjectVeto(p_ReportSPITObject) == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
ptrSPITObject = new SPITObject();
|
||||
boolNew = true;
|
||||
}
|
||||
else {
|
||||
//The user's app my veto the SPITType
|
||||
if (mCallbacks.onCheckSpitObjectVeto(p_ReportSPITObject) == false) {
|
||||
//SpitObject exists and User APp denied the SPITObject -> remove the SPITObject without sending a message
|
||||
SPITObject::removeSPITObject(ptrSPITObject);
|
||||
delete ptrSPITObject;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
boolRemote = true;
|
||||
ptrSPITObject = SPITObject::getSPITObjectRemote(p_ReportSPITObject->getID());
|
||||
ptrSPITType = SPITType::getSPITTypeRemote(p_ReportSPITObject->getSPITTypeID());
|
||||
}
|
||||
if (ptrSPITType == NULL) {
|
||||
//No associated SPITType found
|
||||
return;
|
||||
@@ -911,8 +1224,17 @@ void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject* p_Report
|
||||
ptrSPITObject = new SPITObject();
|
||||
boolNew = true;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
boolChanged = ptrSPITObject->setMessageOP(p_ReportSPITObject);
|
||||
}
|
||||
catch (...) {
|
||||
//setMessageOP error - the SPITObject can't be changed, it may be fixed and crated by this client
|
||||
sendSPITObjectInternal(ptrSPITObject);
|
||||
return;
|
||||
}
|
||||
|
||||
ptrSPITObject->setMessageOP(p_ReportSPITObject);
|
||||
|
||||
if (boolRemote == false) {
|
||||
//set the virtual action assignment
|
||||
@@ -930,7 +1252,7 @@ void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject* p_Report
|
||||
mCallbacks.onSpitObject(boolNew, *ptrSPITType, *ptrSPITObject);
|
||||
}
|
||||
|
||||
if (ptrSPITObject->setConfirmed(true) == true) {
|
||||
if (ptrSPITObject->setConfirmed(true) == true || boolChanged == true) {
|
||||
//Confirmation has changed
|
||||
sendSPITObjectInternal(ptrSPITObject);
|
||||
}
|
||||
@@ -976,7 +1298,6 @@ int SPIT_Client::sendSPITObjectInternal(SPITObject* ptrSPITObject) {
|
||||
if (ptrSPITObject == NULL) return -1;
|
||||
SPIT_Message::ReportSPITObject ptrSMReportSPITObject;
|
||||
ptrSPITObject->fillMessageOP(&ptrSMReportSPITObject);
|
||||
fillHeader(ptrSMReportSPITObject.getHeader());
|
||||
|
||||
return sendSPITMessage(ptrSMReportSPITObject);
|
||||
}
|
||||
@@ -1041,7 +1362,6 @@ int SPIT_Client::removeSPITObject(string p_SPITObjectID) {
|
||||
ptrSPITType = SPITType::getSPITType(ptrSPITObject->getSPITTypeID());
|
||||
if (ptrSPITType == NULL) return -1;
|
||||
ptrSPITObject->fillMessageOP(&sMRemoveSPITObject);
|
||||
fillHeader(sMRemoveSPITObject.getHeader());
|
||||
mCallbacks.onSpitObjectRemoved(*ptrSPITType, *ptrSPITObject);
|
||||
SPITObject::removeSPITObject(ptrSPITObject);
|
||||
delete ptrSPITObject;
|
||||
@@ -1071,30 +1391,24 @@ void SPIT_Client::parsePlaySPITStart(SPIT_Message::PlaySPITStart* p_PlaySPITStar
|
||||
void SPIT_Client::parsePlaySPITObject(SPIT_Message::PlaySPITObject* p_PlaySPITObject) {
|
||||
// printf("parse RPlaySPITObject Object:%s\n", p_PlaySPITObject->getSPITObjectID());
|
||||
SPITPlayer* ptrSPITPlayer;
|
||||
SPITPlayer::PlayObject* ptrPlayObject;
|
||||
SPITPlayer::PlaySPITType* ptrPlaySPITType;
|
||||
SPITObject* ptrSPITObject;
|
||||
{
|
||||
ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITObject->getPlayerID());
|
||||
if (ptrSPITPlayer == NULL) return;
|
||||
ptrPlayObject = ptrSPITPlayer->addSPITObject_Playing(p_PlaySPITObject->getSPITObjectID());
|
||||
|
||||
//Fetch infoemations from SPITObject
|
||||
{
|
||||
|
||||
|
||||
ptrSPITObject = SPITObject::getSPITObject(p_PlaySPITObject->getSPITObjectID());
|
||||
if (ptrSPITObject == NULL) {
|
||||
return;
|
||||
}
|
||||
if (ptrPlayObject == NULL) {
|
||||
ptrPlaySPITType = ptrSPITPlayer->addSPITType_Playing(ptrSPITObject->getSPITTypeID());
|
||||
if (ptrPlaySPITType == NULL) {
|
||||
|
||||
return;
|
||||
}
|
||||
ptrPlayObject->setPlayerIsRunning(ptrSPITPlayer->getIsRunning());
|
||||
ptrPlayObject->setFrameInside(p_PlaySPITObject->getFrameInsideObject(), p_PlaySPITObject->getPlayPrePosition());
|
||||
ptrPlayObject->setValue(p_PlaySPITObject->getValue(), p_PlaySPITObject->getPlayPrePosition());
|
||||
ptrPlayObject->setValueFactor(ptrSPITObject->getValueFactor());
|
||||
ptrPlayObject->setValueFlag(p_PlaySPITObject->getValueFlag());
|
||||
}
|
||||
ptrPlaySPITType->setPlayerIsRunning(ptrSPITPlayer->getIsRunning());
|
||||
ptrPlaySPITType->addValue(((double)p_PlaySPITObject->getValue()/1000000), ((double)ptrSPITObject->getValueFactor()/1000000));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1102,44 +1416,69 @@ void SPIT_Client::parsePlaySPITEnd(SPIT_Message::PlaySPITEnd* p_PlaySPITEnd) {
|
||||
// printf("parse PlaySPITEnd \n");
|
||||
SPITPlayer* ptrSPITPlayer;
|
||||
SPITType* ptrSPITType = NULL;
|
||||
SPITObject* ptrSPITObject = NULL;
|
||||
|
||||
{
|
||||
// {
|
||||
// ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITEnd->getPlayerID());
|
||||
// if (ptrSPITPlayer == NULL) return;
|
||||
|
||||
// unordered_map<string, SPITPlayer::PlayObject*>* ptrPlayObjects;
|
||||
// SPITPlayer::PlayObject* ptrPlayObject;
|
||||
// bool boolStarted;
|
||||
// bool boolStopped;
|
||||
|
||||
// ptrPlayObjects = ptrSPITPlayer->getPlayObjects();
|
||||
// for (auto i = ptrPlayObjects->begin(); i != ptrPlayObjects->end(); i++) {
|
||||
// ptrPlayObject = i->second;
|
||||
// boolStarted = false;
|
||||
// boolStopped = false;
|
||||
// if (ptrPlayObject->getIsNew()) {
|
||||
// boolStarted = true;
|
||||
// }
|
||||
// if (ptrPlayObject->getIsPlayed() == false) {
|
||||
// boolStopped = true;
|
||||
// }
|
||||
// {
|
||||
// ptrSPITObject = SPITObject::getSPITObject(ptrPlayObject->getSPITObjectID());
|
||||
// if (ptrSPITObject == NULL) {
|
||||
// return;
|
||||
// }
|
||||
// ptrSPITType = SPITType::getSPITType(ptrSPITObject->getSPITTypeID());
|
||||
// if (ptrSPITType == NULL) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// mCallbacks.onPlaySpitType(ptrPlayObject->getPlayerID(), boolStarted, boolStopped, *ptrSPITType, *ptrSPITObject, *ptrPlayObject);
|
||||
// }
|
||||
// }
|
||||
// ptrSPITPlayer->endPlaySequence();
|
||||
// }
|
||||
|
||||
ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITEnd->getPlayerID());
|
||||
if (ptrSPITPlayer == NULL) return;
|
||||
|
||||
unordered_map<string, SPITPlayer::PlayObject*>* ptrPlayObjects;
|
||||
SPITPlayer::PlayObject* ptrPlayObject;
|
||||
bool boolStarted;
|
||||
bool boolStopped;
|
||||
|
||||
ptrPlayObjects = ptrSPITPlayer->getPlayObjects();
|
||||
for (auto i = ptrPlayObjects->begin(); i != ptrPlayObjects->end(); i++) {
|
||||
ptrPlayObject = i->second;
|
||||
boolStarted = false;
|
||||
boolStopped = false;
|
||||
if (ptrPlayObject->getIsNew()) {
|
||||
unordered_map<string, SPITPlayer::PlaySPITType*>* ptrPlaySPITTypes = ptrSPITPlayer->getPlaySPITTypes();
|
||||
for (auto i = ptrPlaySPITTypes->begin(); i != ptrPlaySPITTypes->end(); i++) {
|
||||
SPITPlayer::PlaySPITType* ptrPlaySPITType = i->second;
|
||||
bool boolStarted = false;
|
||||
bool boolStopped = false;
|
||||
if (ptrPlaySPITType->getIsNew()) {
|
||||
boolStarted = true;
|
||||
}
|
||||
if (ptrPlayObject->getIsPlayed() == false) {
|
||||
if (ptrPlaySPITType->getIsPlayed() == false) {
|
||||
boolStopped = true;
|
||||
}
|
||||
{
|
||||
ptrSPITObject = SPITObject::getSPITObject(ptrPlayObject->getSPITObjectID());
|
||||
if (ptrSPITObject == NULL) {
|
||||
return;
|
||||
}
|
||||
ptrSPITType = SPITType::getSPITType(ptrSPITObject->getSPITTypeID());
|
||||
ptrSPITType = SPITType::getSPITType(ptrPlaySPITType->getSPITTypeID());
|
||||
if (ptrSPITType == NULL) {
|
||||
return;
|
||||
//set isplayed to false, the ptrPlayObject will be removed by ptrSPITPlayer->endPlaySequence()
|
||||
ptrPlaySPITType->setIsPlayed(false);
|
||||
continue;
|
||||
}
|
||||
|
||||
mCallbacks.onPlayObject(ptrPlayObject->getPlayerID(), boolStarted, boolStopped, *ptrSPITType, *ptrSPITObject, *ptrPlayObject);
|
||||
mCallbacks.onPlaySpitType(ptrPlaySPITType->getPlayerID(), ptrPlaySPITType->getSPITTypeID(), ptrPlaySPITType->getPlayerIsRunning(), boolStarted, boolStopped, ptrPlaySPITType->getValue() );
|
||||
}
|
||||
}
|
||||
ptrSPITPlayer->endPlaySequence();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SPIT_Client::parseReportPlayStatus(SPIT_Message::ReportPlayStatus* p_ReportPlayStatus) {
|
||||
@@ -1151,10 +1490,19 @@ void SPIT_Client::parseReportPlayStatus(SPIT_Message::ReportPlayStatus* p_Report
|
||||
|
||||
|
||||
ptrSPITObject = SPITObject::getSPITObjectRemote(p_ReportPlayStatus->getID());
|
||||
if (ptrSPITObject == NULL) {
|
||||
ptrSPITObject = SPITObject::getSPITObject(p_ReportPlayStatus->getID());
|
||||
if (ptrSPITObject == NULL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (ptrSPITObject->getServerRemote() == false) {
|
||||
ptrSPITType = SPITType::getSPITType(ptrSPITObject->getSPITTypeID());
|
||||
}
|
||||
else {
|
||||
ptrSPITType = SPITType::getSPITTypeRemote(ptrSPITObject->getSPITTypeID());
|
||||
}
|
||||
|
||||
if (ptrSPITType == NULL) {
|
||||
return;
|
||||
}
|
||||
@@ -1185,7 +1533,6 @@ void SPIT_Client::sendRemoteObject(string p_SPITObjectID, int p_Valueppm, char p
|
||||
if (ptrRemoteSPITObject == NULL) return;
|
||||
|
||||
SPIT_Message::PlaySPITStart playSPITStart;
|
||||
fillHeader(playSPITStart.getHeader());
|
||||
playSPITStart.setPlayerID(m_ID);
|
||||
playSPITStart.setPlayerName(m_ProjName);
|
||||
playSPITStart.setPlayerIsRunning(false);
|
||||
@@ -1194,7 +1541,6 @@ void SPIT_Client::sendRemoteObject(string p_SPITObjectID, int p_Valueppm, char p
|
||||
sendSPITMessage(playSPITStart);
|
||||
|
||||
SPIT_Message::PlaySPITObject playSPITObject;
|
||||
fillHeader(playSPITObject.getHeader());
|
||||
playSPITObject.setID(ptrRemoteSPITObject->getID());
|
||||
playSPITObject.setPlayPrePosition(false);
|
||||
playSPITObject.setPlayerID(m_ID);
|
||||
@@ -1203,7 +1549,6 @@ void SPIT_Client::sendRemoteObject(string p_SPITObjectID, int p_Valueppm, char p
|
||||
sendSPITMessage(playSPITObject);
|
||||
|
||||
SPIT_Message::PlaySPITEnd playSPITEnd;
|
||||
fillHeader(playSPITEnd.getHeader());
|
||||
playSPITEnd.setPlayerID(m_ID);
|
||||
sendSPITMessage(playSPITEnd);
|
||||
}
|
||||
@@ -1223,7 +1568,7 @@ static constexpr int WATCHDOGTIME = 3000;
|
||||
string stringDatagram = SERVERAUTODETECT_PRECODE + SERVERAUTODETECT_SEPERATOR + SERVERAUTODETECT_TASKID;
|
||||
int intDatagramLength = stringDatagram.length();
|
||||
string stringPart;
|
||||
string stringParts[9];
|
||||
string stringParts[10];
|
||||
|
||||
while (true) {
|
||||
sStartSad.take();
|
||||
@@ -1266,7 +1611,7 @@ static constexpr int WATCHDOGTIME = 3000;
|
||||
}
|
||||
int intIndex = 0;
|
||||
int intOldPos = 0;
|
||||
while (intIndex < 8) {
|
||||
while (intIndex < SAD_DetectedServer::PARAMINDEX_IP) {
|
||||
int intPos = stringMessage.find(SERVERAUTODETECT_SEPERATOR.data(), intOldPos);
|
||||
if (intPos == string::npos) {
|
||||
stringPart = "";
|
||||
@@ -1277,7 +1622,7 @@ static constexpr int WATCHDOGTIME = 3000;
|
||||
stringParts[intIndex] = stringPart;
|
||||
intIndex++;
|
||||
}
|
||||
stringParts[8] = stringServerIP;
|
||||
stringParts[SAD_DetectedServer::PARAMINDEX_IP] = stringServerIP;
|
||||
SAD_DetectedServer::addDetectedServer(true, stringParts[SAD_DetectedServer::PARAMINDEX_ID], stringParts);
|
||||
}
|
||||
fos::Task::delayMs(100);
|
||||
|
||||
Reference in New Issue
Block a user