Further refactoring for better safety and maintainability
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
# SPIT
|
||||
|
||||
Original implementation from Hag seem to be not suited for Embedded devices.
|
||||
|
||||
- Supports IPv4 only
|
||||
- Reduced Threads to a minimum
|
||||
- Then reduced usage of Mutexes to a minimum
|
||||
- Reduced Sockets to a minimum
|
||||
- Introduced containers and removed plain new and delete
|
||||
- Removed UUID-Generation because SPIT-Types never change on embedded devices
|
||||
- Callbacks instead of interfaces where suitable
|
||||
Binary file not shown.
@@ -18,6 +18,7 @@
|
||||
#include "SPIT_Message.h"
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -25,13 +26,13 @@ class SPITObjectListener;
|
||||
|
||||
class SPITObject {
|
||||
private:
|
||||
static unordered_map<string, SPITObject *> sSpitObjects;
|
||||
static unordered_map<string, SPITObject *> sSpitObjectsRemote;
|
||||
static unordered_map<string, unique_ptr<SPITObject>> sSpitObjects;
|
||||
static unordered_map<string, unique_ptr<SPITObject>> sSpitObjectsRemote;
|
||||
|
||||
public:
|
||||
static SPITObject *getSPITObject(const string &id);
|
||||
static const SPITObject &getSPITObjectRef(const string &id);
|
||||
static void addSPITObject(SPITObject &spitObject);
|
||||
static void addSPITObject(unique_ptr<SPITObject> spitObject);
|
||||
static bool removeSPITObject(const SPITObject &spitObject);
|
||||
static bool removeSPITObject(const string & spitObjectID);
|
||||
static int getSPITObjectCount() {
|
||||
@@ -39,13 +40,13 @@ class SPITObject {
|
||||
}
|
||||
static SPITObject *getSPITObject(int p_Index);
|
||||
static const SPITObject &getSPITObjectRef(int p_Index);
|
||||
static void clearSPITObjects();
|
||||
static void clearSPITObjects() { sSpitObjects.clear(); }
|
||||
static void clearUnconfirmedSPITObjects();
|
||||
static void setConfirmedFalse();
|
||||
|
||||
static SPITObject *getSPITObjectRemote(const string &id);
|
||||
static const SPITObject &getSPITObjectRemoteRef(const string &id);
|
||||
static void addSPITObjectRemote(SPITObject &spitObject);
|
||||
static void addSPITObjectRemote(unique_ptr<SPITObject> spitObject);
|
||||
static bool removeSPITObjectRemote(const SPITObject &spitObject);
|
||||
static bool removeSPITObjectRemote(const string & spitObjectID);
|
||||
static int getSPITObjectRemoteCount() {
|
||||
@@ -53,11 +54,11 @@ class SPITObject {
|
||||
}
|
||||
static SPITObject *getSPITObjectRemote(int p_Index);
|
||||
static const SPITObject &getSPITObjectRemoteRef(int p_Index);
|
||||
static void clearSPITObjectsRemote();
|
||||
static void clearSPITObjectsRemote(){ sSpitObjectsRemote.clear(); }
|
||||
|
||||
static void eventProjectClosed();
|
||||
|
||||
SPITObject();
|
||||
SPITObject(string p_ID);
|
||||
|
||||
private:
|
||||
string m_ID;
|
||||
|
||||
@@ -58,7 +58,7 @@ class SPITPlayer {
|
||||
public:
|
||||
// list the SPITPlayers
|
||||
static unordered_map<string, SPITPlayer *> s_SPITPlayers; // all actual played objects
|
||||
static SPITPlayer *getSPITPlayer(string p_PlayerID); // if a player does not exist creates a new one
|
||||
static SPITPlayer &getSPITPlayer(string p_PlayerID); // if a player does not exist creates a new one
|
||||
static void clearPlayers();
|
||||
|
||||
SPITPlayer(string p_PlayerID);
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "SPIT_Message.h"
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -25,32 +26,32 @@ class SPITTypeListener;
|
||||
|
||||
class SPITType {
|
||||
private:
|
||||
static unordered_map<string, SPITType *> sSpitTypes;
|
||||
static unordered_map<string, SPITType *> sSpitTypesRemote;
|
||||
static unordered_map<string, unique_ptr<SPITType>> sSpitTypes;
|
||||
static unordered_map<string, unique_ptr<SPITType>> sSpitTypesRemote;
|
||||
|
||||
public:
|
||||
static SPITType *getSPITType(const string &id);
|
||||
static const SPITType &getSPITTypeRef(const string &id);
|
||||
static void addSPITType(SPITType &spitType);
|
||||
static void addSPITType( unique_ptr<SPITType> spitType);
|
||||
static bool removeSPITType(const SPITType &spitType);
|
||||
static int getSPITTypeCount() { return sSpitTypes.size(); }
|
||||
static SPITType *getSPITType(int p_Index);
|
||||
static const SPITType &getSPITTypeRef(int p_Index);
|
||||
static void clearSPITTypes();
|
||||
static void clearSPITTypes() { sSpitTypes.clear(); }
|
||||
static void setConfirmedFalse();
|
||||
|
||||
static SPITType *getSPITTypeRemote(const string &id);
|
||||
static const SPITType &getSPITTypeRemoteRef(const string &id);
|
||||
static void addSPITTypeRemote(SPITType &spitType);
|
||||
static void addSPITTypeRemote(unique_ptr<SPITType> spitType);
|
||||
static bool removeSPITTypeRemote(const SPITType &spitType);
|
||||
static int getSPITTypeRemoteCount() { return sSpitTypesRemote.size(); }
|
||||
static SPITType *getSPITTypeRemote(int p_Index);
|
||||
static const SPITType &getSPITTypeRemoteRef(int p_Index);
|
||||
static void clearSPITTypesRemote();
|
||||
static void clearSPITTypesRemote() { sSpitTypesRemote.clear(); }
|
||||
|
||||
static void eventProjectClosed();
|
||||
|
||||
SPITType();
|
||||
SPITType(string p_ID);
|
||||
SPITType(string p_ID, string p_GroupName, string p_Name, bool p_Fixed, bool p_ProjectIndepended, long long p_DefaultDelay, long long p_DefaultDuration);
|
||||
|
||||
private:
|
||||
@@ -80,7 +81,6 @@ class 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.
|
||||
|
||||
@@ -52,11 +52,8 @@ class SPIT_Client : I_SAD_Client {
|
||||
void (*onServerEvent)(ServerEvent event, const SAD_DetectedServer &p_DetectedServer){};
|
||||
void (*onConnectionStatus)(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime, int p_ConnectionStatus, int p_OldConnectionStatus){};
|
||||
void (*onProjectUpdate)(ProjUpdate state, string projectId){};
|
||||
|
||||
void (*onSpitType)(ObjectEvent event, const SPITType &p_SPITType){};
|
||||
void (*onSpitTypeRemote)(ObjectEvent event, const SPITType &p_SPITType){};
|
||||
void (*onSpitObject)(ObjectEvent event, const SPITType &p_SPITType, const SPITObject &p_SPITObject){};
|
||||
void (*onSpitObjectRemote)(ObjectEvent event, const SPITType &p_SPITType, const SPITObject &p_SPITObject){};
|
||||
void (*onSpitType)(ObjectEvent event, bool isRemote, const SPITType &p_SPITType){};
|
||||
void (*onSpitObject)(ObjectEvent event, bool isRemote, const SPITType &p_SPITType, const SPITObject &p_SPITObject){};
|
||||
|
||||
void (*onPlay)(string p_PlayerID, string p_PlayerName, char p_PlayerType, bool p_PlayerIsRunning, long long p_TimeFrames){};
|
||||
void (*onPlaySpitType)(string p_PlayerID, string p_SPITTypeID, bool p_PlayerIsRunning, bool p_Started, bool p_Ended, double p_Value){};
|
||||
@@ -96,12 +93,12 @@ class SPIT_Client : I_SAD_Client {
|
||||
static constexpr char VALUEFLAG_INCREASE = 0x01;
|
||||
/**Decrease the existing value by the given value.<br>This is usefull e.g. when instead of a fader a endless wheel is used*/
|
||||
static constexpr char VALUEFLAG_DECREASE = 0x02;
|
||||
static constexpr int MAX_OVERTAKING_SPIT_MESSAGES = 10;
|
||||
|
||||
//----- SPIT_Client -----
|
||||
public:
|
||||
SPIT_Client(string name, string projName, Callbacks calls);
|
||||
virtual ~SPIT_Client();
|
||||
static int s_MAX_OVERTAKING_SPIT_MESSAGES;
|
||||
|
||||
private:
|
||||
Callbacks mCallbacks;
|
||||
@@ -120,7 +117,7 @@ class SPIT_Client : I_SAD_Client {
|
||||
|
||||
unsigned char m_MessageNumber_Send;
|
||||
int m_MessageNumber_Received;
|
||||
vector<SPIT_Message *> m_OvertakingSPIT_Messages;
|
||||
vector<unique_ptr<SPIT_Message>> m_OvertakingSPIT_Messages;
|
||||
|
||||
// Server's info filled by parseConnectAnswer
|
||||
string m_ServerID{};
|
||||
@@ -220,7 +217,7 @@ class SPIT_Client : I_SAD_Client {
|
||||
void resetMessageNumberReceived();
|
||||
void parseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage);
|
||||
void checkParseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage);
|
||||
void addOvertakingSPIT_Message(SPIT_Message *p_SPIT_Message);
|
||||
void addOvertakingSPIT_Message(unique_ptr<SPIT_Message> p_SPIT_Message);
|
||||
void parseConnectAnswer(SPIT_Message::ConnectAnswer *p_ConnectAnswer);
|
||||
void parseDisconnect(SPIT_Message::Disconnect *p_Disconnect);
|
||||
void parseWatchdog(SPIT_Message::Watchdog *p_Watchdog);
|
||||
|
||||
@@ -14,16 +14,17 @@
|
||||
|
||||
#include "SPITObject.h"
|
||||
#include "SPITSocket.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
unordered_map<string, SPITObject *> SPITObject::sSpitObjects;
|
||||
unordered_map<string, SPITObject *> SPITObject::sSpitObjectsRemote;
|
||||
unordered_map<string, unique_ptr<SPITObject>> SPITObject::sSpitObjects;
|
||||
unordered_map<string, unique_ptr<SPITObject>> SPITObject::sSpitObjectsRemote;
|
||||
|
||||
SPITObject *SPITObject::getSPITObject(const string &id) {
|
||||
auto i = sSpitObjects.find(id);
|
||||
if (i == sSpitObjects.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return i->second;
|
||||
return i->second.get();
|
||||
}
|
||||
/**
|
||||
* Returns the reference of the SPITObject with ID == id.
|
||||
@@ -40,7 +41,7 @@ SPITObject *SPITObject::getSPITObjectRemote(const string &id) {
|
||||
if (i == sSpitObjectsRemote.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return i->second;
|
||||
return i->second.get();
|
||||
}
|
||||
/**
|
||||
* Returns the reference of the remote SPITObject with ID == id.
|
||||
@@ -52,16 +53,18 @@ const SPITObject &SPITObject::getSPITObjectRemoteRef(const string &id) {
|
||||
return *sSpitObjectsRemote.at(id);
|
||||
}
|
||||
|
||||
void SPITObject::addSPITObject(SPITObject &spitObject) {
|
||||
sSpitObjects[spitObject.getID()] = &spitObject;
|
||||
void SPITObject::addSPITObject(unique_ptr<SPITObject> spitObject) {
|
||||
ESP_LOGD("OBJ", "adding spitObject %s/%s", spitObject->getID().c_str(), spitObject->getName().c_str());
|
||||
sSpitObjects[spitObject->getID()] = move(spitObject);
|
||||
}
|
||||
void SPITObject::addSPITObjectRemote(SPITObject &spitObject) {
|
||||
sSpitObjectsRemote[spitObject.getID()] = &spitObject;
|
||||
void SPITObject::addSPITObjectRemote(unique_ptr<SPITObject> spitObject) {
|
||||
ESP_LOGD("OBJ", "adding spitObject %s/%s", spitObject->getID().c_str(), spitObject->getName().c_str());
|
||||
sSpitObjectsRemote[spitObject->getID()] = move(spitObject);
|
||||
}
|
||||
bool SPITObject::removeSPITObject(const SPITObject &spitObject) {
|
||||
return removeSPITObject(spitObject.getID());
|
||||
}
|
||||
bool SPITObject::removeSPITObject(const string & spitObjectID) {
|
||||
bool SPITObject::removeSPITObject(const string &spitObjectID) {
|
||||
auto i = sSpitObjects.find(spitObjectID);
|
||||
if (i == sSpitObjects.end()) {
|
||||
return false;
|
||||
@@ -72,7 +75,7 @@ bool SPITObject::removeSPITObject(const string & spitObjectID) {
|
||||
bool SPITObject::removeSPITObjectRemote(const SPITObject &spitObject) {
|
||||
return removeSPITObjectRemote(spitObject.getID());
|
||||
}
|
||||
bool SPITObject::removeSPITObjectRemote(const string & spitObjectID) {
|
||||
bool SPITObject::removeSPITObjectRemote(const string &spitObjectID) {
|
||||
auto i = sSpitObjectsRemote.find(spitObjectID);
|
||||
if (i == sSpitObjectsRemote.end()) {
|
||||
return false;
|
||||
@@ -83,8 +86,8 @@ bool SPITObject::removeSPITObjectRemote(const string & spitObjectID) {
|
||||
|
||||
SPITObject *SPITObject::getSPITObject(int p_Index) {
|
||||
if (p_Index >= 0 && p_Index < sSpitObjects.size()) {
|
||||
unordered_map<string, SPITObject *>::iterator i = next(sSpitObjects.begin(), p_Index);
|
||||
return i->second;
|
||||
auto i = next(sSpitObjects.begin(), p_Index);
|
||||
return i->second.get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -96,7 +99,7 @@ SPITObject *SPITObject::getSPITObject(int p_Index) {
|
||||
*/
|
||||
const SPITObject &SPITObject::getSPITObjectRef(int p_Index) {
|
||||
if (p_Index >= 0 && p_Index < sSpitObjects.size()) {
|
||||
unordered_map<string, SPITObject *>::iterator i = next(sSpitObjects.begin(), p_Index);
|
||||
auto i = next(sSpitObjects.begin(), p_Index);
|
||||
return *i->second;
|
||||
} else {
|
||||
throw "SPITObject index out of range";
|
||||
@@ -104,8 +107,8 @@ const SPITObject &SPITObject::getSPITObjectRef(int p_Index) {
|
||||
}
|
||||
SPITObject *SPITObject::getSPITObjectRemote(int p_Index) {
|
||||
if (p_Index >= 0 && p_Index < sSpitObjectsRemote.size()) {
|
||||
unordered_map<string, SPITObject *>::iterator i = next(sSpitObjectsRemote.begin(), p_Index);
|
||||
return i->second;
|
||||
auto i = next(sSpitObjectsRemote.begin(), p_Index);
|
||||
return i->second.get();
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -118,76 +121,48 @@ SPITObject *SPITObject::getSPITObjectRemote(int p_Index) {
|
||||
*/
|
||||
const SPITObject &SPITObject::getSPITObjectRemoteRef(int p_Index) {
|
||||
if (p_Index >= 0 && p_Index < sSpitObjectsRemote.size()) {
|
||||
unordered_map<string, SPITObject *>::iterator i = next(sSpitObjectsRemote.begin(), p_Index);
|
||||
auto i = next(sSpitObjectsRemote.begin(), p_Index);
|
||||
return *i->second;
|
||||
} else {
|
||||
throw "Remote SPITObject index out of range";
|
||||
}
|
||||
}
|
||||
|
||||
void SPITObject::clearSPITObjects() {
|
||||
SPITObject *ptrSPITObject;
|
||||
|
||||
for (auto i = sSpitObjects.begin(); i != sSpitObjects.end(); i++) {
|
||||
ptrSPITObject = i->second;
|
||||
i = sSpitObjects.erase(i);
|
||||
delete ptrSPITObject;
|
||||
}
|
||||
}
|
||||
void SPITObject::clearSPITObjectsRemote() {
|
||||
SPITObject *ptrSPITObject;
|
||||
|
||||
for (auto i = sSpitObjectsRemote.begin(); i != sSpitObjectsRemote.end(); i++) {
|
||||
ptrSPITObject = i->second;
|
||||
i = sSpitObjectsRemote.erase(i);
|
||||
delete ptrSPITObject;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* clears all unconfirmed SPITObjects not created by this SPIT_Client.
|
||||
*/
|
||||
void SPITObject::clearUnconfirmedSPITObjects() {
|
||||
for (auto i = sSpitObjects.begin(); i != sSpitObjects.end(); i++) {
|
||||
SPITObject *ptrSPITObject = i->second;
|
||||
SPITObject *ptrSPITObject = i->second.get();
|
||||
if (ptrSPITObject->getCreatedByClient() == false && ptrSPITObject->getConfirmed() == false) {
|
||||
i = sSpitObjects.erase(i);
|
||||
delete ptrSPITObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SPITObject::eventProjectClosed() {
|
||||
for (auto i = sSpitObjects.begin(); i != sSpitObjects.end(); i++) {
|
||||
SPITObject *ptrSPITObject = i->second;
|
||||
SPITObject *ptrSPITObject = i->second.get();
|
||||
if (ptrSPITObject->getCreatedByClient() == true) {
|
||||
continue;
|
||||
}
|
||||
i = sSpitObjects.erase(i);
|
||||
delete ptrSPITObject;
|
||||
}
|
||||
// Remote
|
||||
for (auto i = sSpitObjectsRemote.begin(); i != sSpitObjectsRemote.end(); i++) {
|
||||
SPITObject *ptrSPITObject = i->second;
|
||||
i = sSpitObjectsRemote.erase(i);
|
||||
delete ptrSPITObject;
|
||||
}
|
||||
sSpitObjectsRemote.clear();
|
||||
}
|
||||
/**
|
||||
* sets confirmed = false for all SPITObjects.
|
||||
* This should be called when the client has loaded a project.
|
||||
*/
|
||||
void SPITObject::setConfirmedFalse() {
|
||||
SPITObject *ptrSPITObject;
|
||||
|
||||
for (auto i = sSpitObjects.begin(); i != sSpitObjects.end(); i++) {
|
||||
ptrSPITObject = i->second;
|
||||
ptrSPITObject->setConfirmed(false);
|
||||
i->second->setConfirmed(false);
|
||||
}
|
||||
}
|
||||
|
||||
SPITObject::SPITObject() {
|
||||
m_ID = createGUID();
|
||||
SPITObject::SPITObject(string p_ID) {
|
||||
m_ID = p_ID;
|
||||
}
|
||||
|
||||
bool SPITObject::setMessageOP(SPIT_Message::ReportSPITObject *p_ReportSPITObject) {
|
||||
@@ -404,7 +379,7 @@ bool SPITObject::setServerRemote(bool p_BelongstoServer) {
|
||||
}
|
||||
/**
|
||||
* This is a virtual construct - ActionAssignedType is not implemented in the SPITProtocol.
|
||||
* This is used when an action is associated with a SPITType.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
@@ -17,17 +17,12 @@
|
||||
|
||||
unordered_map<string, SPITPlayer *> SPITPlayer::s_SPITPlayers;
|
||||
|
||||
SPITPlayer *SPITPlayer::getSPITPlayer(string p_PlayerID) {
|
||||
{
|
||||
auto i = s_SPITPlayers.find(p_PlayerID);
|
||||
if (i == s_SPITPlayers.end()) {
|
||||
s_SPITPlayers[p_PlayerID] = new SPITPlayer(p_PlayerID);
|
||||
}
|
||||
i = s_SPITPlayers.find(p_PlayerID);
|
||||
if (i == s_SPITPlayers.end())
|
||||
return NULL;
|
||||
return i->second;
|
||||
SPITPlayer &SPITPlayer::getSPITPlayer(string p_PlayerID) {
|
||||
auto i = s_SPITPlayers.find(p_PlayerID);
|
||||
if (i == s_SPITPlayers.end()) {
|
||||
s_SPITPlayers[p_PlayerID] = new SPITPlayer(p_PlayerID);
|
||||
}
|
||||
return *s_SPITPlayers.at(p_PlayerID);
|
||||
}
|
||||
|
||||
void SPITPlayer::clearPlayers() {
|
||||
|
||||
@@ -17,15 +17,15 @@
|
||||
|
||||
static const char *TAG = "SPIT";
|
||||
|
||||
unordered_map<string, SPITType *> SPITType::sSpitTypes;
|
||||
unordered_map<string, SPITType *> SPITType::sSpitTypesRemote;
|
||||
unordered_map<string, unique_ptr<SPITType>> SPITType::sSpitTypes;
|
||||
unordered_map<string, unique_ptr<SPITType>> SPITType::sSpitTypesRemote;
|
||||
|
||||
SPITType *SPITType::getSPITType(const string &id) {
|
||||
auto i = sSpitTypes.find(id);
|
||||
if (i == sSpitTypes.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return i->second;
|
||||
return i->second.get();
|
||||
}
|
||||
/**
|
||||
* Returns the reference of the SPITType with ID == id.
|
||||
@@ -42,7 +42,7 @@ SPITType *SPITType::getSPITTypeRemote(const string &id) {
|
||||
if (i == sSpitTypesRemote.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return i->second;
|
||||
return i->second.get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,11 +55,13 @@ const SPITType &SPITType::getSPITTypeRemoteRef(const string &id) {
|
||||
return *sSpitTypesRemote.at(id);
|
||||
}
|
||||
|
||||
void SPITType::addSPITType(SPITType &spitType) {
|
||||
sSpitTypes[spitType.getID()] = &spitType;
|
||||
void SPITType::addSPITType(unique_ptr<SPITType> spitType) {
|
||||
ESP_LOGD("OBJ", "adding spitObject %s/%s", spitType->getID().c_str(), spitType->getName().c_str());
|
||||
sSpitTypes[spitType->getID()] = move(spitType);
|
||||
}
|
||||
void SPITType::addSPITTypeRemote(SPITType &spitType) {
|
||||
sSpitTypesRemote[spitType.getID()] = &spitType;
|
||||
void SPITType::addSPITTypeRemote(unique_ptr<SPITType> spitType) {
|
||||
ESP_LOGD("OBJ", "adding spitObject %s/%s", spitType->getID().c_str(), spitType->getName().c_str());
|
||||
sSpitTypesRemote[spitType->getID()] = move(spitType);
|
||||
}
|
||||
bool SPITType::removeSPITType(const SPITType &spitType) {
|
||||
auto i = sSpitTypes.find(spitType.getID());
|
||||
@@ -79,12 +81,11 @@ bool SPITType::removeSPITTypeRemote(const SPITType &spitType) {
|
||||
}
|
||||
|
||||
SPITType *SPITType::getSPITType(int p_Index) {
|
||||
SPITType *pSpitType = nullptr;
|
||||
if (p_Index < sSpitTypes.size()) {
|
||||
unordered_map<string, SPITType *>::iterator i = next(sSpitTypes.begin(), p_Index);
|
||||
pSpitType = i->second;
|
||||
auto i = next(sSpitTypes.begin(), p_Index);
|
||||
return i->second.get();
|
||||
}
|
||||
return pSpitType;
|
||||
return nullptr;
|
||||
}
|
||||
/**
|
||||
* Returns a reference to the SPITType at position p_Index.
|
||||
@@ -94,7 +95,7 @@ SPITType *SPITType::getSPITType(int p_Index) {
|
||||
*/
|
||||
const SPITType &SPITType::getSPITTypeRef(int p_Index) {
|
||||
if (p_Index >= 0 && p_Index < sSpitTypes.size()) {
|
||||
unordered_map<string, SPITType *>::iterator i = next(sSpitTypes.begin(), p_Index);
|
||||
auto i = next(sSpitTypes.begin(), p_Index);
|
||||
return *i->second;
|
||||
} else {
|
||||
throw "SPITType index out of range";
|
||||
@@ -102,8 +103,8 @@ const SPITType &SPITType::getSPITTypeRef(int p_Index) {
|
||||
}
|
||||
SPITType *SPITType::getSPITTypeRemote(int p_Index) {
|
||||
if (p_Index < sSpitTypesRemote.size()) {
|
||||
unordered_map<string, SPITType *>::iterator i = next(sSpitTypesRemote.begin(), p_Index);
|
||||
return i->second;
|
||||
auto i = next(sSpitTypesRemote.begin(), p_Index);
|
||||
return i->second.get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -115,43 +116,23 @@ SPITType *SPITType::getSPITTypeRemote(int p_Index) {
|
||||
*/
|
||||
const SPITType &SPITType::getSPITTypeRemoteRef(int p_Index) {
|
||||
if (p_Index >= 0 && p_Index < sSpitTypesRemote.size()) {
|
||||
unordered_map<string, SPITType *>::iterator i = next(sSpitTypesRemote.begin(), p_Index);
|
||||
auto i = next(sSpitTypesRemote.begin(), p_Index);
|
||||
return *i->second;
|
||||
} else {
|
||||
throw "Remote SPITType index out of range";
|
||||
}
|
||||
}
|
||||
|
||||
void SPITType::clearSPITTypes() {
|
||||
for (auto i = sSpitTypes.begin(); i != sSpitTypes.end(); i++) {
|
||||
SPITType *pSpitType = i->second;
|
||||
i = sSpitTypes.erase(i);
|
||||
delete pSpitType;
|
||||
}
|
||||
}
|
||||
void SPITType::clearSPITTypesRemote() {
|
||||
for (auto i = sSpitTypesRemote.begin(); i != sSpitTypesRemote.end(); i++) {
|
||||
SPITType *ptrSPITType = i->second;
|
||||
i = sSpitTypesRemote.erase(i);
|
||||
delete ptrSPITType;
|
||||
}
|
||||
}
|
||||
|
||||
void SPITType::eventProjectClosed() {
|
||||
for (auto i = sSpitTypes.begin(); i != sSpitTypes.end(); i++) {
|
||||
SPITType *ptrSPITType = i->second;
|
||||
SPITType *ptrSPITType = i->second.get();
|
||||
if (ptrSPITType->getCreatedByClient() == true) {
|
||||
continue;
|
||||
}
|
||||
i = sSpitTypes.erase(i);
|
||||
delete ptrSPITType;
|
||||
}
|
||||
// Remote
|
||||
for (auto i = sSpitTypesRemote.begin(); i != sSpitTypesRemote.end(); i++) {
|
||||
SPITType *ptrSPITType = i->second;
|
||||
i = sSpitTypesRemote.erase(i);
|
||||
delete ptrSPITType;
|
||||
}
|
||||
sSpitTypesRemote.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,17 +141,15 @@ void SPITType::eventProjectClosed() {
|
||||
*/
|
||||
void SPITType::setConfirmedFalse() {
|
||||
for (auto i = sSpitTypes.begin(); i != sSpitTypes.end(); i++) {
|
||||
SPITType *ptrSPITType = i->second;
|
||||
ptrSPITType->setConfirmed(false);
|
||||
i->second->setConfirmed(false);
|
||||
}
|
||||
}
|
||||
|
||||
SPITType::SPITType() {
|
||||
m_ID = createGUID();
|
||||
SPITType::SPITType(string p_ID) {
|
||||
m_ID = p_ID;
|
||||
}
|
||||
|
||||
SPITType::SPITType(string id, string grpName, string name, bool fixed, bool projectIndependent, long long defaultDelay, long long defaultDuration) {
|
||||
m_ID = createGUID();
|
||||
m_ActionAssigned = false;
|
||||
m_Confirmed = false;
|
||||
m_ID = id;
|
||||
|
||||
+125
-184
@@ -264,7 +264,7 @@ int SPIT_Client::sendSPITMessage(unique_ptr<SPIT_Message::OPPart> spitMessageOPP
|
||||
m_MessageNumber_Send = 1;
|
||||
else
|
||||
m_MessageNumber_Send++;
|
||||
|
||||
|
||||
opPart.getHeader()->setMessageNumber(m_MessageNumber_Send);
|
||||
|
||||
int opFlag = 0;
|
||||
@@ -296,7 +296,7 @@ bool SPIT_Client::startReceiveSPITMessages() {
|
||||
return true;
|
||||
}
|
||||
void SPIT_Client::stopReceiveSPITMessages() {
|
||||
m_StopReceiveSPITMessages = true;
|
||||
m_StopReceiveSPITMessages = true;
|
||||
}
|
||||
|
||||
void SPIT_Client::receiveSPITMessage(SPIT_Client &rM) {
|
||||
@@ -318,14 +318,7 @@ void SPIT_Client::receiveSPITMessage(SPIT_Client &rM) {
|
||||
}
|
||||
|
||||
void SPIT_Client::resetMessageNumberReceived() {
|
||||
SPIT_Message *ptrOvertakingSPIT_Message;
|
||||
|
||||
m_MessageNumber_Received = -1;
|
||||
for (auto it = m_OvertakingSPIT_Messages.begin(); it != m_OvertakingSPIT_Messages.end(); it++) {
|
||||
ptrOvertakingSPIT_Message = *it;
|
||||
delete ptrOvertakingSPIT_Message;
|
||||
// m_OvertakingSPIT_Messages.erase(it);
|
||||
}
|
||||
m_OvertakingSPIT_Messages.clear();
|
||||
}
|
||||
|
||||
@@ -344,11 +337,7 @@ void SPIT_Client::checkParseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage)
|
||||
return;
|
||||
}
|
||||
|
||||
int intActualMessageNumber;
|
||||
int intNextMessageNumber;
|
||||
SPIT_Message *ptrOvertakingSPIT_Message;
|
||||
|
||||
intActualMessageNumber = (int)(p_SPITMessage->getHeader()->getMessageNumber() & 0xFF);
|
||||
int intActualMessageNumber = (int)(p_SPITMessage->getHeader()->getMessageNumber() & 0xFF);
|
||||
|
||||
if (intActualMessageNumber == 0) {
|
||||
parseSPIT_Message(std::move(p_SPITMessage));
|
||||
@@ -360,7 +349,7 @@ void SPIT_Client::checkParseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage)
|
||||
return;
|
||||
}
|
||||
|
||||
intNextMessageNumber = m_MessageNumber_Received + 1;
|
||||
int intNextMessageNumber = m_MessageNumber_Received + 1;
|
||||
if (intNextMessageNumber > 255 || intNextMessageNumber < 1)
|
||||
intNextMessageNumber = 1;
|
||||
|
||||
@@ -376,12 +365,12 @@ void SPIT_Client::checkParseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage)
|
||||
if (intNextMessageNumber > 255 || intNextMessageNumber < 1)
|
||||
intNextMessageNumber = 1;
|
||||
|
||||
ptrOvertakingSPIT_Message = *it;
|
||||
auto &ptrOvertakingSPIT_Message = *it;
|
||||
intActualMessageNumber = (int)(ptrOvertakingSPIT_Message->getHeader()->getMessageNumber() & 0xFF);
|
||||
|
||||
if (intActualMessageNumber == intNextMessageNumber) {
|
||||
m_MessageNumber_Received = intActualMessageNumber;
|
||||
// parseSPIT_Message(ptrOvertakingSPIT_Message);
|
||||
parseSPIT_Message(move(ptrOvertakingSPIT_Message));
|
||||
m_OvertakingSPIT_Messages.erase(it);
|
||||
|
||||
it = m_OvertakingSPIT_Messages.begin();
|
||||
@@ -392,33 +381,28 @@ void SPIT_Client::checkParseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage)
|
||||
|
||||
} else {
|
||||
// p_SPITMessage has overtaken another message
|
||||
addOvertakingSPIT_Message(p_SPITMessage.get());
|
||||
addOvertakingSPIT_Message(move(p_SPITMessage));
|
||||
}
|
||||
}
|
||||
|
||||
int SPIT_Client::s_MAX_OVERTAKING_SPIT_MESSAGES = 10;
|
||||
|
||||
void SPIT_Client::addOvertakingSPIT_Message(SPIT_Message *p_SPIT_Message) {
|
||||
if (p_SPIT_Message == nullptr)
|
||||
void SPIT_Client::addOvertakingSPIT_Message(unique_ptr<SPIT_Message> p_SPIT_Message) {
|
||||
if (!p_SPIT_Message) {
|
||||
return;
|
||||
int intMessageNumber;
|
||||
SPIT_Message *ptrOvertakingSPIT_Message;
|
||||
int intOvertakingMessageNumber;
|
||||
|
||||
if (m_OvertakingSPIT_Messages.size() > s_MAX_OVERTAKING_SPIT_MESSAGES) {
|
||||
}
|
||||
if (m_OvertakingSPIT_Messages.size() > MAX_OVERTAKING_SPIT_MESSAGES) {
|
||||
ESP_LOGD(TAG, "SPIT_Client receiveing: perhaps message lost !!!!!");
|
||||
}
|
||||
|
||||
intMessageNumber = (int)(p_SPIT_Message->getHeader()->getMessageNumber() & 0xFF);
|
||||
for (auto it = m_OvertakingSPIT_Messages.begin(); it != m_OvertakingSPIT_Messages.end(); it++) {
|
||||
ptrOvertakingSPIT_Message = *it;
|
||||
intOvertakingMessageNumber = (int)(ptrOvertakingSPIT_Message->getHeader()->getMessageNumber() & 0xFF);
|
||||
int intMessageNumber = (int)(p_SPIT_Message->getHeader()->getMessageNumber() & 0xFF);
|
||||
for (auto it = m_OvertakingSPIT_Messages.begin(); it != m_OvertakingSPIT_Messages.end(); ++it) {
|
||||
const auto &overtaking = *it;
|
||||
int intOvertakingMessageNumber = (int)(overtaking->getHeader()->getMessageNumber() & 0xFF);
|
||||
if (intMessageNumber < intOvertakingMessageNumber) {
|
||||
m_OvertakingSPIT_Messages.insert(it, p_SPIT_Message);
|
||||
m_OvertakingSPIT_Messages.insert(it, move(p_SPIT_Message));
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_OvertakingSPIT_Messages.push_back(p_SPIT_Message);
|
||||
m_OvertakingSPIT_Messages.push_back(move(p_SPIT_Message));
|
||||
}
|
||||
|
||||
void SPIT_Client::parseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage) {
|
||||
@@ -612,8 +596,7 @@ void SPIT_Client::disconnectInternal(int p_Cause) {
|
||||
}
|
||||
|
||||
void SPIT_Client::parseConnectAnswer(SPIT_Message::ConnectAnswer *p_ConnectAnswer) {
|
||||
int intOldConnectionStatus;
|
||||
intOldConnectionStatus = m_ConnectionStatus;
|
||||
int intOldConnectionStatus = m_ConnectionStatus;
|
||||
|
||||
if (p_ConnectAnswer->getClientID() != m_ID)
|
||||
return;
|
||||
@@ -726,6 +709,7 @@ void SPIT_Client::parseCloseSPITProject(SPIT_Message::CloseSPITProject *p_CloseS
|
||||
return;
|
||||
string stringProjectID;
|
||||
mCallbacks.onProjectUpdate(ProjUpdate::ServerClosed, p_CloseSPITProject->getProjectID());
|
||||
SPITPlayer::clearPlayers();
|
||||
}
|
||||
|
||||
string SPIT_Client::getServerProjectID() { return m_ServerProjectID; }
|
||||
@@ -926,13 +910,17 @@ void SPIT_Client::parseReportSPITType(SPIT_Message::ReportSPITType *p_ReportSPIT
|
||||
if (mCallbacks.onCheckSpitTypeVeto(p_ReportSPITType) == false) {
|
||||
return;
|
||||
}
|
||||
ptrSPITType = new SPITType();
|
||||
auto spitType = make_unique<SPITType>(p_ReportSPITType->getID());
|
||||
ptrSPITType = spitType.get();
|
||||
SPITType::addSPITType(move(spitType));
|
||||
boolNew = true;
|
||||
}
|
||||
} else {
|
||||
ptrSPITType = SPITType::getSPITTypeRemote(p_ReportSPITType->getID());
|
||||
if (ptrSPITType == nullptr) {
|
||||
ptrSPITType = new SPITType();
|
||||
auto spitType = make_unique<SPITType>(p_ReportSPITType->getID());
|
||||
ptrSPITType = spitType.get();
|
||||
SPITType::addSPITTypeRemote(move(spitType));
|
||||
boolNew = true;
|
||||
}
|
||||
}
|
||||
@@ -944,13 +932,7 @@ void SPIT_Client::parseReportSPITType(SPIT_Message::ReportSPITType *p_ReportSPIT
|
||||
|
||||
auto eventType = boolNew ? ObjectEvent::Created : ObjectEvent::Changed;
|
||||
// add or change SPITType
|
||||
if (ptrSPITType->getServerRemote() == false) {
|
||||
SPITType::addSPITType(*ptrSPITType);
|
||||
mCallbacks.onSpitType(eventType, *ptrSPITType);
|
||||
} else {
|
||||
SPITType::addSPITTypeRemote(*ptrSPITType);
|
||||
mCallbacks.onSpitTypeRemote(eventType, *ptrSPITType);
|
||||
}
|
||||
mCallbacks.onSpitType(eventType, ptrSPITType->getServerRemote(), *ptrSPITType);
|
||||
|
||||
if (ptrSPITType != nullptr) {
|
||||
if (ptrSPITType->setConfirmed(true) == true || boolChanged == true) {
|
||||
@@ -961,42 +943,37 @@ void SPIT_Client::parseReportSPITType(SPIT_Message::ReportSPITType *p_ReportSPIT
|
||||
}
|
||||
void SPIT_Client::parseRemoveSPITType(SPIT_Message::RemoveSPITType *p_RemoveSPITType) {
|
||||
// printf("parse RemoveSPITType %s\n", p_RemoveSPITType->getID());
|
||||
if (p_RemoveSPITType == nullptr)
|
||||
if (!p_RemoveSPITType) {
|
||||
return;
|
||||
string stringSPITTypeID;
|
||||
}
|
||||
bool boolRemote = false;
|
||||
SPITType *ptrSPITType;
|
||||
stringSPITTypeID = p_RemoveSPITType->getID();
|
||||
string stringSPITTypeID = p_RemoveSPITType->getID();
|
||||
|
||||
{
|
||||
ptrSPITType = SPITType::getSPITTypeRemote(stringSPITTypeID);
|
||||
if (ptrSPITType != nullptr) {
|
||||
boolRemote = true;
|
||||
SPITType *ptrSPITType = SPITType::getSPITTypeRemote(stringSPITTypeID);
|
||||
if (!ptrSPITType) {
|
||||
boolRemote = true;
|
||||
} else {
|
||||
ptrSPITType = SPITType::getSPITType(stringSPITTypeID);
|
||||
if (!ptrSPITType) {
|
||||
boolRemote = false;
|
||||
} else {
|
||||
ptrSPITType = SPITType::getSPITType(stringSPITTypeID);
|
||||
if (ptrSPITType != nullptr) {
|
||||
boolRemote = false;
|
||||
} else {
|
||||
// No SPITType with stringSPITTypeID is listet
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (ptrSPITType->getCreatedByClient() && ptrSPITType->getFixed()) {
|
||||
// the SPITyte is created by client himself and it is fixed -> don't remove the SPITType!!
|
||||
// Send the SPITTyp back to the server
|
||||
sendSPITTypeInternal(*ptrSPITType);
|
||||
// No SPITType with stringSPITTypeID is listet
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (boolRemote == false) {
|
||||
mCallbacks.onSpitType(ObjectEvent::Deleted, *ptrSPITType);
|
||||
SPITType::removeSPITType(*ptrSPITType);
|
||||
} else {
|
||||
mCallbacks.onSpitTypeRemote(ObjectEvent::Deleted, *ptrSPITType);
|
||||
SPITType::removeSPITTypeRemote(*ptrSPITType);
|
||||
}
|
||||
delete ptrSPITType;
|
||||
if (ptrSPITType->getCreatedByClient() && ptrSPITType->getFixed()) {
|
||||
// the SPITyte is created by client himself and it is fixed -> don't remove the SPITType!!
|
||||
// Send the SPITTyp back to the server
|
||||
sendSPITTypeInternal(*ptrSPITType);
|
||||
return;
|
||||
}
|
||||
|
||||
mCallbacks.onSpitType(ObjectEvent::Deleted, boolRemote, *ptrSPITType);
|
||||
if (boolRemote == false) {
|
||||
SPITType::removeSPITType(*ptrSPITType);
|
||||
} else {
|
||||
SPITType::removeSPITTypeRemote(*ptrSPITType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1031,7 +1008,7 @@ bool SPIT_Client::changeSPITType(SPITType *p_SPITType) {
|
||||
ptrSPITType->setName(p_SPITType->getName());
|
||||
ptrSPITType->setProjectIndepended(p_SPITType->getProjectIndepended());
|
||||
|
||||
mCallbacks.onSpitType(ObjectEvent::Changed, *ptrSPITType);
|
||||
mCallbacks.onSpitType(ObjectEvent::Changed, false, *ptrSPITType);
|
||||
sendSPITTypeInternal(*ptrSPITType);
|
||||
|
||||
return true;
|
||||
@@ -1055,9 +1032,8 @@ int SPIT_Client::removeSPITType(string p_SPITTypeID) {
|
||||
return -1;
|
||||
auto sMRemoveSPITType = make_unique<SPIT_Message::RemoveSPITType>();
|
||||
ptrSPITType->fillMessageOP(*sMRemoveSPITType);
|
||||
mCallbacks.onSpitType(ObjectEvent::Deleted, *ptrSPITType);
|
||||
mCallbacks.onSpitType(ObjectEvent::Deleted, false, *ptrSPITType);
|
||||
SPITType::removeSPITType(*ptrSPITType);
|
||||
delete ptrSPITType;
|
||||
return sendSPITMessage(move(sMRemoveSPITType));
|
||||
}
|
||||
return -1;
|
||||
@@ -1071,7 +1047,9 @@ SPITType *SPIT_Client::createSPITType(string p_ID, string p_GroupName, string p_
|
||||
bool boolNew;
|
||||
SPITType *ptrSPITType = SPITType::getSPITType(p_ID);
|
||||
if (ptrSPITType == nullptr) {
|
||||
ptrSPITType = new SPITType(p_ID, p_GroupName, p_Name, p_FIxed, p_ProjectIndepended, p_DefaultDelay, p_DefaultDuration);
|
||||
auto spitType = make_unique<SPITType>(p_ID, p_GroupName, p_Name, p_FIxed, p_ProjectIndepended, p_DefaultDelay, p_DefaultDuration);
|
||||
ptrSPITType = spitType.get();
|
||||
SPITType::addSPITType(move(spitType));
|
||||
ptrSPITType->setCreatedByClient(true);
|
||||
boolNew = true;
|
||||
} else {
|
||||
@@ -1086,8 +1064,7 @@ SPITType *SPIT_Client::createSPITType(string p_ID, string p_GroupName, string p_
|
||||
}
|
||||
|
||||
auto eventType = boolNew ? ObjectEvent::Created : ObjectEvent::Changed;
|
||||
SPITType::addSPITType(*ptrSPITType);
|
||||
mCallbacks.onSpitType(eventType, *ptrSPITType);
|
||||
mCallbacks.onSpitType(eventType, false, *ptrSPITType);
|
||||
sendSPITTypeInternal(*ptrSPITType);
|
||||
return ptrSPITType;
|
||||
}
|
||||
@@ -1103,6 +1080,7 @@ void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject *p_Report
|
||||
bool boolRemote = false;
|
||||
bool boolChanged = false;
|
||||
{
|
||||
ESP_LOGD(TAG, "parseReportSPITObject %s / %s", p_ReportSPITObject->getID().c_str(), p_ReportSPITObject->getName().c_str());
|
||||
if (p_ReportSPITObject->getServerRemote() == false) {
|
||||
boolRemote = false;
|
||||
ptrSPITObject = SPITObject::getSPITObject(p_ReportSPITObject->getID());
|
||||
@@ -1114,7 +1092,6 @@ void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject *p_Report
|
||||
// SpitObject exists but has no corresponding SPITType -> remove the SPITObject without sending a message
|
||||
// Maybe the SPITObject has changed the SPITTypeID to a SPITTypeID of another board
|
||||
SPITObject::removeSPITObject(*ptrSPITObject);
|
||||
delete ptrSPITObject;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -1124,8 +1101,9 @@ void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject *p_Report
|
||||
ESP_LOGD(TAG, "ObjectVeto %s / %s", p_ReportSPITObject->getID().c_str(), p_ReportSPITObject->getName().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
ptrSPITObject = new SPITObject();
|
||||
auto spitObj = make_unique<SPITObject>(p_ReportSPITObject->getID());
|
||||
ptrSPITObject = spitObj.get();
|
||||
SPITObject::addSPITObject(move(spitObj));
|
||||
boolNew = true;
|
||||
} else {
|
||||
// The user's app my veto the SPITType
|
||||
@@ -1133,7 +1111,6 @@ void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject *p_Report
|
||||
// SpitObject exists and User APp denied the SPITObject -> remove the SPITObject without sending a message
|
||||
SPITObject::removeSPITObject(*ptrSPITObject);
|
||||
ESP_LOGD(TAG, "TypeVeto %s / %s", p_ReportSPITObject->getID().c_str(), p_ReportSPITObject->getName().c_str());
|
||||
delete ptrSPITObject;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1146,12 +1123,15 @@ void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject *p_Report
|
||||
return;
|
||||
}
|
||||
if (ptrSPITObject == nullptr) {
|
||||
ptrSPITObject = new SPITObject();
|
||||
auto spitObj = make_unique<SPITObject>(p_ReportSPITObject->getID());
|
||||
ptrSPITObject = spitObj.get();
|
||||
SPITObject::addSPITObjectRemote(move(spitObj));
|
||||
boolNew = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ptrSPITObject->setMessageOP(p_ReportSPITObject)) {
|
||||
ESP_LOGE(TAG, "Change not allowed");
|
||||
// setMessageOP error - the SPITObject can't be changed, it may be fixed and crated by this client
|
||||
sendSPITObjectInternal(ptrSPITObject);
|
||||
return;
|
||||
@@ -1160,17 +1140,10 @@ void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject *p_Report
|
||||
if (boolRemote == false) {
|
||||
// set the virtual action assignment
|
||||
ptrSPITObject->setActionAssignedType(ptrSPITType->getActionAssigned());
|
||||
SPITObject::addSPITObject(*ptrSPITObject);
|
||||
} else {
|
||||
SPITObject::addSPITObjectRemote(*ptrSPITObject);
|
||||
}
|
||||
|
||||
auto eventType = boolNew ? ObjectEvent::Created : ObjectEvent::Changed;
|
||||
if (boolRemote) {
|
||||
mCallbacks.onSpitObjectRemote(eventType, *ptrSPITType, *ptrSPITObject);
|
||||
} else {
|
||||
mCallbacks.onSpitObject(eventType, *ptrSPITType, *ptrSPITObject);
|
||||
}
|
||||
mCallbacks.onSpitObject(eventType, boolRemote, *ptrSPITType, *ptrSPITObject);
|
||||
|
||||
if (ptrSPITObject->setConfirmed(true) == true || boolChanged == true) {
|
||||
// Confirmation has changed
|
||||
@@ -1180,33 +1153,20 @@ void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject *p_Report
|
||||
}
|
||||
void SPIT_Client::parseRemoveSPITObject(SPIT_Message::RemoveSPITObject *p_RemoveSPITObject) {
|
||||
// printf("parse RemoveSPITObject %s\n", p_RemoveSPITObject->getID());
|
||||
if (p_RemoveSPITObject == nullptr)
|
||||
if (!p_RemoveSPITObject) {
|
||||
return;
|
||||
bool boolRemote = false;
|
||||
SPITObject *ptrSPITObject;
|
||||
SPITType *ptrSPITType;
|
||||
}
|
||||
|
||||
{
|
||||
ptrSPITObject = SPITObject::getSPITObjectRemote(p_RemoveSPITObject->getID());
|
||||
if (ptrSPITObject != nullptr) {
|
||||
boolRemote = true;
|
||||
ptrSPITType = SPITType::getSPITTypeRemote(ptrSPITObject->getSPITTypeID());
|
||||
if (ptrSPITType != nullptr) {
|
||||
if (boolRemote) {
|
||||
mCallbacks.onSpitObjectRemote(ObjectEvent::Deleted, *ptrSPITType, *ptrSPITObject);
|
||||
} else {
|
||||
mCallbacks.onSpitObject(ObjectEvent::Deleted, *ptrSPITType, *ptrSPITObject);
|
||||
}
|
||||
} else {
|
||||
// No associated SPITType found
|
||||
// delete the SPITObject without a notification
|
||||
}
|
||||
SPITObject::removeSPITObjectRemote(*ptrSPITObject);
|
||||
delete ptrSPITObject;
|
||||
} else {
|
||||
// call removeSPITObject, this will notify the server that the object is removed
|
||||
removeSPITObject(p_RemoveSPITObject->getID());
|
||||
SPITObject *ptrSPITObject = SPITObject::getSPITObjectRemote(p_RemoveSPITObject->getID());
|
||||
if (ptrSPITObject != nullptr) {
|
||||
SPITType *ptrSPITType = SPITType::getSPITTypeRemote(ptrSPITObject->getSPITTypeID());
|
||||
if (ptrSPITType != nullptr) {
|
||||
mCallbacks.onSpitObject(ObjectEvent::Deleted, true, *ptrSPITType, *ptrSPITObject);
|
||||
}
|
||||
SPITObject::removeSPITObjectRemote(*ptrSPITObject);
|
||||
} else {
|
||||
// call removeSPITObject, this will notify the server that the object is removed
|
||||
removeSPITObject(p_RemoveSPITObject->getID());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1256,7 +1216,7 @@ bool SPIT_Client::changeSPITObject(SPITObject *p_SPITObject) {
|
||||
ptrSPITObject->setValueFactor(p_SPITObject->getValueFactor());
|
||||
ptrSPITObject->setValueUse(p_SPITObject->getValueUse());
|
||||
|
||||
mCallbacks.onSpitObject(ObjectEvent::Changed, *ptrSPITType, *ptrSPITObject);
|
||||
mCallbacks.onSpitObject(ObjectEvent::Changed, false, *ptrSPITType, *ptrSPITObject);
|
||||
sendSPITObjectInternal(ptrSPITObject);
|
||||
}
|
||||
return true;
|
||||
@@ -1286,9 +1246,8 @@ int SPIT_Client::removeSPITObject(string p_SPITObjectID) {
|
||||
if (ptrSPITType == nullptr)
|
||||
return -1;
|
||||
ptrSPITObject->fillMessageOP(*sMRemoveSPITObject);
|
||||
mCallbacks.onSpitObject(ObjectEvent::Deleted, *ptrSPITType, *ptrSPITObject);
|
||||
mCallbacks.onSpitObject(ObjectEvent::Deleted, false, *ptrSPITType, *ptrSPITObject);
|
||||
SPITObject::removeSPITObject(*ptrSPITObject);
|
||||
delete ptrSPITObject;
|
||||
return sendSPITMessage(move(sMRemoveSPITObject));
|
||||
}
|
||||
return -1;
|
||||
@@ -1298,38 +1257,33 @@ int SPIT_Client::removeSPITObject(string p_SPITObjectID) {
|
||||
|
||||
void SPIT_Client::parsePlaySPITStart(SPIT_Message::PlaySPITStart *p_PlaySPITStart) {
|
||||
ESP_LOGD(TAG, "parse PlaySPITStart ID: %s Name: %s Running: %d", p_PlaySPITStart->getPlayerID().c_str(), p_PlaySPITStart->getPlayerName().c_str(), (int)p_PlaySPITStart->getPlayerIsRunning());
|
||||
SPITPlayer *ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITStart->getPlayerID());
|
||||
if (ptrSPITPlayer == nullptr)
|
||||
return;
|
||||
ptrSPITPlayer->setIsRunning(p_PlaySPITStart->getPlayerIsRunning());
|
||||
ptrSPITPlayer->setName(p_PlaySPITStart->getPlayerName());
|
||||
ptrSPITPlayer->setType(p_PlaySPITStart->getPlayerType());
|
||||
ptrSPITPlayer->setTime(p_PlaySPITStart->getTime());
|
||||
ptrSPITPlayer->startPlaySequence();
|
||||
SPITPlayer &spitPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITStart->getPlayerID());
|
||||
spitPlayer.setIsRunning(p_PlaySPITStart->getPlayerIsRunning());
|
||||
spitPlayer.setName(p_PlaySPITStart->getPlayerName());
|
||||
spitPlayer.setType(p_PlaySPITStart->getPlayerType());
|
||||
spitPlayer.setTime(p_PlaySPITStart->getTime());
|
||||
spitPlayer.startPlaySequence();
|
||||
|
||||
mCallbacks.onPlay(ptrSPITPlayer->getID(), ptrSPITPlayer->getName(), ptrSPITPlayer->getType(), ptrSPITPlayer->getIsRunning(), ptrSPITPlayer->getTime());
|
||||
mCallbacks.onPlay(spitPlayer.getID(), spitPlayer.getName(), spitPlayer.getType(), spitPlayer.getIsRunning(), spitPlayer.getTime());
|
||||
}
|
||||
void SPIT_Client::parsePlaySPITObject(SPIT_Message::PlaySPITObject *p_PlaySPITObject) {
|
||||
SPITPlayer *ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITObject->getPlayerID());
|
||||
if (ptrSPITPlayer == nullptr)
|
||||
return;
|
||||
|
||||
SPITPlayer &ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITObject->getPlayerID());
|
||||
SPITObject *ptrSPITObject = SPITObject::getSPITObject(p_PlaySPITObject->getSPITObjectID());
|
||||
|
||||
if (ptrSPITObject == nullptr) {
|
||||
return;
|
||||
}
|
||||
SPITPlayer::PlaySPITType *ptrPlaySPITType = ptrSPITPlayer->addSPITType_Playing(ptrSPITObject->getSPITTypeID());
|
||||
SPITPlayer::PlaySPITType *ptrPlaySPITType = ptrSPITPlayer.addSPITType_Playing(ptrSPITObject->getSPITTypeID());
|
||||
if (ptrPlaySPITType == nullptr) {
|
||||
return;
|
||||
}
|
||||
ptrPlaySPITType->setPlayerIsRunning(ptrSPITPlayer->getIsRunning());
|
||||
ptrPlaySPITType->setPlayerIsRunning(ptrSPITPlayer.getIsRunning());
|
||||
ptrPlaySPITType->addValue(((double)p_PlaySPITObject->getValue() / 1000000), ((double)ptrSPITObject->getValueFactor() / 1000000));
|
||||
}
|
||||
void SPIT_Client::parsePlaySPITEnd(SPIT_Message::PlaySPITEnd *p_PlaySPITEnd) {
|
||||
SPITPlayer *ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITEnd->getPlayerID());
|
||||
if (ptrSPITPlayer == nullptr)
|
||||
return;
|
||||
|
||||
void SPIT_Client::parsePlaySPITEnd(SPIT_Message::PlaySPITEnd *p_PlaySPITEnd) {
|
||||
SPITPlayer &ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITEnd->getPlayerID());
|
||||
// unordered_map<string, SPITPlayer::PlaySPITType*>* ptrPlayObjects;
|
||||
// bool boolStarted;
|
||||
// bool boolStopped;
|
||||
@@ -1358,59 +1312,46 @@ void SPIT_Client::parsePlaySPITEnd(SPIT_Message::PlaySPITEnd *p_PlaySPITEnd) {
|
||||
// mCallbacks.onPlaySpitType(ptrPlayObject->getPlayerID(), boolStarted, boolStopped, *ptrSPITType, *ptrSPITObject, *ptrPlayObject);
|
||||
// }
|
||||
// }
|
||||
// ptrSPITPlayer->endPlaySequence();
|
||||
// ptrSPITPlayer.endPlaySequence();
|
||||
|
||||
// SPITPlayer *ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITEnd->getPlayerID());
|
||||
// if (ptrSPITPlayer == nullptr)
|
||||
// return;
|
||||
// SPITPlayer &ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITEnd->getPlayerID());
|
||||
|
||||
unordered_map<string, SPITPlayer::PlaySPITType *> *ptrPlaySPITTypes = ptrSPITPlayer->getPlaySPITTypes();
|
||||
unordered_map<string, SPITPlayer::PlaySPITType *> *ptrPlaySPITTypes = ptrSPITPlayer.getPlaySPITTypes();
|
||||
for (auto i = ptrPlaySPITTypes->begin(); i != ptrPlaySPITTypes->end(); i++) {
|
||||
SPITPlayer::PlaySPITType *ptrPlaySPITType = i->second;
|
||||
bool boolStarted = false;
|
||||
bool boolStopped = false;
|
||||
if (ptrPlaySPITType->getIsNew()) {
|
||||
boolStarted = true;
|
||||
}
|
||||
if (ptrPlaySPITType->getIsPlayed() == false) {
|
||||
boolStopped = true;
|
||||
}
|
||||
{
|
||||
SPITType *ptrSPITType = SPITType::getSPITType(ptrPlaySPITType->getSPITTypeID());
|
||||
if (ptrSPITType == nullptr) {
|
||||
// set isplayed to false, the ptrPlayObject will be removed by ptrSPITPlayer->endPlaySequence()
|
||||
ptrPlaySPITType->setIsPlayed(false);
|
||||
continue;
|
||||
}
|
||||
mCallbacks.onPlaySpitType(ptrPlaySPITType->getPlayerID(), ptrPlaySPITType->getSPITTypeID(), ptrPlaySPITType->getPlayerIsRunning(), boolStarted, boolStopped, ptrPlaySPITType->getValue());
|
||||
bool boolStarted = ptrPlaySPITType->getIsNew();
|
||||
bool boolStopped = (ptrPlaySPITType->getIsPlayed() == false);
|
||||
SPITType *ptrSPITType = SPITType::getSPITType(ptrPlaySPITType->getSPITTypeID());
|
||||
if (ptrSPITType == nullptr) {
|
||||
// set isplayed to false, the ptrPlayObject will be removed by ptrSPITPlayer.endPlaySequence()
|
||||
ptrPlaySPITType->setIsPlayed(false);
|
||||
continue;
|
||||
}
|
||||
mCallbacks.onPlaySpitType(ptrPlaySPITType->getPlayerID(), ptrPlaySPITType->getSPITTypeID(), ptrPlaySPITType->getPlayerIsRunning(), boolStarted, boolStopped, ptrPlaySPITType->getValue());
|
||||
}
|
||||
ptrSPITPlayer->endPlaySequence();
|
||||
ptrSPITPlayer.endPlaySequence();
|
||||
}
|
||||
|
||||
void SPIT_Client::parseReportPlayStatus(SPIT_Message::ReportPlayStatus *p_ReportPlayStatus) {
|
||||
ESP_LOGD(TAG, "parseReportPlayStatus");
|
||||
SPITType *ptrSPITType = NULL;
|
||||
{
|
||||
|
||||
SPITObject *ptrSPITObject = SPITObject::getSPITObjectRemote(p_ReportPlayStatus->getID());
|
||||
SPITObject *ptrSPITObject = SPITObject::getSPITObjectRemote(p_ReportPlayStatus->getID());
|
||||
if (ptrSPITObject == nullptr) {
|
||||
ptrSPITObject = SPITObject::getSPITObject(p_ReportPlayStatus->getID());
|
||||
if (ptrSPITObject == nullptr) {
|
||||
ptrSPITObject = SPITObject::getSPITObject(p_ReportPlayStatus->getID());
|
||||
if (ptrSPITObject == nullptr) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (ptrSPITObject->getServerRemote() == false) {
|
||||
ptrSPITType = SPITType::getSPITType(ptrSPITObject->getSPITTypeID());
|
||||
} else {
|
||||
ptrSPITType = SPITType::getSPITTypeRemote(ptrSPITObject->getSPITTypeID());
|
||||
}
|
||||
|
||||
if (ptrSPITType == nullptr) {
|
||||
return;
|
||||
}
|
||||
mCallbacks.onPlayRemoteObjectStatus(*ptrSPITType, *ptrSPITObject, p_ReportPlayStatus->getFrameInsideObject(), p_ReportPlayStatus->getValue());
|
||||
}
|
||||
if (ptrSPITObject->getServerRemote() == false) {
|
||||
ptrSPITType = SPITType::getSPITType(ptrSPITObject->getSPITTypeID());
|
||||
} else {
|
||||
ptrSPITType = SPITType::getSPITTypeRemote(ptrSPITObject->getSPITTypeID());
|
||||
}
|
||||
|
||||
if (ptrSPITType == nullptr) {
|
||||
return;
|
||||
}
|
||||
mCallbacks.onPlayRemoteObjectStatus(*ptrSPITType, *ptrSPITObject, p_ReportPlayStatus->getFrameInsideObject(), p_ReportPlayStatus->getValue());
|
||||
}
|
||||
|
||||
//--------- Remote ----------
|
||||
@@ -1517,15 +1458,15 @@ void SPIT_Client::processSocketTask(SPIT_Client &instance) {
|
||||
strParts[intIndex] = stringPart;
|
||||
intIndex++;
|
||||
}
|
||||
|
||||
auto server = make_unique<SAD_DetectedServer> (
|
||||
strParts[SAD_DetectedServer::PARAMINDEX_NAME],
|
||||
strParts[SAD_DetectedServer::PARAMINDEX_ID],
|
||||
strParts[SAD_DetectedServer::PARAMINDEX_COMPUTERNAME],
|
||||
stringServerIP,
|
||||
strParts[SAD_DetectedServer::PARAMINDEX_PORT],
|
||||
strParts[SAD_DetectedServer::PARAMINDEX_CLIENTIP],
|
||||
strParts[SAD_DetectedServer::PARAMINDEX_ADDITIONS],
|
||||
|
||||
auto server = make_unique<SAD_DetectedServer>(
|
||||
strParts[SAD_DetectedServer::PARAMINDEX_NAME],
|
||||
strParts[SAD_DetectedServer::PARAMINDEX_ID],
|
||||
strParts[SAD_DetectedServer::PARAMINDEX_COMPUTERNAME],
|
||||
stringServerIP,
|
||||
strParts[SAD_DetectedServer::PARAMINDEX_PORT],
|
||||
strParts[SAD_DetectedServer::PARAMINDEX_CLIENTIP],
|
||||
strParts[SAD_DetectedServer::PARAMINDEX_ADDITIONS],
|
||||
strParts[SAD_DetectedServer::PARAMINDEX_SERVERPROJECTNAME]);
|
||||
|
||||
SAD_DetectedServer::addDetectedServer(move(server));
|
||||
|
||||
+80
-94
@@ -733,13 +733,13 @@ void onProjectUpdate(SPIT_Client::ProjUpdate state, string projectId) {
|
||||
bool onCheckSpitTypeVeto(SPIT_Message::ReportSPITType *p_ReportSPITType) {
|
||||
return true; // Bypass veto
|
||||
|
||||
if (p_ReportSPITType == NULL)
|
||||
if (p_ReportSPITType == nullptr)
|
||||
return true;
|
||||
SPITType *ptrSPITType;
|
||||
ptrSPITType = SPITType::getSPITType(p_ReportSPITType->getID());
|
||||
|
||||
// Don't allow foreign SPITTypes
|
||||
if (ptrSPITType == NULL) {
|
||||
if (ptrSPITType == nullptr) {
|
||||
// ESP_LOGW(TAG, "ObjectVeto NoSpitType");
|
||||
return false;
|
||||
}
|
||||
@@ -753,10 +753,10 @@ bool onCheckSpitTypeVeto(SPIT_Message::ReportSPITType *p_ReportSPITType) {
|
||||
bool onCheckSpitObjectVeto(SPIT_Message::ReportSPITObject *p_ReportSPITObject) {
|
||||
return true; // Bypass veto
|
||||
|
||||
if (p_ReportSPITObject == NULL)
|
||||
if (p_ReportSPITObject == nullptr)
|
||||
return true;
|
||||
SPITType *ptrSPITType = SPITType::getSPITType(p_ReportSPITObject->getSPITTypeID());
|
||||
if (ptrSPITType == NULL) {
|
||||
if (ptrSPITType == nullptr) {
|
||||
// ESP_LOGW(TAG, "ObjectVeto NoSpitObj");
|
||||
return false;
|
||||
}
|
||||
@@ -768,7 +768,7 @@ bool onCheckSpitObjectVeto(SPIT_Message::ReportSPITObject *p_ReportSPITObject) {
|
||||
}
|
||||
SPITObject *ptrSPITObject = SPITObject::getSPITObject(p_ReportSPITObject->getID());
|
||||
// Don't allow foreign SPITTypes
|
||||
if (ptrSPITObject == NULL) {
|
||||
if (ptrSPITObject == nullptr) {
|
||||
// ESP_LOGE(TAG, "Unknown ID");
|
||||
return false;
|
||||
}
|
||||
@@ -776,102 +776,90 @@ bool onCheckSpitObjectVeto(SPIT_Message::ReportSPITObject *p_ReportSPITObject) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Called when the server has created, loaded, changed or deleted a SPITType.
|
||||
// Called when the server has created, loaded, changed or deleted a (Remote) SPITType.
|
||||
// Remote SPITType are used in Remote SPITObjects. A Remote SPITObject is used to remote control the SPITServer.
|
||||
// May also occur when the server confirms a SPITType created or changed by the client.
|
||||
void onSpitType(SPIT_Client::ObjectEvent event, const SPITType &p_SPITType) {
|
||||
if (event == SPIT_Client::ObjectEvent::Created) {
|
||||
// Whenever you provide an action for this SPITType take this over in your code.
|
||||
// call _SpitClient.setActionSPITType(p_SPITType.getID(), true);
|
||||
ESP_LOGI(TAG, "NEW SPIT-Type ID: %s GroupName: %s Name: %s confirmed: %d", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data(), p_SPITType.getConfirmed());
|
||||
} else if (event == SPIT_Client::ObjectEvent::Changed) {
|
||||
ESP_LOGI(TAG, "SPIT-Type CHANGED ID: %s GroupName: %s Name: %s confirmed: %d", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data(), p_SPITType.getConfirmed());
|
||||
} else if (event == SPIT_Client::ObjectEvent::Deleted) {
|
||||
ESP_LOGI(TAG, "SPIT-Type Removed ID: %s GroupName: %s Name: %s\n", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the server has created or changed a Remote SPITType.
|
||||
* Remote SPITType are used in Remote SPITObjects. A Remote SPITObject is used to remote control the SPITServer.
|
||||
* @param p_New true = server created a new SPITType / false = server changed a existing SPITType
|
||||
*/
|
||||
void onSpitTypeRemote(SPIT_Client::ObjectEvent event, const SPITType &p_SPITType) {
|
||||
if (event == SPIT_Client::ObjectEvent::Created) {
|
||||
ESP_LOGI(TAG, "NEW SPIT-REMOTE-Type ID: %s GroupName: %s Name: %s confirmed: %d", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data(), p_SPITType.getConfirmed());
|
||||
auto typeName = p_SPITType.getName();
|
||||
if (ExpectedObjects.contains(typeName)) {
|
||||
ExpectedObjects[typeName] = p_SPITType.getID();
|
||||
}
|
||||
} else if (event == SPIT_Client::ObjectEvent::Changed) {
|
||||
// we had to inform all Remote SPITObjects using the p_SPITType
|
||||
// perhaps the SPITObject uses information from the SPITType
|
||||
SPITObject *ptrSPITObject;
|
||||
int intSPITObjectCount;
|
||||
intSPITObjectCount = SPITObject::getSPITObjectRemoteCount();
|
||||
for (int intObject = 0; intObject < intSPITObjectCount; intObject++) {
|
||||
ptrSPITObject = SPITObject::getSPITObjectRemote(intObject);
|
||||
if (ptrSPITObject == NULL)
|
||||
continue;
|
||||
if (ptrSPITObject->getSPITTypeID() == p_SPITType.getID()) {
|
||||
// call ecentSPITObjectRemote
|
||||
// onSpitObjectRemote(SPIT_Client::ObjectEvent::Changed, p_SPITType, *ptrSPITObject);
|
||||
void onSpitType(SPIT_Client::ObjectEvent event, bool isRemote, const SPITType &p_SPITType) {
|
||||
if (isRemote) {
|
||||
if (event == SPIT_Client::ObjectEvent::Created) {
|
||||
ESP_LOGI(TAG, "NEW SPIT-REMOTE-Type ID: %s GroupName: %s Name: %s confirmed: %d", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data(), p_SPITType.getConfirmed());
|
||||
auto typeName = p_SPITType.getName();
|
||||
if (ExpectedObjects.contains(typeName)) {
|
||||
ExpectedObjects[typeName] = p_SPITType.getID();
|
||||
}
|
||||
} else if (event == SPIT_Client::ObjectEvent::Changed) {
|
||||
// we had to inform all Remote SPITObjects using the p_SPITType
|
||||
// perhaps the SPITObject uses information from the SPITType
|
||||
SPITObject *ptrSPITObject;
|
||||
int intSPITObjectCount;
|
||||
intSPITObjectCount = SPITObject::getSPITObjectRemoteCount();
|
||||
for (int intObject = 0; intObject < intSPITObjectCount; intObject++) {
|
||||
ptrSPITObject = SPITObject::getSPITObjectRemote(intObject);
|
||||
if (ptrSPITObject == nullptr)
|
||||
continue;
|
||||
if (ptrSPITObject->getSPITTypeID() == p_SPITType.getID()) {
|
||||
// call ecentSPITObjectRemote
|
||||
// onSpitObjectRemote(SPIT_Client::ObjectEvent::Changed, p_SPITType, *ptrSPITObject);
|
||||
}
|
||||
}
|
||||
ESP_LOGI(TAG, "SPIT-REMOTE-Type CHANGED ID: %s GroupName: %s Name: %s confirmed: %d", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data(), p_SPITType.getConfirmed());
|
||||
} else if (event == SPIT_Client::ObjectEvent::Deleted) {
|
||||
ESP_LOGD(TAG, "SPIT-REMOTE-Type Removed ID: %s GroupName: %s Name: %s\n", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data());
|
||||
}
|
||||
} else {
|
||||
if (event == SPIT_Client::ObjectEvent::Created) {
|
||||
// Whenever you provide an action for this SPITType take this over in your code.
|
||||
// call _SpitClient.setActionSPITType(p_SPITType.getID(), true);
|
||||
ESP_LOGI(TAG, "NEW SPIT-Type ID: %s GroupName: %s Name: %s confirmed: %d", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data(), p_SPITType.getConfirmed());
|
||||
} else if (event == SPIT_Client::ObjectEvent::Changed) {
|
||||
ESP_LOGI(TAG, "SPIT-Type CHANGED ID: %s GroupName: %s Name: %s confirmed: %d", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data(), p_SPITType.getConfirmed());
|
||||
} else if (event == SPIT_Client::ObjectEvent::Deleted) {
|
||||
ESP_LOGI(TAG, "SPIT-Type Removed ID: %s GroupName: %s Name: %s\n", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data());
|
||||
}
|
||||
ESP_LOGI(TAG, "SPIT-REMOTE-Type CHANGED ID: %s GroupName: %s Name: %s confirmed: %d", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data(), p_SPITType.getConfirmed());
|
||||
} else if (event == SPIT_Client::ObjectEvent::Deleted) {
|
||||
ESP_LOGD(TAG, "SPIT-REMOTE-Type Removed ID: %s GroupName: %s Name: %s\n", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the server has created, loaded or changed a SPITObject.
|
||||
* May also occur when the server confirms a SPITObject created by the client, what the client should never do!!.
|
||||
* false = server changed a existing SPITObject
|
||||
* @param p_SPITType a reference to a copy of the associated SPITType instance.
|
||||
* @param p_SPITObject a reference to a copy of the SPITObject instance.
|
||||
*/
|
||||
void onSpitObject(SPIT_Client::ObjectEvent event, const SPITType &p_SPITType, const SPITObject &p_SPITObject) {
|
||||
if (event == SPIT_Client::ObjectEvent::Created) {
|
||||
ESP_LOGI(TAG, "NEW SPIT-Object ID: %s Name: %s -> SPITType: %s", p_SPITObject.getID().data(), p_SPITObject.getName().data(), p_SPITType.getName().data());
|
||||
// check your actions
|
||||
// Whenever you provide an action for this SPITObject take this over in your code.
|
||||
// call _SpitClient.setActionSPITObject(p_SPITObject.getID(), true);
|
||||
// Called when the server has created, loaded or changed a SPITObject.
|
||||
// A Remote SPITObject is used to remote control the SPITServer.
|
||||
// May also occur when the server confirms a SPITObject created by the client, what the client should never do!!.
|
||||
// false = server changed a existing SPITObject
|
||||
// @param p_SPITType a reference to a copy of the associated SPITType instance.
|
||||
// @param p_SPITObject a reference to a copy of the SPITObject instance.
|
||||
void onSpitObject(SPIT_Client::ObjectEvent event, bool isRemote, const SPITType &p_SPITType, const SPITObject &p_SPITObject) {
|
||||
if (isRemote) {
|
||||
if (event == SPIT_Client::ObjectEvent::Created) {
|
||||
ESP_LOGI(TAG, "NEW SPIT-REMOTE-Object ID: %s Name: %s -> SPITType: %s", p_SPITObject.getID().data(), p_SPITObject.getName().data(), p_SPITType.getName().data());
|
||||
// This is a remote SPITObject which can be used to remote control the server.
|
||||
// If you want you can list this for later use
|
||||
} else if (event == SPIT_Client::ObjectEvent::Changed) {
|
||||
ESP_LOGI(TAG, "SPIT-REMOTE-Object CHANGED ID: %s Name: %s -> SPITType: %s", p_SPITObject.getID().data(), p_SPITObject.getName().data(), p_SPITType.getName().data());
|
||||
} else if (event == SPIT_Client::ObjectEvent::Deleted) {
|
||||
ESP_LOGD(TAG, "SPIT-REMOTE-Object Removed ID: %s Name: %s\n", p_SPITObject.getID().data(), p_SPITObject.getName().data());
|
||||
// This is a remote SPITObject
|
||||
// If you have listet this prior you should remove it from the list
|
||||
}
|
||||
} else {
|
||||
if (event == SPIT_Client::ObjectEvent::Created) {
|
||||
ESP_LOGI(TAG, "NEW SPIT-Object ID: %s Name: %s -> SPITType: %s", p_SPITObject.getID().data(), p_SPITObject.getName().data(), p_SPITType.getName().data());
|
||||
// check your actions
|
||||
// Whenever you provide an action for this SPITObject take this over in your code.
|
||||
// call _SpitClient.setActionSPITObject(p_SPITObject.getID(), true);
|
||||
|
||||
// for our little excample as described in loadClientProject:
|
||||
// We have only actions for SPITTypes - means every SPITObject with the associated "Actionx"-SPITTypes will trigger the action when it is played
|
||||
//-> no need to do something here, because setActionSPITType has been set prior and the SPITObject will automatically inherits this
|
||||
// SPITObjects with other SPITTypes asscciated will trigger no actions
|
||||
// for our little excample as described in loadClientProject:
|
||||
// We have only actions for SPITTypes - means every SPITObject with the associated "Actionx"-SPITTypes will trigger the action when it is played
|
||||
//-> no need to do something here, because setActionSPITType has been set prior and the SPITObject will automatically inherits this
|
||||
// SPITObjects with other SPITTypes asscciated will trigger no actions
|
||||
|
||||
} else if (event == SPIT_Client::ObjectEvent::Changed) {
|
||||
ESP_LOGI(TAG, "SPIT-Object CHANGED ID: %s Name: %s -> SPITType: %s", p_SPITObject.getID().data(), p_SPITObject.getName().data(), p_SPITType.getName().data());
|
||||
} else if (event == SPIT_Client::ObjectEvent::Deleted) {
|
||||
ESP_LOGD(TAG, "SPIT-Object Removed ID: %s Name: %s\n", p_SPITObject.getID().data(), p_SPITObject.getName().data());
|
||||
// Check your actions
|
||||
// take the removal of the SPITObject over in your code
|
||||
} else if (event == SPIT_Client::ObjectEvent::Changed) {
|
||||
ESP_LOGI(TAG, "SPIT-Object CHANGED ID: %s Name: %s -> SPITType: %s", p_SPITObject.getID().data(), p_SPITObject.getName().data(), p_SPITType.getName().data());
|
||||
} else if (event == SPIT_Client::ObjectEvent::Deleted) {
|
||||
ESP_LOGD(TAG, "SPIT-Object Removed ID: %s Name: %s\n", p_SPITObject.getID().data(), p_SPITObject.getName().data());
|
||||
// Check your actions
|
||||
// take the removal of the SPITObject over in your code
|
||||
|
||||
// CAUTION: Deleted SPITObjects can be added later again (perhaps per UNDO on the SPITServer)
|
||||
//-> don't remove your assigned action immediately - keep it to reassign it later
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Called when the server has created or changed a Remote SPITObject.
|
||||
* A Remote SPITObject is used to remote control the SPITServer.
|
||||
* @param p_New true = server created a new remote SPITObject
|
||||
* false = server changed a existing remote SPITObject
|
||||
* @param p_SPITType a reference to a copy of the associated SPITType instance.
|
||||
* @param p_SPITObject a reference to a copy of the SPITObject instance.
|
||||
*/
|
||||
void onSpitObjectRemote(SPIT_Client::ObjectEvent event, const SPITType &p_SPITType, const SPITObject &p_SPITObject) {
|
||||
if (event == SPIT_Client::ObjectEvent::Created) {
|
||||
ESP_LOGI(TAG, "NEW SPIT-REMOTE-Object ID: %s Name: %s -> SPITType: %s", p_SPITObject.getID().data(), p_SPITObject.getName().data(), p_SPITType.getName().data());
|
||||
// This is a remote SPITObject which can be used to remote control the server.
|
||||
// If you want you can list this for later use
|
||||
} else if (event == SPIT_Client::ObjectEvent::Changed) {
|
||||
ESP_LOGI(TAG, "SPIT-REMOTE-Object CHANGED ID: %s Name: %s -> SPITType: %s", p_SPITObject.getID().data(), p_SPITObject.getName().data(), p_SPITType.getName().data());
|
||||
} else if (event == SPIT_Client::ObjectEvent::Deleted) {
|
||||
ESP_LOGD(TAG, "SPIT-REMOTE-Object Removed ID: %s Name: %s\n", p_SPITObject.getID().data(), p_SPITObject.getName().data());
|
||||
// This is a remote SPITObject
|
||||
// If you have listet this prior you should remove it from the list
|
||||
// CAUTION: Deleted SPITObjects can be added later again (perhaps per UNDO on the SPITServer)
|
||||
//-> don't remove your assigned action immediately - keep it to reassign it later
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -951,9 +939,7 @@ void SpitClientApp() {
|
||||
.onConnectionStatus = onConnectionStatus,
|
||||
.onProjectUpdate = onProjectUpdate,
|
||||
.onSpitType = onSpitType,
|
||||
.onSpitTypeRemote = onSpitTypeRemote,
|
||||
.onSpitObject = onSpitObject,
|
||||
.onSpitObjectRemote = onSpitObjectRemote,
|
||||
.onPlay = onPlay,
|
||||
.onPlaySpitType = onPlaySpitType,
|
||||
.onPlayRemoteObjectStatus = onPlayRemoteObjectStatus,
|
||||
|
||||
Reference in New Issue
Block a user