refactor: Heavy refactoring of SPIT
This commit is contained in:
@@ -1,150 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class SAD_DetectedServer;
|
||||
class I_SAD_Client {
|
||||
public:
|
||||
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) {
|
||||
}
|
||||
|
||||
private:
|
||||
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; }
|
||||
string getName() const { return m_Name; }
|
||||
string getComputerName() const { return m_ComputerName; }
|
||||
string getIP() const { return m_IP; }
|
||||
string getPort() const { return m_Port; }
|
||||
string getClientIP() const { return m_ClientIP; }
|
||||
string getAdditions() const { return m_Additions; }
|
||||
string getProjectName() const { return m_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 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 resetFlags() {
|
||||
m_Changed = false;
|
||||
m_FoundAgain = false;
|
||||
m_New = false;
|
||||
}
|
||||
|
||||
private:
|
||||
static unordered_map<string, unique_ptr<SAD_DetectedServer>> sKnownServers;
|
||||
|
||||
public:
|
||||
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 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(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 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>
|
||||
* If no DetectedServer is found an eyception is thrown.
|
||||
* @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(const string &id) {
|
||||
return *sKnownServers.at(id);
|
||||
}
|
||||
};
|
||||
@@ -1,147 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/*
|
||||
* File: SPITObject.h
|
||||
* Author: Hagi
|
||||
*
|
||||
* Created on 9. April 2019, 12:11
|
||||
*/
|
||||
|
||||
#ifndef SPITOBJECT_H
|
||||
#define SPITOBJECT_H
|
||||
|
||||
#include "SPITType.h"
|
||||
#include "spit_message.hpp"
|
||||
#include "spit_repo.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace spit;
|
||||
|
||||
class SPITObjectListener;
|
||||
|
||||
class SPITObject {
|
||||
public:
|
||||
static void clearUnconfirmedSPITObjects(SpitRepo<SPITObject> &repo);
|
||||
static void setConfirmedFalse(SpitRepo<SPITObject> &repo);
|
||||
static void eventProjectClosed(SpitRepo<SPITObject> &repo, SpitRepo<SPITObject> &remoteRepo);
|
||||
|
||||
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{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;
|
||||
|
||||
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; }
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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; }
|
||||
|
||||
/**
|
||||
* 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 getCreatedByClient() const { return m_CreatedByClient; }
|
||||
/**
|
||||
* 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.
|
||||
* @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; }
|
||||
|
||||
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; }
|
||||
|
||||
bool getProjectIndepended(SpitRepo<SPITType> &repo, SpitRepo<SPITType> &remoteRepo) const {
|
||||
SPITType *ptrSPITType;
|
||||
if (m_ServerRemote == false) {
|
||||
ptrSPITType = repo.getEntry(m_SPITTypeID);
|
||||
if (ptrSPITType == nullptr)
|
||||
return true;
|
||||
return ptrSPITType->getProjectIndepended();
|
||||
} else {
|
||||
ptrSPITType = remoteRepo.getEntry(m_SPITTypeID);
|
||||
if (ptrSPITType == nullptr)
|
||||
return true;
|
||||
return ptrSPITType->getProjectIndepended();
|
||||
}
|
||||
};
|
||||
|
||||
bool setConfirmed(bool p_Confirmed);
|
||||
void setCreatedByClient(bool p_CreatedByClient) { m_CreatedByClient = p_CreatedByClient; }
|
||||
bool setName(string p_Name);
|
||||
bool setRemark(string p_Remark);
|
||||
bool setServerParams(string p_ServerParams);
|
||||
bool setSPITTypeID(string p_GroupName);
|
||||
bool setServerRemote(bool p_BelongstoServer);
|
||||
bool setActionAssignedType(bool p_ActionAssigned);
|
||||
bool setActionAssigned(bool p_ActionAssigned);
|
||||
bool setFixed(bool p_Fixed);
|
||||
bool setFrameStart(long long p_FrameStart);
|
||||
bool setFrameLength(long long p_FrameLength);
|
||||
bool setFrameFadeInLength(long long p_FrameFadeInLength);
|
||||
bool setFrameFadeOutLength(long long p_FrameFadeOutLength);
|
||||
bool setValueUse(char p_ValueUse);
|
||||
bool setValueFactor(int p_ValueFactor);
|
||||
bool setTrack(int p_Track);
|
||||
bool setDelay(long long p_Delay);
|
||||
bool setDuration(long long p_Duration);
|
||||
|
||||
bool setMessageOP(Message::ReportObject *p_ReportSPITObject);
|
||||
void fillMessageOP(Message::ReportObject &p_ReportSPITObject);
|
||||
void fillMessageOP(Message::RemoveObject &p_RemoveSPITObject);
|
||||
};
|
||||
|
||||
#endif /* SPITOBJECT_H */
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/*
|
||||
* File: SPITPLayer.h
|
||||
* Author: Hagi
|
||||
*
|
||||
* Created on 30. April 2019, 11:44
|
||||
*/
|
||||
|
||||
#ifndef SPITPLAYER_H
|
||||
#define SPITPLAYER_H
|
||||
|
||||
#include "SPITObject.h"
|
||||
#include <unordered_map>
|
||||
|
||||
class SPITPlayer {
|
||||
|
||||
//----- PlayObject used in PlaySequences: PlaySPITStart, PlaySPITObject,..., PlaySPITEnd ------
|
||||
public:
|
||||
class PlaySPITType {
|
||||
public:
|
||||
PlaySPITType(SPITPlayer *p_SPITPlayer, string p_SPITObjectID);
|
||||
PlaySPITType(const PlaySPITType &orig);
|
||||
|
||||
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(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_SPITTypeID;
|
||||
bool m_IsPlayed;
|
||||
bool m_IsNew;
|
||||
double m_Value;
|
||||
};
|
||||
|
||||
//----- SPITPlayer ------
|
||||
public:
|
||||
// list the SPITPlayers
|
||||
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();
|
||||
|
||||
void startPlaySequence(); // 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, 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() 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, unique_ptr<PlaySPITType>> m_PlaySPITTypes;
|
||||
|
||||
bool m_IsRunning;
|
||||
long long m_TimeFrames;
|
||||
};
|
||||
|
||||
#endif /* SPITPLAYER_H */
|
||||
@@ -1,149 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPITSocket is the base class for WindowsSocket, UnixSocket,.
|
||||
* Used by SPIT_Client and SAD_Client.
|
||||
* File: SPITSocket.h
|
||||
* Author: Hagi
|
||||
*
|
||||
* Created on 12. April 2019, 15:40
|
||||
*/
|
||||
|
||||
#ifndef SPITSOCKET_H
|
||||
#define SPITSOCKET_H
|
||||
|
||||
#include "Task.hpp"
|
||||
#include "esp_log.h"
|
||||
#include "esp_netif.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <fcntl.h>
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/** Returns an guid */
|
||||
string createGUID();
|
||||
/** Returns the name of the client's host computer*/
|
||||
string getClientHostName();
|
||||
|
||||
class SPITSocket {
|
||||
public:
|
||||
static const int FAMILY_IP4 = AF_INET;
|
||||
|
||||
/**
|
||||
* IPAddress class is used to fetch all available IP addresses of the computer
|
||||
* This is for internal usage
|
||||
*/
|
||||
struct IPAddress {
|
||||
public:
|
||||
IPAddress(const string &p_IPAddress, const string &p_SubnetMask)
|
||||
: m_IPAddress(p_IPAddress), m_SubnetMask(p_SubnetMask) {}
|
||||
const string m_IPAddress;
|
||||
const string m_SubnetMask;
|
||||
|
||||
/**
|
||||
* Calculates the broadcast address from a ip4 address
|
||||
* @param p_IPAddress the ip4 address
|
||||
* @return returns the broadcast address
|
||||
*/
|
||||
string getBroadcastIP4() const {
|
||||
struct in_addr broadcast;
|
||||
unsigned long ulIPAddress;
|
||||
unsigned long ulSubnetMask;
|
||||
|
||||
ulIPAddress = inet_addr(m_IPAddress.data());
|
||||
ulSubnetMask = inet_addr(m_SubnetMask.data());
|
||||
broadcast.s_addr = ulIPAddress | ~ulSubnetMask;
|
||||
|
||||
return inet_ntoa(broadcast);
|
||||
}
|
||||
};
|
||||
const IPAddress mOwnIp;
|
||||
static IPAddress getAdaptersInfo();
|
||||
bool createSocket_UDP();
|
||||
static const int INVALID_SOCKET = -1;
|
||||
|
||||
private:
|
||||
int m_UDPSocketIP4;
|
||||
|
||||
public:
|
||||
//-------- class --------------
|
||||
SPITSocket(IPAddress ip) : mOwnIp(ip) {
|
||||
m_UDPSocketIP4 = INVALID_SOCKET;
|
||||
createSocket_UDP();
|
||||
}
|
||||
virtual ~SPITSocket() {
|
||||
ESP_LOGD("UDP", "Shutting down ...");
|
||||
|
||||
if (m_UDPSocketIP4 != INVALID_SOCKET) {
|
||||
shutdown(m_UDPSocketIP4, 2);
|
||||
close(m_UDPSocketIP4);
|
||||
m_UDPSocketIP4 = INVALID_SOCKET;
|
||||
}
|
||||
fos::Task::delayMs(100);
|
||||
m_IsBound = false;
|
||||
}
|
||||
|
||||
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
|
||||
bool m_IsBound{};
|
||||
|
||||
public:
|
||||
// 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 message byte buffer containing the message
|
||||
* @param length length of the message
|
||||
* @return
|
||||
*/
|
||||
int sendMessage(const char *message, int length) {
|
||||
if (m_ServerPort.length() <= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (m_IsBound == false) {
|
||||
return -1;
|
||||
}
|
||||
int intResult = sendMessageTo(m_ServerIP, m_ServerPort, message, length);
|
||||
return intResult;
|
||||
}
|
||||
|
||||
int receiveMessage(char *p_Buffer, int p_BufferLength, string *serverIp) const;
|
||||
int setBroadcast(bool p_Broadcast) const;
|
||||
int bindSocket(string clientIp, string clientPort);
|
||||
|
||||
int sendMessageTo(const string &ip, const string &port, const char *message, int msgLength);
|
||||
|
||||
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() const { return m_IsBound; }
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif /* SPITSOCKET_H */
|
||||
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/*
|
||||
* File: SPITType.h
|
||||
* Author: Hagi
|
||||
*
|
||||
* Created on 8. April 2019, 08:40
|
||||
*/
|
||||
|
||||
#ifndef SPITTYPE_H
|
||||
#define SPITTYPE_H
|
||||
|
||||
#include "SPITSocket.h"
|
||||
#include "spit_message.hpp"
|
||||
#include "spit_repo.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace spit;
|
||||
|
||||
class SPITTypeListener;
|
||||
|
||||
class SPITType {
|
||||
public:
|
||||
static void setConfirmedFalse(SpitRepo<SPITType> &repo);
|
||||
static void eventProjectClosed(SpitRepo<SPITType> &repo, SpitRepo<SPITType> &remoteRepo);
|
||||
|
||||
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);
|
||||
|
||||
private:
|
||||
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_CreatedByClient; // flag true = the SPITTyype is created by the client
|
||||
// false = the SPITType is received from the server
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
* 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; }
|
||||
/**
|
||||
* 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; }
|
||||
long long getDefaultDelay() const { return m_DefaultDelay; }
|
||||
long long getDefaultDuration() const { return m_DefaultDuration; }
|
||||
bool getCreatedByClient() const { return m_CreatedByClient; }
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
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.
|
||||
* 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(Message::ReportType &reportSpitType);
|
||||
void fillMessageOP(Message::ReportType &smReportSpitType) const;
|
||||
void fillMessageOP(Message::RemoveType &smRemoveSpitType) const;
|
||||
};
|
||||
|
||||
#endif /* SPITTYPE_H */
|
||||
@@ -0,0 +1,155 @@
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace spit {
|
||||
|
||||
class SadDetectedServer;
|
||||
class ISadClient {
|
||||
public:
|
||||
virtual void eventServerDetected(SadDetectedServer &server) = 0;
|
||||
virtual void eventServerChanged(SadDetectedServer &server) = 0;
|
||||
virtual void eventServerLost(SadDetectedServer &server) = 0;
|
||||
};
|
||||
|
||||
class SadDetectedServer {
|
||||
public:
|
||||
SadDetectedServer(string name, string iD, string computerName,
|
||||
string iP, string port, string clientIP,
|
||||
string additions, string projName)
|
||||
: mName(name),
|
||||
mID(iD),
|
||||
mComputerName(computerName),
|
||||
mIP(iP),
|
||||
mPort(port),
|
||||
mClientIP(clientIP),
|
||||
mAdditions(additions),
|
||||
mServerProjectName(projName) {
|
||||
}
|
||||
|
||||
private:
|
||||
string mName{};
|
||||
string mID{};
|
||||
string mComputerName{};
|
||||
string mIP{};
|
||||
string mPort{};
|
||||
string mClientIP{};
|
||||
string mAdditions{};
|
||||
string mServerProjectName{};
|
||||
bool mNew{true};
|
||||
bool mChanged{};
|
||||
bool mFoundAgain{};
|
||||
|
||||
public:
|
||||
string getID() const { return mID; }
|
||||
string getName() const { return mName; }
|
||||
string getComputerName() const { return mComputerName; }
|
||||
string getIP() const { return mIP; }
|
||||
string getPort() const { return mPort; }
|
||||
string getClientIP() const { return mClientIP; }
|
||||
string getAdditions() const { return mAdditions; }
|
||||
string getProjectName() const { return mServerProjectName; }
|
||||
bool getNew() const { return mNew; }
|
||||
bool getChanged() const { return mChanged; }
|
||||
bool getFoundAgain() const { return mFoundAgain; }
|
||||
|
||||
void setChanged() { mChanged = true; }
|
||||
void setKnown() { mNew = false; }
|
||||
void setFoundAgain() { mFoundAgain = true; }
|
||||
void updateProjectName(string newProjectName) {
|
||||
mServerProjectName = newProjectName;
|
||||
if (mServerProjectName != newProjectName) {
|
||||
mChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
// SAD_Client mThreadSend will send to Multicast addresses
|
||||
void resetFlags() {
|
||||
mChanged = false;
|
||||
mFoundAgain = false;
|
||||
mNew = false;
|
||||
}
|
||||
|
||||
private:
|
||||
static unordered_map<string, unique_ptr<SadDetectedServer>> sKnownServers;
|
||||
|
||||
public:
|
||||
enum ParamIndex {
|
||||
PARAM_PRECODE = 0,
|
||||
PARAM_SPITTASKID = 1,
|
||||
PARAM_NAME = 2,
|
||||
PARAM_ID = 3,
|
||||
PARAM_COMPUTERNAME = 4,
|
||||
PARAM_PORT = 5,
|
||||
PARAM_CLIENTIP = 6,
|
||||
PARAM_ADDITIONS = 7,
|
||||
PARAM_SERVERPROJECTNAME = 8,
|
||||
PARAM_IP = 9,
|
||||
};
|
||||
|
||||
/**
|
||||
* Used by SAD_Client to add a found SPITServer - don't use this manually
|
||||
* @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(unique_ptr<SadDetectedServer> 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(SadDetectedServer &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
|
||||
*/
|
||||
static void evaluateDetectedServers(ISadClient &sadClient) {
|
||||
for (auto &srv : sKnownServers) {
|
||||
SadDetectedServer &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>
|
||||
* If no DetectedServer is found an eyception is thrown.
|
||||
* @param id the id of the SPITServer
|
||||
* @return the reference of the SadDetectedServer instance with getID() == p_ServerID
|
||||
*/
|
||||
static const SadDetectedServer &getRefDetectedServer(const string &id) {
|
||||
return *sKnownServers.at(id);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,34 +1,21 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* File: SPIT_Client.h
|
||||
* Author: Hagi
|
||||
*
|
||||
* Created on 7. April 2019, 08:50
|
||||
*/
|
||||
|
||||
#ifndef SPIT_CLIENT_H
|
||||
#define SPIT_CLIENT_H
|
||||
|
||||
#include "SAD_DetectedServer.hpp"
|
||||
#include "SPITObject.h"
|
||||
#include "SPITPlayer.h"
|
||||
#include "SPITSocket.h"
|
||||
#include "SPITType.h"
|
||||
#include "sad_DetectedServer.hpp"
|
||||
#include "spit_object.hpp"
|
||||
#include "spit_player.hpp"
|
||||
#include "spit_socket.hpp"
|
||||
#include "spit_type.hpp"
|
||||
#include "spit_message.hpp"
|
||||
#include "spit_repo.hpp"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
using namespace std;
|
||||
using namespace spit;
|
||||
|
||||
class SPIT_Client : I_SAD_Client {
|
||||
namespace spit {
|
||||
|
||||
class SClient : ISadClient {
|
||||
public:
|
||||
/** Maximal length of a SPITMessage*/
|
||||
static const int MAXSPITMESSAGEBYTECOUNT = 512;
|
||||
@@ -58,17 +45,16 @@ class SPIT_Client : I_SAD_Client {
|
||||
};
|
||||
|
||||
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, Connection p_ConnectionStatus, Connection p_OldConnectionStatus){};
|
||||
void (*onProjectUpdate)(ProjUpdate state, string projectId){};
|
||||
void (*onSpitType)(ObjectEvent event, bool isRemote, const SPITType &p_SPITType){};
|
||||
void (*onSpitObject)(ObjectEvent event, bool isRemote, const SPITType &p_SPITType, const SPITObject &p_SPITObject){};
|
||||
|
||||
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)(bool knownType, bool createdByClient){};
|
||||
bool (*onCheckSpitObjectVeto)(bool knownType){};
|
||||
function<void(ServerEvent event, const SadDetectedServer &detectedServer)> onServerEvent;
|
||||
function<void(string serverID, string serverComputerName, string serverName, int serverStepTime, Connection connectionStatus, Connection oldConnectionStatus)> onConnectionStatus;
|
||||
function<void(ProjUpdate state, string projectId)> onProjectUpdate;
|
||||
function<void(ObjectEvent event, bool isRemote, const SType &spitType)> onSpitType;
|
||||
function<void(ObjectEvent event, bool isRemote, const SType &spitType, const SObject &spitObject)> onSpitObject;
|
||||
function<void(string playerID, string playerName, char playerType, bool playerIsRunning, uint64_t timeFrames)> onPlay;
|
||||
function<void(string playerID, string spitTypeID, bool playerIsRunning, bool started, bool ended, double value)> onPlaySpitType;
|
||||
function<void(const SType &spitType, const SObject &spitObject, uint64_t p_FrameInsideObject, int value)> onPlayRemoteObjectStatus;
|
||||
function<bool(bool knownType, bool createdByClient)> onCheckSpitTypeVeto;
|
||||
function<bool(bool knownType)> onCheckSpitObjectVeto;
|
||||
};
|
||||
|
||||
//------ PlayerType ------
|
||||
@@ -91,65 +77,65 @@ class SPIT_Client : I_SAD_Client {
|
||||
static constexpr char VALUEFLAG_DECREASE = 0x02;
|
||||
static constexpr int MAX_OVERTAKING_SPIT_MESSAGES = 10;
|
||||
|
||||
//----- SPIT_Client -----
|
||||
//----- SClient -----
|
||||
public:
|
||||
SPIT_Client(string name, string projName, Callbacks calls);
|
||||
virtual ~SPIT_Client();
|
||||
SClient(string name, string projName, ISocket &socket, Callbacks calls);
|
||||
virtual ~SClient();
|
||||
|
||||
private:
|
||||
Callbacks mCallbacks;
|
||||
|
||||
fos::TaskT<SPIT_Client &> *m_ThreadReceive{};
|
||||
bool m_StopReceiveSPITMessages{};
|
||||
fos::TaskT<SClient &> *mThreadReceive{};
|
||||
bool mStopReceiveMessages{};
|
||||
|
||||
Connection m_ConnectionStatus{Connection::None};
|
||||
bool m_DisconnectedByServer{}; // flag true = when server disconnects
|
||||
string m_ID;
|
||||
string m_Name;
|
||||
string m_ProjName;
|
||||
string m_ComputerName;
|
||||
Connection mConnectionStatus{Connection::None};
|
||||
bool mDisconnectedByServer{}; // flag true = when server disconnects
|
||||
string mID;
|
||||
string mName;
|
||||
string mProjName;
|
||||
string mComputerName;
|
||||
|
||||
string m_ClientProjectName;
|
||||
string mClientProjectName;
|
||||
|
||||
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<Message>> m_OvertakingSPIT_Messages;
|
||||
uint8_t mMessageNumberSend{1};
|
||||
int mMessageNumberReceived{-1}; // set to -1 because the first received message will set the number (1..255)
|
||||
vector<unique_ptr<Message>> mOvertakingMessages;
|
||||
|
||||
// Server's info filled by parseConnectAnswer
|
||||
string m_ServerID{};
|
||||
string m_ServerName{};
|
||||
string m_ServerComputerName{};
|
||||
int m_ServerStepTime{-1};
|
||||
string mServerID{};
|
||||
string mServerName{};
|
||||
string mServerComputerName{};
|
||||
int mServerStepTime{-1};
|
||||
|
||||
//--- Server Project ---
|
||||
string m_ServerProjectID;
|
||||
string m_ServerProjectName;
|
||||
int m_ServerFramesPerSecond;
|
||||
string mServerProjectID;
|
||||
string mServerProjectName;
|
||||
int mServerFramesPerSecond;
|
||||
|
||||
public:
|
||||
/** The ID of the client.<br>Every client instance should set an unique id*/
|
||||
string getID() { return m_ID; }
|
||||
string getID() { return mID; }
|
||||
/** The name of the client, should be set by the user app*/
|
||||
string getName() { return m_Name; }
|
||||
string getName() { return mName; }
|
||||
//----- Computer Params -----
|
||||
/** The name of the client's host computer*/
|
||||
string getComputerName() { return m_ComputerName; }
|
||||
void setClientProjectName(string p_ClientProjectName) { m_ClientProjectName = p_ClientProjectName; }
|
||||
string getClientProjectName() { return m_ClientProjectName; }
|
||||
string getComputerName() { return mComputerName; }
|
||||
void setClientProjectName(string clientProjectName) { mClientProjectName = clientProjectName; }
|
||||
string getClientProjectName() { return mClientProjectName; }
|
||||
|
||||
// connected Server Infos
|
||||
/** The ID of the connected SPITServer*/
|
||||
string getServerID() { return m_ServerID; }
|
||||
string getServerID() { return mServerID; }
|
||||
/** The host computername of the connected SPITServer*/
|
||||
string getServerComputerName() { return m_ServerComputerName; }
|
||||
string getServerComputerName() { return mServerComputerName; }
|
||||
/** The name of the connected SPITServer*/
|
||||
string getServerName() { return m_ServerName; }
|
||||
string getServerName() { return mServerName; }
|
||||
|
||||
/** 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() { return m_ServerStepTime; }
|
||||
int getServerStepTime() { return mServerStepTime; }
|
||||
|
||||
/** Should be called when the client wants to close his project*/
|
||||
void clientProjectClose();
|
||||
@@ -158,21 +144,16 @@ class SPIT_Client : I_SAD_Client {
|
||||
*/
|
||||
void clientProjectLoaded();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param p_SPITTypeID
|
||||
* @param p_ActionAssigned
|
||||
*/
|
||||
void setActionSPITType(string p_SPITTypeID, bool p_ActionAssigned);
|
||||
void setActionSPITObject(string p_SPITObjectID, bool p_ActionAssigned);
|
||||
void setActionSPITType(string spitypeID, bool actionAssigned);
|
||||
void setActionSPITObject(string objectID, bool actionAssigned);
|
||||
|
||||
//--------------- SPITMessage ---------------
|
||||
private:
|
||||
bool startReceiveSPITMessages();
|
||||
void stopReceiveSPITMessages();
|
||||
static void receiveSPITMessage(SPIT_Client &rM);
|
||||
static void receiveSPITMessage(SClient &rM);
|
||||
// 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
|
||||
bool _doReconnect{}; // true = on eventServerDetected connect to the server identified by mServerID
|
||||
public:
|
||||
int sendSPITMessage(Message::OPPart & spitMessageOPPart);
|
||||
|
||||
@@ -183,10 +164,10 @@ class SPIT_Client : I_SAD_Client {
|
||||
/** 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(SAD_DetectedServer &server);
|
||||
void eventServerDetected(SadDetectedServer &server);
|
||||
/** Called every time a prior detected SPITServer is is no longer found.*/
|
||||
void eventServerLost(SAD_DetectedServer &server);
|
||||
void eventServerChanged(SAD_DetectedServer &server);
|
||||
void eventServerLost(SadDetectedServer &server);
|
||||
void eventServerChanged(SadDetectedServer &server);
|
||||
|
||||
//--------------- Connection ---------------
|
||||
public:
|
||||
@@ -201,22 +182,22 @@ class SPIT_Client : I_SAD_Client {
|
||||
* @return true = the connection try is ok, SPITServer will answer with COnnectAnswer and an eventConnectionStatus will occur.<br>
|
||||
* false = something is going wrong. (client could not bind)
|
||||
*/
|
||||
bool connect(string p_ServerIP, string p_ServerPort, string p_ClientIP, string p_ClientPort, string p_LoginName = "", string p_LoginPassword = "");
|
||||
bool connect(string serverIP, string serverPort, string clientIP, string clientPort, string loginName = "", string loginPassword = "");
|
||||
/**
|
||||
* Terminates the connection to the SPITServer.
|
||||
*/
|
||||
void disconnect();
|
||||
|
||||
private:
|
||||
void disconnectInternal(Connection p_Cause);
|
||||
void disconnectInternal(Connection cause);
|
||||
void resetMessageNumberReceived();
|
||||
void parseSPIT_Message(unique_ptr<Message> p_SPITMessage);
|
||||
void checkParseSPIT_Message(unique_ptr<Message> p_SPITMessage);
|
||||
void addOvertakingSPIT_Message(unique_ptr<Message> p_SPIT_Message);
|
||||
void parseConnectAnswer(Message::ConnectAnswer &p_ConnectAnswer);
|
||||
void parseDisconnect(Message::Disconnect &p_Disconnect);
|
||||
void parseWatchdog(Message::Watchdog &p_Watchdog);
|
||||
void parseWatchdogAnswer(Message::WatchdogAnswer &p_WatchdogAnswer);
|
||||
void parseMessage(unique_ptr<Message> message);
|
||||
void checkParseMessage(unique_ptr<Message> message);
|
||||
void addOvertakingMessage(unique_ptr<Message> message);
|
||||
void parseConnectAnswer(Message::ConnectAnswer &message);
|
||||
void parseDisconnect(Message::Disconnect &message);
|
||||
void parseWatchdog(Message::Watchdog &message);
|
||||
void parseWatchdogAnswer(Message::WatchdogAnswer &message);
|
||||
|
||||
public:
|
||||
/** Used internally*/
|
||||
@@ -225,8 +206,8 @@ class SPIT_Client : I_SAD_Client {
|
||||
void eventWatchdogLost();
|
||||
//--------------- SPIT Project ---------------
|
||||
private:
|
||||
void parseReportSPITProject(Message::ReportProject &p_ReportSPITProject);
|
||||
void parseCloseSPITProject(Message::CloseProject &p_CloseSPITProject);
|
||||
void parseReportProject(Message::ReportProject &message);
|
||||
void parseCloseProject(Message::CloseProject &message);
|
||||
|
||||
public:
|
||||
/** Returns the SPITServer's project ID - may be the same as the project's name*/
|
||||
@@ -237,12 +218,12 @@ class SPIT_Client : I_SAD_Client {
|
||||
int getServerFramesPerSecond();
|
||||
|
||||
private:
|
||||
void parseRequestProjectTransfer(Message::RequestProjectTransfer &p_RequestProjectTransfer);
|
||||
void parseStartProjectTransfer(Message::StartProjectTransfer &p_StartProjectTransfer);
|
||||
void parseEndProjectTransfer(Message::EndProjectTransfer &p_EndProjectTransfer);
|
||||
void parseRequestProjectTransfer(Message::RequestProjectTransfer &message);
|
||||
void parseStartProjectTransfer(Message::StartProjectTransfer &message);
|
||||
void parseEndProjectTransfer(Message::EndProjectTransfer &message);
|
||||
|
||||
public:
|
||||
static void sendProject(SPIT_Client *p_PtrSPIT_Client);
|
||||
static void sendProject(SClient *p_PtrSClient);
|
||||
|
||||
// --------------- SPIT Types ---------------
|
||||
public:
|
||||
@@ -257,7 +238,7 @@ class SPIT_Client : I_SAD_Client {
|
||||
* @param p_DefaultDuration maybe the action has a default duration, this is only used for graphical representations, 0 is allowd
|
||||
* @return the pointer to the new SPITType.
|
||||
*/
|
||||
SPITType *createSPITTypeFixed(string p_ID, string p_GroupName, string p_Name, long long p_DefaultDelay, long long p_DefaultDuration);
|
||||
SType *createSPITTypeFixed(string iD, string groupName, string name, uint64_t defaultDelay, uint64_t defaultDuration);
|
||||
|
||||
/**
|
||||
* Creates a SPITType for application actions.<br>
|
||||
@@ -271,80 +252,80 @@ class SPIT_Client : I_SAD_Client {
|
||||
* @param p_ProjectIndepended true = the SPITType belongs to a specific project, false = the SpitType always exists for every project
|
||||
* @return the pointer to the new SPITType.
|
||||
*/
|
||||
SPITType *createSPITType(string p_ID, string p_GroupName, string p_Name, long long p_DefaultDelay, long long p_DefaultDuration, bool p_Fixed, bool p_ProjectIndepended);
|
||||
SType *createSPITType(string iD, string groupName, string name, uint64_t defaultDelay, uint64_t defaultDuration, bool fixed, bool projectIndepended);
|
||||
|
||||
private:
|
||||
// receive SPITTypes
|
||||
void parseReportSPITType(Message::ReportType &p_ReportSPITType);
|
||||
void parseRemoveSPITType(Message::RemoveType &p_RemoveSPITType);
|
||||
int sendSPITTypeInternal(SPITType &p_SPITType);
|
||||
void parseReportSPITType(Message::ReportType &message);
|
||||
void parseRemoveSPITType(Message::RemoveType &message);
|
||||
int sendSPITTypeInternal(SType &spitType);
|
||||
|
||||
public:
|
||||
/**
|
||||
* If a client wants to change a SPITType, he should send it to the server.<br>
|
||||
* If the SPITTye is a fixed one and not created by the client himself, then an eventSPITType can be sent from the server, which cancels the change.<br>
|
||||
* @param p_SPITTypeID the id of the SPITType to remove.
|
||||
* @param spitypeID the id of the SPITType to remove.
|
||||
* @return 0 = is sended, -1 = is not sended
|
||||
*/
|
||||
bool changeSPITType(SPITType *p_SPITType);
|
||||
bool changeSPITType(SType *spitType);
|
||||
/**
|
||||
* If a client wants to remove a SPITType, he should send it to the server.<br>
|
||||
* If the SPITTye is a fixed one and not created by the client himself, then an eventSPITType can be sent from the server, which cancels the deletion.<br>
|
||||
* @param p_SPITTypeID the id of the SPITType to remove.
|
||||
* @param spitypeID the id of the SPITType to remove.
|
||||
* @return 0 = is sended, -1 = is not sended
|
||||
*/
|
||||
int removeSPITType(string p_SPITTypeID);
|
||||
int removeSPITType(string spitypeID);
|
||||
|
||||
public:
|
||||
//--------------- SPIT Objects ---------------
|
||||
private:
|
||||
void parseReportSPITObject(Message::ReportObject &p_ReportSPITObject);
|
||||
void parseRemoveSPITObject(Message::RemoveObject &p_RemoveSPITObject);
|
||||
int sendSPITObjectInternal(SPITObject *ptrSPITObject);
|
||||
void parseReportSPITObject(Message::ReportObject &message);
|
||||
void parseRemoveSPITObject(Message::RemoveObject &message);
|
||||
int sendSPITObjectInternal(SObject *ptrObject);
|
||||
|
||||
public:
|
||||
/**
|
||||
* When the client changes a SPITObject (normally the client should not do this), then it should send the changes to the SPITServer.<br>
|
||||
* The SPITServer may discard the changes and an eventSPITObject occurs.<br>
|
||||
* @param p_SPITObject the pointer to the changed SPITObject.
|
||||
* @param spitObject the pointer to the changed SPITObject.
|
||||
* @return 0 = sended, -1 = not sended
|
||||
*/
|
||||
bool changeSPITObject(SPITObject *p_SPITObject);
|
||||
bool changeSPITObject(SObject *spitObject);
|
||||
/**
|
||||
* When the client removes a SPITObject (normally the client should not do this), then he should send it to the SPITServer.<br>
|
||||
* The SPITServer may discard the deletion and an eventSPITObject occurs.<br>
|
||||
* @param p_SPITObjectID the id of the SPITObject to remove.
|
||||
* @param objectID the id of the SPITObject to remove.
|
||||
* @return 0 = sended, -1 = not sended
|
||||
*/
|
||||
int removeSPITObject(string p_SPITObjectID);
|
||||
int removeSPITObject(string objectID);
|
||||
|
||||
public:
|
||||
//--------------- Play SPIT Objects ---------------
|
||||
private:
|
||||
void parsePlaySPITStart(Message::PlayStart &p_PlaySPITStart);
|
||||
void parsePlaySPITObject(Message::PlayObject &p_PlaySPITObject);
|
||||
void parsePlaySPITEnd(Message::PlayEnd &p_PlaySPITEnd);
|
||||
void parseReportPlayStatus(Message::ReportPlayStatus &p_ReportPlayStatus);
|
||||
void parsePlaySPITStart(Message::PlayStart &message);
|
||||
void parsePlaySPITObject(Message::PlayObject &message);
|
||||
void parsePlaySPITEnd(Message::PlayEnd &message);
|
||||
void parseReportPlayStatus(Message::ReportPlayStatus &message);
|
||||
|
||||
public:
|
||||
//--------- Remote ----------
|
||||
void sendRemoteObject(string p_SPITObjectID, int p_Valueppm = 0, char p_ValueFlag = 0x00);
|
||||
void sendRemoteObject(string objectID, int valuePpm = 0, char valueFlag = 0x00);
|
||||
|
||||
private:
|
||||
static void processSocketTask(SPIT_Client &instance);
|
||||
fos::TaskT<SPIT_Client &> *sThread{};
|
||||
static void processSocketTask(SClient &instance);
|
||||
fos::TaskT<SClient &> *sThread{};
|
||||
bool mAbortSearch{};
|
||||
bool sAnswered{};
|
||||
static fos::Semaphore sStartSad;
|
||||
SPITSocket *mSPITSocket;
|
||||
ISocket &mSocket;
|
||||
void answerWatchdog() {
|
||||
sAnswered = true;
|
||||
}
|
||||
|
||||
SpitRepo<SPITObject> mSpitObjects;
|
||||
SpitRepo<SPITObject> mRemoteSpitObjects;
|
||||
SpitRepo<SPITType> mSpitTypes;
|
||||
SpitRepo<SPITType> mRemoteSpitTypes;
|
||||
SpitRepo<SObject> mSpitObjects;
|
||||
SpitRepo<SObject> mRemoteSpitObjects;
|
||||
SpitRepo<SType> mSpitTypes;
|
||||
SpitRepo<SType> mRemoteSpitTypes;
|
||||
};
|
||||
|
||||
#endif /* SPIT_CLIENT_H */
|
||||
}
|
||||
@@ -1,15 +1,3 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/*
|
||||
* File: Message.h
|
||||
* Author: Hagi
|
||||
*
|
||||
* Created on 3. April 2019, 08:51
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <cstdlib>
|
||||
@@ -37,8 +25,8 @@ class Message {
|
||||
int mVersion{SPITVERSION};
|
||||
unsigned char mMessageNumber{};
|
||||
int mBytesCount{BYTESLENGTH};
|
||||
string mServerID{};
|
||||
string mClientID{};
|
||||
string mServerId{};
|
||||
string mClientId{};
|
||||
int mOpFlag{-1};
|
||||
int mParseOffset{};
|
||||
|
||||
@@ -47,8 +35,8 @@ class Message {
|
||||
int getSPITVersion() const { return mVersion; }
|
||||
unsigned char getMessageNumber() const { return mMessageNumber; }
|
||||
int getBytesCount() const { return mBytesCount; }
|
||||
string getServerID() const { return mServerID; }
|
||||
string getClientID() const { return mClientID; }
|
||||
string getServerID() const { return mServerId; }
|
||||
string getClientID() const { return mClientId; }
|
||||
int getType() const { return mOpFlag; }
|
||||
|
||||
// Receive
|
||||
@@ -56,9 +44,9 @@ class Message {
|
||||
|
||||
// Send
|
||||
Header(int p_SPITVersion, int pOpFlag);
|
||||
void setMessageNumber(unsigned char p_MessageNumber) { mMessageNumber = p_MessageNumber; }
|
||||
void setServerID(string p_ID) { mServerID = p_ID; }
|
||||
void setClientID(string p_ID) { mClientID = p_ID; }
|
||||
void setMessageNumber(unsigned char messageNumber) { mMessageNumber = messageNumber; }
|
||||
void setServerID(string iD) { mServerId = iD; }
|
||||
void setClientID(string iD) { mClientId = iD; }
|
||||
void setOPFlag(int pOpFlag) { mOpFlag = pOpFlag; }
|
||||
bool fillBytes(std::vector<char> &message);
|
||||
};
|
||||
@@ -112,7 +100,7 @@ class Message {
|
||||
}
|
||||
|
||||
// Receive
|
||||
OPPart(unique_ptr<Header> p_Header, int pOpFlag, int size);
|
||||
OPPart(unique_ptr<Header> header, int pOpFlag, int size);
|
||||
void setHeader(int opFlag);
|
||||
virtual bool parse(const std::vector<char> &message) = 0;
|
||||
|
||||
@@ -145,22 +133,22 @@ class Message {
|
||||
|
||||
// Members
|
||||
private:
|
||||
unique_ptr<OPPart> m_OPPart{};
|
||||
unique_ptr<OPPart> oPPart{};
|
||||
|
||||
// Receive
|
||||
public:
|
||||
Message(std::vector<char> message);
|
||||
|
||||
const Header *getHeader() const { return m_OPPart->getHeader(); }
|
||||
const Header *getHeader() const { return oPPart->getHeader(); }
|
||||
int getType() const {
|
||||
if (!m_OPPart || !m_OPPart->getHeader()) {
|
||||
if (!oPPart || !oPPart->getHeader()) {
|
||||
return -1;
|
||||
}
|
||||
return m_OPPart->getHeader()->getType();
|
||||
return oPPart->getHeader()->getType();
|
||||
}
|
||||
const OPPart *getOPPart() const { return m_OPPart.get(); }
|
||||
const OPPart *getOPPart() const { return oPPart.get(); }
|
||||
template<typename T>
|
||||
T &getAs() const { return *reinterpret_cast<T *>(m_OPPart.get()); }
|
||||
T &getAs() const { return *reinterpret_cast<T *>(oPPart.get()); }
|
||||
|
||||
private:
|
||||
bool parse(std::vector<char> message);
|
||||
@@ -179,31 +167,31 @@ class Message {
|
||||
static constexpr int BYTESLENGTH = 304;
|
||||
|
||||
private:
|
||||
string m_ClientComputerName{};
|
||||
string m_ClientName{};
|
||||
string m_LoginName{};
|
||||
string m_LoginPassword{};
|
||||
string m_ServerIP{};
|
||||
int m_ServerPort{};
|
||||
string mClientComputerName{};
|
||||
string mClientName{};
|
||||
string mLoginName{};
|
||||
string mLoginPassword{};
|
||||
string mServerIp{};
|
||||
int mServerPort{};
|
||||
|
||||
public:
|
||||
// Receive
|
||||
Connect(unique_ptr<Header> p_Header);
|
||||
Connect(unique_ptr<Header> header);
|
||||
bool parse(const std::vector<char> &message);
|
||||
|
||||
string getClientComputerName() const { return m_ClientComputerName; }
|
||||
string getClientName() const { return m_ClientName; }
|
||||
string getLoginName() const { return m_LoginName; }
|
||||
string getLoginPassword() const { return m_LoginPassword; }
|
||||
string getServerIP() const { return m_ServerIP; }
|
||||
int getServerPort() const { return m_ServerPort; }
|
||||
string getClientComputerName() const { return mClientComputerName; }
|
||||
string getClientName() const { return mClientName; }
|
||||
string getLoginName() const { return mLoginName; }
|
||||
string getLoginPassword() const { return mLoginPassword; }
|
||||
string getServerIP() const { return mServerIp; }
|
||||
int getServerPort() const { return mServerPort; }
|
||||
|
||||
// Send
|
||||
Connect(string p_ComputerName, string p_ClientName);
|
||||
|
||||
void setLoginName(string p_LoginName) { m_LoginName = p_LoginName; }
|
||||
void setLoginPassword(string p_LoginPassword) { m_LoginPassword = p_LoginPassword; }
|
||||
void setServerIP(string p_ServerIP) { m_ServerIP = p_ServerIP; }
|
||||
void setLoginName(string p_LoginName) { mLoginName = p_LoginName; }
|
||||
void setLoginPassword(string p_LoginPassword) { mLoginPassword = p_LoginPassword; }
|
||||
void setServerIP(string p_ServerIP) { mServerIp = p_ServerIP; }
|
||||
void setServerPort(int p_ServerPort);
|
||||
bool fillBytes(std::vector<char> &message);
|
||||
};
|
||||
@@ -216,28 +204,28 @@ class Message {
|
||||
static constexpr int BYTESLENGTH = 137;
|
||||
|
||||
private:
|
||||
string m_ServerComputerName{};
|
||||
string m_ServerName{};
|
||||
bool m_Connected{};
|
||||
int m_StepTime{40}; // ms step size the Server will send play sequences
|
||||
string mServerComputerName{};
|
||||
string mServerName{};
|
||||
bool mConnected{};
|
||||
int mStepTime{40}; // ms step size the Server will send play sequences
|
||||
|
||||
public:
|
||||
ConnectAnswer(const ConnectAnswer &orig);
|
||||
// Receive
|
||||
ConnectAnswer(unique_ptr<Header> p_Header);
|
||||
ConnectAnswer(unique_ptr<Header> header);
|
||||
|
||||
bool parse(const std::vector<char> &message);
|
||||
|
||||
const string getServerComputerName() const { return m_ServerComputerName; }
|
||||
const string getServerName() const { return m_ServerName; }
|
||||
bool getConnected() const { return m_Connected; }
|
||||
int getStepTime() const { return m_StepTime; }
|
||||
const string getServerComputerName() const { return mServerComputerName; }
|
||||
const string getServerName() const { return mServerName; }
|
||||
bool getConnected() const { return mConnected; }
|
||||
int getStepTime() const { return mStepTime; }
|
||||
|
||||
// Send
|
||||
ConnectAnswer();
|
||||
void setServerComputerName(string p_ServerComputerName) { m_ServerComputerName = p_ServerComputerName; }
|
||||
void setServerName(string p_ServerName) { m_ServerName = p_ServerName; }
|
||||
void setConnected(bool p_Connected) { m_Connected = p_Connected; }
|
||||
void setServerComputerName(string p_ServerComputerName) { mServerComputerName = p_ServerComputerName; }
|
||||
void setServerName(string p_ServerName) { mServerName = p_ServerName; }
|
||||
void setConnected(bool p_Connected) { mConnected = p_Connected; }
|
||||
void setStepTime(int p_StepTime_ms);
|
||||
bool fillBytes(std::vector<char> &message);
|
||||
};
|
||||
@@ -251,7 +239,7 @@ class Message {
|
||||
|
||||
Disconnect(const Disconnect &orig);
|
||||
// Receive
|
||||
Disconnect(unique_ptr<Header> p_Header);
|
||||
Disconnect(unique_ptr<Header> header);
|
||||
bool parse(const std::vector<char> &message);
|
||||
|
||||
// Send
|
||||
@@ -268,7 +256,7 @@ class Message {
|
||||
|
||||
Watchdog(const Watchdog &orig);
|
||||
// Receive
|
||||
Watchdog(unique_ptr<Header> p_Header);
|
||||
Watchdog(unique_ptr<Header> header);
|
||||
bool parse(const std::vector<char> &message);
|
||||
|
||||
// Send
|
||||
@@ -285,7 +273,7 @@ class Message {
|
||||
|
||||
// Receive
|
||||
WatchdogAnswer(const WatchdogAnswer &orig);
|
||||
WatchdogAnswer(unique_ptr<Header> p_Header);
|
||||
WatchdogAnswer(unique_ptr<Header> header);
|
||||
bool parse(const std::vector<char> &message);
|
||||
|
||||
// Send
|
||||
@@ -303,22 +291,22 @@ class Message {
|
||||
static constexpr int BYTESLENGTH = 113;
|
||||
|
||||
private:
|
||||
string m_ProjectID{};
|
||||
string m_ProjectName{};
|
||||
int m_FramesPerSecond{1000}; // Frames per second
|
||||
string mProjectID{};
|
||||
string mProjectName{};
|
||||
int mFramesPerSecond{1000}; // Frames per second
|
||||
|
||||
// Receive
|
||||
public:
|
||||
ReportProject(const ReportProject &orig);
|
||||
ReportProject(unique_ptr<Header> p_Header);
|
||||
ReportProject(unique_ptr<Header> header);
|
||||
bool parse(const std::vector<char> &message);
|
||||
const string getProjectID() const { return m_ProjectID; }
|
||||
const string getProjectName() const { return m_ProjectName; }
|
||||
int getFramesPerSecond() const { return m_FramesPerSecond; }
|
||||
const string getProjectID() const { return mProjectID; }
|
||||
const string getProjectName() const { return mProjectName; }
|
||||
int getFramesPerSecond() const { return mFramesPerSecond; }
|
||||
// Send
|
||||
ReportProject(string p_ProjectID, string p_ProjectName);
|
||||
|
||||
void setFramesPerSecond(const int p_FramesPerSecond) { m_FramesPerSecond = p_FramesPerSecond; }
|
||||
void setFramesPerSecond(const int p_FramesPerSecond) { mFramesPerSecond = p_FramesPerSecond; }
|
||||
bool fillBytes(std::vector<char> &message);
|
||||
};
|
||||
|
||||
@@ -330,15 +318,15 @@ class Message {
|
||||
static constexpr int BYTESLENGTH = 45;
|
||||
|
||||
private:
|
||||
string m_ProjectID{};
|
||||
string mProjectID{};
|
||||
|
||||
public:
|
||||
CloseProject(const CloseProject &orig);
|
||||
// Receive
|
||||
CloseProject(unique_ptr<Header> p_Header);
|
||||
CloseProject(unique_ptr<Header> header);
|
||||
bool parse(const std::vector<char> &message);
|
||||
const string getProjectID() const {
|
||||
return m_ProjectID;
|
||||
return mProjectID;
|
||||
}
|
||||
// Send
|
||||
CloseProject(string projectID);
|
||||
@@ -353,7 +341,7 @@ class Message {
|
||||
|
||||
RequestProjectTransfer(const RequestProjectTransfer &orig);
|
||||
// Receive
|
||||
RequestProjectTransfer(unique_ptr<Header> p_Header);
|
||||
RequestProjectTransfer(unique_ptr<Header> header);
|
||||
bool parse(const std::vector<char> &message);
|
||||
// Send
|
||||
RequestProjectTransfer();
|
||||
@@ -369,7 +357,7 @@ class Message {
|
||||
|
||||
StartProjectTransfer(const StartProjectTransfer &orig);
|
||||
// Receive
|
||||
StartProjectTransfer(unique_ptr<Header> p_Header);
|
||||
StartProjectTransfer(unique_ptr<Header> header);
|
||||
bool parse(const std::vector<char> &message);
|
||||
// Send
|
||||
StartProjectTransfer();
|
||||
@@ -384,7 +372,7 @@ class Message {
|
||||
|
||||
EndProjectTransfer(const EndProjectTransfer &orig);
|
||||
// Receive
|
||||
EndProjectTransfer(unique_ptr<Header> p_Header);
|
||||
EndProjectTransfer(unique_ptr<Header> header);
|
||||
bool parse(const std::vector<char> &message);
|
||||
// Send
|
||||
EndProjectTransfer();
|
||||
@@ -400,43 +388,43 @@ class Message {
|
||||
static constexpr int BYTESLENGTH = 168;
|
||||
|
||||
private:
|
||||
bool m_Confirmed{};
|
||||
string m_SPITTypeID{};
|
||||
bool m_Fixed{};
|
||||
bool m_ServerRemote{};
|
||||
bool m_ServerProjectIndepended{};
|
||||
string m_SPITTypeGroupName{};
|
||||
string m_SPITTypeName{};
|
||||
uint64_t m_Delay{};
|
||||
uint64_t m_Duration{};
|
||||
bool mConfirmed{};
|
||||
string mSPITTypeID{};
|
||||
bool mFixed{};
|
||||
bool mServerRemote{};
|
||||
bool mServerProjectIndepended{};
|
||||
string mTypeGroupName{};
|
||||
string mSPITTypeName{};
|
||||
uint64_t mDelay{};
|
||||
uint64_t mDuration{};
|
||||
|
||||
public:
|
||||
ReportType(const ReportType &orig);
|
||||
// Receive
|
||||
ReportType(unique_ptr<Header> p_Header);
|
||||
ReportType(unique_ptr<Header> header);
|
||||
bool parse(const std::vector<char> &message);
|
||||
|
||||
bool getConfirmed() const { return m_Confirmed; }
|
||||
const string getID() const { return m_SPITTypeID; }
|
||||
bool getFixed() const { return m_Fixed; }
|
||||
bool getServerRemote() const { return m_ServerRemote; }
|
||||
bool getServerProjectIndepended() const { return m_ServerProjectIndepended; }
|
||||
const string getGroupName() const { return m_SPITTypeGroupName; }
|
||||
const string getName() const { return m_SPITTypeName; }
|
||||
uint64_t getDelay() const { return m_Delay; }
|
||||
uint64_t getDuration() const { return m_Duration; }
|
||||
bool getConfirmed() const { return mConfirmed; }
|
||||
const string getID() const { return mSPITTypeID; }
|
||||
bool getFixed() const { return mFixed; }
|
||||
bool getServerRemote() const { return mServerRemote; }
|
||||
bool getServerProjectIndepended() const { return mServerProjectIndepended; }
|
||||
const string getGroupName() const { return mTypeGroupName; }
|
||||
const string getName() const { return mSPITTypeName; }
|
||||
uint64_t getDelay() const { return mDelay; }
|
||||
uint64_t getDuration() const { return mDuration; }
|
||||
// Send
|
||||
|
||||
ReportType();
|
||||
void setConfirmed(bool p_Confirmed) { m_Confirmed = p_Confirmed; }
|
||||
void setID(string p_ID) { m_SPITTypeID = p_ID; }
|
||||
void setFixed(bool p_Fixed) { m_Fixed = p_Fixed; }
|
||||
void setServerRemote(bool p_IsServerRemote) { m_ServerRemote = p_IsServerRemote; }
|
||||
void setServerProjectIndepended(bool p_ProjectIndpended) { m_ServerProjectIndepended = p_ProjectIndpended; }
|
||||
void setGroupName(string p_GroupName) { m_SPITTypeGroupName = p_GroupName; }
|
||||
void setName(string p_Name) { m_SPITTypeName = p_Name; }
|
||||
void setDelay(uint64_t p_Delay) { m_Delay = p_Delay; }
|
||||
void setDuration(uint64_t p_Duration) { m_Duration = p_Duration; }
|
||||
void setConfirmed(bool p_Confirmed) { mConfirmed = p_Confirmed; }
|
||||
void setID(string iD) { mSPITTypeID = iD; }
|
||||
void setFixed(bool p_Fixed) { mFixed = p_Fixed; }
|
||||
void setServerRemote(bool p_IsServerRemote) { mServerRemote = p_IsServerRemote; }
|
||||
void setServerProjectIndepended(bool p_ProjectIndpended) { mServerProjectIndepended = p_ProjectIndpended; }
|
||||
void setGroupName(string p_GroupName) { mTypeGroupName = p_GroupName; }
|
||||
void setName(string p_Name) { mSPITTypeName = p_Name; }
|
||||
void setDelay(uint64_t p_Delay) { mDelay = p_Delay; }
|
||||
void setDuration(uint64_t p_Duration) { mDuration = p_Duration; }
|
||||
|
||||
bool fillBytes(std::vector<char> &message);
|
||||
};
|
||||
@@ -449,19 +437,19 @@ class Message {
|
||||
static constexpr int BYTESLENGTH = 45;
|
||||
|
||||
private:
|
||||
string m_SPITTypeID{};
|
||||
string mSPITTypeID{};
|
||||
|
||||
public:
|
||||
RemoveType(const RemoveType &orig);
|
||||
// Receive
|
||||
RemoveType(unique_ptr<Header> p_Header);
|
||||
RemoveType(unique_ptr<Header> header);
|
||||
bool parse(const std::vector<char> &message);
|
||||
|
||||
const string getID() const { return m_SPITTypeID; }
|
||||
const string getID() const { return mSPITTypeID; }
|
||||
|
||||
// Send
|
||||
RemoveType();
|
||||
void setID(string p_ID) { m_SPITTypeID = p_ID; }
|
||||
void setID(string iD) { mSPITTypeID = iD; }
|
||||
bool fillBytes(std::vector<char> &message);
|
||||
};
|
||||
|
||||
@@ -475,71 +463,71 @@ class Message {
|
||||
static constexpr int BYTESLENGTH = 339;
|
||||
|
||||
private:
|
||||
bool m_Confirmed{};
|
||||
string m_SPITObjectID{};
|
||||
bool m_Fixed{};
|
||||
bool m_ServerRemote{};
|
||||
string m_SPITObjectName{};
|
||||
string m_SPITTypeID{};
|
||||
string m_ServerParams{};
|
||||
uint64_t m_FrameStart{};
|
||||
uint64_t m_FrameLength{};
|
||||
uint64_t m_FrameFadeInLength{};
|
||||
uint64_t m_FrameFadeOutLength{};
|
||||
int m_ValueFactor{};
|
||||
char m_ValueUse{VALUEUSE_DISCARD};
|
||||
int m_Track{};
|
||||
string m_Remark{};
|
||||
uint64_t m_Delay{};
|
||||
uint64_t m_Duration{};
|
||||
bool m_ActionAssigned{};
|
||||
bool mConfirmed{};
|
||||
string mSPITObjectID{};
|
||||
bool mFixed{};
|
||||
bool mServerRemote{};
|
||||
string mSPITObjectName{};
|
||||
string mSPITTypeID{};
|
||||
string mServerParams{};
|
||||
uint64_t mFrameStart{};
|
||||
uint64_t mFrameLength{};
|
||||
uint64_t mFrameFadeInLength{};
|
||||
uint64_t mFrameFadeOutLength{};
|
||||
int mValueFactor{};
|
||||
char mValueUse{VALUEUSE_DISCARD};
|
||||
int mTrack{};
|
||||
string mRemark{};
|
||||
uint64_t mDelay{};
|
||||
uint64_t mDuration{};
|
||||
bool mActionAssigned{};
|
||||
|
||||
public:
|
||||
ReportObject(const ReportObject &orig);
|
||||
// Receive
|
||||
ReportObject(unique_ptr<Header> p_Header);
|
||||
ReportObject(unique_ptr<Header> header);
|
||||
bool parse(const std::vector<char> &message);
|
||||
|
||||
bool getConfirmed() const { return m_Confirmed; }
|
||||
const string getID() const { return m_SPITObjectID; }
|
||||
bool getFixed() const { return m_Fixed; }
|
||||
bool getServerRemote() const { return m_ServerRemote; }
|
||||
const string getName() const { return m_SPITObjectName; }
|
||||
const string getSPITTypeID() const { return m_SPITTypeID; }
|
||||
const string getServerParams() const { return m_ServerParams; }
|
||||
uint64_t getFrameStart() const { return m_FrameStart; }
|
||||
uint64_t getFrameLength() const { return m_FrameLength; }
|
||||
uint64_t getFrameFadeInLength() const { return m_FrameFadeInLength; }
|
||||
uint64_t getFrameFadeOutLength() const { return m_FrameFadeOutLength; }
|
||||
int getValueFactor() const { return m_ValueFactor; }
|
||||
char getValueUse() const { return m_ValueUse; }
|
||||
int getTrack() const { return m_Track; }
|
||||
const string getRemark() const { return m_Remark; }
|
||||
uint64_t getDelay() const { return m_Delay; }
|
||||
uint64_t getDuration() const { return m_Duration; }
|
||||
bool getActionAssigned() const { return m_ActionAssigned; }
|
||||
bool getConfirmed() const { return mConfirmed; }
|
||||
const string getID() const { return mSPITObjectID; }
|
||||
bool getFixed() const { return mFixed; }
|
||||
bool getServerRemote() const { return mServerRemote; }
|
||||
const string getName() const { return mSPITObjectName; }
|
||||
const string getSPITTypeID() const { return mSPITTypeID; }
|
||||
const string getServerParams() const { return mServerParams; }
|
||||
uint64_t getFrameStart() const { return mFrameStart; }
|
||||
uint64_t getFrameLength() const { return mFrameLength; }
|
||||
uint64_t getFrameFadeInLength() const { return mFrameFadeInLength; }
|
||||
uint64_t getFrameFadeOutLength() const { return mFrameFadeOutLength; }
|
||||
int getValueFactor() const { return mValueFactor; }
|
||||
char getValueUse() const { return mValueUse; }
|
||||
int getTrack() const { return mTrack; }
|
||||
const string getRemark() const { return mRemark; }
|
||||
uint64_t getDelay() const { return mDelay; }
|
||||
uint64_t getDuration() const { return mDuration; }
|
||||
bool getActionAssigned() const { return mActionAssigned; }
|
||||
// Send
|
||||
public:
|
||||
ReportObject();
|
||||
|
||||
void setConfirmed(bool p_Confirmed) { m_Confirmed = p_Confirmed; };
|
||||
void setID(string p_ID) { m_SPITObjectID = p_ID; };
|
||||
void setFixed(bool p_Fixed) { m_Fixed = p_Fixed; };
|
||||
void setServerRemote(bool p_IsRemote) { m_ServerRemote = p_IsRemote; };
|
||||
void setName(string p_Name) { m_SPITObjectName = p_Name; };
|
||||
void setSPITTypeID(string p_ID) { m_SPITTypeID = p_ID; };
|
||||
void setServerParams(string p_Parameters) { m_ServerParams = p_Parameters; };
|
||||
void setFrameStart(uint64_t p_StartTime) { m_FrameStart = p_StartTime; };
|
||||
void setFrameLength(uint64_t p_Length) { m_FrameLength = p_Length; };
|
||||
void setFrameFadeInLength(uint64_t p_FadeInTime) { m_FrameFadeInLength = p_FadeInTime; };
|
||||
void setFrameFadeOutLength(uint64_t p_FadeOutTime) { m_FrameFadeOutLength = p_FadeOutTime; };
|
||||
void setValueFactor(int p_Volume) { m_ValueFactor = p_Volume; };
|
||||
void setValueUse(char p_ValueUse) { m_ValueUse = p_ValueUse; };
|
||||
void setTrack(int p_Track) { m_Track = p_Track; };
|
||||
void setRemark(string p_Description) { m_Remark = p_Description; };
|
||||
void setConfirmed(bool p_Confirmed) { mConfirmed = p_Confirmed; };
|
||||
void setID(string iD) { mSPITObjectID = iD; };
|
||||
void setFixed(bool p_Fixed) { mFixed = p_Fixed; };
|
||||
void setServerRemote(bool p_IsRemote) { mServerRemote = p_IsRemote; };
|
||||
void setName(string p_Name) { mSPITObjectName = p_Name; };
|
||||
void setSPITTypeID(string iD) { mSPITTypeID = iD; };
|
||||
void setServerParams(string p_Parameters) { mServerParams = p_Parameters; };
|
||||
void setFrameStart(uint64_t p_StartTime) { mFrameStart = p_StartTime; };
|
||||
void setFrameLength(uint64_t p_Length) { mFrameLength = p_Length; };
|
||||
void setFrameFadeInLength(uint64_t p_FadeInTime) { mFrameFadeInLength = p_FadeInTime; };
|
||||
void setFrameFadeOutLength(uint64_t p_FadeOutTime) { mFrameFadeOutLength = p_FadeOutTime; };
|
||||
void setValueFactor(int p_Volume) { mValueFactor = p_Volume; };
|
||||
void setValueUse(char p_ValueUse) { mValueUse = p_ValueUse; };
|
||||
void setTrack(int p_Track) { mTrack = p_Track; };
|
||||
void setRemark(string p_Description) { mRemark = p_Description; };
|
||||
void setDelay(uint64_t p_Delay);
|
||||
void setDuration(uint64_t p_Duration);
|
||||
void setActionAssigned(bool p_ActionAssigned) { m_ActionAssigned = p_ActionAssigned; }
|
||||
void setActionAssigned(bool p_ActionAssigned) { mActionAssigned = p_ActionAssigned; }
|
||||
bool fillBytes(std::vector<char> &message);
|
||||
};
|
||||
|
||||
@@ -551,19 +539,19 @@ class Message {
|
||||
static constexpr int BYTESLENGTH = 45;
|
||||
|
||||
private:
|
||||
string m_SPITObjectID{};
|
||||
string mSPITObjectID{};
|
||||
|
||||
public:
|
||||
RemoveObject(const RemoveObject &orig);
|
||||
// Receive
|
||||
RemoveObject(unique_ptr<Header> p_Header);
|
||||
RemoveObject(unique_ptr<Header> header);
|
||||
bool parse(const std::vector<char> &message);
|
||||
|
||||
const string getID() const { return m_SPITObjectID; }
|
||||
const string getID() const { return mSPITObjectID; }
|
||||
// Send
|
||||
public:
|
||||
RemoveObject();
|
||||
void setID(string p_ID) { m_SPITObjectID = p_ID; }
|
||||
void setID(string iD) { mSPITObjectID = iD; }
|
||||
bool fillBytes(std::vector<char> &message);
|
||||
};
|
||||
|
||||
@@ -577,28 +565,28 @@ class Message {
|
||||
static constexpr int BYTESLENGTH = 119;
|
||||
|
||||
private:
|
||||
string m_PlayerID{};
|
||||
string m_PlayerName{};
|
||||
char m_PlayerType{};
|
||||
bool m_PlayerIsRunning{};
|
||||
uint64_t m_Time; // Frames
|
||||
string mPlayerID{};
|
||||
string mPlayerName{};
|
||||
char mPlayerType{};
|
||||
bool mPlayerIsRunning{};
|
||||
uint64_t mTime; // Frames
|
||||
|
||||
public:
|
||||
PlayStart(const PlayStart &orig);
|
||||
// Receive
|
||||
PlayStart(unique_ptr<Header> p_Header);
|
||||
PlayStart(unique_ptr<Header> header);
|
||||
bool parse(const std::vector<char> &message);
|
||||
|
||||
const string getPlayerID() const { return m_PlayerID; }
|
||||
const string getPlayerName() const { return m_PlayerName; }
|
||||
char getPlayerType() const { return m_PlayerType; }
|
||||
bool getPlayerIsRunning() const { return m_PlayerIsRunning; }
|
||||
uint64_t getTime() const { return m_Time; }
|
||||
const string getPlayerID() const { return mPlayerID; }
|
||||
const string getPlayerName() const { return mPlayerName; }
|
||||
char getPlayerType() const { return mPlayerType; }
|
||||
bool getPlayerIsRunning() const { return mPlayerIsRunning; }
|
||||
uint64_t getTime() const { return mTime; }
|
||||
|
||||
// Send
|
||||
PlayStart(string p_PlayerID, string p_PlayerName, char p_PlayerType);
|
||||
void setPlayerIsRunning(bool p_IsPlaying) { m_PlayerIsRunning = p_IsPlaying; }
|
||||
void setTime(uint64_t p_Time) { m_Time = p_Time; }
|
||||
void setPlayerIsRunning(bool p_IsPlaying) { mPlayerIsRunning = p_IsPlaying; }
|
||||
void setTime(uint64_t p_Time) { mTime = p_Time; }
|
||||
bool fillBytes(std::vector<char> &message);
|
||||
};
|
||||
|
||||
@@ -610,34 +598,34 @@ class Message {
|
||||
static constexpr int BYTESLENGTH = 100;
|
||||
|
||||
private:
|
||||
string m_PlayerID{};
|
||||
string m_SPITObjectID{};
|
||||
uint64_t m_FrameInsideObject{}; // Frames
|
||||
bool m_PlayPrePosition{};
|
||||
int m_Value{};
|
||||
char m_ValueFlag{VALUEFLAG_DIRECT};
|
||||
string mPlayerID{};
|
||||
string mSPITObjectID{};
|
||||
uint64_t mFrameInsideObject{}; // Frames
|
||||
bool mPlayPrePosition{};
|
||||
int mValue{};
|
||||
char mValueFlag{VALUEFLAG_DIRECT};
|
||||
|
||||
public:
|
||||
PlayObject(const PlayObject &orig);
|
||||
// Receive
|
||||
PlayObject(unique_ptr<Header> p_Header);
|
||||
PlayObject(unique_ptr<Header> header);
|
||||
bool parse(const std::vector<char> &message);
|
||||
|
||||
const string getPlayerID() const { return m_PlayerID; }
|
||||
const string getSPITObjectID() const { return m_SPITObjectID; }
|
||||
uint64_t getFrameInsideObject() const { return m_FrameInsideObject; }
|
||||
bool getPlayPrePosition() const { return m_PlayPrePosition; }
|
||||
int getValue() const { return m_Value; }
|
||||
char getValueFlag() const { return m_ValueFlag; }
|
||||
const string getPlayerID() const { return mPlayerID; }
|
||||
const string getSPITObjectID() const { return mSPITObjectID; }
|
||||
uint64_t getFrameInsideObject() const { return mFrameInsideObject; }
|
||||
bool getPlayPrePosition() const { return mPlayPrePosition; }
|
||||
int getValue() const { return mValue; }
|
||||
char getValueFlag() const { return mValueFlag; }
|
||||
// Send
|
||||
PlayObject();
|
||||
|
||||
void setPlayerID(string p_PlayerID) { m_PlayerID = p_PlayerID; }
|
||||
void setID(string p_ID) { m_SPITObjectID = p_ID; }
|
||||
void setFrameInsideObject(uint64_t p_TimeInside) { m_FrameInsideObject = p_TimeInside; }
|
||||
void setPlayPrePosition(bool p_PlayOldPosition) { m_PlayPrePosition = p_PlayOldPosition; }
|
||||
void setValue(int p_Value) { m_Value = p_Value; }
|
||||
void setValueFlag(char p_ValueFlag) { m_ValueFlag = p_ValueFlag; }
|
||||
void setPlayerID(string p_PlayerID) { mPlayerID = p_PlayerID; }
|
||||
void setID(string iD) { mSPITObjectID = iD; }
|
||||
void setFrameInsideObject(uint64_t p_TimeInside) { mFrameInsideObject = p_TimeInside; }
|
||||
void setPlayPrePosition(bool p_PlayOldPosition) { mPlayPrePosition = p_PlayOldPosition; }
|
||||
void setValue(int p_Value) { mValue = p_Value; }
|
||||
void setValueFlag(char p_ValueFlag) { mValueFlag = p_ValueFlag; }
|
||||
bool fillBytes(std::vector<char> &message);
|
||||
};
|
||||
|
||||
@@ -648,14 +636,14 @@ class Message {
|
||||
static constexpr int BYTESLENGTH = 45;
|
||||
|
||||
private:
|
||||
string m_PlayerID{};
|
||||
string mPlayerID{};
|
||||
|
||||
public:
|
||||
PlayEnd(const PlayEnd &orig);
|
||||
// Receive
|
||||
PlayEnd(unique_ptr<Header> p_Header);
|
||||
PlayEnd(unique_ptr<Header> header);
|
||||
bool parse(const std::vector<char> &message);
|
||||
const string getPlayerID() const { return m_PlayerID; }
|
||||
const string getPlayerID() const { return mPlayerID; }
|
||||
|
||||
// Send
|
||||
PlayEnd(string p_PlayerID);
|
||||
@@ -669,23 +657,23 @@ class Message {
|
||||
static constexpr int BYTESLENGTH = 57;
|
||||
|
||||
private:
|
||||
string m_SPITObjectID{};
|
||||
uint64_t m_FrameInsideObject{};
|
||||
int m_Value{};
|
||||
string mSPITObjectID{};
|
||||
uint64_t mFrameInsideObject{};
|
||||
int mValue{};
|
||||
|
||||
public:
|
||||
ReportPlayStatus(const ReportPlayStatus &orig);
|
||||
// Receive
|
||||
ReportPlayStatus(unique_ptr<Header> p_Header);
|
||||
ReportPlayStatus(unique_ptr<Header> header);
|
||||
bool parse(const std::vector<char> &message);
|
||||
|
||||
const string getID() const { return m_SPITObjectID; }
|
||||
uint64_t getFrameInsideObject() const { return m_FrameInsideObject; }
|
||||
int getValue() const { return m_Value; }
|
||||
const string getID() const { return mSPITObjectID; }
|
||||
uint64_t getFrameInsideObject() const { return mFrameInsideObject; }
|
||||
int getValue() const { return mValue; }
|
||||
// Send
|
||||
ReportPlayStatus();
|
||||
|
||||
void setID(string p_ID);
|
||||
void setID(string iD);
|
||||
void setFrameInsideObject(uint64_t p_TimeInside);
|
||||
void setValue(int p_Value);
|
||||
bool fillBytes(std::vector<char> &message);
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
#pragma once
|
||||
|
||||
#include "spit_type.hpp"
|
||||
#include "spit_message.hpp"
|
||||
#include "spit_repo.hpp"
|
||||
|
||||
using namespace std;
|
||||
namespace spit {
|
||||
|
||||
class SObjectListener;
|
||||
|
||||
class SObject {
|
||||
public:
|
||||
template <typename T>
|
||||
struct Property {
|
||||
friend SObject;
|
||||
Property(bool &confirmed)
|
||||
: rConfirmed(confirmed) {
|
||||
}
|
||||
bool set(const T& val) {
|
||||
if (mValue == val)
|
||||
return false;
|
||||
mValue = val;
|
||||
rConfirmed = false;
|
||||
return true;
|
||||
}
|
||||
T get () const {
|
||||
return mValue;
|
||||
}
|
||||
private:
|
||||
bool & rConfirmed;
|
||||
T mValue{};
|
||||
};
|
||||
|
||||
Property<string> Name{mConfirmed};
|
||||
Property<string> Remark{mConfirmed};
|
||||
Property<string> ServerParams{mConfirmed};
|
||||
Property<string> SPITTypeID{mConfirmed};
|
||||
// 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
|
||||
// true = the action is triggered on the server. The server waits for the client to play objects of this SPITType.
|
||||
Property<bool> ServerRemote{mConfirmed};
|
||||
Property<bool> Fixed{mConfirmed};
|
||||
Property<uint64_t> FrameStart{mConfirmed};
|
||||
Property<uint64_t> FrameLength{mConfirmed};
|
||||
Property<uint64_t> FrameFadeInLength{mConfirmed};
|
||||
Property<uint64_t> FrameFadeOutLength{mConfirmed};
|
||||
Property<char> ValueUse{mConfirmed};
|
||||
Property<int> ValueFactor{mConfirmed};
|
||||
Property<int> Track{mConfirmed};
|
||||
Property<uint64_t> Delay{mConfirmed};
|
||||
Property<uint64_t> Duration{mConfirmed};
|
||||
|
||||
static void clearUnconfirmedObjects(SpitRepo<SObject> &repo);
|
||||
static void setConfirmedFalse(SpitRepo<SObject> &repo);
|
||||
static void eventProjectClosed(SpitRepo<SObject> &repo, SpitRepo<SObject> &remoteRepo);
|
||||
|
||||
SObject(string iD) {
|
||||
mID = iD;
|
||||
}
|
||||
|
||||
private:
|
||||
string mID;
|
||||
bool mConfirmed{};
|
||||
bool mCreatedByClient{};
|
||||
bool mActionAssigned{};
|
||||
bool mActionAssignedType{}; // Virtual construct
|
||||
char mValueUse{0x01};
|
||||
int mValueFactor{1000000}; // Values are given in ppm -> 1000000 = 1/1;
|
||||
bool mPlayPrePosition;
|
||||
uint64_t mPlayTimeInsideFrames;
|
||||
int mPlayValue;
|
||||
char mPlayValueFlag;
|
||||
|
||||
public:
|
||||
string getID() const { return mID; }
|
||||
|
||||
/**
|
||||
* 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 mConfirmed; }
|
||||
bool getCreatedByClient() const { return mCreatedByClient; }
|
||||
/**
|
||||
* 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 SObject with the SPITType.
|
||||
* @return true = an action is assigned for the SPITType.
|
||||
*/
|
||||
bool getActionAssignedType() const { return mActionAssignedType; }
|
||||
/** Returns if this SObject has an associated action or not.
|
||||
* @return true = the user has asscociated an action with this SObject or
|
||||
* the user has asscociated an action with the SPITType of this SObject
|
||||
*/
|
||||
bool getActionAssigned() const { return mActionAssigned || mActionAssignedType; }
|
||||
|
||||
bool getProjectIndepended(SpitRepo<SType> &repo, SpitRepo<SType> &remoteRepo) const {
|
||||
SType *ptrSPITType;
|
||||
if (ServerRemote.get() == false) {
|
||||
ptrSPITType = repo.getEntry(SPITTypeID.get());
|
||||
if (ptrSPITType == nullptr)
|
||||
return true;
|
||||
return ptrSPITType->ProjectIndepended.get();
|
||||
} else {
|
||||
ptrSPITType = remoteRepo.getEntry(SPITTypeID.get());
|
||||
if (ptrSPITType == nullptr)
|
||||
return true;
|
||||
return ptrSPITType->ProjectIndepended.get();
|
||||
}
|
||||
};
|
||||
|
||||
bool setConfirmed(bool confirmed);
|
||||
void setCreatedByClient(bool createdByClient) { mCreatedByClient = createdByClient; }
|
||||
bool setActionAssignedType(bool actionAssigned);
|
||||
bool setActionAssigned(bool actionAssigned);
|
||||
|
||||
bool setMessageOP(Message::ReportObject *message);
|
||||
void fillMessageOP(Message::ReportObject &message);
|
||||
void fillMessageOP(Message::RemoveObject &message);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#include "spit_object.hpp"
|
||||
#include <unordered_map>
|
||||
|
||||
namespace spit {
|
||||
|
||||
class SPlayer {
|
||||
|
||||
//----- PlayObject used in PlaySequences: PlaySPITStart, PlaySPITObject,..., PlaySPITEnd ------
|
||||
public:
|
||||
class PlayType {
|
||||
public:
|
||||
PlayType(SPlayer *spitPlayer, string spitObjectID);
|
||||
PlayType(const PlayType &orig);
|
||||
|
||||
string getSPITTypeID() const { return mSpitTypeID; }
|
||||
|
||||
void startPlaySequence();
|
||||
bool getIsNew() const { return mIsNew; }
|
||||
void setIsNew(bool isNew) { mIsNew = isNew; }
|
||||
bool getIsPlayed() const { return mIsPlayed; }
|
||||
void setIsPlayed(bool p_IsFound) { mIsPlayed = p_IsFound; }
|
||||
string getPlayerID() const { return mPlayerID; }
|
||||
string getPlayerName() const { return mPlayerName; }
|
||||
bool getPlayerIsRunning() const { return mPlayerRuns; }
|
||||
void setPlayerIsRunning(bool playerRuns) { mPlayerRuns = playerRuns; }
|
||||
void setValue(double value) { mValue = value; }
|
||||
void addValue(double value, double valueFactor) { mValue += (value * valueFactor); }
|
||||
double getValue() const { return mValue; }
|
||||
|
||||
private:
|
||||
string mPlayerID;
|
||||
string mPlayerName;
|
||||
bool mPlayerRuns;
|
||||
string mSpitTypeID;
|
||||
bool mIsPlayed;
|
||||
bool mIsNew;
|
||||
double mValue;
|
||||
};
|
||||
|
||||
//----- SPlayer ------
|
||||
public:
|
||||
// list the SPITPlayers
|
||||
static unordered_map<string, unique_ptr<SPlayer>> sSpitPlayers; // all actual played objects
|
||||
static SPlayer &getSPITPlayer(string pPlayerID); // if a player does not exist creates a new one
|
||||
static void clearPlayers() { sSpitPlayers.clear(); }
|
||||
|
||||
SPlayer(string pPlayerID);
|
||||
virtual ~SPlayer();
|
||||
|
||||
void startPlaySequence(); // called by SPIT_Client::parsePlaySPITStart
|
||||
PlayType *addTypePlaying(string spitTypeID); // called by SPIT_Client::parsePlaySPITStart
|
||||
void endPlaySequence(); // called by SPIT_Client::parsePlaySPITEnd
|
||||
|
||||
string getID() {
|
||||
return mId;
|
||||
}
|
||||
|
||||
unordered_map<string, unique_ptr<PlayType>> &getPlaySPITTypes() { return mPlaySPITTypes; }
|
||||
void setIsRunning(bool isRunning) { mIsRunning = isRunning; }
|
||||
void setName(string name) { mName = name; }
|
||||
void setType(char type) { mType = type; }
|
||||
void setTime(uint64_t frames) { mTimeFrames = frames; }
|
||||
bool getIsRunning() const { return mIsRunning; }
|
||||
string getName() const { return mName; }
|
||||
char getType() const { return mType; }
|
||||
uint64_t getTime() const { return mTimeFrames; }
|
||||
|
||||
private:
|
||||
string mId;
|
||||
string mName;
|
||||
char mType;
|
||||
unordered_map<string, unique_ptr<PlayType>> mPlaySPITTypes;
|
||||
|
||||
bool mIsRunning;
|
||||
uint64_t mTimeFrames;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
#pragma once
|
||||
|
||||
#include "Task.hpp"
|
||||
#include "esp_log.h"
|
||||
#include "esp_netif.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <fcntl.h>
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace spit {
|
||||
|
||||
/** Returns an guid */
|
||||
string createGUID();
|
||||
/** Returns the name of the client's host computer*/
|
||||
string getClientHostName();
|
||||
|
||||
class ISocket {
|
||||
public:
|
||||
/**
|
||||
* IpAddress class is used to fetch all available IP addresses of the computer
|
||||
* This is for internal usage
|
||||
*/
|
||||
struct IpAddress {
|
||||
public:
|
||||
IpAddress(const string &iPAddress, const string &subnetMask)
|
||||
: mIpAddress(iPAddress), mSubnetMask(subnetMask) {}
|
||||
const string mIpAddress;
|
||||
const string mSubnetMask;
|
||||
|
||||
/**
|
||||
* Calculates the broadcast address from a ip4 address
|
||||
* @param iPAddress the ip4 address
|
||||
* @return returns the broadcast address
|
||||
*/
|
||||
string getBroadcastIP4() const {
|
||||
struct in_addr broadcast;
|
||||
unsigned long ipAddress;
|
||||
unsigned long subnetMask;
|
||||
|
||||
ipAddress = inet_addr(mIpAddress.data());
|
||||
subnetMask = inet_addr(mSubnetMask.data());
|
||||
broadcast.s_addr = ipAddress | ~subnetMask;
|
||||
return inet_ntoa(broadcast);
|
||||
}
|
||||
};
|
||||
const IpAddress mOwnIp;
|
||||
|
||||
ISocket(IpAddress ip)
|
||||
: mOwnIp(ip) {}
|
||||
|
||||
virtual int sendMessage(const char *message, int length) = 0;
|
||||
virtual int receiveMessage(char *bu1ffer, int bufferLength, string *serverIp) const =0;
|
||||
virtual void setConnectionParams(const string &serverIp, const string &serverPort, const string &clientIp, const string &clientPort) =0;
|
||||
virtual int bindSocket(string clientIp, string clientPort) =0;
|
||||
virtual int setBroadcast(bool broadcast) const =0;
|
||||
virtual int sendMessageTo(const string &ip, const string &port, const char *message, int msgLength) =0;
|
||||
|
||||
bool getIsBound() const { return mIsBound; }
|
||||
protected:
|
||||
bool mIsBound{};
|
||||
};
|
||||
|
||||
class Socket : public ISocket {
|
||||
public:
|
||||
static const int FAMILY_IP4 = AF_INET;
|
||||
|
||||
|
||||
static IpAddress getAdaptersInfo();
|
||||
bool createSocketUdp();
|
||||
static const int INVALID_SOCKET = -1;
|
||||
|
||||
private:
|
||||
int mUdpSocketIp4;
|
||||
|
||||
public:
|
||||
//-------- class --------------
|
||||
Socket(IpAddress ip) : ISocket(ip) {
|
||||
mUdpSocketIp4 = INVALID_SOCKET;
|
||||
createSocketUdp();
|
||||
}
|
||||
virtual ~Socket() {
|
||||
ESP_LOGD("UDP", "Shutting down ...");
|
||||
|
||||
if (mUdpSocketIp4 != INVALID_SOCKET) {
|
||||
shutdown(mUdpSocketIp4, 2);
|
||||
close(mUdpSocketIp4);
|
||||
mUdpSocketIp4 = INVALID_SOCKET;
|
||||
}
|
||||
fos::Task::delayMs(100);
|
||||
mIsBound = false;
|
||||
}
|
||||
|
||||
private:
|
||||
string mServerIP{};
|
||||
string mServerPort{};
|
||||
string mClientIp{};
|
||||
string mClientPort{}; // port given by the user maybe "0"
|
||||
string mBoundClientPort{}; // port set after bind
|
||||
|
||||
public:
|
||||
// Sets the ip address and port for server and client.
|
||||
void setConnectionParams(const string &serverIp, const string &serverPort, const string &clientIp, const string &clientPort) override {
|
||||
mServerIP = serverIp;
|
||||
mServerPort = serverPort;
|
||||
mClientIp = clientIp;
|
||||
mClientPort = clientPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the server as set by setConnectionParams
|
||||
* @param message byte buffer containing the message
|
||||
* @param length length of the message
|
||||
* @return
|
||||
*/
|
||||
int sendMessage(const char *message, int length) override {
|
||||
if (mServerPort.length() <= 0) {
|
||||
return -1;
|
||||
}
|
||||
if (mIsBound == false) {
|
||||
return -1;
|
||||
}
|
||||
int intResult = sendMessageTo(mServerIP, mServerPort, message, length);
|
||||
return intResult;
|
||||
}
|
||||
|
||||
int receiveMessage(char *bu1ffer, int bufferLength, string *serverIp) const override;
|
||||
int setBroadcast(bool broadcast) const override;
|
||||
int bindSocket(string clientIp, string clientPort) override;
|
||||
int sendMessageTo(const string &ip, const string &port, const char *message, int msgLength) override;
|
||||
|
||||
string getServerIP() const { return mServerIP; }
|
||||
string getServerPort() const { return mServerPort; }
|
||||
string getClientIP() const { return mClientIp; }
|
||||
string getClientPort() const { return mClientPort; }
|
||||
string getBoundClientPort() const { return mBoundClientPort; }
|
||||
void setBoundClientPort(const string &port) { mBoundClientPort = port; }
|
||||
void setIsBound(bool isBound) { mIsBound = isBound; }
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
#pragma once
|
||||
|
||||
#include "spit_socket.hpp"
|
||||
#include "spit_message.hpp"
|
||||
#include "spit_repo.hpp"
|
||||
|
||||
using namespace std;
|
||||
namespace spit {
|
||||
|
||||
class STypeListener;
|
||||
|
||||
class SType {
|
||||
public:
|
||||
template <typename T>
|
||||
struct Property {
|
||||
friend SType;
|
||||
Property(bool &confirmed)
|
||||
: rConfirmed(confirmed) {
|
||||
}
|
||||
bool set(const T& val) {
|
||||
if (mValue == val)
|
||||
return false;
|
||||
mValue = val;
|
||||
rConfirmed = false;
|
||||
return true;
|
||||
}
|
||||
T get () const {
|
||||
return mValue;
|
||||
}
|
||||
private:
|
||||
bool & rConfirmed;
|
||||
T mValue{};
|
||||
};
|
||||
|
||||
Property<string> GroupName{mConfirmed};
|
||||
Property<string> Name{mConfirmed};
|
||||
Property<bool> Fixed{mConfirmed};
|
||||
Property<bool> ProjectIndepended{mConfirmed};
|
||||
// Returns if the SType 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 SType
|
||||
// true = the action is triggered on the server. The server waits for the client to play objects of this SType.
|
||||
Property<bool> ServerRemote{mConfirmed};
|
||||
Property<uint64_t> DefaultDelay{mConfirmed};
|
||||
Property<uint64_t> DefaultDuration{mConfirmed};
|
||||
// Virtual construct - means ActionAssigned for STypes is is not implemented in SPITProtocol.
|
||||
// This can used to setActionAssigned to all SPITObjects with this SType.
|
||||
// This may be used in the case when the same action should be done for every SPITObject with this SType associated.
|
||||
// @return true = the user has associated an action with this SType.
|
||||
Property<bool> ActionAssigned{mConfirmed};
|
||||
|
||||
// Sets confirmed = false for all STypes.
|
||||
// This should be called when the client has loaded a project.
|
||||
static void setConfirmedFalse(SpitRepo<SType> &repo) {
|
||||
auto &entries = repo.getRepo();
|
||||
for (auto i = entries.begin(); i != entries.end(); i++) {
|
||||
i->second->setConfirmed(false);
|
||||
}
|
||||
}
|
||||
static void eventProjectClosed(SpitRepo<SType> &repo, SpitRepo<SType> &remoteRepo) {
|
||||
auto &entries = repo.getRepo();
|
||||
for (auto i = entries.begin(); i != entries.end();) {
|
||||
SType *ptrSType = i->second.get();
|
||||
if (ptrSType->getCreatedByClient() == true) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
i = entries.erase(i);
|
||||
}
|
||||
// Remote
|
||||
remoteRepo.clearEntries();
|
||||
}
|
||||
|
||||
SType(string iD) {
|
||||
mID = iD;
|
||||
}
|
||||
SType(string iD, string grpName, string name, bool fixed, bool projectIndependent, uint64_t delay, uint64_t duration) {
|
||||
mConfirmed = false;
|
||||
mID = iD;
|
||||
ActionAssigned.set(false);
|
||||
GroupName.set(grpName);
|
||||
Name.set(name);
|
||||
Fixed.set(fixed);
|
||||
ProjectIndepended.set(projectIndependent);
|
||||
DefaultDelay.set(delay);
|
||||
DefaultDuration.set(duration);
|
||||
}
|
||||
|
||||
private:
|
||||
bool mConfirmed{};
|
||||
string mID;
|
||||
bool mCreatedByClient; // flag true = the SPITTyype is created by the client
|
||||
// false = the SType is received from the server
|
||||
|
||||
public:
|
||||
string getID() const { return mID; }
|
||||
|
||||
// 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 mConfirmed; }
|
||||
bool getCreatedByClient() const { return mCreatedByClient; }
|
||||
void setCreatedByClient(bool createdByClient) { mCreatedByClient = createdByClient; }
|
||||
|
||||
// Set the content of the SType as received from the server
|
||||
// @param p_ReportSType
|
||||
// @return true = the SType is changed
|
||||
// false = the SType is NOT changed, because it is not allowed to change.
|
||||
bool setMessageOP(Message::ReportType &message) {
|
||||
bool changeAllowed;
|
||||
|
||||
if ((mCreatedByClient == true) && (Fixed.get() == true)) {
|
||||
changeAllowed = false;
|
||||
} else {
|
||||
changeAllowed = true;
|
||||
}
|
||||
|
||||
// Confirmation should be changeable
|
||||
if (mCreatedByClient) {
|
||||
// Server reports a client created SType -> the type is confirmed
|
||||
mConfirmed = true;
|
||||
} else {
|
||||
// type is NOT client created -> the client has to confirm the SPITtype
|
||||
mConfirmed = message.getConfirmed();
|
||||
}
|
||||
|
||||
if (changeAllowed == false) {
|
||||
return false;
|
||||
}
|
||||
bool changed = false;
|
||||
|
||||
if (DefaultDelay.mValue != message.getDelay()) {
|
||||
DefaultDelay.mValue = message.getDelay();
|
||||
changed = true;
|
||||
}
|
||||
if (DefaultDuration.mValue != message.getDuration()) {
|
||||
DefaultDuration.mValue = message.getDuration();
|
||||
changed = true;
|
||||
}
|
||||
if (Fixed.mValue != message.getFixed()) {
|
||||
Fixed.mValue = message.getFixed();
|
||||
changed = true;
|
||||
}
|
||||
if (GroupName.mValue != message.getGroupName()) {
|
||||
GroupName.mValue = message.getGroupName();
|
||||
changed = true;
|
||||
}
|
||||
if (mID != message.getID()) {
|
||||
mID = message.getID();
|
||||
changed = true;
|
||||
}
|
||||
if (Name.mValue != message.getName()) {
|
||||
Name.mValue = message.getName();
|
||||
changed = true;
|
||||
}
|
||||
if (ProjectIndepended.mValue != message.getServerProjectIndepended()) {
|
||||
ProjectIndepended.mValue = message.getServerProjectIndepended();
|
||||
changed = true;
|
||||
}
|
||||
if (ServerRemote.mValue != message.getServerRemote()) {
|
||||
ServerRemote.mValue = message.getServerRemote();
|
||||
changed = true;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
void fillMessageOP(Message::ReportType &message) const {
|
||||
message.setConfirmed(mConfirmed);
|
||||
message.setDelay(DefaultDelay.mValue);
|
||||
message.setDuration(DefaultDuration.mValue);
|
||||
message.setFixed(Fixed.mValue);
|
||||
message.setGroupName(GroupName.mValue);
|
||||
message.setID(mID);
|
||||
message.setName(Name.mValue);
|
||||
message.setServerProjectIndepended(ProjectIndepended.mValue);
|
||||
message.setServerRemote(ServerRemote.mValue);
|
||||
}
|
||||
void fillMessageOP(Message::RemoveType &message) const {
|
||||
message.setID(mID);
|
||||
}
|
||||
|
||||
// This is used by the server and client to tell if the other side has registered the changes.
|
||||
// @param confirmed
|
||||
// @return if mConfirmed has changed
|
||||
bool setConfirmed(bool confirmed) {
|
||||
if (mConfirmed == confirmed)
|
||||
return false;
|
||||
mConfirmed = confirmed;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user