additional refactoring of object and type classes

This commit is contained in:
2025-04-03 21:31:08 +02:00
parent decaf80d1f
commit 1208bee756
5 changed files with 465 additions and 662 deletions
+46 -46
View File
@@ -25,28 +25,32 @@ class SPITObjectListener;
class SPITObject { class SPITObject {
private: private:
static unordered_map<string, SPITObject *> s_SPITObjects; static unordered_map<string, SPITObject *> sSpitObjects;
static unordered_map<string, SPITObject *> s_SPITObjectsRemote; static unordered_map<string, SPITObject *> sSpitObjectsRemote;
public: public:
static SPITObject *getSPITObject(string p_ID); static SPITObject *getSPITObject(const string &id);
static const SPITObject &getSPITObjectRef(string p_ID); static const SPITObject &getSPITObjectRef(const string &id);
static bool addSPITObject(SPITObject *p_ptrSpitObject); static void addSPITObject(SPITObject &spitObject);
static bool removeSPITObject(SPITObject *p_ptrSpitObject); static bool removeSPITObject(const SPITObject &spitObject);
static bool removeSPITObject(string p_SpitObjectID); static bool removeSPITObject(const string & spitObjectID);
static int getSPITObjectCount(); static int getSPITObjectCount() {
return sSpitObjects.size();
}
static SPITObject *getSPITObject(int p_Index); static SPITObject *getSPITObject(int p_Index);
static const SPITObject &getSPITObjectRef(int p_Index); static const SPITObject &getSPITObjectRef(int p_Index);
static void clearSPITObjects(); static void clearSPITObjects();
static void clearUnconfirmedSPITObjects(); static void clearUnconfirmedSPITObjects();
static void setConfirmedFalse(); static void setConfirmedFalse();
static SPITObject *getSPITObjectRemote(string p_ID); static SPITObject *getSPITObjectRemote(const string &id);
static const SPITObject &getSPITObjectRemoteRef(string p_ID); static const SPITObject &getSPITObjectRemoteRef(const string &id);
static bool addSPITObjectRemote(SPITObject *p_ptrSpitObject); static void addSPITObjectRemote(SPITObject &spitObject);
static bool removeSPITObjectRemote(SPITObject *p_ptrSpitObject); static bool removeSPITObjectRemote(const SPITObject &spitObject);
static bool removeSPITObjectRemote(string p_SpitObjectID); static bool removeSPITObjectRemote(const string & spitObjectID);
static int getSPITObjectRemoteCount(); static int getSPITObjectRemoteCount() {
return sSpitObjectsRemote.size();
}
static SPITObject *getSPITObjectRemote(int p_Index); static SPITObject *getSPITObjectRemote(int p_Index);
static const SPITObject &getSPITObjectRemoteRef(int p_Index); static const SPITObject &getSPITObjectRemoteRef(int p_Index);
static void clearSPITObjectsRemote(); static void clearSPITObjectsRemote();
@@ -54,38 +58,34 @@ class SPITObject {
static void eventProjectClosed(); static void eventProjectClosed();
SPITObject(); SPITObject();
// SPITObject(const SPITObject& orig);
~SPITObject();
private: private:
string m_ID; string m_ID;
string m_Name; string m_Name{};
string m_SPITTypeID; string m_SPITTypeID{};
string m_ServerParams; string m_ServerParams{};
string m_Remark; string m_Remark{};
bool m_Confirmed; bool m_Confirmed{};
bool m_Fixed; bool m_Fixed{};
bool m_CreatedByClient; bool m_CreatedByClient{};
bool m_ServerRemote; bool m_ServerRemote{};
bool m_ActionAssigned; bool m_ActionAssigned{};
bool m_ActionAssignedType; // Virtual construct bool m_ActionAssignedType{}; // Virtual construct
long long m_FrameStart; long long m_FrameStart{};
long long m_FrameLength; long long m_FrameLength{};
long long m_FrameFadeInLength; long long m_FrameFadeInLength{};
long long m_FrameFadeOutLength; long long m_FrameFadeOutLength{};
char m_ValueUse; char m_ValueUse{0x01};
int m_ValueFactor; int m_ValueFactor{1000000}; // Values are given in ppm -> 1000000 = 1/1;
int m_Track; int m_Track{};
long long m_Delay; long long m_Delay{};
long long m_Duration; long long m_Duration{};
bool m_PlayPrePosition; bool m_PlayPrePosition;
long long m_PlayTimeInsideFrames; long long m_PlayTimeInsideFrames;
int m_PlayValue; int m_PlayValue;
char m_PlayValueFlag; char m_PlayValueFlag;
void initMembers();
public: public:
string getID() const { return m_ID; } string getID() const { return m_ID; }
string getName() const { return m_Name; } string getName() const { return m_Name; }
@@ -95,7 +95,7 @@ class SPITObject {
/** /**
* Returns if the SPITType triggers an action on the Server or on the client. * Returns if the SPITType triggers an action on the Server or on the client.
* @return false = the action is triggered on the client The client waits for the server to play objects of this SPITType<br> * @return false = the action is triggered on the client The client waits for the server to play objects of this SPITType
* true = the action is triggered on the server. The server waits for the client to play objects of this SPITType. * true = the action is triggered on the server. The server waits for the client to play objects of this SPITType.
*/ */
bool getServerRemote() const { return m_ServerRemote; } bool getServerRemote() const { return m_ServerRemote; }
@@ -106,16 +106,16 @@ class SPITObject {
*/ */
bool getConfirmed() const { return m_Confirmed; } bool getConfirmed() const { return m_Confirmed; }
bool getFixed() const { return m_Fixed; } bool getFixed() const { return m_Fixed; }
bool getCreatedByClient() { return m_CreatedByClient; } bool getCreatedByClient() const { return m_CreatedByClient; }
/** /**
* This is a virtual construct - ActionAssignedType is not implemented in the SPITProtocol.<br> * This is a virtual construct - ActionAssignedType is not implemented in the SPITProtocol.
* This is used when an action is associated with a SPITType. <br> * This is used when an action is associated with a SPITType.
* Then this action is done for every SPITObject with the SPITType. * Then this action is done for every SPITObject with the SPITType.
* @return true = an action is assigned for the SPITType. * @return true = an action is assigned for the SPITType.
*/ */
bool getActionAssignedType() const { return m_ActionAssignedType; } bool getActionAssignedType() const { return m_ActionAssignedType; }
/** Returns if this SPITObject has an associated action or not.<br> /** Returns if this SPITObject has an associated action or not.
* @return true = the user has asscociated an action with this SPITObject or <br> * @return true = the user has asscociated an action with this SPITObject or
* the user has asscociated an action with the SPITType of this SPITObject * the user has asscociated an action with the SPITType of this SPITObject
*/ */
bool getActionAssigned() const { return m_ActionAssigned || m_ActionAssignedType; } bool getActionAssigned() const { return m_ActionAssigned || m_ActionAssignedType; }
@@ -136,18 +136,18 @@ class SPITObject {
SPITType *ptrSPITType; SPITType *ptrSPITType;
if (m_ServerRemote == false) { if (m_ServerRemote == false) {
ptrSPITType = SPITType::getSPITType(m_SPITTypeID); ptrSPITType = SPITType::getSPITType(m_SPITTypeID);
if (ptrSPITType == NULL) if (ptrSPITType == nullptr)
return true; return true;
return ptrSPITType->getProjectIndepended(); return ptrSPITType->getProjectIndepended();
} else { } else {
ptrSPITType = SPITType::getSPITTypeRemote(m_SPITTypeID); ptrSPITType = SPITType::getSPITTypeRemote(m_SPITTypeID);
if (ptrSPITType == NULL) if (ptrSPITType == nullptr)
return true; return true;
return ptrSPITType->getProjectIndepended(); return ptrSPITType->getProjectIndepended();
} }
}; };
void setID(string p_ID); void setID(const string &id);
bool setConfirmed(bool p_Confirmed); bool setConfirmed(bool p_Confirmed);
void setCreatedByClient(bool p_CreatedByClient); void setCreatedByClient(bool p_CreatedByClient);
bool setName(string p_Name); bool setName(string p_Name);
+35 -46
View File
@@ -25,25 +25,25 @@ class SPITTypeListener;
class SPITType { class SPITType {
private: private:
static unordered_map<string, SPITType *> s_SPITTypes; static unordered_map<string, SPITType *> sSpitTypes;
static unordered_map<string, SPITType *> s_SPITTypesRemote; static unordered_map<string, SPITType *> sSpitTypesRemote;
public: public:
static SPITType *getSPITType(string p_ID); static SPITType *getSPITType(const string &id);
static const SPITType &getSPITTypeRef(string p_ID); static const SPITType &getSPITTypeRef(const string &id);
static bool addSPITType(SPITType *p_ptrSpitType); static void addSPITType(SPITType &spitType);
static bool removeSPITType(SPITType *p_ptrSpitType); static bool removeSPITType(const SPITType &spitType);
static int getSPITTypeCount(); static int getSPITTypeCount() { return sSpitTypes.size(); }
static SPITType *getSPITType(int p_Index); static SPITType *getSPITType(int p_Index);
static const SPITType &getSPITTypeRef(int p_Index); static const SPITType &getSPITTypeRef(int p_Index);
static void clearSPITTypes(); static void clearSPITTypes();
static void setConfirmedFalse(); static void setConfirmedFalse();
static SPITType *getSPITTypeRemote(string p_ID); static SPITType *getSPITTypeRemote(const string &id);
static const SPITType &getSPITTypeRemoteRef(string p_ID); static const SPITType &getSPITTypeRemoteRef(const string &id);
static bool addSPITTypeRemote(SPITType *p_ptrSpitType); static void addSPITTypeRemote(SPITType &spitType);
static bool removeSPITTypeRemote(SPITType *p_ptrSpitType); static bool removeSPITTypeRemote(const SPITType &spitType);
static int getSPITTypeRemoteCount(); static int getSPITTypeRemoteCount() { return sSpitTypesRemote.size(); }
static SPITType *getSPITTypeRemote(int p_Index); static SPITType *getSPITTypeRemote(int p_Index);
static const SPITType &getSPITTypeRemoteRef(int p_Index); static const SPITType &getSPITTypeRemoteRef(int p_Index);
static void clearSPITTypesRemote(); static void clearSPITTypesRemote();
@@ -52,19 +52,17 @@ class SPITType {
SPITType(); SPITType();
SPITType(string p_ID, string p_GroupName, string p_Name, bool p_Fixed, bool p_ProjectIndepended, long long p_DefaultDelay, long long p_DefaultDuration); SPITType(string p_ID, string p_GroupName, string p_Name, bool p_Fixed, bool p_ProjectIndepended, long long p_DefaultDelay, long long p_DefaultDuration);
// SPITType(const SPITType& orig);
~SPITType();
private: private:
bool m_Confirmed; bool m_Confirmed{};
string m_ID; string m_ID;
bool m_Fixed; bool m_Fixed{};
bool m_ServerRemote; bool m_ServerRemote{};
bool m_ServerProjectIndepended; bool m_ServerProjectIndepended{};
string m_GroupName; string m_GroupName{};
string m_Name; string m_Name{};
long long m_DefaultDelay; long long m_DefaultDelay{};
long long m_DefaultDuration; long long m_DefaultDuration{};
bool m_CreatedByClient; // flag true = the SPITTyype is created by the client bool m_CreatedByClient; // flag true = the SPITTyype is created by the client
// false = the SPITType is received from the server // false = the SPITType is received from the server
@@ -72,24 +70,18 @@ class SPITType {
bool m_ActionAssigned; // This is a virtual flag if user associates an action with a SPITType. bool m_ActionAssigned; // This is a virtual flag if user associates an action with a SPITType.
// Can be used to setActionAssigned for all SPITObjects with this SPITType // Can be used to setActionAssigned for all SPITObjects with this SPITType
void initMembers();
public: public:
string getID() const { return m_ID; } string getID() const { return m_ID; }
string getGroupName() const { return m_GroupName; } string getGroupName() const { return m_GroupName; }
string getName() const { return m_Name; } string getName() const { return m_Name; }
/** /**
* Returns if the SPITType triggers an action on the Server or on the client. * Returns if the SPITType triggers an action on the Server or on the client.
* @return false = the action is triggered on the client The client waits for the server to play objects of this SPITType<br> * @return false = the action is triggered on the client The client waits for the server to play objects of this SPITType
* true = the action is triggered on the server. The server waits for the client to play objects of this SPITType. * true = the action is triggered on the server. The server waits for the client to play objects of this SPITType.
*/ */
bool getServerRemote() const { bool getServerRemote() const { return m_ServerRemote; }
return m_ServerRemote;
}
bool getProjectIndepended() const { bool getProjectIndepended() const { return m_ServerProjectIndepended; }
return m_ServerProjectIndepended;
}
/** /**
* This is used by the server and client to tell if the other side has registered the changes. * 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. * @return true = other side has registered the changes.
@@ -101,40 +93,37 @@ class SPITType {
bool getCreatedByClient() const { return m_CreatedByClient; } bool getCreatedByClient() const { return m_CreatedByClient; }
/** /**
* Virtual construct - means ActionAssigned for SPITTypes is is not implemented in SPITProtocol.<br> * Virtual construct - means ActionAssigned for SPITTypes is is not implemented in SPITProtocol.
* This can used to setActionAssigned to all SPITObjects with this SPITType.<br> * This can used to setActionAssigned to all SPITObjects with this SPITType.
* This may be used in the case when the same action should be done for every SPITObject with this SPITType associated.<br> * This may be used in the case when the same action should be done for every SPITObject with this SPITType associated.
* @return true = the user has associated an action with this SPITType. * @return true = the user has associated an action with this SPITType.
*/ */
bool getActionAssigned() const { bool getActionAssigned() const {
return m_ActionAssigned; return m_ActionAssigned;
} }
public: void setID(const string &p_ID) { m_ID = p_ID; }
void setID(string p_ID); bool setGroupName(const string &p_GroupName);
bool setGroupName(string p_GroupName); bool setName(const string &p_Name);
bool setName(string p_Name);
bool setServerRemote(bool p_BelongstoServer); bool setServerRemote(bool p_BelongstoServer);
bool setProjectIndepended(bool p_ProjectIndepeneded); bool setProjectIndepended(bool p_ProjectIndepeneded);
bool setConfirmed(bool p_Confirmed); bool setConfirmed(bool p_Confirmed);
bool setFixed(bool p_Fixed); bool setFixed(bool p_Fixed);
bool setDefaultDelay(long long p_Delay); bool setDefaultDelay(long long p_Delay);
bool setDefaultDuration(long long p_Duration); bool setDefaultDuration(long long p_Duration);
void setCreatedByClient(bool p_CreatedByClient); void setCreatedByClient(bool p_CreatedByClient);
/** /**
* Virtual construct - means ActionAssigned for SPITTypes is is not implemented in SPITProtocol.<br> * Virtual construct - means ActionAssigned for SPITTypes is is not implemented in SPITProtocol.
* This can used to setActionAssigned to all SPITObjects with this SPITType.<br> * This can used to setActionAssigned to all SPITObjects with this SPITType.
* This may be used in the case when the same action should be done for every SPITObject with this SPITType associated.<br> * This may be used in the case when the same action should be done for every SPITObject with this SPITType associated.
* @return true = the m_ActionAssigned has changed. * @return true = the m_ActionAssigned has changed.
*/ */
bool setActionAssigned(bool p_ActionAssigned); bool setActionAssigned(bool p_ActionAssigned);
bool setMessageOP(SPIT_Message::ReportSPITType *p_ReportSPITType); bool setMessageOP(SPIT_Message::ReportSPITType &reportSpitType);
void fillMessageOP(SPIT_Message::ReportSPITType *p_ReportSPITType); void fillMessageOP(SPIT_Message::ReportSPITType &smReportSpitType) const;
void fillMessageOP(SPIT_Message::RemoveSPITType *p_RemoveSPITType); void fillMessageOP(SPIT_Message::RemoveSPITType &smRemoveSpitType) const;
// static char* stringCopy(const char* p_String);
}; };
#endif /* SPITTYPE_H */ #endif /* SPITTYPE_H */
+143 -226
View File
@@ -15,197 +15,132 @@
#include "SPITObject.h" #include "SPITObject.h"
#include "SPITSocket.h" #include "SPITSocket.h"
unordered_map<string, SPITObject *> SPITObject::s_SPITObjects; unordered_map<string, SPITObject *> SPITObject::sSpitObjects;
unordered_map<string, SPITObject *> SPITObject::s_SPITObjectsRemote; unordered_map<string, SPITObject *> SPITObject::sSpitObjectsRemote;
SPITObject *SPITObject::getSPITObject(string p_ID) { SPITObject *SPITObject::getSPITObject(const string &id) {
{ auto i = sSpitObjects.find(id);
auto i = s_SPITObjects.find(p_ID); if (i == sSpitObjects.end()) {
if (i == s_SPITObjects.end()) { return nullptr;
return NULL;
}
return i->second;
} }
return i->second;
} }
/** /**
* Returns the reference of the SPITObject with ID == p_ID.<br> * Returns the reference of the SPITObject with ID == id.
* Throws an exception if no SPITObject is not found.<br> * Throws an exception if no SPITObject is not found.
* @param p_ID the ID * @param id the ID
* @return reference of the SPITType with ID == p_ID * @return reference of the SPITType with ID == id
*/ */
const SPITObject &SPITObject::getSPITObjectRef(string p_ID) { const SPITObject &SPITObject::getSPITObjectRef(const string &id) {
{ return *sSpitObjects.at(id);
auto i = s_SPITObjects.find(p_ID);
if (i == s_SPITObjects.end()) {
throw "SPITObject no SPITObject with given id";
}
return *(i->second);
}
} }
SPITObject *SPITObject::getSPITObjectRemote(string p_ID) { SPITObject *SPITObject::getSPITObjectRemote(const string &id) {
{ auto i = sSpitObjectsRemote.find(id);
auto i = s_SPITObjectsRemote.find(p_ID); if (i == sSpitObjectsRemote.end()) {
if (i == s_SPITObjectsRemote.end()) { return nullptr;
return NULL;
}
return i->second;
} }
return i->second;
} }
/** /**
* Returns the reference of the remote SPITObject with ID == p_ID.<br> * Returns the reference of the remote SPITObject with ID == id.
* Throws an exception if no SPITObject is not found.<br> * Throws an exception if no SPITObject is not found.
* @param p_ID the ID * @param id the ID
* @return reference of the SPITType with ID == p_ID * @return reference of the SPITType with ID == id
*/ */
const SPITObject &SPITObject::getSPITObjectRemoteRef(string p_ID) { const SPITObject &SPITObject::getSPITObjectRemoteRef(const string &id) {
{ return *sSpitObjectsRemote.at(id);
auto i = s_SPITObjectsRemote.find(p_ID);
if (i == s_SPITObjectsRemote.end()) {
throw "Remote SPITObject no SPITObject with given id";
}
return *(i->second);
}
} }
bool SPITObject::addSPITObject(SPITObject *p_ptrSPITObject) { void SPITObject::addSPITObject(SPITObject &spitObject) {
if (p_ptrSPITObject == NULL) sSpitObjects[spitObject.getID()] = &spitObject;
}
void SPITObject::addSPITObjectRemote(SPITObject &spitObject) {
sSpitObjectsRemote[spitObject.getID()] = &spitObject;
}
bool SPITObject::removeSPITObject(const SPITObject &spitObject) {
return removeSPITObject(spitObject.getID());
}
bool SPITObject::removeSPITObject(const string & spitObjectID) {
auto i = sSpitObjects.find(spitObjectID);
if (i == sSpitObjects.end()) {
return false; return false;
{
s_SPITObjects[p_ptrSPITObject->getID()] = p_ptrSPITObject;
return true;
} }
i = sSpitObjects.erase(i);
return true;
} }
bool SPITObject::addSPITObjectRemote(SPITObject *p_ptrSPITObject) { bool SPITObject::removeSPITObjectRemote(const SPITObject &spitObject) {
if (p_ptrSPITObject == NULL) return removeSPITObjectRemote(spitObject.getID());
}
bool SPITObject::removeSPITObjectRemote(const string & spitObjectID) {
auto i = sSpitObjectsRemote.find(spitObjectID);
if (i == sSpitObjectsRemote.end()) {
return false; return false;
{
s_SPITObjectsRemote[p_ptrSPITObject->getID()] = p_ptrSPITObject;
return true;
}
}
bool SPITObject::removeSPITObject(SPITObject *p_ptrSPITObject) {
if (p_ptrSPITObject == NULL)
return false;
return removeSPITObject(p_ptrSPITObject->getID());
}
bool SPITObject::removeSPITObject(string p_SPITObjectID) {
{
auto i = s_SPITObjects.find(p_SPITObjectID);
if (i == s_SPITObjects.end()) {
return false;
}
i = s_SPITObjects.erase(i);
return true;
}
}
bool SPITObject::removeSPITObjectRemote(SPITObject *p_ptrSPITObject) {
if (p_ptrSPITObject == NULL)
return false;
return removeSPITObjectRemote(p_ptrSPITObject->getID());
}
bool SPITObject::removeSPITObjectRemote(string p_ptrSPITObject) {
{
auto i = s_SPITObjectsRemote.find(p_ptrSPITObject);
if (i == s_SPITObjectsRemote.end()) {
return false;
}
i = s_SPITObjectsRemote.erase(i);
return true;
} }
i = sSpitObjectsRemote.erase(i);
return true;
} }
int SPITObject::getSPITObjectCount() {
return s_SPITObjects.size();
}
int SPITObject::getSPITObjectRemoteCount() {
return s_SPITObjectsRemote.size();
}
SPITObject *SPITObject::getSPITObject(int p_Index) { SPITObject *SPITObject::getSPITObject(int p_Index) {
SPITObject *ptrSPITObject = NULL; if (p_Index >= 0 && p_Index < sSpitObjects.size()) {
{ unordered_map<string, SPITObject *>::iterator i = next(sSpitObjects.begin(), p_Index);
if (p_Index >= 0 && p_Index < s_SPITObjects.size()) { return i->second;
unordered_map<string, SPITObject *>::iterator i = next(s_SPITObjects.begin(), p_Index);
ptrSPITObject = i->second;
return ptrSPITObject;
} else {
return NULL;
}
} }
return nullptr;
} }
/** /**
* Returns a reference to the SPITObject at position p_Index.<br> * Returns a reference to the SPITObject at position p_Index.
* Throws an exception if p_Index is out of range.<br> * Throws an exception if p_Index is out of range.
* @param p_Index position * @param p_Index position
* @return the reference of the SPITObject at position. * @return the reference of the SPITObject at position.
*/ */
const SPITObject &SPITObject::getSPITObjectRef(int p_Index) { const SPITObject &SPITObject::getSPITObjectRef(int p_Index) {
SPITObject *ptrSPITObject = NULL; if (p_Index >= 0 && p_Index < sSpitObjects.size()) {
{ unordered_map<string, SPITObject *>::iterator i = next(sSpitObjects.begin(), p_Index);
if (p_Index >= 0 && p_Index < s_SPITObjects.size()) { return *i->second;
unordered_map<string, SPITObject *>::iterator i = next(s_SPITObjects.begin(), p_Index); } else {
ptrSPITObject = i->second; throw "SPITObject index out of range";
return *ptrSPITObject;
} else {
throw "SPITObject index out of range";
}
} }
} }
SPITObject *SPITObject::getSPITObjectRemote(int p_Index) { SPITObject *SPITObject::getSPITObjectRemote(int p_Index) {
SPITObject *ptrSPITObject = NULL; if (p_Index >= 0 && p_Index < sSpitObjectsRemote.size()) {
{ unordered_map<string, SPITObject *>::iterator i = next(sSpitObjectsRemote.begin(), p_Index);
if (p_Index >= 0 && p_Index < s_SPITObjectsRemote.size()) { return i->second;
unordered_map<string, SPITObject *>::iterator i = next(s_SPITObjectsRemote.begin(), p_Index); } else {
ptrSPITObject = i->second; return nullptr;
return ptrSPITObject;
} else {
return NULL;
}
} }
} }
/** /**
* Returns a reference to the remote SPITObject at position p_Index.<br> * Returns a reference to the remote SPITObject at position p_Index.
* Throws an exception if p_Index is out of range.<br> * Throws an exception if p_Index is out of range.
* @param p_Index position * @param p_Index position
* @return the reference of the SPITObject at position. * @return the reference of the SPITObject at position.
*/ */
const SPITObject &SPITObject::getSPITObjectRemoteRef(int p_Index) { const SPITObject &SPITObject::getSPITObjectRemoteRef(int p_Index) {
SPITObject *ptrSPITObject = NULL; if (p_Index >= 0 && p_Index < sSpitObjectsRemote.size()) {
{ unordered_map<string, SPITObject *>::iterator i = next(sSpitObjectsRemote.begin(), p_Index);
if (p_Index >= 0 && p_Index < s_SPITObjectsRemote.size()) { return *i->second;
unordered_map<string, SPITObject *>::iterator i = next(s_SPITObjectsRemote.begin(), p_Index); } else {
ptrSPITObject = i->second; throw "Remote SPITObject index out of range";
return *ptrSPITObject;
} else {
throw "Remote SPITObject index out of range";
}
} }
} }
void SPITObject::clearSPITObjects() { void SPITObject::clearSPITObjects() {
SPITObject *ptrSPITObject; SPITObject *ptrSPITObject;
{
for (auto i = s_SPITObjects.begin(); i != s_SPITObjects.end(); i++) { for (auto i = sSpitObjects.begin(); i != sSpitObjects.end(); i++) {
ptrSPITObject = i->second; ptrSPITObject = i->second;
i = s_SPITObjects.erase(i); i = sSpitObjects.erase(i);
delete ptrSPITObject; delete ptrSPITObject;
if (i == s_SPITObjects.end()) {
break;
}
}
} }
} }
void SPITObject::clearSPITObjectsRemote() { void SPITObject::clearSPITObjectsRemote() {
SPITObject *ptrSPITObject; SPITObject *ptrSPITObject;
{
for (auto i = s_SPITObjectsRemote.begin(); i != s_SPITObjectsRemote.end(); i++) { for (auto i = sSpitObjectsRemote.begin(); i != sSpitObjectsRemote.end(); i++) {
ptrSPITObject = i->second; ptrSPITObject = i->second;
i = s_SPITObjectsRemote.erase(i); i = sSpitObjectsRemote.erase(i);
delete ptrSPITObject; delete ptrSPITObject;
if (i == s_SPITObjectsRemote.end()) {
break;
}
}
} }
} }
@@ -213,82 +148,48 @@ void SPITObject::clearSPITObjectsRemote() {
* clears all unconfirmed SPITObjects not created by this SPIT_Client. * clears all unconfirmed SPITObjects not created by this SPIT_Client.
*/ */
void SPITObject::clearUnconfirmedSPITObjects() { void SPITObject::clearUnconfirmedSPITObjects() {
for (auto i = s_SPITObjects.begin(); i != s_SPITObjects.end(); i++) { for (auto i = sSpitObjects.begin(); i != sSpitObjects.end(); i++) {
SPITObject *ptrSPITObject = i->second; SPITObject *ptrSPITObject = i->second;
if (ptrSPITObject->getCreatedByClient() == false && ptrSPITObject->getConfirmed() == false) { if (ptrSPITObject->getCreatedByClient() == false && ptrSPITObject->getConfirmed() == false) {
i = s_SPITObjects.erase(i); i = sSpitObjects.erase(i);
delete ptrSPITObject; delete ptrSPITObject;
} }
if (i == s_SPITObjects.end()) {
break;
}
} }
} }
void SPITObject::eventProjectClosed() { void SPITObject::eventProjectClosed() {
for (auto i = s_SPITObjects.begin(); i != s_SPITObjects.end(); i++) { for (auto i = sSpitObjects.begin(); i != sSpitObjects.end(); i++) {
SPITObject *ptrSPITObject = i->second; SPITObject *ptrSPITObject = i->second;
if (ptrSPITObject->getCreatedByClient() == true) { if (ptrSPITObject->getCreatedByClient() == true) {
continue; continue;
} }
i = s_SPITObjects.erase(i); i = sSpitObjects.erase(i);
delete ptrSPITObject; delete ptrSPITObject;
if (i == s_SPITObjects.end()) {
break;
}
} }
// Remote // Remote
for (auto i = s_SPITObjectsRemote.begin(); i != s_SPITObjectsRemote.end(); i++) { for (auto i = sSpitObjectsRemote.begin(); i != sSpitObjectsRemote.end(); i++) {
SPITObject *ptrSPITObject = i->second; SPITObject *ptrSPITObject = i->second;
i = s_SPITObjectsRemote.erase(i); i = sSpitObjectsRemote.erase(i);
delete ptrSPITObject; delete ptrSPITObject;
if (i == s_SPITObjectsRemote.end()) {
break;
}
} }
} }
/** /**
* sets confirmed = false for all SPITObjects.<br> * sets confirmed = false for all SPITObjects.
* This should be called when the client has loaded a project.<br> * This should be called when the client has loaded a project.
*/ */
void SPITObject::setConfirmedFalse() { void SPITObject::setConfirmedFalse() {
SPITObject *ptrSPITObject; SPITObject *ptrSPITObject;
{
for (auto i = s_SPITObjects.begin(); i != s_SPITObjects.end(); i++) { for (auto i = sSpitObjects.begin(); i != sSpitObjects.end(); i++) {
ptrSPITObject = i->second; ptrSPITObject = i->second;
ptrSPITObject->setConfirmed(false); ptrSPITObject->setConfirmed(false);
}
} }
} }
SPITObject::SPITObject() { SPITObject::SPITObject() {
initMembers();
}
void SPITObject::initMembers() {
m_ActionAssigned = false;
m_ActionAssignedType = false;
m_Confirmed = false;
m_Delay = 0;
m_Duration = 0;
m_Fixed = false;
m_CreatedByClient = false;
m_FrameFadeInLength = 0;
m_FrameFadeOutLength = 0;
m_FrameLength = 0;
m_FrameStart = 0;
m_Remark = "";
m_ID = createGUID(); m_ID = createGUID();
m_Name = "";
m_SPITTypeID = "";
m_ServerParams = "";
m_ServerRemote = false;
m_Track = 0;
m_ValueFactor = 1000000; // Values are given in ppm -> 1000000 = 1/1;
m_ValueUse = 0x01;
} }
SPITObject::~SPITObject() {}
bool SPITObject::setMessageOP(SPIT_Message::ReportSPITObject *p_ReportSPITObject) { bool SPITObject::setMessageOP(SPIT_Message::ReportSPITObject *p_ReportSPITObject) {
bool boolChangeAllowed; bool boolChangeAllowed;
bool boolChanged = false; bool boolChanged = false;
@@ -309,98 +210,114 @@ bool SPITObject::setMessageOP(SPIT_Message::ReportSPITObject *p_ReportSPITObject
} }
if (m_Delay != p_ReportSPITObject->getDelay()) { if (m_Delay != p_ReportSPITObject->getDelay()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
}
m_Delay = p_ReportSPITObject->getDelay(); m_Delay = p_ReportSPITObject->getDelay();
boolChanged = true; boolChanged = true;
} }
if (m_Duration != p_ReportSPITObject->getDuration()) { if (m_Duration != p_ReportSPITObject->getDuration()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
}
m_Duration = p_ReportSPITObject->getDuration(); m_Duration = p_ReportSPITObject->getDuration();
boolChanged = true; boolChanged = true;
} }
if (m_Fixed != p_ReportSPITObject->getFixed()) { if (m_Fixed != p_ReportSPITObject->getFixed()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
}
m_Fixed = p_ReportSPITObject->getFixed(); m_Fixed = p_ReportSPITObject->getFixed();
boolChanged = true; boolChanged = true;
} }
if (m_FrameFadeInLength != p_ReportSPITObject->getFrameFadeInLength()) { if (m_FrameFadeInLength != p_ReportSPITObject->getFrameFadeInLength()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
}
m_FrameFadeInLength = p_ReportSPITObject->getFrameFadeInLength(); m_FrameFadeInLength = p_ReportSPITObject->getFrameFadeInLength();
boolChanged = true; boolChanged = true;
} }
if (m_FrameFadeOutLength != p_ReportSPITObject->getFrameFadeOutLength()) { if (m_FrameFadeOutLength != p_ReportSPITObject->getFrameFadeOutLength()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
}
m_FrameFadeOutLength = p_ReportSPITObject->getFrameFadeOutLength(); m_FrameFadeOutLength = p_ReportSPITObject->getFrameFadeOutLength();
boolChanged = true; boolChanged = true;
} }
if (m_FrameLength != p_ReportSPITObject->getFrameLength()) { if (m_FrameLength != p_ReportSPITObject->getFrameLength()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
}
m_FrameLength = p_ReportSPITObject->getFrameLength(); m_FrameLength = p_ReportSPITObject->getFrameLength();
boolChanged = true; boolChanged = true;
} }
if (m_FrameStart != p_ReportSPITObject->getFrameStart()) { if (m_FrameStart != p_ReportSPITObject->getFrameStart()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
}
m_FrameStart = p_ReportSPITObject->getFrameStart(); m_FrameStart = p_ReportSPITObject->getFrameStart();
boolChanged = true; boolChanged = true;
} }
if (m_Remark != p_ReportSPITObject->getRemark()) { if (m_Remark != p_ReportSPITObject->getRemark()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
}
m_Remark = p_ReportSPITObject->getRemark(); m_Remark = p_ReportSPITObject->getRemark();
boolChanged = true; boolChanged = true;
} }
if (m_ID != p_ReportSPITObject->getID()) { if (m_ID != p_ReportSPITObject->getID()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
}
m_ID = p_ReportSPITObject->getID(); m_ID = p_ReportSPITObject->getID();
boolChanged = true; boolChanged = true;
} }
if (m_Name != p_ReportSPITObject->getName()) { if (m_Name != p_ReportSPITObject->getName()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
}
m_Name = p_ReportSPITObject->getName(); m_Name = p_ReportSPITObject->getName();
boolChanged = true; boolChanged = true;
} }
if (m_SPITTypeID != p_ReportSPITObject->getSPITTypeID()) { if (m_SPITTypeID != p_ReportSPITObject->getSPITTypeID()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
}
m_SPITTypeID = p_ReportSPITObject->getSPITTypeID(); m_SPITTypeID = p_ReportSPITObject->getSPITTypeID();
boolChanged = true; boolChanged = true;
} }
if (m_ServerParams != p_ReportSPITObject->getServerParams()) { if (m_ServerParams != p_ReportSPITObject->getServerParams()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
}
m_ServerParams = p_ReportSPITObject->getServerParams(); m_ServerParams = p_ReportSPITObject->getServerParams();
boolChanged = true; boolChanged = true;
} }
if (m_ServerRemote != p_ReportSPITObject->getServerRemote()) { if (m_ServerRemote != p_ReportSPITObject->getServerRemote()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
}
m_ServerRemote = p_ReportSPITObject->getServerRemote(); m_ServerRemote = p_ReportSPITObject->getServerRemote();
boolChanged = true; boolChanged = true;
} }
if (m_Track != p_ReportSPITObject->getTrack()) { if (m_Track != p_ReportSPITObject->getTrack()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
}
m_Track = p_ReportSPITObject->getTrack(); m_Track = p_ReportSPITObject->getTrack();
boolChanged = true; boolChanged = true;
} }
if (m_ValueFactor != p_ReportSPITObject->getValueFactor()) { if (m_ValueFactor != p_ReportSPITObject->getValueFactor()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
}
m_ValueFactor = p_ReportSPITObject->getValueFactor(); m_ValueFactor = p_ReportSPITObject->getValueFactor();
boolChanged = true; boolChanged = true;
} }
if (m_ValueUse != p_ReportSPITObject->getValueUse()) { if (m_ValueUse != p_ReportSPITObject->getValueUse()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
}
m_ValueUse = p_ReportSPITObject->getValueUse(); m_ValueUse = p_ReportSPITObject->getValueUse();
boolChanged = true; boolChanged = true;
} }
@@ -431,8 +348,8 @@ void SPITObject::fillMessageOP(SPIT_Message::RemoveSPITObject *p_RemoveSPITObjec
p_RemoveSPITObject->setID(m_ID); p_RemoveSPITObject->setID(m_ID);
} }
void SPITObject::setID(string p_ID) { void SPITObject::setID(const string &id) {
m_ID = p_ID; m_ID = id;
} }
void SPITObject::setCreatedByClient(bool p_CreatedByClient) { void SPITObject::setCreatedByClient(bool p_CreatedByClient) {
m_CreatedByClient = p_CreatedByClient; m_CreatedByClient = p_CreatedByClient;
@@ -486,8 +403,8 @@ bool SPITObject::setServerRemote(bool p_BelongstoServer) {
return true; return true;
} }
/** /**
* This is a virtual construct - ActionAssignedType is not implemented in the SPITProtocol.<br> * This is a virtual construct - ActionAssignedType is not implemented in the SPITProtocol.
* This is used when an action is associated with a SPITType. <br> * This is used when an action is associated with a SPITType.
* Then this action is done for every SPITObject with the SPITType. * Then this action is done for every SPITObject with the SPITType.
* @return true = an action is assigned for the SPITType. * @return true = an action is assigned for the SPITType.
*/ */
+153 -250
View File
@@ -17,280 +17,175 @@
static const char *TAG = "SPIT"; static const char *TAG = "SPIT";
unordered_map<string, SPITType *> SPITType::s_SPITTypes; unordered_map<string, SPITType *> SPITType::sSpitTypes;
unordered_map<string, SPITType *> SPITType::s_SPITTypesRemote; unordered_map<string, SPITType *> SPITType::sSpitTypesRemote;
SPITType *SPITType::getSPITType(string p_ID) { SPITType *SPITType::getSPITType(const string &id) {
{ auto i = sSpitTypes.find(id);
auto i = s_SPITTypes.find(p_ID); if (i == sSpitTypes.end()) {
if (i == s_SPITTypes.end()) { return nullptr;
return NULL;
}
return i->second;
} }
return i->second;
} }
/** /**
* Returns the reference of the SPITType with ID == p_ID.<br> * Returns the reference of the SPITType with ID == id.
* Throws an exception if no SPITType is not found.<br> * Throws an exception if no SPITType is not found.
* @param p_ID the ID * @param id the ID
* @return reference of the SPITType with ID == p_ID * @return reference of the SPITType with ID == id
*/ */
const SPITType &SPITType::getSPITTypeRef(string p_ID) { const SPITType &SPITType::getSPITTypeRef(const string &id) {
{ return *sSpitTypes.at(id);
auto i = s_SPITTypes.find(p_ID);
if (i == s_SPITTypes.end()) {
throw "SPITType no SPITType with given ID";
}
return *(i->second);
}
} }
SPITType *SPITType::getSPITTypeRemote(string p_ID) { SPITType *SPITType::getSPITTypeRemote(const string &id) {
{ auto i = sSpitTypesRemote.find(id);
auto i = s_SPITTypesRemote.find(p_ID); if (i == sSpitTypesRemote.end()) {
if (i == s_SPITTypesRemote.end()) { return nullptr;
return NULL;
}
return i->second;
} }
return i->second;
} }
/** /**
* Returns the reference of the remote SPITType with ID == p_ID.<br> * Returns the reference of the remote SPITType with ID == id.
* Throws an exception if no SPITType is not found.<br> * Throws an exception if no SPITType is not found.
* @param p_ID the ID * @param id the ID
* @return reference of the SPITType with ID == p_ID * @return reference of the SPITType with ID == id
*/ */
const SPITType &SPITType::getSPITTypeRemoteRef(string p_ID) { const SPITType &SPITType::getSPITTypeRemoteRef(const string &id) {
{ return *sSpitTypesRemote.at(id);
auto i = s_SPITTypesRemote.find(p_ID);
if (i == s_SPITTypesRemote.end()) {
throw "Remote SPITType no SPITType with given ID";
}
return *(i->second);
}
} }
bool SPITType::addSPITType(SPITType *p_ptrSpitType) { void SPITType::addSPITType(SPITType &spitType) {
if (p_ptrSpitType == NULL) sSpitTypes[spitType.getID()] = &spitType;
return false;
{
s_SPITTypes[p_ptrSpitType->getID()] = p_ptrSpitType;
return true;
}
} }
bool SPITType::addSPITTypeRemote(SPITType *p_ptrSpitType) { void SPITType::addSPITTypeRemote(SPITType &spitType) {
if (p_ptrSpitType == NULL) sSpitTypesRemote[spitType.getID()] = &spitType;
return false;
{
s_SPITTypesRemote[p_ptrSpitType->getID()] = p_ptrSpitType;
return true;
}
} }
bool SPITType::removeSPITType(SPITType *p_ptrSpitType) { bool SPITType::removeSPITType(const SPITType &spitType) {
if (p_ptrSpitType == NULL) auto i = sSpitTypes.find(spitType.getID());
if (i == sSpitTypes.end()) {
return false; return false;
{
auto i = s_SPITTypes.find(p_ptrSpitType->getID());
if (i == s_SPITTypes.end()) {
return false;
}
i = s_SPITTypes.erase(i);
return true;
} }
i = sSpitTypes.erase(i);
return true;
} }
bool SPITType::removeSPITTypeRemote(SPITType *p_ptrSpitType) { bool SPITType::removeSPITTypeRemote(const SPITType &spitType) {
if (p_ptrSpitType == NULL) auto i = sSpitTypesRemote.find(spitType.getID());
if (i == sSpitTypesRemote.end()) {
return false; return false;
{
auto i = s_SPITTypesRemote.find(p_ptrSpitType->getID());
if (i == s_SPITTypesRemote.end()) {
return false;
}
i = s_SPITTypesRemote.erase(i);
return true;
} }
i = sSpitTypesRemote.erase(i);
return true;
} }
int SPITType::getSPITTypeCount() {
return s_SPITTypes.size();
}
int SPITType::getSPITTypeRemoteCount() {
return s_SPITTypesRemote.size();
}
SPITType *SPITType::getSPITType(int p_Index) { SPITType *SPITType::getSPITType(int p_Index) {
SPITType *ptrSPITType = NULL; SPITType *pSpitType = nullptr;
{ if (p_Index < sSpitTypes.size()) {
if (p_Index < s_SPITTypes.size()) { unordered_map<string, SPITType *>::iterator i = next(sSpitTypes.begin(), p_Index);
unordered_map<string, SPITType *>::iterator i = next(s_SPITTypes.begin(), p_Index); pSpitType = i->second;
ptrSPITType = i->second;
}
return ptrSPITType;
} }
return pSpitType;
} }
/** /**
* Returns a reference to the SPITType at position p_Index.<br> * Returns a reference to the SPITType at position p_Index.
* Throws an exception if p_Index is out of range.<br> * Throws an exception if p_Index is out of range.
* @param p_Index position * @param p_Index position
* @return the reference of the SPITType at position. * @return the reference of the SPITType at position.
*/ */
const SPITType &SPITType::getSPITTypeRef(int p_Index) { const SPITType &SPITType::getSPITTypeRef(int p_Index) {
SPITType *ptrSPITType = NULL; if (p_Index >= 0 && p_Index < sSpitTypes.size()) {
{ unordered_map<string, SPITType *>::iterator i = next(sSpitTypes.begin(), p_Index);
if (p_Index >= 0 && p_Index < s_SPITTypes.size()) { return *i->second;
unordered_map<string, SPITType *>::iterator i = next(s_SPITTypes.begin(), p_Index); } else {
ptrSPITType = i->second; throw "SPITType index out of range";
return *ptrSPITType;
} else {
throw "SPITType index out of range";
}
} }
} }
SPITType *SPITType::getSPITTypeRemote(int p_Index) { SPITType *SPITType::getSPITTypeRemote(int p_Index) {
SPITType *ptrSPITType = NULL; if (p_Index < sSpitTypesRemote.size()) {
{ unordered_map<string, SPITType *>::iterator i = next(sSpitTypesRemote.begin(), p_Index);
if (p_Index < s_SPITTypesRemote.size()) { return i->second;
unordered_map<string, SPITType *>::iterator i = next(s_SPITTypesRemote.begin(), p_Index);
ptrSPITType = i->second;
}
return ptrSPITType;
} }
return nullptr;
} }
/** /**
* Returns a reference to the remote SPITType at position p_Index.<br> * Returns a reference to the remote SPITType at position p_Index.
* Throws an exception if p_Index is out of range.<br> * Throws an exception if p_Index is out of range.
* @param p_Index position * @param p_Index position
* @return the reference of the SPITType at position. * @return the reference of the SPITType at position.
*/ */
const SPITType &SPITType::getSPITTypeRemoteRef(int p_Index) { const SPITType &SPITType::getSPITTypeRemoteRef(int p_Index) {
SPITType *ptrSPITType = NULL; if (p_Index >= 0 && p_Index < sSpitTypesRemote.size()) {
{ unordered_map<string, SPITType *>::iterator i = next(sSpitTypesRemote.begin(), p_Index);
if (p_Index >= 0 && p_Index < s_SPITTypesRemote.size()) { return *i->second;
unordered_map<string, SPITType *>::iterator i = next(s_SPITTypesRemote.begin(), p_Index); } else {
ptrSPITType = i->second; throw "Remote SPITType index out of range";
return *ptrSPITType;
} else {
throw "Remote SPITType index out of range";
}
} }
} }
void SPITType::clearSPITTypes() { void SPITType::clearSPITTypes() {
SPITType *ptrSPITType; for (auto i = sSpitTypes.begin(); i != sSpitTypes.end(); i++) {
{ SPITType *pSpitType = i->second;
for (auto i = s_SPITTypes.begin(); i != s_SPITTypes.end(); i++) { i = sSpitTypes.erase(i);
ptrSPITType = i->second; delete pSpitType;
i = s_SPITTypes.erase(i);
delete ptrSPITType;
if (i == s_SPITTypes.end()) {
break;
}
}
} }
} }
void SPITType::clearSPITTypesRemote() { void SPITType::clearSPITTypesRemote() {
SPITType *ptrSPITType; for (auto i = sSpitTypesRemote.begin(); i != sSpitTypesRemote.end(); i++) {
{ SPITType *ptrSPITType = i->second;
for (auto i = s_SPITTypesRemote.begin(); i != s_SPITTypesRemote.end(); i++) { i = sSpitTypesRemote.erase(i);
ptrSPITType = i->second; delete ptrSPITType;
i = s_SPITTypesRemote.erase(i);
delete ptrSPITType;
if (i == s_SPITTypesRemote.end()) {
break;
}
}
} }
} }
void SPITType::eventProjectClosed() { void SPITType::eventProjectClosed() {
SPITType *ptrSPITType; for (auto i = sSpitTypes.begin(); i != sSpitTypes.end(); i++) {
for (auto i = s_SPITTypes.begin(); i != s_SPITTypes.end(); i++) { SPITType *ptrSPITType = i->second;
ptrSPITType = i->second;
if (ptrSPITType->getCreatedByClient() == true) { if (ptrSPITType->getCreatedByClient() == true) {
continue; continue;
} }
i = s_SPITTypes.erase(i); i = sSpitTypes.erase(i);
delete ptrSPITType; delete ptrSPITType;
if (i == s_SPITTypes.end()) {
break;
}
} }
// Remote // Remote
for (auto i = s_SPITTypesRemote.begin(); i != s_SPITTypesRemote.end(); i++) { for (auto i = sSpitTypesRemote.begin(); i != sSpitTypesRemote.end(); i++) {
ptrSPITType = i->second; SPITType *ptrSPITType = i->second;
i = s_SPITTypesRemote.erase(i); i = sSpitTypesRemote.erase(i);
delete ptrSPITType; delete ptrSPITType;
if (i == s_SPITTypesRemote.end()) {
break;
}
} }
} }
/** /**
* Sets confirmed = false for all SPITTypes.<br> * Sets confirmed = false for all SPITTypes.
* This should be called when the client has loaded a project.<br> * This should be called when the client has loaded a project.
*/ */
void SPITType::setConfirmedFalse() { void SPITType::setConfirmedFalse() {
SPITType *ptrSPITType; for (auto i = sSpitTypes.begin(); i != sSpitTypes.end(); i++) {
{ SPITType *ptrSPITType = i->second;
for (auto i = s_SPITTypes.begin(); i != s_SPITTypes.end(); i++) { ptrSPITType->setConfirmed(false);
ptrSPITType = i->second;
ptrSPITType->setConfirmed(false);
}
} }
} }
SPITType::SPITType() { SPITType::SPITType() {
initMembers(); m_ID = createGUID();
} }
/*
SPITType::SPITType(const SPITType& orig) { SPITType::SPITType(string id, string grpName, string name, bool fixed, bool projectIndependent, long long defaultDelay, long long defaultDuration) {
m_Confirmed = orig.getConfirmed(); m_ID = createGUID();
m_DefaultDelay = orig.getDefaultDelay();
m_DefaultDuration = orig.getDefaultDuration();
m_Fixed = orig.getFixed();
m_GroupName = orig.getGroupName();
m_ID = orig.getID();
m_Name = orig.getName();
m_ServerProjectIndepended = orig.getProjectIndepended();
m_ServerRemote = orig.getServerRemote();
}
*/
SPITType::SPITType(string p_ID, string p_GroupName, string p_Name, bool p_Fixed, bool p_ProjectIndepended, long long p_DefaultDelay, long long p_DefaultDuration) {
initMembers();
m_ActionAssigned = false; m_ActionAssigned = false;
m_Confirmed = false; m_Confirmed = false;
m_ID = p_ID; m_ID = id;
m_GroupName = p_GroupName; m_GroupName = grpName;
m_Name = p_Name; m_Name = name;
m_Fixed = p_Fixed; m_Fixed = fixed;
m_ServerProjectIndepended = p_ProjectIndepended; m_ServerProjectIndepended = projectIndependent;
m_DefaultDelay = p_DefaultDelay; m_DefaultDelay = defaultDelay;
m_DefaultDuration = p_DefaultDuration; m_DefaultDuration = defaultDuration;
}
SPITType::~SPITType() {
}
void SPITType::initMembers() {
m_Confirmed = false;
m_DefaultDelay = 0;
m_DefaultDuration = 0;
m_Fixed = false;
m_GroupName = "";
m_ID = createGUID();
m_Name = "";
m_ServerProjectIndepended = false;
m_ServerRemote = false;
} }
void SPITType::setCreatedByClient(bool p_CreatedByClient) { void SPITType::setCreatedByClient(bool p_CreatedByClient) {
m_CreatedByClient = p_CreatedByClient; m_CreatedByClient = p_CreatedByClient;
} }
void SPITType::setID(string p_ID) {
m_ID = p_ID;
}
/** /**
* This is used by the server and client to tell if the other side has registered the changes. * This is used by the server and client to tell if the other side has registered the changes.
* @param p_Confirmed * @param p_Confirmed
@@ -303,14 +198,14 @@ bool SPITType::setConfirmed(bool p_Confirmed) {
return true; return true;
} }
bool SPITType::setGroupName(string p_GroupName) { bool SPITType::setGroupName(const string &p_GroupName) {
if (m_GroupName == p_GroupName) if (m_GroupName == p_GroupName)
return false; return false;
m_GroupName = p_GroupName; m_GroupName = p_GroupName;
m_Confirmed = false; m_Confirmed = false;
return true; return true;
} }
bool SPITType::setName(string p_Name) { bool SPITType::setName(const string &p_Name) {
if (m_Name == p_Name) if (m_Name == p_Name)
return false; return false;
m_Name = p_Name; m_Name = p_Name;
@@ -354,9 +249,9 @@ bool SPITType::setDefaultDuration(long long p_Duration) {
} }
/** /**
* Virtual construct - means ActionAssigned for SPITTypes is is not implemented in SPITProtocol.<br> * Virtual construct - means ActionAssigned for SPITTypes is is not implemented in SPITProtocol.
* This can used to setActionAssigned to all SPITObjects with this SPITType.<br> * This can used to setActionAssigned to all SPITObjects with this SPITType.
* This may be used in the case when the same action should be done for every SPITObject with this SPITType associated.<br> * This may be used in the case when the same action should be done for every SPITObject with this SPITType associated.
* @return true = the m_ActionAssigned has changed. * @return true = the m_ActionAssigned has changed.
*/ */
bool SPITType::setActionAssigned(bool p_ActionAssigned) { bool SPITType::setActionAssigned(bool p_ActionAssigned) {
@@ -370,10 +265,10 @@ bool SPITType::setActionAssigned(bool p_ActionAssigned) {
/** /**
* Set the content of the SPITType as received from the server * Set the content of the SPITType as received from the server
* @param p_ReportSPITType * @param p_ReportSPITType
* @return true = the SPITType is changed<br> * @return true = the SPITType is changed
* false = the SPITType is NOT changed, because it is not allowed to change. * false = the SPITType is NOT changed, because it is not allowed to change.
*/ */
bool SPITType::setMessageOP(SPIT_Message::ReportSPITType *p_ReportSPITType) { bool SPITType::setMessageOP(SPIT_Message::ReportSPITType &reportSpitType) {
bool boolChangeAllowed; bool boolChangeAllowed;
bool boolChanged = false; bool boolChanged = false;
@@ -383,76 +278,84 @@ bool SPITType::setMessageOP(SPIT_Message::ReportSPITType *p_ReportSPITType) {
boolChangeAllowed = true; boolChangeAllowed = true;
} }
// Confirmation should be changable // Confirmation should be changeable
if (m_CreatedByClient) { if (m_CreatedByClient) {
// Server reports a client created SPITType -> the type is confirmed // Server reports a client created SPITType -> the type is confirmed
m_Confirmed = true; m_Confirmed = true;
} else { } else {
// type is NOT client created -> the client has to confirm the SPITtype // type is NOT client created -> the client has to confirm the SPITtype
m_Confirmed = p_ReportSPITType->getConfirmed(); m_Confirmed = reportSpitType.getConfirmed();
} }
if (m_DefaultDelay != p_ReportSPITType->getDelay()) { if (m_DefaultDelay != reportSpitType.getDelay()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
m_DefaultDelay = p_ReportSPITType->getDelay(); }
m_DefaultDelay = reportSpitType.getDelay();
boolChanged = true; boolChanged = true;
} }
if (m_DefaultDuration != p_ReportSPITType->getDuration()) { if (m_DefaultDuration != reportSpitType.getDuration()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
m_DefaultDuration = p_ReportSPITType->getDuration(); }
m_DefaultDuration = reportSpitType.getDuration();
boolChanged = true; boolChanged = true;
} }
if (m_Fixed != p_ReportSPITType->getFixed()) { if (m_Fixed != reportSpitType.getFixed()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
m_Fixed = p_ReportSPITType->getFixed(); }
m_Fixed = reportSpitType.getFixed();
boolChanged = true; boolChanged = true;
} }
if (m_GroupName != p_ReportSPITType->getGroupName()) { if (m_GroupName != reportSpitType.getGroupName()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
m_GroupName = p_ReportSPITType->getGroupName(); }
m_GroupName = reportSpitType.getGroupName();
boolChanged = true; boolChanged = true;
} }
if (m_ID != p_ReportSPITType->getID()) { if (m_ID != reportSpitType.getID()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
m_ID = p_ReportSPITType->getID(); }
m_ID = reportSpitType.getID();
boolChanged = true; boolChanged = true;
} }
if (m_Name != p_ReportSPITType->getName()) { if (m_Name != reportSpitType.getName()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
m_Name = p_ReportSPITType->getName(); }
m_Name = reportSpitType.getName();
boolChanged = true; boolChanged = true;
} }
if (m_ServerProjectIndepended != p_ReportSPITType->getServerProjectIndepended()) { if (m_ServerProjectIndepended != reportSpitType.getServerProjectIndepended()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
m_ServerProjectIndepended = p_ReportSPITType->getServerProjectIndepended(); }
m_ServerProjectIndepended = reportSpitType.getServerProjectIndepended();
boolChanged = true; boolChanged = true;
} }
if (m_ServerRemote != p_ReportSPITType->getServerRemote()) { if (m_ServerRemote != reportSpitType.getServerRemote()) {
if (boolChangeAllowed == false) if (boolChangeAllowed == false) {
throw new exception(); return false;
m_ServerRemote = p_ReportSPITType->getServerRemote(); }
m_ServerRemote = reportSpitType.getServerRemote();
boolChanged = true; boolChanged = true;
} }
return boolChanged; return boolChanged;
} }
void SPITType::fillMessageOP(SPIT_Message::ReportSPITType *ptrSMReportSPITType) { void SPITType::fillMessageOP(SPIT_Message::ReportSPITType &smReportSpitType) const {
ptrSMReportSPITType->setConfirmed(m_Confirmed); smReportSpitType.setConfirmed(m_Confirmed);
ptrSMReportSPITType->setDelay(m_DefaultDelay); smReportSpitType.setDelay(m_DefaultDelay);
ptrSMReportSPITType->setDuration(m_DefaultDuration); smReportSpitType.setDuration(m_DefaultDuration);
ptrSMReportSPITType->setFixed(m_Fixed); smReportSpitType.setFixed(m_Fixed);
ptrSMReportSPITType->setGroupName(m_GroupName); smReportSpitType.setGroupName(m_GroupName);
ptrSMReportSPITType->setID(m_ID); smReportSpitType.setID(m_ID);
ptrSMReportSPITType->setName(m_Name); smReportSpitType.setName(m_Name);
ptrSMReportSPITType->setServerProjectIndepended(m_ServerProjectIndepended); smReportSpitType.setServerProjectIndepended(m_ServerProjectIndepended);
ptrSMReportSPITType->setServerRemote(m_ServerRemote); smReportSpitType.setServerRemote(m_ServerRemote);
} }
void SPITType::fillMessageOP(SPIT_Message::RemoveSPITType *ptrSMRemoveSPITType) { void SPITType::fillMessageOP(SPIT_Message::RemoveSPITType &smRemoveSpitType) const {
ptrSMRemoveSPITType->setID(m_ID); smRemoveSpitType.setID(m_ID);
} }
+88 -94
View File
@@ -87,14 +87,14 @@ void SPIT_Client::setActionSPITType(string p_SPITTypeID, bool p_ActionAssigned)
SPITObject *ptrSPITObject; SPITObject *ptrSPITObject;
{ {
ptrSPITType = SPITType::getSPITType(p_SPITTypeID); ptrSPITType = SPITType::getSPITType(p_SPITTypeID);
if (ptrSPITType == NULL) if (ptrSPITType == nullptr)
return; return;
if (ptrSPITType->setActionAssigned(p_ActionAssigned) == true) { if (ptrSPITType->setActionAssigned(p_ActionAssigned) == true) {
sendSPITTypeInternal(ptrSPITType); sendSPITTypeInternal(ptrSPITType);
for (int i = 0; i < SPITObject::getSPITObjectCount(); i++) { for (int i = 0; i < SPITObject::getSPITObjectCount(); i++) {
ptrSPITObject = SPITObject::getSPITObject(i); ptrSPITObject = SPITObject::getSPITObject(i);
if (ptrSPITObject == NULL) if (ptrSPITObject == nullptr)
continue; continue;
if (ptrSPITObject->getSPITTypeID() == ptrSPITType->getID()) { if (ptrSPITObject->getSPITTypeID() == ptrSPITType->getID()) {
if (ptrSPITObject->setActionAssignedType(p_ActionAssigned) == true) { if (ptrSPITObject->setActionAssignedType(p_ActionAssigned) == true) {
@@ -115,7 +115,7 @@ void SPIT_Client::setActionSPITObject(string p_SPITObjectID, bool p_ActionAssign
SPITObject *ptrSPITObject; SPITObject *ptrSPITObject;
{ {
ptrSPITObject = SPITObject::getSPITObject(p_SPITObjectID); ptrSPITObject = SPITObject::getSPITObject(p_SPITObjectID);
if (ptrSPITObject == NULL) if (ptrSPITObject == nullptr)
return; return;
if (ptrSPITObject->setActionAssigned(p_ActionAssigned) == true) { if (ptrSPITObject->setActionAssigned(p_ActionAssigned) == true) {
sendSPITObjectInternal(ptrSPITObject); sendSPITObjectInternal(ptrSPITObject);
@@ -227,7 +227,7 @@ void SPIT_Client::eventServerChanged(SAD_DetectedServer &server) {
// boolSuccess = false; // boolSuccess = false;
// //Stop auto detection because a suitable server was found // //Stop auto detection because a suitable server was found
// stopServerAutoDetect(); // stopServerAutoDetect();
// if (m_SPIT_Client != NULL) { // if (m_SPIT_Client != nullptr) {
// m_ServerProjectName = p_DetectedServer.getProjectName(); // m_ServerProjectName = p_DetectedServer.getProjectName();
// m_ServerIP = p_DetectedServer.getIP(); // m_ServerIP = p_DetectedServer.getIP();
@@ -254,7 +254,7 @@ void SPIT_Client::eventServerChanged(SAD_DetectedServer &server) {
// } // }
void SPIT_Client::fillHeader(SPIT_Message::Header *p_Header) { void SPIT_Client::fillHeader(SPIT_Message::Header *p_Header) {
if (p_Header == NULL) if (p_Header == nullptr)
return; return;
p_Header->setClientID(m_ID); p_Header->setClientID(m_ID);
p_Header->setServerID(m_ServerID); p_Header->setServerID(m_ServerID);
@@ -278,7 +278,7 @@ int SPIT_Client::sendSPITMessage(SPIT_Message::OPPart &spitMessageOPPart) {
const char *ptrMessageBytes = ptrSPIT_Message->getMessageBytes(); const char *ptrMessageBytes = ptrSPIT_Message->getMessageBytes();
int intByteCount = ptrSPIT_Message->getMesageByteCount(); int intByteCount = ptrSPIT_Message->getMesageByteCount();
if (ptrMessageBytes == NULL) { if (ptrMessageBytes == nullptr) {
return -1; return -1;
} }
try { try {
@@ -346,15 +346,15 @@ void SPIT_Client::resetMessageNumberReceived() {
void SPIT_Client::checkParseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage) { void SPIT_Client::checkParseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage) {
answerWatchdog(); answerWatchdog();
if (p_SPITMessage == NULL) { if (p_SPITMessage == nullptr) {
ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message Parameter == NULL\n"); ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message Parameter == nullptr\n");
return; return;
} }
if (p_SPITMessage->getHeader() == NULL) { if (p_SPITMessage->getHeader() == nullptr) {
ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message no Header\n"); ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message no Header\n");
return; return;
} }
if (p_SPITMessage->getOPPart() == NULL) { if (p_SPITMessage->getOPPart() == nullptr) {
ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message no OPPart\n"); ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message no OPPart\n");
return; return;
} }
@@ -439,7 +439,7 @@ void SPIT_Client::addOvertakingSPIT_Message(SPIT_Message *p_SPIT_Message) {
void SPIT_Client::parseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage) { void SPIT_Client::parseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage) {
answerWatchdog(); answerWatchdog();
if (!p_SPITMessage) { if (!p_SPITMessage) {
ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message Parameter == NULL"); ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message Parameter == nullptr");
return; return;
} }
if (p_SPITMessage->getHeader() == nullptr) { if (p_SPITMessage->getHeader() == nullptr) {
@@ -716,7 +716,7 @@ void SPIT_Client::eventWatchdogLost() {
//----- SPIT Project ------ //----- SPIT Project ------
void SPIT_Client::parseReportSPITProject(SPIT_Message::ReportSPITProject *p_ReportSPITProject) { void SPIT_Client::parseReportSPITProject(SPIT_Message::ReportSPITProject *p_ReportSPITProject) {
// printf("parse ReportSPITProject \n"); // printf("parse ReportSPITProject \n");
if (p_ReportSPITProject == NULL) if (p_ReportSPITProject == nullptr)
return; return;
m_ServerProjectID = p_ReportSPITProject->getProjectID(); m_ServerProjectID = p_ReportSPITProject->getProjectID();
m_ServerProjectName = p_ReportSPITProject->getProjectName(); m_ServerProjectName = p_ReportSPITProject->getProjectName();
@@ -745,7 +745,7 @@ void SPIT_Client::parseReportSPITProject(SPIT_Message::ReportSPITProject *p_Repo
} }
void SPIT_Client::parseCloseSPITProject(SPIT_Message::CloseSPITProject *p_CloseSPITProject) { void SPIT_Client::parseCloseSPITProject(SPIT_Message::CloseSPITProject *p_CloseSPITProject) {
// printf("parse CloseSPITProject \n"); // printf("parse CloseSPITProject \n");
if (p_CloseSPITProject == NULL) if (p_CloseSPITProject == nullptr)
return; return;
string stringProjectID; string stringProjectID;
mCallbacks.onProjectUpdate(ProjUpdate::ServerClosed, p_CloseSPITProject->getProjectID()); mCallbacks.onProjectUpdate(ProjUpdate::ServerClosed, p_CloseSPITProject->getProjectID());
@@ -770,7 +770,7 @@ void SPIT_Client::parseRequestProjectTransfer(SPIT_Message::RequestProjectTransf
int intCount = SPITType::getSPITTypeCount(); int intCount = SPITType::getSPITTypeCount();
for (int i = 0; i < intCount; i++) { for (int i = 0; i < intCount; i++) {
SPITType *ptrSPITType = SPITType::getSPITType(i); SPITType *ptrSPITType = SPITType::getSPITType(i);
if (ptrSPITType == NULL) if (ptrSPITType == nullptr)
break; break;
sendSPITTypeInternal(ptrSPITType); sendSPITTypeInternal(ptrSPITType);
fos::Task::delayMs(10); fos::Task::delayMs(10);
@@ -781,7 +781,7 @@ void SPIT_Client::parseRequestProjectTransfer(SPIT_Message::RequestProjectTransf
int intCount = SPITObject::getSPITObjectCount(); int intCount = SPITObject::getSPITObjectCount();
for (int i = 0; i < intCount; i++) { for (int i = 0; i < intCount; i++) {
SPITObject *ptrSPITObject = SPITObject::getSPITObject(i); SPITObject *ptrSPITObject = SPITObject::getSPITObject(i);
if (ptrSPITObject == NULL) if (ptrSPITObject == nullptr)
break; break;
sendSPITObjectInternal(ptrSPITObject); sendSPITObjectInternal(ptrSPITObject);
fos::Task::delayMs(10); fos::Task::delayMs(10);
@@ -826,7 +826,7 @@ void SPIT_Client::parseRequestProjectTransfer(SPIT_Message::RequestProjectTransf
// intCount = SPITType::getSPITTypeCount(); // intCount = SPITType::getSPITTypeCount();
// for (int i = 0; i < intCount; i++) { // for (int i = 0; i < intCount; i++) {
// ptrSPITType = SPITType::getSPITType(i); // ptrSPITType = SPITType::getSPITType(i);
// if (ptrSPITType == NULL) continue; // if (ptrSPITType == nullptr) continue;
// intResult = sendSPITTypeInternal(ptrSPITType); // intResult = sendSPITTypeInternal(ptrSPITType);
// if (intResult < 0) return; // if (intResult < 0) return;
// m_Watchdog->answerWatchdog(); // m_Watchdog->answerWatchdog();
@@ -839,7 +839,7 @@ void SPIT_Client::parseRequestProjectTransfer(SPIT_Message::RequestProjectTransf
// intCount = SPITObject::getSPITObjectCount(); // intCount = SPITObject::getSPITObjectCount();
// for (int i = 0; i < intCount; i++) { // for (int i = 0; i < intCount; i++) {
// ptrSPITObject = SPITObject::getSPITObject(i); // ptrSPITObject = SPITObject::getSPITObject(i);
// if (ptrSPITObject == NULL) continue; // if (ptrSPITObject == nullptr) continue;
// intResult = sendSPITObjectInternal(ptrSPITObject); // intResult = sendSPITObjectInternal(ptrSPITObject);
// if (intResult < 0) return; // if (intResult < 0) return;
// m_Watchdog->answerWatchdog(); // m_Watchdog->answerWatchdog();
@@ -886,7 +886,7 @@ void SPIT_Client::sendProject(SPIT_Client *p_PtrSPIT_Client) {
// intCount = SPITType::getSPITTypeCount(); // intCount = SPITType::getSPITTypeCount();
// for (int i = 0; i < intCount; i++) { // for (int i = 0; i < intCount; i++) {
// ptrSPITType = SPITType::getSPITType(i); // ptrSPITType = SPITType::getSPITType(i);
// if (ptrSPITType == NULL) continue; // if (ptrSPITType == nullptr) continue;
// if (ptrSPITType->getCreatedByClient() == false) continue; // if (ptrSPITType->getCreatedByClient() == false) continue;
// intResult = p_PtrSPIT_Client->sendSPITTypeInternal(ptrSPITType); // intResult = p_PtrSPIT_Client->sendSPITTypeInternal(ptrSPITType);
// if (intResult < 0) return; // if (intResult < 0) return;
@@ -900,7 +900,7 @@ void SPIT_Client::sendProject(SPIT_Client *p_PtrSPIT_Client) {
// intCount = SPITObject::getSPITObjectCount(); // intCount = SPITObject::getSPITObjectCount();
// for (int i = 0; i < intCount; i++) { // for (int i = 0; i < intCount; i++) {
// ptrSPITObject = SPITObject::getSPITObject(i); // ptrSPITObject = SPITObject::getSPITObject(i);
// if (ptrSPITObject == NULL) continue; // if (ptrSPITObject == nullptr) continue;
// if (ptrSPITObject->getCreatedByClient() == false) continue; // if (ptrSPITObject->getCreatedByClient() == false) continue;
// intResult = p_PtrSPIT_Client->sendSPITObjectInternal(ptrSPITObject); // intResult = p_PtrSPIT_Client->sendSPITObjectInternal(ptrSPITObject);
// if (intResult < 0) return; // if (intResult < 0) return;
@@ -942,7 +942,7 @@ void SPIT_Client::parseEndProjectTransfer(SPIT_Message::EndProjectTransfer *p_En
//----- SPIT Types ------ //----- SPIT Types ------
void SPIT_Client::parseReportSPITType(SPIT_Message::ReportSPITType *p_ReportSPITType) { void SPIT_Client::parseReportSPITType(SPIT_Message::ReportSPITType *p_ReportSPITType) {
// printf("parse ReportSPITType ID %s Name %s \n",p_ReportSPITType->getID(), p_ReportSPITType->getName()); // printf("parse ReportSPITType ID %s Name %s \n",p_ReportSPITType->getID(), p_ReportSPITType->getName());
if (p_ReportSPITType == NULL) if (p_ReportSPITType == nullptr)
return; return;
SPITType *ptrSPITType; SPITType *ptrSPITType;
bool boolNew = false; bool boolNew = false;
@@ -950,7 +950,7 @@ void SPIT_Client::parseReportSPITType(SPIT_Message::ReportSPITType *p_ReportSPIT
{ {
if (p_ReportSPITType->getServerRemote() == false) { if (p_ReportSPITType->getServerRemote() == false) {
ptrSPITType = SPITType::getSPITType(p_ReportSPITType->getID()); ptrSPITType = SPITType::getSPITType(p_ReportSPITType->getID());
if (ptrSPITType == NULL) { if (ptrSPITType == nullptr) {
// The user's app my veto the SPITType // The user's app my veto the SPITType
if (mCallbacks.onCheckSpitTypeVeto(p_ReportSPITType) == false) { if (mCallbacks.onCheckSpitTypeVeto(p_ReportSPITType) == false) {
return; return;
@@ -960,14 +960,12 @@ void SPIT_Client::parseReportSPITType(SPIT_Message::ReportSPITType *p_ReportSPIT
} }
} else { } else {
ptrSPITType = SPITType::getSPITTypeRemote(p_ReportSPITType->getID()); ptrSPITType = SPITType::getSPITTypeRemote(p_ReportSPITType->getID());
if (ptrSPITType == NULL) { if (ptrSPITType == nullptr) {
ptrSPITType = new SPITType(); ptrSPITType = new SPITType();
boolNew = true; boolNew = true;
} }
} }
try { if (!ptrSPITType->setMessageOP(*p_ReportSPITType)) {
boolChanged = ptrSPITType->setMessageOP(p_ReportSPITType);
} catch (...) {
// SPITType is not changable -> send back to the server // SPITType is not changable -> send back to the server
sendSPITTypeInternal(ptrSPITType); sendSPITTypeInternal(ptrSPITType);
return; return;
@@ -976,14 +974,14 @@ void SPIT_Client::parseReportSPITType(SPIT_Message::ReportSPITType *p_ReportSPIT
auto eventType = boolNew ? ObjectEvent::Created : ObjectEvent::Changed; auto eventType = boolNew ? ObjectEvent::Created : ObjectEvent::Changed;
// add or change SPITType // add or change SPITType
if (ptrSPITType->getServerRemote() == false) { if (ptrSPITType->getServerRemote() == false) {
SPITType::addSPITType(ptrSPITType); SPITType::addSPITType(*ptrSPITType);
mCallbacks.onSpitType(eventType, *ptrSPITType); mCallbacks.onSpitType(eventType, *ptrSPITType);
} else { } else {
SPITType::addSPITTypeRemote(ptrSPITType); SPITType::addSPITTypeRemote(*ptrSPITType);
mCallbacks.onSpitTypeRemote(eventType, *ptrSPITType); mCallbacks.onSpitTypeRemote(eventType, *ptrSPITType);
} }
if (ptrSPITType != NULL) { if (ptrSPITType != nullptr) {
if (ptrSPITType->setConfirmed(true) == true || boolChanged == true) { if (ptrSPITType->setConfirmed(true) == true || boolChanged == true) {
sendSPITTypeInternal(ptrSPITType); sendSPITTypeInternal(ptrSPITType);
} }
@@ -992,7 +990,7 @@ void SPIT_Client::parseReportSPITType(SPIT_Message::ReportSPITType *p_ReportSPIT
} }
void SPIT_Client::parseRemoveSPITType(SPIT_Message::RemoveSPITType *p_RemoveSPITType) { void SPIT_Client::parseRemoveSPITType(SPIT_Message::RemoveSPITType *p_RemoveSPITType) {
// printf("parse RemoveSPITType %s\n", p_RemoveSPITType->getID()); // printf("parse RemoveSPITType %s\n", p_RemoveSPITType->getID());
if (p_RemoveSPITType == NULL) if (p_RemoveSPITType == nullptr)
return; return;
string stringSPITTypeID; string stringSPITTypeID;
bool boolRemote = false; bool boolRemote = false;
@@ -1001,11 +999,11 @@ void SPIT_Client::parseRemoveSPITType(SPIT_Message::RemoveSPITType *p_RemoveSPIT
{ {
ptrSPITType = SPITType::getSPITTypeRemote(stringSPITTypeID); ptrSPITType = SPITType::getSPITTypeRemote(stringSPITTypeID);
if (ptrSPITType != NULL) { if (ptrSPITType != nullptr) {
boolRemote = true; boolRemote = true;
} else { } else {
ptrSPITType = SPITType::getSPITType(stringSPITTypeID); ptrSPITType = SPITType::getSPITType(stringSPITTypeID);
if (ptrSPITType != NULL) { if (ptrSPITType != nullptr) {
boolRemote = false; boolRemote = false;
} else { } else {
// No SPITType with stringSPITTypeID is listet // No SPITType with stringSPITTypeID is listet
@@ -1022,10 +1020,10 @@ void SPIT_Client::parseRemoveSPITType(SPIT_Message::RemoveSPITType *p_RemoveSPIT
if (boolRemote == false) { if (boolRemote == false) {
mCallbacks.onSpitType(ObjectEvent::Deleted, *ptrSPITType); mCallbacks.onSpitType(ObjectEvent::Deleted, *ptrSPITType);
SPITType::removeSPITType(ptrSPITType); SPITType::removeSPITType(*ptrSPITType);
} else { } else {
mCallbacks.onSpitTypeRemote(ObjectEvent::Deleted, *ptrSPITType); mCallbacks.onSpitTypeRemote(ObjectEvent::Deleted, *ptrSPITType);
SPITType::removeSPITTypeRemote(ptrSPITType); SPITType::removeSPITTypeRemote(*ptrSPITType);
} }
delete ptrSPITType; delete ptrSPITType;
} }
@@ -1038,10 +1036,10 @@ void SPIT_Client::parseRemoveSPITType(SPIT_Message::RemoveSPITType *p_RemoveSPIT
* @return 0 = is sended, -1 = is not sended * @return 0 = is sended, -1 = is not sended
*/ */
int SPIT_Client::sendSPITTypeInternal(SPITType *p_SPITType) { int SPIT_Client::sendSPITTypeInternal(SPITType *p_SPITType) {
if (p_SPITType == NULL) if (p_SPITType == nullptr)
return -1; return -1;
SPIT_Message::ReportSPITType ptrSMReportSPITType; SPIT_Message::ReportSPITType ptrSMReportSPITType;
p_SPITType->fillMessageOP(&ptrSMReportSPITType); p_SPITType->fillMessageOP(ptrSMReportSPITType);
return sendSPITMessage(ptrSMReportSPITType); return sendSPITMessage(ptrSMReportSPITType);
} }
@@ -1051,12 +1049,12 @@ int SPIT_Client::sendSPITTypeInternal(SPITType *p_SPITType) {
* @return true = changed, false = not changed maybe p_SPITType is NULL or the SPITType doesn't exists * @return true = changed, false = not changed maybe p_SPITType is NULL or the SPITType doesn't exists
*/ */
bool SPIT_Client::changeSPITType(SPITType *p_SPITType) { bool SPIT_Client::changeSPITType(SPITType *p_SPITType) {
if (p_SPITType == NULL) if (p_SPITType == nullptr)
return false; return false;
SPITType *ptrSPITType; SPITType *ptrSPITType;
{ {
ptrSPITType = SPITType::getSPITType(p_SPITType->getID()); ptrSPITType = SPITType::getSPITType(p_SPITType->getID());
if (ptrSPITType == NULL) if (ptrSPITType == nullptr)
return false; return false;
ptrSPITType->setDefaultDelay(p_SPITType->getDefaultDelay()); ptrSPITType->setDefaultDelay(p_SPITType->getDefaultDelay());
@@ -1086,12 +1084,12 @@ int SPIT_Client::removeSPITType(string p_SPITTypeID) {
SPITType *ptrSPITType; SPITType *ptrSPITType;
{ {
ptrSPITType = SPITType::getSPITType(p_SPITTypeID); ptrSPITType = SPITType::getSPITType(p_SPITTypeID);
if (ptrSPITType == NULL) if (ptrSPITType == nullptr)
return -1; return -1;
SPIT_Message::RemoveSPITType sMRemoveSPITType; SPIT_Message::RemoveSPITType sMRemoveSPITType;
ptrSPITType->fillMessageOP(&sMRemoveSPITType); ptrSPITType->fillMessageOP(sMRemoveSPITType);
mCallbacks.onSpitType(ObjectEvent::Deleted, *ptrSPITType); mCallbacks.onSpitType(ObjectEvent::Deleted, *ptrSPITType);
SPITType::removeSPITType(ptrSPITType); SPITType::removeSPITType(*ptrSPITType);
delete ptrSPITType; delete ptrSPITType;
return sendSPITMessage(sMRemoveSPITType); return sendSPITMessage(sMRemoveSPITType);
} }
@@ -1105,26 +1103,24 @@ SPITType *SPIT_Client::createSPITTypeFixed(string p_ID, string p_GroupName, stri
SPITType *SPIT_Client::createSPITType(string p_ID, string p_GroupName, string p_Name, long long p_DefaultDelay, long long p_DefaultDuration, bool p_FIxed, bool p_ProjectIndepended) { SPITType *SPIT_Client::createSPITType(string p_ID, string p_GroupName, string p_Name, long long p_DefaultDelay, long long p_DefaultDuration, bool p_FIxed, bool p_ProjectIndepended) {
SPITType *ptrSPITType; SPITType *ptrSPITType;
bool boolNew; bool boolNew;
{ ptrSPITType = SPITType::getSPITType(p_ID);
ptrSPITType = SPITType::getSPITType(p_ID); if (ptrSPITType == nullptr) {
if (ptrSPITType == NULL) { ptrSPITType = new SPITType(p_ID, p_GroupName, p_Name, p_FIxed, p_ProjectIndepended, p_DefaultDelay, p_DefaultDuration);
ptrSPITType = new SPITType(p_ID, p_GroupName, p_Name, p_FIxed, p_ProjectIndepended, p_DefaultDelay, p_DefaultDuration); ptrSPITType->setCreatedByClient(true);
ptrSPITType->setCreatedByClient(true); boolNew = true;
boolNew = true; } else {
} else { ptrSPITType->setID(p_ID);
ptrSPITType->setID(p_ID); ptrSPITType->setGroupName(p_GroupName);
ptrSPITType->setGroupName(p_GroupName); ptrSPITType->setName(p_Name);
ptrSPITType->setName(p_Name); ptrSPITType->setFixed(p_FIxed);
ptrSPITType->setFixed(p_FIxed); ptrSPITType->setProjectIndepended(p_ProjectIndepended);
ptrSPITType->setProjectIndepended(p_ProjectIndepended); ptrSPITType->setDefaultDelay(p_DefaultDelay);
ptrSPITType->setDefaultDelay(p_DefaultDelay); ptrSPITType->setDefaultDuration(p_DefaultDuration);
ptrSPITType->setDefaultDuration(p_DefaultDuration); boolNew = false;
boolNew = false;
}
} }
auto eventType = boolNew ? ObjectEvent::Created : ObjectEvent::Changed; auto eventType = boolNew ? ObjectEvent::Created : ObjectEvent::Changed;
SPITType::addSPITType(ptrSPITType); SPITType::addSPITType(*ptrSPITType);
mCallbacks.onSpitType(eventType, *ptrSPITType); mCallbacks.onSpitType(eventType, *ptrSPITType);
sendSPITTypeInternal(ptrSPITType); sendSPITTypeInternal(ptrSPITType);
return ptrSPITType; return ptrSPITType;
@@ -1133,7 +1129,7 @@ SPITType *SPIT_Client::createSPITType(string p_ID, string p_GroupName, string p_
//----- SPIT Objects ------ //----- SPIT Objects ------
void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject *p_ReportSPITObject) { void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject *p_ReportSPITObject) {
ESP_LOGD(TAG, "parse ReportSPITObject %s\n", p_ReportSPITObject->getID().c_str()); ESP_LOGD(TAG, "parse ReportSPITObject %s\n", p_ReportSPITObject->getID().c_str());
if (p_ReportSPITObject == NULL) if (p_ReportSPITObject == nullptr)
return; return;
SPITObject *ptrSPITObject; SPITObject *ptrSPITObject;
SPITType *ptrSPITType; SPITType *ptrSPITType;
@@ -1146,17 +1142,17 @@ void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject *p_Report
ptrSPITObject = SPITObject::getSPITObject(p_ReportSPITObject->getID()); ptrSPITObject = SPITObject::getSPITObject(p_ReportSPITObject->getID());
ptrSPITType = SPITType::getSPITType(p_ReportSPITObject->getSPITTypeID()); ptrSPITType = SPITType::getSPITType(p_ReportSPITObject->getSPITTypeID());
if (ptrSPITType == NULL) { if (ptrSPITType == nullptr) {
// No associated SPITType found // No associated SPITType found
if (ptrSPITObject != NULL) { if (ptrSPITObject != nullptr) {
// SpitObject exists but has no corresponding SPITType -> remove the SPITObject without sending a message // 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 // Maybe the SPITObject has changed the SPITTypeID to a SPITTypeID of another board
SPITObject::removeSPITObject(ptrSPITObject); SPITObject::removeSPITObject(*ptrSPITObject);
delete ptrSPITObject; delete ptrSPITObject;
} }
return; return;
} }
if (ptrSPITObject == NULL) { if (ptrSPITObject == nullptr) {
// The user's app my veto the SPITType // The user's app my veto the SPITType
if (mCallbacks.onCheckSpitObjectVeto(p_ReportSPITObject) == false) { if (mCallbacks.onCheckSpitObjectVeto(p_ReportSPITObject) == false) {
ESP_LOGD(TAG, "ObjectVeto %s / %s", p_ReportSPITObject->getID().c_str(), p_ReportSPITObject->getName().c_str()); ESP_LOGD(TAG, "ObjectVeto %s / %s", p_ReportSPITObject->getID().c_str(), p_ReportSPITObject->getName().c_str());
@@ -1169,7 +1165,7 @@ void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject *p_Report
// The user's app my veto the SPITType // The user's app my veto the SPITType
if (mCallbacks.onCheckSpitObjectVeto(p_ReportSPITObject) == false) { if (mCallbacks.onCheckSpitObjectVeto(p_ReportSPITObject) == false) {
// SpitObject exists and User APp denied the SPITObject -> remove the SPITObject without sending a message // SpitObject exists and User APp denied the SPITObject -> remove the SPITObject without sending a message
SPITObject::removeSPITObject(ptrSPITObject); SPITObject::removeSPITObject(*ptrSPITObject);
ESP_LOGD(TAG, "TypeVeto %s / %s", p_ReportSPITObject->getID().c_str(), p_ReportSPITObject->getName().c_str()); ESP_LOGD(TAG, "TypeVeto %s / %s", p_ReportSPITObject->getID().c_str(), p_ReportSPITObject->getName().c_str());
delete ptrSPITObject; delete ptrSPITObject;
return; return;
@@ -1179,19 +1175,17 @@ void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject *p_Report
boolRemote = true; boolRemote = true;
ptrSPITObject = SPITObject::getSPITObjectRemote(p_ReportSPITObject->getID()); ptrSPITObject = SPITObject::getSPITObjectRemote(p_ReportSPITObject->getID());
ptrSPITType = SPITType::getSPITTypeRemote(p_ReportSPITObject->getSPITTypeID()); ptrSPITType = SPITType::getSPITTypeRemote(p_ReportSPITObject->getSPITTypeID());
if (ptrSPITType == NULL) { if (ptrSPITType == nullptr) {
// No associated SPITType found // No associated SPITType found
return; return;
} }
if (ptrSPITObject == NULL) { if (ptrSPITObject == nullptr) {
ptrSPITObject = new SPITObject(); ptrSPITObject = new SPITObject();
boolNew = true; boolNew = true;
} }
} }
try { if (!ptrSPITObject->setMessageOP(p_ReportSPITObject)) {
boolChanged = ptrSPITObject->setMessageOP(p_ReportSPITObject);
} catch (...) {
// setMessageOP error - the SPITObject can't be changed, it may be fixed and crated by this client // setMessageOP error - the SPITObject can't be changed, it may be fixed and crated by this client
sendSPITObjectInternal(ptrSPITObject); sendSPITObjectInternal(ptrSPITObject);
return; return;
@@ -1200,9 +1194,9 @@ void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject *p_Report
if (boolRemote == false) { if (boolRemote == false) {
// set the virtual action assignment // set the virtual action assignment
ptrSPITObject->setActionAssignedType(ptrSPITType->getActionAssigned()); ptrSPITObject->setActionAssignedType(ptrSPITType->getActionAssigned());
SPITObject::addSPITObject(ptrSPITObject); SPITObject::addSPITObject(*ptrSPITObject);
} else { } else {
SPITObject::addSPITObjectRemote(ptrSPITObject); SPITObject::addSPITObjectRemote(*ptrSPITObject);
} }
auto eventType = boolNew ? ObjectEvent::Created : ObjectEvent::Changed; auto eventType = boolNew ? ObjectEvent::Created : ObjectEvent::Changed;
@@ -1220,7 +1214,7 @@ void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject *p_Report
} }
void SPIT_Client::parseRemoveSPITObject(SPIT_Message::RemoveSPITObject *p_RemoveSPITObject) { void SPIT_Client::parseRemoveSPITObject(SPIT_Message::RemoveSPITObject *p_RemoveSPITObject) {
// printf("parse RemoveSPITObject %s\n", p_RemoveSPITObject->getID()); // printf("parse RemoveSPITObject %s\n", p_RemoveSPITObject->getID());
if (p_RemoveSPITObject == NULL) if (p_RemoveSPITObject == nullptr)
return; return;
bool boolRemote = false; bool boolRemote = false;
SPITObject *ptrSPITObject; SPITObject *ptrSPITObject;
@@ -1228,10 +1222,10 @@ void SPIT_Client::parseRemoveSPITObject(SPIT_Message::RemoveSPITObject *p_Remove
{ {
ptrSPITObject = SPITObject::getSPITObjectRemote(p_RemoveSPITObject->getID()); ptrSPITObject = SPITObject::getSPITObjectRemote(p_RemoveSPITObject->getID());
if (ptrSPITObject != NULL) { if (ptrSPITObject != nullptr) {
boolRemote = true; boolRemote = true;
ptrSPITType = SPITType::getSPITTypeRemote(ptrSPITObject->getSPITTypeID()); ptrSPITType = SPITType::getSPITTypeRemote(ptrSPITObject->getSPITTypeID());
if (ptrSPITType != NULL) { if (ptrSPITType != nullptr) {
if (boolRemote) { if (boolRemote) {
mCallbacks.onSpitObjectRemote(ObjectEvent::Deleted, *ptrSPITType, *ptrSPITObject); mCallbacks.onSpitObjectRemote(ObjectEvent::Deleted, *ptrSPITType, *ptrSPITObject);
} else { } else {
@@ -1241,7 +1235,7 @@ void SPIT_Client::parseRemoveSPITObject(SPIT_Message::RemoveSPITObject *p_Remove
// No associated SPITType found // No associated SPITType found
// delete the SPITObject without a notification // delete the SPITObject without a notification
} }
SPITObject::removeSPITObjectRemote(ptrSPITObject); SPITObject::removeSPITObjectRemote(*ptrSPITObject);
delete ptrSPITObject; delete ptrSPITObject;
} else { } else {
// call removeSPITObject, this will notify the server that the object is removed // call removeSPITObject, this will notify the server that the object is removed
@@ -1251,7 +1245,7 @@ void SPIT_Client::parseRemoveSPITObject(SPIT_Message::RemoveSPITObject *p_Remove
} }
int SPIT_Client::sendSPITObjectInternal(SPITObject *ptrSPITObject) { int SPIT_Client::sendSPITObjectInternal(SPITObject *ptrSPITObject) {
if (ptrSPITObject == NULL) if (ptrSPITObject == nullptr)
return -1; return -1;
SPIT_Message::ReportSPITObject ptrSMReportSPITObject; SPIT_Message::ReportSPITObject ptrSMReportSPITObject;
ptrSPITObject->fillMessageOP(&ptrSMReportSPITObject); ptrSPITObject->fillMessageOP(&ptrSMReportSPITObject);
@@ -1267,16 +1261,16 @@ int SPIT_Client::sendSPITObjectInternal(SPITObject *ptrSPITObject) {
* @return true = SPITObject is changed, false = not changed, maybe p_SPITObject is NULL or the SPITObject doesn't exists * @return true = SPITObject is changed, false = not changed, maybe p_SPITObject is NULL or the SPITObject doesn't exists
*/ */
bool SPIT_Client::changeSPITObject(SPITObject *p_SPITObject) { bool SPIT_Client::changeSPITObject(SPITObject *p_SPITObject) {
if (p_SPITObject == NULL) if (p_SPITObject == nullptr)
return false; return false;
SPITObject *ptrSPITObject; SPITObject *ptrSPITObject;
SPITType *ptrSPITType; SPITType *ptrSPITType;
{ {
ptrSPITObject = SPITObject::getSPITObject(p_SPITObject->getID()); ptrSPITObject = SPITObject::getSPITObject(p_SPITObject->getID());
if (ptrSPITObject == NULL) if (ptrSPITObject == nullptr)
return false; return false;
ptrSPITType = SPITType::getSPITType(p_SPITObject->getID()); ptrSPITType = SPITType::getSPITType(p_SPITObject->getID());
if (ptrSPITObject == NULL) if (ptrSPITObject == nullptr)
return false; return false;
ptrSPITObject->setActionAssigned(p_SPITObject->getActionAssigned()); ptrSPITObject->setActionAssigned(p_SPITObject->getActionAssigned());
@@ -1320,14 +1314,14 @@ int SPIT_Client::removeSPITObject(string p_SPITObjectID) {
SPIT_Message::RemoveSPITObject sMRemoveSPITObject; SPIT_Message::RemoveSPITObject sMRemoveSPITObject;
ptrSPITObject = SPITObject::getSPITObject(p_SPITObjectID); ptrSPITObject = SPITObject::getSPITObject(p_SPITObjectID);
if (ptrSPITObject == NULL) if (ptrSPITObject == nullptr)
return -1; return -1;
ptrSPITType = SPITType::getSPITType(ptrSPITObject->getSPITTypeID()); ptrSPITType = SPITType::getSPITType(ptrSPITObject->getSPITTypeID());
if (ptrSPITType == NULL) if (ptrSPITType == nullptr)
return -1; return -1;
ptrSPITObject->fillMessageOP(&sMRemoveSPITObject); ptrSPITObject->fillMessageOP(&sMRemoveSPITObject);
mCallbacks.onSpitObject(ObjectEvent::Deleted, *ptrSPITType, *ptrSPITObject); mCallbacks.onSpitObject(ObjectEvent::Deleted, *ptrSPITType, *ptrSPITObject);
SPITObject::removeSPITObject(ptrSPITObject); SPITObject::removeSPITObject(*ptrSPITObject);
delete ptrSPITObject; delete ptrSPITObject;
return sendSPITMessage(sMRemoveSPITObject); return sendSPITMessage(sMRemoveSPITObject);
} }
@@ -1339,7 +1333,7 @@ int SPIT_Client::removeSPITObject(string p_SPITObjectID) {
void SPIT_Client::parsePlaySPITStart(SPIT_Message::PlaySPITStart *p_PlaySPITStart) { 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()); 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()); SPITPlayer *ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITStart->getPlayerID());
if (ptrSPITPlayer == NULL) if (ptrSPITPlayer == nullptr)
return; return;
ptrSPITPlayer->setIsRunning(p_PlaySPITStart->getPlayerIsRunning()); ptrSPITPlayer->setIsRunning(p_PlaySPITStart->getPlayerIsRunning());
ptrSPITPlayer->setName(p_PlaySPITStart->getPlayerName()); ptrSPITPlayer->setName(p_PlaySPITStart->getPlayerName());
@@ -1351,15 +1345,15 @@ void SPIT_Client::parsePlaySPITStart(SPIT_Message::PlaySPITStart *p_PlaySPITStar
} }
void SPIT_Client::parsePlaySPITObject(SPIT_Message::PlaySPITObject *p_PlaySPITObject) { void SPIT_Client::parsePlaySPITObject(SPIT_Message::PlaySPITObject *p_PlaySPITObject) {
SPITPlayer *ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITObject->getPlayerID()); SPITPlayer *ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITObject->getPlayerID());
if (ptrSPITPlayer == NULL) if (ptrSPITPlayer == nullptr)
return; return;
SPITObject *ptrSPITObject = SPITObject::getSPITObject(p_PlaySPITObject->getSPITObjectID()); SPITObject *ptrSPITObject = SPITObject::getSPITObject(p_PlaySPITObject->getSPITObjectID());
if (ptrSPITObject == NULL) { if (ptrSPITObject == nullptr) {
return; return;
} }
SPITPlayer::PlaySPITType *ptrPlaySPITType = ptrSPITPlayer->addSPITType_Playing(ptrSPITObject->getSPITTypeID()); SPITPlayer::PlaySPITType *ptrPlaySPITType = ptrSPITPlayer->addSPITType_Playing(ptrSPITObject->getSPITTypeID());
if (ptrPlaySPITType == NULL) { if (ptrPlaySPITType == nullptr) {
return; return;
} }
ptrPlaySPITType->setPlayerIsRunning(ptrSPITPlayer->getIsRunning()); ptrPlaySPITType->setPlayerIsRunning(ptrSPITPlayer->getIsRunning());
@@ -1367,7 +1361,7 @@ void SPIT_Client::parsePlaySPITObject(SPIT_Message::PlaySPITObject *p_PlaySPITOb
} }
void SPIT_Client::parsePlaySPITEnd(SPIT_Message::PlaySPITEnd *p_PlaySPITEnd) { void SPIT_Client::parsePlaySPITEnd(SPIT_Message::PlaySPITEnd *p_PlaySPITEnd) {
SPITPlayer *ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITEnd->getPlayerID()); SPITPlayer *ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITEnd->getPlayerID());
if (ptrSPITPlayer == NULL) if (ptrSPITPlayer == nullptr)
return; return;
// unordered_map<string, SPITPlayer::PlaySPITType*>* ptrPlayObjects; // unordered_map<string, SPITPlayer::PlaySPITType*>* ptrPlayObjects;
@@ -1387,11 +1381,11 @@ void SPIT_Client::parsePlaySPITEnd(SPIT_Message::PlaySPITEnd *p_PlaySPITEnd) {
// } // }
// { // {
// ptrSPITObject = SPITObject::getSPITObject(ptrPlayObject->getSPITObjectID()); // ptrSPITObject = SPITObject::getSPITObject(ptrPlayObject->getSPITObjectID());
// if (ptrSPITObject == NULL) { // if (ptrSPITObject == nullptr) {
// return; // return;
// } // }
// SPITType *ptrSPITType = SPITType::getSPITType(ptrSPITObject->getSPITTypeID()); // SPITType *ptrSPITType = SPITType::getSPITType(ptrSPITObject->getSPITTypeID());
// if (ptrSPITType == NULL) { // if (ptrSPITType == nullptr) {
// return; // return;
// } // }
@@ -1401,7 +1395,7 @@ void SPIT_Client::parsePlaySPITEnd(SPIT_Message::PlaySPITEnd *p_PlaySPITEnd) {
// ptrSPITPlayer->endPlaySequence(); // ptrSPITPlayer->endPlaySequence();
// SPITPlayer *ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITEnd->getPlayerID()); // SPITPlayer *ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITEnd->getPlayerID());
// if (ptrSPITPlayer == NULL) // if (ptrSPITPlayer == nullptr)
// return; // return;
unordered_map<string, SPITPlayer::PlaySPITType *> *ptrPlaySPITTypes = ptrSPITPlayer->getPlaySPITTypes(); unordered_map<string, SPITPlayer::PlaySPITType *> *ptrPlaySPITTypes = ptrSPITPlayer->getPlaySPITTypes();
@@ -1417,7 +1411,7 @@ void SPIT_Client::parsePlaySPITEnd(SPIT_Message::PlaySPITEnd *p_PlaySPITEnd) {
} }
{ {
SPITType *ptrSPITType = SPITType::getSPITType(ptrPlaySPITType->getSPITTypeID()); SPITType *ptrSPITType = SPITType::getSPITType(ptrPlaySPITType->getSPITTypeID());
if (ptrSPITType == NULL) { if (ptrSPITType == nullptr) {
// set isplayed to false, the ptrPlayObject will be removed by ptrSPITPlayer->endPlaySequence() // set isplayed to false, the ptrPlayObject will be removed by ptrSPITPlayer->endPlaySequence()
ptrPlaySPITType->setIsPlayed(false); ptrPlaySPITType->setIsPlayed(false);
continue; continue;
@@ -1434,9 +1428,9 @@ void SPIT_Client::parseReportPlayStatus(SPIT_Message::ReportPlayStatus *p_Report
{ {
SPITObject *ptrSPITObject = SPITObject::getSPITObjectRemote(p_ReportPlayStatus->getID()); SPITObject *ptrSPITObject = SPITObject::getSPITObjectRemote(p_ReportPlayStatus->getID());
if (ptrSPITObject == NULL) { if (ptrSPITObject == nullptr) {
ptrSPITObject = SPITObject::getSPITObject(p_ReportPlayStatus->getID()); ptrSPITObject = SPITObject::getSPITObject(p_ReportPlayStatus->getID());
if (ptrSPITObject == NULL) { if (ptrSPITObject == nullptr) {
return; return;
} }
} }
@@ -1446,7 +1440,7 @@ void SPIT_Client::parseReportPlayStatus(SPIT_Message::ReportPlayStatus *p_Report
ptrSPITType = SPITType::getSPITTypeRemote(ptrSPITObject->getSPITTypeID()); ptrSPITType = SPITType::getSPITTypeRemote(ptrSPITObject->getSPITTypeID());
} }
if (ptrSPITType == NULL) { if (ptrSPITType == nullptr) {
return; return;
} }
mCallbacks.onPlayRemoteObjectStatus(*ptrSPITType, *ptrSPITObject, p_ReportPlayStatus->getFrameInsideObject(), p_ReportPlayStatus->getValue()); mCallbacks.onPlayRemoteObjectStatus(*ptrSPITType, *ptrSPITObject, p_ReportPlayStatus->getFrameInsideObject(), p_ReportPlayStatus->getValue());
@@ -1473,7 +1467,7 @@ void SPIT_Client::sendRemoteObject(string p_SPITObjectID, int p_Valueppm, char p
SPITObject *ptrRemoteSPITObject; SPITObject *ptrRemoteSPITObject;
{ {
ptrRemoteSPITObject = SPITObject::getSPITObjectRemote(p_SPITObjectID); ptrRemoteSPITObject = SPITObject::getSPITObjectRemote(p_SPITObjectID);
if (ptrRemoteSPITObject == NULL) if (ptrRemoteSPITObject == nullptr)
return; return;
SPIT_Message::PlaySPITStart playSPITStart; SPIT_Message::PlaySPITStart playSPITStart;