refactor: Heavy refactoring to modern code style

This commit is contained in:
2025-04-03 21:31:08 +02:00
parent 04a8904cbe
commit 9ebbedb04a
32 changed files with 2360 additions and 4112 deletions
-39
View File
@@ -1,39 +0,0 @@
#pragma once
#include <string>
using namespace std;
class SAD_DetectedServer;
class I_SAD_Client {
public:
/**
* If a new server was found by the ServerAutoDetect mechanism, this function is called.<br>
* To do so the SAD_Client ServerAutoDetect has to be startet - see SAD_Client::startServerAutoDetect.<br>
* If a server can be reached via several IP addresses, the IP address is selected according to the following preference:<br>
* 1.) If a loopback address is available, it is used.<br>
* 2.) If an IP4 address is available, it is used.<br>
* 3.) In the other cases the IP6 address is used.<br>
* @param p_ID the id of the server (every started server should generate an id)
* @param p_Name the name of the SPIT server
* @param p_ComputerName the Hostname of the cpmputer on which the SPIT server is running
* @param p_IP the selected ip address of the SPIT server
* @param p_Port the port of the SPIT server
* @param p_Addition sometimes server may have additional informations
* @param p_IsIP4 the server ip is a ip4 address
*/
virtual void eventServerDetected(SAD_DetectedServer &server) = 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>
* @param p_ID the id of the server (every started server should generate an id)
* @param p_Name the name of the SPIT server
* @param p_ComputerName the Hostname of the cpmputer on which the SPIT server is running
* @param p_IP the selected ip address of the SPIT server
* @param p_Port the port of the SPIT server
* @param p_Addition sometimes server may have additional informations
* @param p_IsIP4 the server ip is a ip4 address
*/
virtual void eventServerChanged(SAD_DetectedServer &server) = 0;
virtual void eventServerLost(SAD_DetectedServer &server) = 0;
};
+97 -66
View File
@@ -1,39 +1,47 @@
#pragma once
#include "I_SAD_Client.hpp"
#include <list>
#include <memory>
#include <string>
#include <unordered_map>
using namespace std;
class SAD_DetectedServer {
class SAD_DetectedServer;
class I_SAD_Client {
public:
SAD_DetectedServer();
SAD_DetectedServer(const SAD_DetectedServer &orig) {
m_ID = orig.getID();
m_Name = orig.getName();
m_ComputerName = orig.getComputerName();
m_IP = orig.getIP();
m_ClientIP = orig.getClientIP();
m_Port = orig.getPort();
m_Additions = orig.getAdditions();
virtual void eventServerDetected(SAD_DetectedServer &server) = 0;
virtual void eventServerChanged(SAD_DetectedServer &server) = 0;
virtual void eventServerLost(SAD_DetectedServer &server) = 0;
};
class SAD_DetectedServer {
public:
SAD_DetectedServer(string p_Name, string p_ID, string p_ComputerName,
string p_IP, string p_Port, string p_ClientIP,
string p_Additions, string projName)
: m_Name(p_Name),
m_ID(p_ID),
m_ComputerName(p_ComputerName),
m_IP(p_IP),
m_Port(p_Port),
m_ClientIP(p_ClientIP),
m_Additions(p_Additions),
m_ServerProjectName(projName) {
}
~SAD_DetectedServer();
private:
string m_ID;
string m_Name;
string m_ComputerName;
string m_IP;
string m_ClientIP;
string m_Port;
string m_Additions;
string m_ServerProjectName;
bool m_New;
bool m_Changed;
bool m_FoundAgain;
string m_Name{};
string m_ID{};
string m_ComputerName{};
string m_IP{};
string m_Port{};
string m_ClientIP{};
string m_Additions{};
string m_ServerProjectName{};
bool m_New{true};
bool m_Changed{};
bool m_FoundAgain{};
public:
string getID() const { return m_ID; }
@@ -44,70 +52,91 @@ class SAD_DetectedServer {
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; }
void setComputerName(string p_ComputerName) { m_ComputerName = p_ComputerName; }
void setIP(string p_IP) { m_IP = p_IP; }
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);
bool getNew() const { return m_New; }
bool getChanged() const { return m_Changed; }
bool getFoundAgain() const { return m_FoundAgain; }
void setChanged() { m_Changed = true; }
void setNew(bool p_New) { m_New = p_New; }
void setKnown() { m_New = false; }
void setFoundAgain() { m_FoundAgain = true; }
void updateProjectName(string newProjectName) {
m_ServerProjectName = newProjectName;
if (m_ServerProjectName != newProjectName) {
m_Changed = true;
}
}
// SAD_Client m_ThreadSend will send to Multicast addresses
void startCycleSAD() {
void resetFlags() {
m_Changed = false;
m_FoundAgain = false;
m_New = false;
}
private:
static unordered_map<string, SAD_DetectedServer *> s_DetectedServers;
static unordered_map<string, unique_ptr<SAD_DetectedServer>> sKnownServers;
public:
static const int PARAMINDEX_PRECODE = 0;
static const int PARAMINDEX_SPITTASKID = 1;
static const int PARAMINDEX_NAME = 2;
static const int PARAMINDEX_ID = 3;
static const int PARAMINDEX_COMPUTERNAME = 4;
static const int PARAMINDEX_PORT = 5;
static const int PARAMINDEX_CLIENTIP = 6;
static const int PARAMINDEX_ADDITIONS = 7;
static const int PARAMINDEX_SERVERPROJECTNAME = 8;
static const int PARAMINDEX_IP = 9;
static constexpr int PARAMINDEX_PRECODE = 0;
static constexpr int PARAMINDEX_SPITTASKID = 1;
static constexpr int PARAMINDEX_NAME = 2;
static constexpr int PARAMINDEX_ID = 3;
static constexpr int PARAMINDEX_COMPUTERNAME = 4;
static constexpr int PARAMINDEX_PORT = 5;
static constexpr int PARAMINDEX_CLIENTIP = 6;
static constexpr int PARAMINDEX_ADDITIONS = 7;
static constexpr int PARAMINDEX_SERVERPROJECTNAME = 8;
static constexpr 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
* @param p_ServerID the id of the server, every instance of a SPITServer has an own id
* @param id the id of the server, every instance of a SPITServer has an own id
* @param p_ServerParams the server's parameter
*/
static void addDetectedServer(string p_ServerID, string p_ServerParams[]);
/**
* Used by SAD_Client to remove a SPITServer - don't use this manually
* @param p_DetectedServer
*/
static void removeDetectedServer(SAD_DetectedServer &server);
/**
* Used by SAD_Client to clear all found SPITServers - don't use this manually
*/
static void clearDetectedServers();
/**
* Used by SAD_Client internally - don't use this manually
*/
static void cycleStart();
static void addDetectedServer(unique_ptr<SAD_DetectedServer> detected) {
if (auto i = sKnownServers.find(detected->getID()); i != sKnownServers.end()) {
auto &known = *(i->second.get());
known.setFoundAgain();
if (detected->getProjectName() != known.getProjectName()) {
known.updateProjectName(detected->getProjectName());
}
return;
}
sKnownServers[detected->getID()] = move(detected);
}
static void removeDetectedServer(SAD_DetectedServer &server) {
auto i = sKnownServers.find(server.getID());
if (i != sKnownServers.end()) {
sKnownServers.erase(i);
}
}
static void clearDetectedServers() {
sKnownServers.clear();
}
static void resetServerFlags() {
for (auto &srv : sKnownServers) {
srv.second->resetFlags();
}
}
/**
* Used by SAD_Client internally -don't use this manually
* @param p_SADClientInterface
*/
static void cycleEnd(I_SAD_Client &p_SADClientInterface);
static void evaluateDetectedServers(I_SAD_Client &sadClient) {
for (auto &srv : sKnownServers) {
SAD_DetectedServer &known = *srv.second;
if (known.getNew()) {
known.setKnown();
sadClient.eventServerDetected(known);
} else if (known.getChanged()) {
sadClient.eventServerChanged(known);
} else if (known.getFoundAgain() == false) {
sadClient.eventServerLost(known);
removeDetectedServer(known);
}
}
}
/**
* Returns a reference of the DetectedServer with the id p_ServerID.<br>
@@ -115,5 +144,7 @@ class SAD_DetectedServer {
* @param p_ServerID the id of the SPITServer
* @return the reference of the SAD_DetectedServer instance with getID() == p_ServerID
*/
static const SAD_DetectedServer &getRefDetectedServer(string p_ServerID);
static const SAD_DetectedServer &getRefDetectedServer(const string &id) {
return *sKnownServers.at(id);
}
};
+38 -68
View File
@@ -16,76 +16,47 @@
#include "SPITType.h"
#include "SPIT_Message.h"
#include <string>
#include <unordered_map>
#include "SpitRepo.hpp"
using namespace std;
class SPITObjectListener;
class SPITObject {
private:
static unordered_map<string, SPITObject *> s_SPITObjects;
static unordered_map<string, SPITObject *> s_SPITObjectsRemote;
public:
static SPITObject *getSPITObject(string p_ID);
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 void clearUnconfirmedSPITObjects(SpitRepo<SPITObject> &repo);
static void setConfirmedFalse(SpitRepo<SPITObject> &repo);
static void eventProjectClosed(SpitRepo<SPITObject> &repo, SpitRepo<SPITObject> &remoteRepo);
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();
SPITObject(string p_ID);
private:
string m_ID;
string m_Name;
string m_SPITTypeID;
string m_ServerParams;
string m_Remark;
bool m_Confirmed;
bool m_Fixed;
bool m_CreatedByClient;
bool m_ServerRemote;
bool m_ActionAssigned;
bool m_ActionAssignedType; // Virtual construct
long long m_FrameStart;
long long m_FrameLength;
long long m_FrameFadeInLength;
long long m_FrameFadeOutLength;
char m_ValueUse;
int m_ValueFactor;
int m_Track;
long long m_Delay;
long long m_Duration;
string m_Name{};
string m_SPITTypeID{};
string m_ServerParams{};
string m_Remark{};
bool m_Confirmed{};
bool m_Fixed{};
bool m_CreatedByClient{};
bool m_ServerRemote{};
bool m_ActionAssigned{};
bool m_ActionAssignedType{}; // Virtual construct
long long m_FrameStart{};
long long m_FrameLength{};
long long m_FrameFadeInLength{};
long long m_FrameFadeOutLength{};
char m_ValueUse{0x01};
int m_ValueFactor{1000000}; // Values are given in ppm -> 1000000 = 1/1;
int m_Track{};
long long m_Delay{};
long long m_Duration{};
bool m_PlayPrePosition;
long long m_PlayTimeInsideFrames;
int m_PlayValue;
char m_PlayValueFlag;
void initMembers();
public:
string getID() const { return m_ID; }
string getName() const { return m_Name; }
@@ -95,7 +66,7 @@ class SPITObject {
/**
* 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>
* @return false = the action is triggered on the client The client waits for the server to play objects of this SPITType
* 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; }
@@ -106,16 +77,16 @@ class SPITObject {
*/
bool getConfirmed() const { return m_Confirmed; }
bool getFixed() const { return m_Fixed; }
bool getCreatedByClient() { return m_CreatedByClient; }
bool getCreatedByClient() const { 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>
* This is a virtual construct - ActionAssignedType is not implemented in the SPITProtocol.
* This is used when an action is associated with a SPITType.
* 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; }
/** Returns if this SPITObject has an associated action or not.<br>
* @return true = the user has asscociated an action with this SPITObject or <br>
/** Returns if this SPITObject has an associated action or not.
* @return true = the user has asscociated an action with this SPITObject or
* the user has asscociated an action with the SPITType of this SPITObject
*/
bool getActionAssigned() const { return m_ActionAssigned || m_ActionAssignedType; }
@@ -132,24 +103,23 @@ class SPITObject {
long long getDelay() const { return m_Delay; }
long long getDuration() const { return m_Duration; }
bool getProjectIndepended() const {
bool getProjectIndepended(SpitRepo<SPITType> &repo, SpitRepo<SPITType> &remoteRepo) const {
SPITType *ptrSPITType;
if (m_ServerRemote == false) {
ptrSPITType = SPITType::getSPITType(m_SPITTypeID);
if (ptrSPITType == NULL)
ptrSPITType = repo.getEntry(m_SPITTypeID);
if (ptrSPITType == nullptr)
return true;
return ptrSPITType->getProjectIndepended();
} else {
ptrSPITType = SPITType::getSPITTypeRemote(m_SPITTypeID);
if (ptrSPITType == NULL)
ptrSPITType = remoteRepo.getEntry(m_SPITTypeID);
if (ptrSPITType == nullptr)
return true;
return ptrSPITType->getProjectIndepended();
}
};
void setID(string p_ID);
bool setConfirmed(bool p_Confirmed);
void setCreatedByClient(bool p_CreatedByClient);
void setCreatedByClient(bool p_CreatedByClient) { m_CreatedByClient = p_CreatedByClient; }
bool setName(string p_Name);
bool setRemark(string p_Remark);
bool setServerParams(string p_ServerParams);
@@ -169,8 +139,8 @@ class SPITObject {
bool setDuration(long long p_Duration);
bool setMessageOP(SPIT_Message::ReportSPITObject *p_ReportSPITObject);
void fillMessageOP(SPIT_Message::ReportSPITObject *p_ReportSPITObject);
void fillMessageOP(SPIT_Message::RemoveSPITObject *p_RemoveSPITObject);
void fillMessageOP(SPIT_Message::ReportSPITObject &p_ReportSPITObject);
void fillMessageOP(SPIT_Message::RemoveSPITObject &p_RemoveSPITObject);
};
#endif /* SPITOBJECT_H */
+11 -13
View File
@@ -23,13 +23,10 @@ class SPITPlayer {
public:
class PlaySPITType {
public:
PlaySPITType();
PlaySPITType(SPITPlayer *p_SPITPlayer, string p_SPITObjectID);
PlaySPITType(const PlaySPITType &orig);
string getSPITTypeID() const {
return m_SPITTypeID;
}
string getSPITTypeID() const { return m_SPITTypeID; }
void startPlaySequence();
bool getIsNew() const { return m_IsNew; }
@@ -57,9 +54,9 @@ class SPITPlayer {
//----- SPITPlayer ------
public:
// list the SPITPlayers
static unordered_map<string, SPITPlayer *> s_SPITPlayers; // all actual played objects
static SPITPlayer *getSPITPlayer(string p_PlayerID); // if a player does not exist creates a new one
static void clearPlayers();
static unordered_map<string, unique_ptr<SPITPlayer>> s_SPITPlayers; // all actual played objects
static SPITPlayer &getSPITPlayer(string p_PlayerID); // if a player does not exist creates a new one
static void clearPlayers() { s_SPITPlayers.clear(); }
SPITPlayer(string p_PlayerID);
virtual ~SPITPlayer();
@@ -72,21 +69,22 @@ class SPITPlayer {
return m_ID;
}
unordered_map<string, PlaySPITType *> *getPlaySPITTypes();
unordered_map<string, unique_ptr<PlaySPITType>> &getPlaySPITTypes() { return m_PlaySPITTypes; }
void setIsRunning(bool p_IsRunning) { m_IsRunning = p_IsRunning; }
void setName(string p_Name) { m_Name = p_Name; }
void setType(char p_Type) { m_Type = p_Type; }
void setTime(long long p_Frames) { m_TimeFrames = p_Frames; }
bool getIsRunning() { return m_IsRunning; }
string getName() { return m_Name; }
char getType() { return m_Type; }
long long getTime() { return m_TimeFrames; }
bool getIsRunning() const { return m_IsRunning; }
string getName() const { return m_Name; }
char getType() const { return m_Type; }
long long getTime() const { return m_TimeFrames; }
private:
string m_ID;
string m_Name;
char m_Type;
unordered_map<string, PlaySPITType *> m_PlaySPITTypes;
unordered_map<string, unique_ptr<PlaySPITType>> m_PlaySPITTypes;
bool m_IsRunning;
long long m_TimeFrames;
};
+34 -51
View File
@@ -79,14 +79,6 @@ class SPITSocket {
//-------- class --------------
SPITSocket(IPAddress ip) : mOwnIp(ip) {
m_UDPSocketIP4 = INVALID_SOCKET;
m_ServerIP = "";
m_ServerPort = "";
m_ClientIP = "";
m_ClientPort = "";
m_BoundClientPort = "";
m_BoundClientFamily = 0;
m_IsBound = false;
createSocket_UDP();
}
virtual ~SPITSocket() {
@@ -102,65 +94,56 @@ class SPITSocket {
}
private:
string m_ServerIP;
string m_ServerPort;
string m_ClientIP;
string m_ClientPort; // port given by the user maybe "0"
string m_BoundClientPort; // port set after bind
int m_BoundClientFamily;
bool m_IsBound;
string m_ServerIP{};
string m_ServerPort{};
string m_ClientIP{};
string m_ClientPort{}; // port given by the user maybe "0"
string m_BoundClientPort{}; // port set after bind
bool m_IsBound{};
public:
/**
* Sets the ip address and port for server and client.
* @param p_ServerIP
* @param p_ServerPort
* @param p_ClientIP
* @param p_ClientPort
*/
void setConnectionParams(string p_ServerIP, string p_ServerPort, string p_ClientIP, string p_ClientPort) {
m_ServerIP = p_ServerIP;
m_ServerPort = p_ServerPort;
m_ClientIP = p_ClientIP;
m_ClientPort = p_ClientPort;
// Sets the ip address and port for server and client.
void setConnectionParams(const string &serverIp, const string &serverPort, const string &clientIp, const string &clientPort) {
m_ServerIP = serverIp;
m_ServerPort = serverPort;
m_ClientIP = clientIp;
m_ClientPort = clientPort;
}
/**
* Send a message to the server as set by setConnectionParams
* @param p_MessageBytes byte buffer containing the message
* @param p_MessageLength length of the messaeg
* @param message byte buffer containing the message
* @param length length of the message
* @return
*/
int sendMessage(const char *p_MessageBytes, int p_MessageLength) {
if (m_ServerPort.length() <= 0)
int sendMessage(const char *message, int length) {
if (m_ServerPort.length() <= 0) {
return -1;
int intResult;
{
if (m_IsBound == false)
return -1;
intResult = sendMessageTo(m_BoundClientFamily, m_ServerIP, m_ServerPort, p_MessageBytes, p_MessageLength);
}
if (m_IsBound == false) {
return -1;
}
int intResult = sendMessageTo(m_ServerIP, m_ServerPort, message, length);
return intResult;
}
int receiveMessage(int p_InetFamily, char *p_Buffer, int p_BufferLength, string *p_ServerIP);
int setBroadcast(bool p_Broadcast);
int bindSocket(string p_ServerIP, string p_ClientIP, string p_ClientPort);
int receiveMessage(char *p_Buffer, int p_BufferLength, string *serverIp) const;
int setBroadcast(bool p_Broadcast) const;
int bindSocket(string clientIp, string clientPort);
// * Internal usage - don't use this manually
// * Use sendMessage instead
int sendMessageTo(int p_InetFamily, string p_ServerIP, string p_Port, const char *p_MessageBytes, int p_MessageLength);
int sendMessageTo(const string &ip, const string &port, const char *message, int msgLength);
string getServerIP() { return m_ServerIP; }
string getServerPort() { return m_ServerPort; }
string getClientIP() { return m_ClientIP; }
string getClientPort() { return m_ClientPort; }
string getBoundClientPort() { return m_BoundClientPort; }
void setBoundClientPort(string p_Port) { m_BoundClientPort = p_Port; }
void setBoundClientFamily(int p_Family) { m_BoundClientFamily = p_Family; }
int getBoundClientFamily() { return m_BoundClientFamily; }
string getServerIP() const { return m_ServerIP; }
string getServerPort() const { return m_ServerPort; }
string getClientIP() const { return m_ClientIP; }
string getClientPort() const { return m_ClientPort; }
string getBoundClientPort() const { return m_BoundClientPort; }
void setBoundClientPort(const string &p_Port) { m_BoundClientPort = p_Port; }
void setIsBound(bool p_IsBound) { m_IsBound = p_IsBound; }
bool getIsBound() { return m_IsBound; }
bool getIsBound() const { return m_IsBound; }
private:
};
#endif /* SPITSOCKET_H */
+26 -62
View File
@@ -16,55 +16,30 @@
#include "SPITSocket.h"
#include "SPIT_Message.h"
#include <string>
#include <unordered_map>
#include "SpitRepo.hpp"
using namespace std;
class SPITTypeListener;
class SPITType {
private:
static unordered_map<string, SPITType *> s_SPITTypes;
static unordered_map<string, SPITType *> s_SPITTypesRemote;
public:
static SPITType *getSPITType(string p_ID);
static const SPITType &getSPITTypeRef(string p_ID);
static bool addSPITType(SPITType *p_ptrSpitType);
static bool removeSPITType(SPITType *p_ptrSpitType);
static int getSPITTypeCount();
static SPITType *getSPITType(int p_Index);
static const SPITType &getSPITTypeRef(int p_Index);
static void clearSPITTypes();
static void setConfirmedFalse();
static void setConfirmedFalse(SpitRepo<SPITType> &repo);
static void eventProjectClosed(SpitRepo<SPITType> &repo, SpitRepo<SPITType> &remoteRepo);
static SPITType *getSPITTypeRemote(string p_ID);
static const SPITType &getSPITTypeRemoteRef(string p_ID);
static bool addSPITTypeRemote(SPITType *p_ptrSpitType);
static bool removeSPITTypeRemote(SPITType *p_ptrSpitType);
static int getSPITTypeRemoteCount();
static SPITType *getSPITTypeRemote(int p_Index);
static const SPITType &getSPITTypeRemoteRef(int p_Index);
static void clearSPITTypesRemote();
static void eventProjectClosed();
SPITType();
SPITType(string p_ID);
SPITType(string p_ID, string p_GroupName, string p_Name, bool p_Fixed, bool p_ProjectIndepended, long long p_DefaultDelay, long long p_DefaultDuration);
// SPITType(const SPITType& orig);
~SPITType();
private:
bool m_Confirmed;
bool m_Confirmed{};
string m_ID;
bool m_Fixed;
bool m_ServerRemote;
bool m_ServerProjectIndepended;
string m_GroupName;
string m_Name;
long long m_DefaultDelay;
long long m_DefaultDuration;
bool m_Fixed{};
bool m_ServerRemote{};
bool m_ServerProjectIndepended{};
string m_GroupName{};
string m_Name{};
long long m_DefaultDelay{};
long long m_DefaultDuration{};
bool m_CreatedByClient; // flag true = the SPITTyype is created by the client
// false = the SPITType is received from the server
@@ -72,24 +47,17 @@ class SPITType {
bool m_ActionAssigned; // This is a virtual flag if user associates an action with a SPITType.
// Can be used to setActionAssigned for all SPITObjects with this SPITType
void initMembers();
public:
string getID() const { return m_ID; }
string getGroupName() const { return m_GroupName; }
string getName() const { return m_Name; }
/**
* 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>
* @return false = the action is triggered on the client The client waits for the server to play objects of this SPITType
* 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 getProjectIndepended() const {
return m_ServerProjectIndepended;
}
bool getServerRemote() const { return m_ServerRemote; }
bool getProjectIndepended() const { return m_ServerProjectIndepended; }
/**
* 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.
@@ -101,40 +69,36 @@ class SPITType {
bool getCreatedByClient() const { return m_CreatedByClient; }
/**
* Virtual construct - means ActionAssigned for SPITTypes is is not implemented in SPITProtocol.<br>
* This can used to setActionAssigned to all SPITObjects with this SPITType.<br>
* This may be used in the case when the same action should be done for every SPITObject with this SPITType associated.<br>
* Virtual construct - means ActionAssigned for SPITTypes is is not implemented in SPITProtocol.
* This can used to setActionAssigned to all SPITObjects with this SPITType.
* This may be used in the case when the same action should be done for every SPITObject with this SPITType associated.
* @return true = the user has associated an action with this SPITType.
*/
bool getActionAssigned() const {
return m_ActionAssigned;
}
public:
void setID(string p_ID);
bool setGroupName(string p_GroupName);
bool setName(string p_Name);
bool setGroupName(const string &p_GroupName);
bool setName(const string &p_Name);
bool setServerRemote(bool p_BelongstoServer);
bool setProjectIndepended(bool p_ProjectIndepeneded);
bool setConfirmed(bool p_Confirmed);
bool setFixed(bool p_Fixed);
bool setDefaultDelay(long long p_Delay);
bool setDefaultDuration(long long p_Duration);
void setCreatedByClient(bool p_CreatedByClient);
/**
* Virtual construct - means ActionAssigned for SPITTypes is is not implemented in SPITProtocol.<br>
* This can used to setActionAssigned to all SPITObjects with this SPITType.<br>
* This may be used in the case when the same action should be done for every SPITObject with this SPITType associated.<br>
* Virtual construct - means ActionAssigned for SPITTypes is is not implemented in SPITProtocol.
* This can used to setActionAssigned to all SPITObjects with this SPITType.
* This may be used in the case when the same action should be done for every SPITObject with this SPITType associated.
* @return true = the m_ActionAssigned has changed.
*/
bool setActionAssigned(bool p_ActionAssigned);
bool setMessageOP(SPIT_Message::ReportSPITType *p_ReportSPITType);
void fillMessageOP(SPIT_Message::ReportSPITType *p_ReportSPITType);
void fillMessageOP(SPIT_Message::RemoveSPITType *p_RemoveSPITType);
// static char* stringCopy(const char* p_String);
bool setMessageOP(SPIT_Message::ReportSPITType &reportSpitType);
void fillMessageOP(SPIT_Message::ReportSPITType &smReportSpitType) const;
void fillMessageOP(SPIT_Message::RemoveSPITType &smRemoveSpitType) const;
};
#endif /* SPITTYPE_H */
+56 -60
View File
@@ -20,6 +20,7 @@
#include "SPITSocket.h"
#include "SPITType.h"
#include "SPIT_Message.h"
#include "SpitRepo.hpp"
#include <memory>
#include <vector>
@@ -32,10 +33,10 @@ class SPIT_Client : I_SAD_Client {
static const int MAXSPITMESSAGEBYTECOUNT = 512;
enum class ProjUpdate {
ServerLoaded,
StartTransfer,
EndTransfer,
ServerClosed,
ServerLoaded,
StartTransfer,
EndTransfer,
ServerClosed,
};
enum class ServerEvent {
Detect,
@@ -47,69 +48,60 @@ class SPIT_Client : I_SAD_Client {
Changed,
Deleted
};
enum class Connection {
None = 0, // No Connection established.<br>Either no connect tried or disconnected
NoneServer = 1, // Server has disconnected
Lost = 2, // The connection is lost<br>Either because of a network crash or because the server no longer responds.
Ok = 3, // Connection to the serv er is established.
TryConnection = 4, // A connection to the server is tried.
};
struct Callbacks {
void (*onServerEvent)(ServerEvent event, const SAD_DetectedServer &p_DetectedServer){};
void (*onConnectionStatus)(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime, int p_ConnectionStatus, int p_OldConnectionStatus){};
void (*onConnectionStatus)(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime, Connection p_ConnectionStatus, Connection p_OldConnectionStatus){};
void (*onProjectUpdate)(ProjUpdate state, string projectId){};
void (*onSpitType)(ObjectEvent event, const SPITType &p_SPITType){};
void (*onSpitTypeRemote)(ObjectEvent event, const SPITType &p_SPITType){};
void (*onSpitObject)(ObjectEvent event, const SPITType &p_SPITType, const SPITObject &p_SPITObject){};
void (*onSpitObjectRemote)(ObjectEvent event, const SPITType &p_SPITType, const SPITObject &p_SPITObject){};
void (*onSpitType)(ObjectEvent event, bool isRemote, const SPITType &p_SPITType){};
void (*onSpitObject)(ObjectEvent event, bool isRemote, 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 (*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){};
bool (*onCheckSpitTypeVeto)(bool knownType, bool createdByClient){};
bool (*onCheckSpitObjectVeto)(bool knownType){};
};
//----- Connection Status -----
public:
/** No Connection established.<br>Either no connect tried or disconnected*/
static const int CONNECTION_NONE = 0;
/** Server has disconnected*/
static const int CONNECTION_NONESERVER = 1;
/** The connection is lost<br>Either because of a network crash or because the server no longer responds.*/
static const int CONNECTION_LOST = 2;
/** Connection to the serv er is established.*/
static const int CONNECTION_OK = 3;
/** A connection to the server is tried.*/
static const int CONNECTION_TRYCONNECTION = 4;
//------ PlayerType ------
public:
/** continous main player, time value can be used like a timecode.<br>The time value is the position in server's project.<br>A server should use only one main player.*/
static const char PLAYERTYPE_MAIN = 0x02;
static constexpr char PLAYERTYPE_MAIN = 0x02;
/** continous player. This player plays SPIT objects sometime during the project.*/
static const char PLAYERTYPE_CONTINOUS = 0x01;
static constexpr char PLAYERTYPE_CONTINOUS = 0x01;
/** diescrete player. This player is used to transmit single discrete values.*/
static const char PLAYERTYPE_DISCRETE = 0x00;
static constexpr char PLAYERTYPE_DISCRETE = 0x00;
//------ Value Flag ------
//------ used by sendRemoteObject
public:
/**Set the given value directly*/
static const char VALUEFLAG_DIRECT = 0x00;
static constexpr char VALUEFLAG_DIRECT = 0x00;
/**Increase the existing value by the given value.<br>This is usefull e.g. when instead of a fader a endless wheel is used*/
static const char VALUEFLAG_INCREASE = 0x01;
static constexpr char VALUEFLAG_INCREASE = 0x01;
/**Decrease the existing value by the given value.<br>This is usefull e.g. when instead of a fader a endless wheel is used*/
static const char VALUEFLAG_DECREASE = 0x02;
static constexpr char VALUEFLAG_DECREASE = 0x02;
static constexpr int MAX_OVERTAKING_SPIT_MESSAGES = 10;
//----- SPIT_Client -----
public:
SPIT_Client(string name, string projName, Callbacks calls);
virtual ~SPIT_Client();
static int s_MAX_OVERTAKING_SPIT_MESSAGES;
private:
Callbacks mCallbacks;
fos::TaskT<SPIT_Client &> *m_ThreadReceive{};
bool m_StopReceiveSPITMessages;
bool m_StopReceiveSPITMessages{};
int m_ConnectionStatus;
Connection m_ConnectionStatus{Connection::None};
bool m_DisconnectedByServer{}; // flag true = when server disconnects
string m_ID;
string m_Name;
@@ -118,9 +110,9 @@ class SPIT_Client : I_SAD_Client {
string m_ClientProjectName;
unsigned char m_MessageNumber_Send;
int m_MessageNumber_Received;
vector<SPIT_Message *> m_OvertakingSPIT_Messages;
uint8_t m_MessageNumber_Send{1};
int m_MessageNumber_Received{-1}; // set to -1 because the first received message will set the number (1..255)
vector<unique_ptr<SPIT_Message>> m_OvertakingSPIT_Messages;
// Server's info filled by parseConnectAnswer
string m_ServerID{};
@@ -181,8 +173,7 @@ class SPIT_Client : I_SAD_Client {
// Reconnect to the server when connection is lost see eventConnectionStatus and eventServerDetected
bool _doReconnect{}; // true = on eventServerDetected connect to the server identified by m_ServerID
public:
void fillHeader(SPIT_Message::Header *p_Header);
int sendSPITMessage(SPIT_Message::OPPart &p_SPITMessageOPPart);
int sendSPITMessage(SPIT_Message::OPPart & spitMessageOPPart);
//--------------- ServerAutoDetection SAD ---------------
public:
@@ -216,15 +207,15 @@ class SPIT_Client : I_SAD_Client {
void disconnect();
private:
void disconnectInternal(int p_Cause);
void disconnectInternal(Connection p_Cause);
void resetMessageNumberReceived();
void parseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage);
void checkParseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage);
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);
void parseWatchdogAnswer(SPIT_Message::WatchdogAnswer *p_WatchdogAnswer);
void addOvertakingSPIT_Message(unique_ptr<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);
void parseWatchdogAnswer(SPIT_Message::WatchdogAnswer &p_WatchdogAnswer);
public:
/** Used internally*/
@@ -233,8 +224,8 @@ class SPIT_Client : I_SAD_Client {
void eventWatchdogLost();
//--------------- SPIT Project ---------------
private:
void parseReportSPITProject(SPIT_Message::ReportSPITProject *p_ReportSPITProject);
void parseCloseSPITProject(SPIT_Message::CloseSPITProject *p_CloseSPITProject);
void parseReportSPITProject(SPIT_Message::ReportSPITProject &p_ReportSPITProject);
void parseCloseSPITProject(SPIT_Message::CloseSPITProject &p_CloseSPITProject);
public:
/** Returns the SPITServer's project ID - may be the same as the project's name*/
@@ -245,9 +236,9 @@ class SPIT_Client : I_SAD_Client {
int getServerFramesPerSecond();
private:
void parseRequestProjectTransfer(SPIT_Message::RequestProjectTransfer *p_RequestProjectTransfer);
void parseStartProjectTransfer(SPIT_Message::StartProjectTransfer *p_StartProjectTransfer);
void parseEndProjectTransfer(SPIT_Message::EndProjectTransfer *p_EndProjectTransfer);
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);
@@ -283,9 +274,9 @@ class SPIT_Client : I_SAD_Client {
private:
// receive SPITTypes
void parseReportSPITType(SPIT_Message::ReportSPITType *p_ReportSPITType);
void parseRemoveSPITType(SPIT_Message::RemoveSPITType *p_RemoveSPITType);
int sendSPITTypeInternal(SPITType *p_SPITType);
void parseReportSPITType(SPIT_Message::ReportSPITType &p_ReportSPITType);
void parseRemoveSPITType(SPIT_Message::RemoveSPITType &p_RemoveSPITType);
int sendSPITTypeInternal(SPITType &p_SPITType);
public:
/**
@@ -306,8 +297,8 @@ class SPIT_Client : I_SAD_Client {
public:
//--------------- SPIT Objects ---------------
private:
void parseReportSPITObject(SPIT_Message::ReportSPITObject *p_ReportSPITObject);
void parseRemoveSPITObject(SPIT_Message::RemoveSPITObject *p_RemoveSPITObject);
void parseReportSPITObject(SPIT_Message::ReportSPITObject &p_ReportSPITObject);
void parseRemoveSPITObject(SPIT_Message::RemoveSPITObject &p_RemoveSPITObject);
int sendSPITObjectInternal(SPITObject *ptrSPITObject);
public:
@@ -329,10 +320,10 @@ class SPIT_Client : I_SAD_Client {
public:
//--------------- Play SPIT Objects ---------------
private:
void parsePlaySPITStart(SPIT_Message::PlaySPITStart *p_PlaySPITStart);
void parsePlaySPITObject(SPIT_Message::PlaySPITObject *p_PlaySPITObject);
void parsePlaySPITEnd(SPIT_Message::PlaySPITEnd *p_PlaySPITEnd);
void parseReportPlayStatus(SPIT_Message::ReportPlayStatus *p_ReportPlayStatus);
void parsePlaySPITStart(SPIT_Message::PlaySPITStart &p_PlaySPITStart);
void parsePlaySPITObject(SPIT_Message::PlaySPITObject &p_PlaySPITObject);
void parsePlaySPITEnd(SPIT_Message::PlaySPITEnd &p_PlaySPITEnd);
void parseReportPlayStatus(SPIT_Message::ReportPlayStatus &p_ReportPlayStatus);
public:
//--------- Remote ----------
@@ -341,13 +332,18 @@ class SPIT_Client : I_SAD_Client {
private:
static void processSocketTask(SPIT_Client &instance);
fos::TaskT<SPIT_Client &> *sThread{};
bool abortSearch{};
bool mAbortSearch{};
bool sAnswered{};
static fos::Semaphore sStartSad;
SPITSocket *mSPITSocket;
void answerWatchdog() {
sAnswered = true;
}
SpitRepo<SPITObject> mSpitObjects;
SpitRepo<SPITObject> mRemoteSpitObjects;
SpitRepo<SPITType> mSpitTypes;
SpitRepo<SPITType> mRemoteSpitTypes;
};
#endif /* SPIT_CLIENT_H */
File diff suppressed because it is too large Load Diff
+68
View File
@@ -0,0 +1,68 @@
#pragma once
#include <memory>
#include <string>
#include <unordered_map>
template <typename T>
class SpitRepo {
public:
bool hasEntry(const string &id) {
return mEntries.contains(id);
}
T *getEntry(const string &id) {
auto i = mEntries.find(id);
if (i == mEntries.end()) {
return nullptr;
}
return i->second.get();
}
const T &getEntryRef(const string &id) {
return *mEntries.at(id);
}
T *getEntry(int index) {
if (index >= 0 && index < mEntries.size()) {
return next(mEntries.begin(), index)->second.get();
}
return nullptr;
}
const T &getEntryRef(int index) {
if (index >= 0 && index < mEntries.size()) {
auto i = next(mEntries.begin(), index);
return *i->second;
} else {
throw "SPITObject index out of range";
}
}
void addEntry(unique_ptr<T> entry) {
mEntries[entry->getID()] = move(entry);
}
bool removeEntry(const T &entry) {
return removeEntry(entry.getID());
}
bool removeEntry(const string &id) {
auto i = mEntries.find(id);
if (i == mEntries.end()) {
return false;
}
mEntries.erase(i);
return true;
}
int getEntryCount() {
return mEntries.size();
}
unordered_map<string, unique_ptr<T>> &getRepo() {
return mEntries;
}
void clearEntries() {
mEntries.clear();
}
private:
unordered_map<string, unique_ptr<T>> mEntries;
};