refactor: simplifying project until runs on embedded system

This commit is contained in:
2025-03-26 21:28:50 +01:00
parent c13310d540
commit 171a48eb71
28 changed files with 1260 additions and 3208 deletions
@@ -1,23 +1,9 @@
/*
* 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: SAD_ClientInterface.h
* Author: Hagi
*
* Created on 16. April 2019, 13:08
*/
#ifndef SAD_CLIENTINTERFACE_H
#define SAD_CLIENTINTERFACE_H
#pragma once
#include <string>
using namespace std;
class SAD_ClientInterface {
class I_SAD_Client {
public:
/**
* If a new server was found by the ServerAutoDetect mechanism, this function is called.<br>
@@ -32,11 +18,9 @@ public:
* @param p_IP the selected ip address of the SPIT server
* @param p_Port the port of the SPIT server
* @param p_Addition sometimes server may have additional informations
* @param p_isLoopback the server ip is a loopback address
* @param p_IsIP4 the server ip is a ip4 address
* @param p_IsIP6 the server ip is a ip6 address
*/
virtual void eventServerDetected(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_CLientIP, bool p_isLoopback, bool p_IsIP4, bool p_IsIP6) = 0;
virtual void eventServerDetected(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_CLientIP, bool p_IsIP4) = 0;
/**
* If a SPITServer is not more found, this function is called.
* To do so the SAD_Client ServerAutoDetect has to be startet - see SAD_Client::startServerAutoDetect.<br>
@@ -46,12 +30,7 @@ public:
* @param p_IP the selected ip address of the SPIT server
* @param p_Port the port of the SPIT server
* @param p_Addition sometimes server may have additional informations
* @param p_isLoopback the server ip is a loopback address
* @param p_IsIP4 the server ip is a ip4 address
* @param p_IsIP6 the server ip is a ip6 address
*/
virtual void eventServerLost(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_CLientIP, bool p_isLoopback, bool p_IsIP4, bool p_IsIP6) = 0;
virtual void eventServerLost(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_CLientIP, bool p_IsIP4) = 0;
};
#endif /* SAD_CLIENTINTERFACE_H */
+56 -88
View File
@@ -4,7 +4,7 @@
* and open the template in the editor.
*/
/*
/*
* File: MySPITApp.h
* Author: Hagi
*
@@ -15,105 +15,73 @@
#define MYSPITAPP_H
#include "SPIT_Client.h"
#include <string>
#include <chrono>
#include <string>
#include "SPITType.h"
#include "SPITObject.h"
#include "SPITPlayer.h"
#include "SAD_DetectedServer.hpp"
using namespace std;
class MyApp : SPIT_ClientInterface {
public:
MyApp();
virtual ~MyApp();
//Client's infos is set by the client
static string s_ClientName;
void loadClientProject();
private:
SPIT_Client* m_SPIT_Client; //pointer to an instance of the SPIT_Client, which do the main work for you
//MySPITApp client project infos they are transferred after the server send his project infos, see eventProjectReport
string m_ClientProjectID; //can be an id or simple the project's name
string m_ClientProjectName; //the name of the client's (this) project
//Server's info filled by eventConnectionStatus when SPIT_Client::CONNECTION_OK
string m_ServerID;
string m_ServerName;
string m_ServerComputerName;
int m_ServerStepTime;
//Server's project infos filled by eventProjectReport
string m_ServerProjectID;
string m_ServerProjectName;
int m_ServerFramesPerSecond; //set when the server reports his project, see eventProjectReport
//liveSHOWsoftware will use 44100 frames per second as time resolution
//All times are given in frames,
class MyApp {
public:
MyApp();
// Client's infos is set by the client
static string s_ClientName;
static string s_ProjectName;
void init();
//Reconnect to the server when connection is lost see eventConnectionStatus and eventServerDetected
bool m_FlagReconnect; //true = on eventServerDetected connect to the server identified by m_ServerID
private:
SPIT_Client _SpitClient; // pointer to an instance of the SPIT_Client, which do the main work for you
public:
//---------- SPIT_ClientInterface -------------
string getClientProjectID(); //should return the client's project id, maybe the same as project name
string getClientProjectName();
// Server's project infos filled by eventProjectReport
static string m_ServerProjectID;
static string m_ServerProjectName;
static int m_ServerFramesPerSecond; // set when the server reports his project, see eventProjectReport
// liveSHOWsoftware will use 44100 frames per second as time resolution
// All times are given in frames,
//----- ServerAutoDetection -----
void startServerAutoDetect(); //starts the autodetection of SPITServers in the local network area (see eventServerDetected)
void stopServerAutoDetect(); //stopps the autodetection
void eventServerDetected(const SAD_DetectedServer& p_DetectedServer); //a SPITServer is detected
void eventServerLost(const SAD_DetectedServer& p_DetectedServer); //a prior detected SPITServer is lost
//----- Connection -----
void eventConnectionStatus(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime, int p_ConnectionStatus, int p_OldConnectionStatus);
//----- Project -----
void eventProjectReport(string p_ProjectID, string p_ProjectName, int p_FramesPerSeoond);
void eventProjectClosed(string p_ProjectID);
void eventStartProjectTransfer();
void eventEndProjectTransfer();
//----- SPITType -----
public:
//----- ServerAutoDetection -----
static void onServerDetected(const SAD_DetectedServer &p_DetectedServer); // a SPITServer is detected
static void onServerLost(const SAD_DetectedServer &p_DetectedServer); // a prior detected SPITServer is lost
//----- Connection -----
void eventConnectionStatus(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime, int p_ConnectionStatus, int p_OldConnectionStatus);
void eventSPITType(bool p_New, const SPITType& p_SPITType);
void eventSPITTypeRemote(bool p_New, const SPITType& p_SPITType);
void eventSPITTypeRemoved(const SPITType& p_SPITType);
void eventSPITTypeRemoteRemoved(const SPITType& p_SPITType);
//----- Project -----
static void onStartProjectTransfer();
static void onEndProjectTransfer();
static void onProjectReport(string p_ProjectID, string p_ProjectName, int p_FramesPerSeoond);
static void onProjectClosed(string p_ProjectID);
//----- SPITObject -----
void eventSPITObject(bool p_New, const SPITType& p_SPITType, const SPITObject& p_SPITObject);
void eventSPITObjectRemote(bool p_New, const SPITType& p_SPITType, const SPITObject& p_SPITObject);
void eventSPITObjectRemoved(const SPITType& p_SPITType, const SPITObject& p_SPITObject);
void eventSPITObjectRemoteRemoved(const SPITType& p_SPITType, const SPITObject& p_SPITObject);
//----- SPITType -----
static void onSpitType(bool p_New, const SPITType &p_SPITType);
static void onSpitTypeRemote(bool p_New, const SPITType &p_SPITType);
static void onSpitTypeRemoved(const SPITType &p_SPITType);
static void onSpitTypeRemoteRemoved(const SPITType &p_SPITType);
//----- Play SPITObjects -----
void eventPlay(string p_PlayerID, string p_PlayerName, char p_PlayerType, bool p_PlayerIsRunning, long long p_TimeFrames);
void eventPlayObject(string p_PlayerID, bool p_Started, bool p_Stopped, const SPITType& p_SPITType, const SPITObject& p_SPITObject, const SPITPlayer::PlayObject& p_PlayObject);
//----- SPITObject -----
static void onSpitObject(bool p_New, const SPITType &p_SPITType, const SPITObject &p_SPITObject);
static void onSpitObjectRemote(bool p_New, const SPITType &p_SPITType, const SPITObject &p_SPITObject);
static void onSpitObjectRemoved(const SPITType &p_SPITType, const SPITObject &p_SPITObject);
static void onSpitObjectRemoteRemoved(const SPITType &p_SPITType, const SPITObject &p_SPITObject);
//----- Server changes status of one of his REMOTE SPITObjects -----
//REMOTE only Server->Client RemoteObject's play status
void eventPlayRemoteObjectStatus(const SPITType& p_SPITType, const SPITObject& p_SPITObject, long long p_FrameInsideObject, int p_Value);
//----- Play SPITObjects -----
static void onPlay(string p_PlayerID, string p_PlayerName, char p_PlayerType, bool p_PlayerIsRunning, long long p_TimeFrames);
static void onPlayObject(string p_PlayerID, bool p_Started, bool p_Stopped, const SPITType &p_SPITType, const SPITObject &p_SPITObject, const SPITPlayer::PlayObject &p_PlayObject);
void sendRemoteObject(string p_SPITObjectID, int p_Valueppm = 0, char p_ValueFlag = 0x00);
//-----
void testLiveShowRemote();
//------ User's options normally should not be used, the server is master of things ------
public:
//----- SPITType -----
int removeSPITType(string p_SPITTypeID);
int changeSPITType(SPITType* p_SPITType);
//----- SPITObject -----
int removeSPITObject(string p_SPITObjectID);
int changeSPITObject(SPITObject* p_SPITObject);
//----- Server changes status of one of his REMOTE SPITObjects -----
// REMOTE only Server->Client RemoteObject's play status
static void onPlayRemoteObjectStatus(const SPITType &p_SPITType, const SPITObject &p_SPITObject, long long p_FrameInsideObject, int p_Value);
void sendRemoteObject(string p_SPITObjectID, int p_Valueppm = 0, char p_ValueFlag = 0x00);
//-----
void testLiveShowRemote();
//------ User's options normally should not be used, the server is master of things ------
public:
};
#endif /* MYSPITAPP_H */
-60
View File
@@ -1,60 +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: ServerAutoDetetc_Client.h
* Author: Hagi
*
* Created on 16. April 2019, 08:57
*/
#ifndef SERVERAUTODETETC_CLIENT_H
#define SERVERAUTODETETC_CLIENT_H
#include "_SPITMACROS.h"
#include "SPIT_Handler.h"
#include "SPITSocket.h"
#include "SAD_DetectedServer.h"
#include <string>
#include <list>
#include "Mutex.hpp"
#include "Semaphore.hpp"
#include "Task.hpp"
static const string SERVERAUTODETECT_PRECODE = "#SAD#";
static const string SERVERAUTODETECT_SEPERATOR = "#,#";
static const string SERVERAUTODETECT_TASKID = "#spit#";
static const string SERVERAUTODETECT_PORT = "15110";
class SAD_Client {
//----- SAD Client Interface ------
private:
static SAD_ClientInterface* s_SADClientInterface;
//----- SAD_Client -----
public:
private:
static fos::Mutex s_MutexSAD;
static fos::Semaphore s_ConditionStopSAD;
static bool s_StopSAD;
static fos::Task* s_ThreadSend;
static fos::Task* s_ThreadReceiveIP4;
static fos::Mutex s_MutexSocket;
static SPITSocket* s_SPITSocket;
static void cycleStart();
static void cycleEnd();
static void sendAutoDetectServer();
static void receiveAutoDetectServer_IP4();
public:
static void startAutoDetectServer(SAD_ClientInterface* p_SADClientInterface, SPITSocket* p_SPITSocket);
static void stopAutoDetectServer(SAD_ClientInterface* p_SADClientInterface);
};
#endif /* SERVERAUTODETETC_CLIENT_H */
@@ -1,32 +1,14 @@
/*
* 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
/*
* This class describes a detected SPITServer, found by SAD_Client.<br>
* File: SAD_DetectedServer.h
* Author: Hagi
*
* Created on 4. Mai 2019, 13:51
*/
#ifndef SAD_DETECTEDSERVER_H
#define SAD_DETECTEDSERVER_H
#include "SAD_ClientInterface.h"
#include "I_SAD_Client.hpp"
#include <string>
#include "Mutex.hpp"
#include <unordered_map>
#include <list>
using namespace std;
class SAD_DetectedServer {
public:
SAD_DetectedServer();
SAD_DetectedServer(const SAD_DetectedServer& orig) {
@@ -34,9 +16,7 @@ public:
m_Name = orig.getName();
m_ComputerName = orig.getComputerName();
m_IP = orig.getIP();
m_IPIsLoopback = orig.getIpIsLoopback();
m_IPIsIP4 = orig.getIpIsIP4();
m_IPIsIP6 = orig.getIpIsIP6();
m_ClientIP = orig.getClientIP();
m_Port = orig.getPort();
m_Additions = orig.getAdditions();
@@ -48,9 +28,7 @@ public:
string m_Name;
string m_ComputerName;
string m_IP;
bool m_IPIsLoopback;
bool m_IPIsIP4;
bool m_IPIsIP6;
string m_ClientIP;
string m_Port;
string m_Additions;
@@ -59,123 +37,40 @@ public:
bool m_FoundAgain;
public:
/**
*
* @return ID of the SPITServer
*/
string getID() const {
return m_ID;
}
/**
*
* @return name of the SPITServer
*/
string getName() const {
return m_Name;
}
/**
*
* @return name of the computer where the SPITServer runs
*/
string getComputerName() const {
return m_ComputerName;
}
/**
* @return IP address at which the server can be reached
*/
string getIP() const {
return m_IP;
}
/**
* @return true = the SPITServer's IP address is a loopback address
*/
bool getIpIsLoopback() const {
return m_IPIsLoopback;
}
/**
* @return true = the SPITServer's IP address is an IP4 address
*/
bool getIpIsIP4() const {
return m_IPIsIP4;
}
/**
* @return true = the SPITServer's IP address is an IP6 address
*/
bool getIpIsIP6() const {
return m_IPIsIP6;
}
/**
* @return port of the SPITServer
*/
string getPort() const {
return m_Port;
}
/**
*
* @return The IP address of the client under which this client reached the server.
*/
string getClientIP() const {
return m_ClientIP;
}
/**
* Sometimes the SPITServer has additional informations
* @return
*/
string getAdditions() const {
return m_Additions;
}
string getID() const { return m_ID; }
string getName() const { return m_Name; }
string getComputerName() const { return m_ComputerName; }
string getIP() const { return m_IP; }
bool getIpIsIP4() const { return m_IPIsIP4; }
string getPort() const { return m_Port; }
string getClientIP() const { return m_ClientIP; }
string getAdditions() const { return m_Additions; }
private:
void setID(string p_ID);
void setName(string p_Name);
void setComputerName(string p_ComputerName);
void setIP(string p_IP);
void setClientIP(string p_IP);
void setPort(string p_Port);
void setAdditions(string p_Additions);
void setIPIsLoopback(bool p_IsLoopback) {
m_IPIsLoopback = p_IsLoopback;
}
void setIPIsIP4(bool p_IsIP4) {
m_IPIsIP4 = p_IsIP4;
}
void setIPIsIP6(bool p_IsIP6) {
m_IPIsIP6 = p_IsIP6;
}
bool getNew() const {
return m_New;
}
bool getChanged() const {
return m_Changed;
}
bool getFoundAgain() const {
return m_FoundAgain;
}
void setChanged() {
m_Changed = true;
}
void setNew(bool p_New) {
m_New = p_New;
}
void setFoundAgain() {
m_FoundAgain = true;
}
void setID(string p_ID) { m_ID = p_ID; }
void setName(string p_Name) { m_Name = p_Name; }
void setComputerName(string p_ComputerName) { m_ComputerName = p_ComputerName; }
void setIP(string p_IP) { m_IP = p_IP; }
void setClientIP(string p_IP) { m_ClientIP = p_IP; }
void setPort(string p_Port) { m_Port = p_Port; }
void setAdditions(string p_Additions) { m_Additions = p_Additions;}
void setIPIsIP4(bool p_IsIP4) { m_IPIsIP4 = p_IsIP4; }
bool getNew() const { return m_New; }
bool getChanged() const { return m_Changed; }
bool getFoundAgain() const { return m_FoundAgain; }
void setChanged() { m_Changed = true; }
void setNew(bool p_New) { m_New = p_New; }
void setFoundAgain() { m_FoundAgain = true; }
//SAD_Client m_ThreadSend will send to Multicast addresses
void startCycleSAD() {
m_IPIsLoopback = false;
m_IPIsIP4 = false;
m_IPIsIP6 = false;
m_Changed = false;
m_FoundAgain = false;
}
//SAD_Client m_Thread_Send has paused in the meantime m_ThreadReceive may received messages from servers
void endCycleSAD() {
}
void endCycleSAD() { }
private:
static fos::Mutex s_MutexDetectedServer;
static unordered_map<string, SAD_DetectedServer*> s_DetectedServers;
public:
static const int PARAMINDEX_PRECODE = 0;
@@ -211,7 +106,7 @@ public:
* Used by SAD_Client internally -don't use this manually
* @param p_SADClientInterface
*/
static void cycleEnd(SAD_ClientInterface* p_SADClientInterface);
static void cycleEnd(I_SAD_Client& p_SADClientInterface);
/**
* Returns a reference of the DetectedServer with the id p_ServerID.<br>
@@ -222,7 +117,6 @@ public:
static const SAD_DetectedServer& getRefDetectedServer(string p_ServerID) {
SAD_DetectedServer* ptrDetectedServer = NULL;
{
fos::MutexGuard o_Lock(s_MutexDetectedServer);
auto i = s_DetectedServers.find(p_ServerID);
if (i != s_DetectedServers.end()) {
ptrDetectedServer = i->second;
@@ -237,6 +131,3 @@ public:
};
#endif /* SAD_DETECTEDSERVER_H */
-5
View File
@@ -18,7 +18,6 @@
#include "SPITType.h"
#include <string>
#include <unordered_map>
#include "Mutex.hpp"
using namespace std;
@@ -27,13 +26,9 @@ class SPITObjectListener;
class SPITObject {
private:
static fos::Mutex s_MutexSPITObject;
static unordered_map<string, SPITObject*> s_SPITObjects;
static unordered_map<string, SPITObject*> s_SPITObjectsRemote;
public:
static fos::Mutex* getMutex() {
return &s_MutexSPITObject;
}
static SPITObject* getSPITObject(string p_ID);
static const SPITObject& getSPITObjectRef(string p_ID);
static bool addSPITObject(SPITObject* p_ptrSpitObject);
-4
View File
@@ -119,10 +119,6 @@ public:
//----- SPITPlayer ------
public:
static fos::Mutex s_Mutex;
static fos::Mutex* getMutex() {
return &s_Mutex;
}
//list the SPITPlayers
static unordered_map<string, SPITPlayer*> s_SPITPlayers; //all actual played objects
static SPITPlayer* getSPITPlayer(string p_PlayerID); //if a player does not exist creates a new one
+110 -114
View File
@@ -5,7 +5,7 @@
*/
/*
* SPITSocket is the base class for WindowsSocket, UnixSocket,..<br>
* SPITSocket is the base class for WindowsSocket, UnixSocket,.
* Used by SPIT_Client and SAD_Client.
* File: SPITSocket.h
* Author: Hagi
@@ -15,66 +15,92 @@
#ifndef SPITSOCKET_H
#define SPITSOCKET_H
#include "_SPITMACROS.h"
#include "Mutex.hpp"
#include <unordered_map>
#include <string>
#include "esp_netif.h"
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include "Task.hpp"
#include "esp_log.h"
using namespace std;
/** Returns an guid */
string createGUID();
/** Returns the name of the client's host computer*/
string getClientHostName();
class SPITSocket{
public:
static int FAMILY_IP4;
static int FAMILY_IP6;
//-------- nested classes --------------
public:
static const int FAMILY_IP4 = AF_INET;
/**
* IPAddress class is used to fetch all available IP addresses of the computer.<br>
* This is for internal usage.<br>
* IPAddress class is used to fetch all available IP addresses of the computer
* This is for internal usage
*/
class IPAddress {
struct IPAddress {
public:
IPAddress();
~IPAddress();
private:
string m_IPAddress;
string m_SubnetMask;
bool m_Found;
public:
const string& getIPAddress() {
return m_IPAddress;
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 string& getSubnetMask() {
return m_SubnetMask;
}
bool getFound() {
return m_Found;
}
void setIPAddress(const string& p_IPAddress);
void setSubnetMask(const string& p_SubnetMask);
void setFound(bool p_Found);
};
const IPAddress mOwnIp;
static IPAddress getAdaptersInfo();
bool createSocket_UDP();
static const int INVALID_SOCKET = -1;
private:
static fos::Mutex s_MutexIPAddresses;
int m_UDPSocketIP4;
public:
static unordered_map<string, IPAddress*> s_IPAddresses;
static void addIPAddress(string p_IPAddress, string p_SubnetMask);
static void removeIPAddress(string p_IPAddress);
static int getIPAddressCount();
static IPAddress* getIPAddress(int p_Index);
static void clearIPAddresses();
static void resetFoundIPAddresses();
static void removeNotFoundIPAddresses();
//-------- class --------------
SPITSocket();
virtual ~SPITSocket();
SPITSocket(IPAddress ip) : mOwnIp(ip) {
m_UDPSocketIP4 = INVALID_SOCKET;
m_ServerIP = "";
m_ServerPort = "";
m_ClientIP = "";
m_ClientPort = "";
m_BoundClientPort = "";
m_BoundClientFamily = 0;
m_IsBound = false;
createSocket_UDP();
}
virtual ~SPITSocket() {
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;
@@ -83,7 +109,7 @@ private:
string m_BoundClientPort; //port set after bind
int m_BoundClientFamily;
bool m_IsBound;
fos::Mutex m_MutexSocket;
public:
/**
* Sets the ip address and port for server and client.
@@ -92,79 +118,49 @@ public:
* @param p_ClientIP
* @param p_ClientPort
*/
void setConnectionParams(string p_ServerIP, string p_ServerPort, string p_ClientIP, string p_ClientPort);
void setConnectionParams(string p_ServerIP, string p_ServerPort, string p_ClientIP, string p_ClientPort) {
m_ServerIP = p_ServerIP;
m_ServerPort = p_ServerPort;
m_ClientIP = p_ClientIP;
m_ClientPort = p_ClientPort;
}
/**
* Send a message to the server as set by setConnectionParams.<br>
* Send a message to the server as set by setConnectionParams
* @param p_MessageBytes byte buffer containing the message
* @param p_MessageLength length of the messaeg
* @return
*/
int sendMessage(const char* p_MessageBytes, int p_MessageLength);
/**
* Call this for receiving a message.<br>
* This will block until a message is received or the underlying socket is closed.<br>
* @param p_InetFamily either AF_INET or AF_INET6<br>
* The SPITSocket creates two udp sockets, one for IP4 and one for IP6.<br>
* This parameter decides from which socket should a message recieved.<br>
* @param p_Buffer the buffer containing the received message later.
* @param p_BufferLength the size of the buffer
* @param p_ServerIP a pointer to a string, when a messages is received the string will contain the ip address of the sender/server.<br>
* if p_ServerIP is NULL - no detection of the server will be done.
* @return
*/
virtual int receiveMessage(int p_InetFamily, char* p_Buffer, int p_BufferLength, string* p_ServerIP) = 0;
/**
* Returns the broadcast address of an ip4 address.<br>
* @param p_IPAdress
* @return
*/
virtual string getBroadcastIP4(IPAddress* p_IPAdress) = 0;
/**
* Set whether the sockat are brodcast sockets or not
* @param p_Broadcast true = the sockets are broadcast sockets
* @return 0 = ok, -1 = error
*/
virtual int setBroadcast(bool p_Broadcast) = 0;
/**
* Bind the client's udp socket to an ip address and port.<br>
* @param p_ClientIP the ip address either IP4 or IP6
* @param p_ClientPort the client port number.<br>
* "0" = bind to any free port.<br>
* @return
*/
virtual int bindSocket(string p_ClientIP, string p_ClientPort) = 0;
/**
* Internal usage - don't use this manually.<br>
* Use sendMessage instead.<br>
* @param p_InetFamily
* @param p_ServerIP
* @param p_Port
* @param p_MessageBytes
* @param p_MessageLength
* @return
*/
virtual int sendMessageTo(int p_InetFamily, string p_ServerIP, string p_Port, const char* p_MessageBytes, int p_MessageLength) = 0;
/**
* Internal usage - don't use this manually.<br>
*/
virtual void getAdaptersInfo() = 0;
string getServerIP();
string getServerPort();
string getClientIP();
string getClientPort();
string getBoundClientPort();
void setBoundClientPort(string p_Port);
void setBoundClientFamily(int p_Family);
int getBoundClientFamily();
void setIsBound(bool p_IsBound);
bool getIsBound();
int sendMessage(const char* p_MessageBytes, int p_MessageLength) {
if (m_ServerPort.length() <= 0)
return -1;
int intResult;
{
if (m_IsBound == false)
return -1;
intResult = sendMessageTo(m_BoundClientFamily, m_ServerIP, m_ServerPort, p_MessageBytes, p_MessageLength);
}
return intResult;
}
int receiveMessage(int p_InetFamily, char* p_Buffer, int p_BufferLength, string* p_ServerIP);
int setBroadcast(bool p_Broadcast);
int bindSocket(string p_ClientIP, string p_ClientPort);
// * Internal usage - don't use this manually
// * Use sendMessage instead
int sendMessageTo(int p_InetFamily, string p_ServerIP, string p_Port, const char* p_MessageBytes, int p_MessageLength);
string getServerIP() { return m_ServerIP; }
string getServerPort(){ return m_ServerPort; }
string getClientIP() { return m_ClientIP; }
string getClientPort() { return m_ClientPort; }
string getBoundClientPort() { return m_BoundClientPort; }
void setBoundClientPort(string p_Port) { m_BoundClientPort = p_Port; }
void setBoundClientFamily(int p_Family) { m_BoundClientFamily = p_Family; }
int getBoundClientFamily() { return m_BoundClientFamily; }
void setIsBound(bool p_IsBound) { m_IsBound = p_IsBound; }
bool getIsBound() { return m_IsBound; }
};
#endif /* SPITSOCKET_H */
+9 -34
View File
@@ -14,12 +14,10 @@
#ifndef SPITTYPE_H
#define SPITTYPE_H
#include "_SPITMACROS.h"
#include "SPITSocket.h"
#include "SPIT_Message.h"
#include <string>
#include <unordered_map>
#include "Mutex.hpp"
using namespace std;
@@ -27,16 +25,10 @@ class SPITTypeListener;
class SPITType {
private:
static fos::Mutex s_MutexSPITType;
static unordered_map<string, SPITType*> s_SPITTypes;
static unordered_map<string, SPITType*> s_SPITTypesRemote;
public:
static fos::Mutex* getMutex() {
return &s_MutexSPITType;
}
static SPITType* getSPITType(string p_ID);
static const SPITType& getSPITTypeRef(string p_ID);
static bool addSPITType(SPITType* p_ptrSpitType);
@@ -82,15 +74,9 @@ private:
void initMembers();
public:
string getID() const{
return m_ID;
}
string getGroupName() const {
return m_GroupName;
}
string getName() const {
return m_Name;
}
string getID() const{ return m_ID; }
string getGroupName() const { return m_GroupName; }
string getName() const { return m_Name; }
/**
* Returns if the SPITType triggers an action on the Server or on the client.
* @return false = the action is triggered on the client The client waits for the server to play objects of this SPITType<br>
@@ -107,22 +93,11 @@ public:
* 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;
}
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.<br>
+59 -376
View File
@@ -14,30 +14,42 @@
#ifndef SPIT_CLIENT_H
#define SPIT_CLIENT_H
#include "_SPITMACROS.h"
#include "UnixSocket.h"
#include "SPITSocket.h"
#include "SAD_Client.h"
#include "SAD_ClientInterface.h"
#include "SAD_DetectedServer.h"
#include "SPIT_ClientInterface.h"
#include "SAD_DetectedServer.hpp"
#include "SPIT_Message.h"
#include "Watchdog.h"
#include "SPITType.h"
#include "SPITObject.h"
#include "SPIT_Handler.h"
#include "SPITPlayer.h"
#include <memory>
using namespace std;
//static char nullChar[] = "\0";
class SPIT_Client : I_SAD_Client {
class SPIT_Client : SAD_ClientInterface, Watchdog::Listener {
public:
/** Maximal length of a SPITMessage*/
static const int MAXSPITMESSAGEBYTECOUNT = 512;
struct Callbacks {
void(*onServerDetect)(const SAD_DetectedServer &p_DetectedServer);
void(*onServerLost)(const SAD_DetectedServer &p_DetectedServer);
void(*onStartProjectTransfer)();
void(*onEndProjectTransfer)();
void(*onProjectClosed)(string);
void(*onProjectReport)(string p_ProjectID, string p_ProjectName, int p_FramesPerSeoond);
void(*onSpitType)(bool p_New, const SPITType &p_SPITType);
void(*onSpitTypeRemote)(bool p_New, const SPITType &p_SPITType);
void(*onSpitObject)(bool p_New, const SPITType &p_SPITType, const SPITObject &p_SPITObject);
void(*onSpitObjectRemote)(bool p_New, const SPITType &p_SPITType, const SPITObject &p_SPITObject);
void(*onSpitTypeRemoved)(const SPITType &p_SPITType);
void(*onSpitTypeRemoteRemoved)(const SPITType &p_SPITType);
void(*onSpitObjectRemoved)(const SPITType &p_SPITType, const SPITObject &p_SPITObject);
void(*onSpitObjectRemoteRemoved)(const SPITType &p_SPITType, const SPITObject &p_SPITObject);
void(*onPlay)(string p_PlayerID, string p_PlayerName, char p_PlayerType, bool p_PlayerIsRunning, long long p_TimeFrames);
void(*onPlayObject)(string p_PlayerID, bool p_Started, bool p_Stopped, const SPITType &p_SPITType, const SPITObject &p_SPITObject, const SPITPlayer::PlayObject &p_PlayObject);
void(*onPlayRemoteObjectStatus)(const SPITType &p_SPITType, const SPITObject &p_SPITObject, long long p_FrameInsideObject, int p_Value);
};
//----- Connection Status -----
public:
/** No Connection established.<br>Either no connect tried or disconnected*/
@@ -46,7 +58,7 @@ public:
static const int CONNECTION_NONESERVER = 1;
/** The connection is lost<br>Either because of a network crash or because the server no longer responds.*/
static const int CONNECTION_LOST = 2;
/** Connection to the server is established.*/
/** Connection to the serv er is established.*/
static const int CONNECTION_OK = 3;
/** A connection to the server is tried.*/
static const int CONNECTION_TRYCONNECTION = 4;
@@ -72,48 +84,38 @@ public:
//----- SPIT_Client -----
public:
static SPITSocket* createSPITSocket();
public:
SPIT_Client(SPIT_ClientInterface* p_SPITClientInterface);
SPIT_Client(string name, string projName, Callbacks calls);
virtual ~SPIT_Client();
private:
/** SPITClientInterface, normally the user app should implement this*/
SPIT_ClientInterface* m_SPITClientInterface;
SPITSocket* m_SPITSocket;
fos::Mutex m_MutexSPITSocket;
fos::TaskT<SPIT_Client&> * m_ThreadReceive;
Callbacks mCallbacks;
fos::TaskT<SPIT_Client&> * m_ThreadReceive{};
bool m_StopReceiveSPITMessages;
int m_ConnectionStatus;
bool m_DisconnectedByServer; //flag true = when server disconnects
bool m_DisconnectedByServer{}; //flag true = when server disconnects
string m_ID;
string m_Name;
string m_ProjName;
string m_ComputerName;
//Server's info filled by parseConnectAnswer
string m_ServerID;
string m_ServerName;
string m_ServerComputerName;
int m_ServerStepTime;
Watchdog* m_Watchdog;
string m_ServerID{};
string m_ServerName{};
string m_ServerComputerName{};
int m_ServerStepTime{-1};
unsigned char m_MessageNumber_Send;
int m_MessageNumber_Received;
//--- Server Project ---
string m_ServerProjectID;
string m_ServerProjectName;
int m_ServerFramesPerSecond;
public:
SPIT_ClientInterface* getSPITClientInterface() {
return m_SPITClientInterface;
}
public:
/** The ID of the client.<br>Every client instance should set an unique id*/
string getID();
/** Set the name of the client, should be done by the user app*/
void setName(string p_Name);
/** The name of the client, should be set by the user app*/
string getName();
//----- Computer Params -----
@@ -153,10 +155,12 @@ private:
bool startReceiveSPITMessages();
void stopReceiveSPITMessages();
static void receiveSPITMessage(SPIT_Client& rM);
int sendSPITMessage(SPIT_Message::OPPart* p_SPITMessageOPPart);
int sendSPITMessage(SPIT_Message::OPPart& p_SPITMessageOPPart);
void fillHeader(SPIT_Message::Header* p_Header);
// Reconnect to the server when connection is lost see eventConnectionStatus and eventServerDetected
bool _doReconnect{}; // true = on eventServerDetected connect to the server identified by m_ServerID
//--------------- ServerAutoDetection SAD ---------------
public:
/** Starts the autodetection of SPITServers in the local network. If a connection is tried, the autodetection should be stopped before.*/
@@ -164,48 +168,10 @@ public:
/** Stops the autodetection of SPITServers in the local network*/
void stopServerAutoDetect();
/** Called every time a new SPITServer is detetced in the local network */
void eventServerDetected(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ClientIP, bool p_isLoopback, bool p_IsIP4, bool p_IsIP6);
void eventServerDetected(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ClientIP, bool p_IsIP4);
/** Called every time a prior detected SPITServer is is no longer found.*/
void eventServerLost(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ClientIP, bool p_isLoopback, bool p_IsIP4, bool p_IsIP6);
void eventServerLost(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ClientIP, bool p_IsIP4);
public:
/** Helper class to notify the SPITClientInterface/user's app*/
class NotifyServerDetected: virtual public SPIT_Handler::Runnable {
private:
SPIT_ClientInterface* m_SPITClientInterface;
SAD_DetectedServer m_DetectedServer;
public:
NotifyServerDetected(SPIT_ClientInterface* p_SPITClientInterface, const SAD_DetectedServer& p_DetetctedServer) {
m_SPITClientInterface = p_SPITClientInterface;
m_DetectedServer = p_DetetctedServer;
}
~NotifyServerDetected(){}
void run() {
if (m_SPITClientInterface != NULL) {
m_SPITClientInterface->eventServerDetected(m_DetectedServer);
}
}
};
public:
/** Helper class to notify the SPITClientInterface/user's app*/
class NotifyServerLost: virtual public SPIT_Handler::Runnable {
private:
SPIT_ClientInterface* m_SPITClientInterface;
SAD_DetectedServer m_DetectedServer;
public:
NotifyServerLost(SPIT_ClientInterface* p_SPITClientInterface, const SAD_DetectedServer& p_DetetctedServer) {
m_SPITClientInterface = p_SPITClientInterface;
m_DetectedServer = p_DetetctedServer;
}
~NotifyServerLost() {}
void run() {
if (m_SPITClientInterface != NULL) {
m_SPITClientInterface->eventServerLost(m_DetectedServer);
}
}
};
//--------------- Connection ---------------
public:
@@ -228,7 +194,7 @@ public:
private:
void disconnectInternal(int p_Cause);
void parseSPIT_Message(SPIT_Message* p_SPITMessage);
void parseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage);
void parseConnectAnswer(SPIT_Message::ConnectAnswer* p_ConnectAnswer);
void parseDisconnect(SPIT_Message::Disconnect* p_Disconnect);
void parseWatchdog(SPIT_Message::Watchdog* p_Watchdog);
@@ -238,36 +204,6 @@ public:
void sendWatchdog();
/** Used internally. When the connection to the SPITServer is lost an eventConnectionStatus will occur*/
void eventWatchdogLost();
public:
/** Helper class to notify the SPITClientInterface/user's app*/
class NotifyConnectionStatus : public SPIT_Handler::Runnable {
public:
NotifyConnectionStatus(SPIT_ClientInterface* p_SPITClientInterface, string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime,
int p_NewConnectionStatus, int p_OldConnectionStatus) {
m_SPITClientInterface = p_SPITClientInterface;
m_ServerID = p_ServerID;
m_ServerComputerName = p_ServerComputerName;
m_ServerName = p_ServerName;
m_ServerStepTime = p_ServerStepTime;
m_NewConnectionStatus = p_NewConnectionStatus;
m_OldConnectionStatus = p_OldConnectionStatus;
}
~NotifyConnectionStatus() {}
void run (){
if (m_SPITClientInterface != NULL) {
m_SPITClientInterface->eventConnectionStatus(m_ServerComputerName, m_ServerID, m_ServerName, m_ServerStepTime, m_NewConnectionStatus, m_OldConnectionStatus);
}
}
private:
SPIT_ClientInterface* m_SPITClientInterface;
string m_ServerID;
string m_ServerComputerName;
string m_ServerName;
int m_ServerStepTime;
int m_NewConnectionStatus;
int m_OldConnectionStatus;
};
//--------------- SPIT Project ---------------
private:
void parseReportSPITProject(SPIT_Message::ReportSPITProject* p_ReportSPITProject);
@@ -279,84 +215,11 @@ public:
string getServerProjectName();
/** Returns frame rate per second. This is the time resolution in which the server transmits time data. The unit of time data is always frames.*/
int getServerFramesPerSecond();
public:
/** Helper class to notify the SPITClientInterface/user's app*/
class NotifyReportProject : public SPIT_Handler::Runnable {
public:
NotifyReportProject(SPIT_ClientInterface* p_SPITClientInterface, string p_ProjectID, string p_ProjectName, int p_FramesPerSecond) {
m_SPITClientInterface = p_SPITClientInterface;
m_ProjectID = p_ProjectID;
m_ProjectName = p_ProjectName;
m_FramesPerSecond = p_FramesPerSecond;
}
~NotifyReportProject() {}
void run() {
if (m_SPITClientInterface != NULL) {
m_SPITClientInterface->eventProjectReport(m_ProjectID, m_ProjectName, m_FramesPerSecond);
}
}
private:
SPIT_ClientInterface* m_SPITClientInterface;
string m_ProjectID;
string m_ProjectName;
int m_FramesPerSecond;
};
public:
/** Helper class to notify the SPITClientInterface/user's app*/
class NotifyProjectClosed : public SPIT_Handler::Runnable {
public:
NotifyProjectClosed(SPIT_ClientInterface* p_SPITClientInterface, string p_ProjectID) {
m_SPITClientInterface = p_SPITClientInterface;
m_ProjectID = p_ProjectID;
}
~NotifyProjectClosed() {}
void run() {
if (m_SPITClientInterface != NULL) {
m_SPITClientInterface->eventProjectClosed(m_ProjectID);
}
}
private:
SPIT_ClientInterface* m_SPITClientInterface;
string m_ProjectID;
};
private:
void parseRequestProjectTransfer(SPIT_Message::RequestProjectTransfer* p_RequestProjectTransfer);
void parseStartProjectTransfer(SPIT_Message::StartProjectTransfer* p_StartProjectTransfer);
void parseEndProjectTransfer(SPIT_Message::EndProjectTransfer* p_EndProjectTransfer);
public:
/** Helper class to notify the SPITClientInterface/user's app*/
class NotifyStartProjectTransfer : public SPIT_Handler::Runnable {
public:
NotifyStartProjectTransfer(SPIT_ClientInterface* p_SPITClientInterface) {
m_SPITClientInterface = p_SPITClientInterface;
}
~NotifyStartProjectTransfer() {}
void run() {
if (m_SPITClientInterface != NULL) {
m_SPITClientInterface->eventStartProjectTransfer();
}
}
private:
SPIT_ClientInterface* m_SPITClientInterface;
};
public:
/** Helper class to notify the SPITClientInterface/user's app*/
class NotifyEndProjectTransfer : public SPIT_Handler::Runnable {
public:
NotifyEndProjectTransfer(SPIT_ClientInterface* p_SPITClientInterface) {
m_SPITClientInterface = p_SPITClientInterface;
}
~NotifyEndProjectTransfer() {}
void run() {
if (m_SPITClientInterface != NULL) {
m_SPITClientInterface->eventEndProjectTransfer();
}
}
private:
SPIT_ClientInterface* m_SPITClientInterface;
};
// --------------- SPIT Types ---------------
@@ -408,60 +271,6 @@ public:
*/
int removeSPITType(string p_SPITTypeID);
public:
/** Helper class to notify the SPITClientInterface/user's app*/
class NotifyReportSPITType : public SPIT_Handler::Runnable {
public:
NotifyReportSPITType(bool p_Remote, bool p_New, SPIT_ClientInterface* p_SPITClientInterface, const SPITType& p_SPITType) {
m_SPITClientInterface = p_SPITClientInterface;
m_Remote = p_Remote;
m_New = p_New;
m_SPITType = p_SPITType;
}
~NotifyReportSPITType() {}
void run() {
if (m_SPITClientInterface != NULL) {
if (m_Remote == false) {
m_SPITClientInterface->eventSPITType(m_New, m_SPITType);
}
else {
m_SPITClientInterface->eventSPITTypeRemote(m_New, m_SPITType);
}
}
}
private:
SPIT_ClientInterface* m_SPITClientInterface;
bool m_Remote;
bool m_New;
SPITType m_SPITType;
};
public:
/** Helper class to notify the SPITClientInterface/user's app*/
class NotifyRemoveSPITType : public SPIT_Handler::Runnable {
public:
NotifyRemoveSPITType(bool p_Remote, SPIT_ClientInterface* p_SPITClientInterface, const SPITType& p_SPITType) {
m_SPITClientInterface = p_SPITClientInterface;
m_Remote = p_Remote;
m_SPITType = p_SPITType;
}
~NotifyRemoveSPITType() {}
void run() {
if (m_SPITClientInterface != NULL) {
if (m_Remote == false) {
m_SPITClientInterface->eventSPITTypeRemoved(m_SPITType);
}
else {
m_SPITClientInterface->eventSPITTypeRemoteRemoved(m_SPITType);
}
}
}
private:
SPIT_ClientInterface* m_SPITClientInterface;
bool m_Remote;
SPITType m_SPITType;
};
//--------------- SPIT Objects ---------------
private:
@@ -484,63 +293,6 @@ public:
*/
int removeSPITObject(string p_SPITObjectID);
public:
/** Helper class to notify the SPITClientInterface/user's app*/
class NotifyReportSPITObject : public SPIT_Handler::Runnable {
public:
NotifyReportSPITObject(bool p_Remote, bool p_New, SPIT_ClientInterface* p_SPITClientInterface, const SPITType& p_SPITType, const SPITObject& p_SPITObject) {
m_SPITClientInterface = p_SPITClientInterface;
m_Remote = p_Remote;
m_New = p_New;
m_SPITType = p_SPITType;
m_SPITObject = p_SPITObject;
}
~NotifyReportSPITObject() {}
void run() {
if (m_SPITClientInterface != NULL) {
if (m_Remote == false) {
m_SPITClientInterface->eventSPITObject(m_New, m_SPITType, m_SPITObject);
}
else {
m_SPITClientInterface->eventSPITObjectRemote(m_New, m_SPITType, m_SPITObject);
}
}
}
private:
SPIT_ClientInterface* m_SPITClientInterface;
bool m_Remote;
bool m_New;
SPITType m_SPITType;
SPITObject m_SPITObject;
};
public:
/** Helper class to notify the SPITClientInterface/user's app*/
class NotifyRemoveSPITObject : public SPIT_Handler::Runnable {
public:
NotifyRemoveSPITObject(bool p_Remote, SPIT_ClientInterface* p_SPITClientInterface, const SPITType& p_SPITType, const SPITObject& p_SPITObject) {
m_SPITClientInterface = p_SPITClientInterface;
m_Remote = p_Remote;
m_SPITType = p_SPITType;
m_SPITObject = p_SPITObject;
}
~NotifyRemoveSPITObject() {}
void run() {
if (m_SPITClientInterface != NULL) {
if (m_Remote == false) {
m_SPITClientInterface->eventSPITObjectRemoved(m_SPITType, m_SPITObject);
}
else {
m_SPITClientInterface->eventSPITObjectRemoteRemoved(m_SPITType, m_SPITObject);
}
}
}
private:
SPIT_ClientInterface* m_SPITClientInterface;
bool m_Remote;
SPITType m_SPITType;
SPITObject m_SPITObject;
};
//--------------- Play SPIT Objects ---------------
private:
@@ -548,91 +300,22 @@ private:
void parsePlaySPITObject(SPIT_Message::PlaySPITObject* p_PlaySPITObject);
void parsePlaySPITEnd(SPIT_Message::PlaySPITEnd* p_PlaySPITEnd);
void parseReportPlayStatus(SPIT_Message::ReportPlayStatus* p_ReportPlayStatus);
public:
/** Helper class to notify the SPITClientInterface/user's app*/
class NotifyPlaySPITStart : public SPIT_Handler::Runnable {
public:
NotifyPlaySPITStart(SPIT_ClientInterface* p_SPITClientInterface, string p_PlayerID, string p_PlayerName, char p_PlayerType, bool p_IsRunning, long long p_TimeFrame) {
m_SPITClientInterface = p_SPITClientInterface;
m_PlayerID = p_PlayerID;
m_PlayerName = p_PlayerName;
m_PlayerType = p_PlayerType;
m_IsRunning = p_IsRunning;
m_TimeFrames = p_TimeFrame;
}
~NotifyPlaySPITStart() {}
void run() {
if (m_SPITClientInterface != NULL) {
m_SPITClientInterface->eventPlay(m_PlayerID, m_PlayerName, m_PlayerType, m_IsRunning, m_TimeFrames);
}
}
private:
SPIT_ClientInterface* m_SPITClientInterface;
string m_PlayerID;
string m_PlayerName;
char m_PlayerType;
bool m_IsRunning;
long long m_TimeFrames;
};
public:
/** Helper class to notify the SPITClientInterface/user's app*/
class NotifyPlaySPITObject : public SPIT_Handler::Runnable {
public:
NotifyPlaySPITObject(bool p_Started, bool p_Stopped,
SPIT_ClientInterface* p_SPITClientInterface, const SPITType& p_SPITType, const SPITObject& p_SPITObject, const SPITPlayer::PlayObject& p_PlayObject) {
m_Started = p_Started;
m_Stopped = p_Stopped;
m_SPITClientInterface = p_SPITClientInterface;
m_SPITType = p_SPITType;
m_SPITObject = p_SPITObject;
m_PlayObject = p_PlayObject;
}
~NotifyPlaySPITObject() {}
void run() {
if (m_SPITClientInterface != NULL) {
m_SPITClientInterface->eventPlayObject(m_PlayObject.getPlayerID(), m_Started, m_Stopped, m_SPITType, m_SPITObject, m_PlayObject);
}
}
private:
bool m_Started;
bool m_Stopped;
SPIT_ClientInterface* m_SPITClientInterface;
SPITObject m_SPITObject;
SPITType m_SPITType;
SPITPlayer::PlayObject m_PlayObject;
};
public:
/** Helper class to notify the SPITClientInterface/user's app*/
class NotifyReportPlayStatus: public SPIT_Handler::Runnable {
public:
NotifyReportPlayStatus(SPIT_ClientInterface* p_SPITClientInterface, const SPITType& p_SPITType, const SPITObject& p_SPITObject,
long long p_FrameInsideObject, int p_Value) {
m_SPITClientInterface = p_SPITClientInterface;
m_SPITObject = p_SPITObject;
m_SPITType = p_SPITType;
m_FrameInsideObject = p_FrameInsideObject;
m_Value = p_Value;
}
~NotifyReportPlayStatus() {}
private:
SPIT_ClientInterface* m_SPITClientInterface;
SPITObject m_SPITObject;
SPITType m_SPITType;
long long m_FrameInsideObject;
int m_Value;
public:
void run() {
if (m_SPITClientInterface != NULL) {
m_SPITClientInterface->eventPlayRemoteObjectStatus(m_SPITType, m_SPITObject, m_FrameInsideObject, m_Value);
}
}
};
public:
//--------- Remote ----------
void sendRemoteObject(string p_SPITObjectID, int p_Valueppm = 0, char p_ValueFlag = 0x00);
private:
static void processSocketTask(SPIT_Client & instance);
fos::TaskT<SPIT_Client &>* sThread{};
bool abortSearch{};
bool sAnswered{};
static fos::Semaphore sStartSad;
SPITSocket * mSPITSocket;
void answerWatchdog() {
sAnswered = true;
}
};
#endif /* SPIT_CLIENT_H */
@@ -1,82 +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: SPIT_ClientInterface.h
* Author: Hagi
*
* Created on 17. April 2019, 16:15
*/
#ifndef SPIT_CLIENTINTERFACE_H
#define SPIT_CLIENTINTERFACE_H
//#include <string>
#include "SPITType.h"
#include "SPITObject.h"
#include "SPITPlayer.h"
#include "SAD_DetectedServer.h"
using namespace std;
class SPIT_ClientInterface {
public:
virtual string getClientProjectID() = 0;
virtual string getClientProjectName() = 0;
/**
* If a new server was found by the ServerAutoDetect mechanism, this function is called.
* If a server can be reached via several IP addresses, the IP address is selected according to the following preference:<br>
* 1.) If a loopback address is available, it is used.<br>
* 2.) If an IP4 address is available, it is used.<br>
* 3.) In the other cases the IP6 address is used.<br>
* @param p_ID the id of the server (every started server should generate an id)
* @param p_Name the name of the SPIT server
* @param p_ComputerName the Hostname of the cpmputer on which the SPIT server is running
* @param p_IP the selected ip address of the SPIT server
* @param p_Port the port of the SPIT server
* @param p_Addition sometimes server may have additional informations
* @param p_isLoopback the server ip is a loopback address
* @param p_IsIP4 the server ip is a ip4 address
* @param p_IsIP6 the server ip is a ip6 address
*/
virtual void eventServerDetected(const SAD_DetectedServer& p_DetectedServer) = 0;
virtual void eventServerLost(const SAD_DetectedServer& p_DetectedServer) = 0;
virtual void eventConnectionStatus(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime, int p_ConnectionStatus, int p_OldConnectionStatus) = 0;
virtual void eventProjectReport(string p_ProjectID, string p_ProjectName, int p_FramesPerSeoond) = 0;
virtual void eventProjectClosed(string p_ProjectID) = 0;
virtual void eventStartProjectTransfer() = 0;
virtual void eventEndProjectTransfer() = 0;
virtual void eventSPITType(bool p_New, const SPITType& p_SPITType) = 0;
virtual void eventSPITTypeRemote(bool p_New, const SPITType& p_SPITType) = 0;
virtual void eventSPITTypeRemoved(const SPITType& p_SPITType) = 0;
virtual void eventSPITTypeRemoteRemoved(const SPITType& p_SPITType) = 0;
virtual void eventSPITObject(bool p_New, const SPITType& p_SPITType, const SPITObject& p_SPITObject) = 0;
virtual void eventSPITObjectRemote(bool p_New, const SPITType& p_SPITType, const SPITObject& p_SPITObject) = 0;
virtual void eventSPITObjectRemoved(const SPITType& p_SPITType, const SPITObject& p_SPITObject) = 0;
virtual void eventSPITObjectRemoteRemoved(const SPITType& p_SPITType, const SPITObject& p_SPITObject) = 0;
virtual void eventPlay(string p_PlayerID, string p_PlayerName, char p_PlayerType, bool p_PlayerIsRunning, long long p_TimeFrames) = 0;
virtual void eventPlayObject(string p_PlayerID, bool p_Started, bool p_Stopped, const SPITType& p_SPITType, const SPITObject& p_SPITObject, const SPITPlayer::PlayObject& p_PlayObject) = 0;
//REMOTE Server->Client
virtual void eventPlayRemoteObjectStatus(const SPITType& p_SPITType, const SPITObject& p_SPITObject, long long p_FrameInsideObject, int p_Value) = 0;
};
#endif /* SPIT_CLIENTINTERFACE_H */
-48
View File
@@ -1,48 +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: SPIT_Handler.h
* Author: Hagi
*
* Created on 24. April 2019, 11:17
*/
#ifndef SPIT_HANDLER_H
#define SPIT_HANDLER_H
#include "Mutex.hpp"
#include "Semaphore.hpp"
#include "Task.hpp"
#include <list>
using namespace std;
class SPIT_Handler {
public:
class Runnable {
public:
Runnable() {};
virtual ~Runnable();
virtual void run() = 0;
};
private:
static list<Runnable*> s_Runnables;
static fos::Mutex s_MutexLock;
static fos::Semaphore s_ConditionVariable;
static fos::Task* s_HandlerThread;
static bool s_WakeUp;
static bool s_Close;
static void run();
public:
static void addRunnable(Runnable* p_Runnable);
static void closeHandler();
};
#endif /* SPIT_HANDLER_H */
-51
View File
@@ -1,51 +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: UnixSocket.h
* Author: Hagi
*
* Created on 12. April 2019, 15:58
*/
#ifndef UNIXSOCKET_H
#define UNIXSOCKET_H
#include "_SPITMACROS.h"
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include "SPITSocket.h"
class UnixSocket : public SPITSocket{
public:
static const int INVALID_SOCKET = -1;
public:
UnixSocket();
virtual ~UnixSocket();
private:
int m_UDPSocketIP4;
int m_UDPSocketIP6;
public:
void getAdaptersInfo();
string getBroadcastIP4(IPAddress* p_IPAdress);
int setBroadcast(bool p_Broadcast);
static int init();
static int cleanUp();
bool createSocket_UDP();
int bindSocket(string p_ClientIP, string p_ClientPort);
int sendMessageTo(int p_InetFamily, string p_ServerIP, string p_ServerPort, const char* p_MessageBytes, int p_MessageLength);
int receiveMessage(int p_InetFamily, char* p_Buffer, int p_BufferLength, string* p_ServerIP);
};
#endif /* UNIXSOCKET_H */
-56
View File
@@ -1,56 +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: Watchdog.h
* Author: Hagi
*
* Created on 22. April 2019, 13:02
*/
#ifndef WATCHDOG_H
#define WATCHDOG_H
#include "_SPITMACROS.h"
#include "Mutex.hpp"
#include "Semaphore.hpp"
#include "Task.hpp"
using namespace std;
class Watchdog {
public:
class Listener {
public:
virtual void sendWatchdog()=0;
virtual void eventWatchdogLost()=0;
};
static int WATCHDOGTIME;
static bool s_StopWatchdog;
Watchdog(Listener* p_Listener);
virtual ~Watchdog();
private:
Listener* m_Listener;
fos::Mutex m_MutexLock;
fos::Semaphore m_ConditionVariable;
fos::TaskT<Watchdog&>* m_WatchdogThread;
bool m_Answered;
static void runWatchdog(Watchdog& wd);
public:
void startWatchdog();
void answerWatchdog();
void stopWatchdog();
};
#endif /* WATCHDOG_H */
-15
View File
@@ -1,15 +0,0 @@
#pragma once
#include <unistd.h>
// #include <uuid/uuid.h>
// To output debug information (printf calls in the code)
// you must set or comment out this precompiler definition
#include <string>
using namespace std;
/** Returns an guid */
string createGUID();
/** Returns the name of the client's host computer*/
string getClientHostName();