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