refactor: Heavy refactoring to modern code style
This commit is contained in:
@@ -14,280 +14,50 @@
|
||||
|
||||
#include "SPITObject.h"
|
||||
#include "SPITSocket.h"
|
||||
|
||||
unordered_map<string, SPITObject *> SPITObject::s_SPITObjects;
|
||||
unordered_map<string, SPITObject *> SPITObject::s_SPITObjectsRemote;
|
||||
|
||||
SPITObject *SPITObject::getSPITObject(string p_ID) {
|
||||
{
|
||||
auto i = s_SPITObjects.find(p_ID);
|
||||
if (i == s_SPITObjects.end()) {
|
||||
return NULL;
|
||||
}
|
||||
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
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
SPITObject *SPITObject::getSPITObjectRemote(string p_ID) {
|
||||
{
|
||||
auto i = s_SPITObjectsRemote.find(p_ID);
|
||||
if (i == s_SPITObjectsRemote.end()) {
|
||||
return NULL;
|
||||
}
|
||||
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
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
bool SPITObject::addSPITObject(SPITObject *p_ptrSPITObject) {
|
||||
if (p_ptrSPITObject == NULL)
|
||||
return false;
|
||||
{
|
||||
s_SPITObjects[p_ptrSPITObject->getID()] = p_ptrSPITObject;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
bool SPITObject::addSPITObjectRemote(SPITObject *p_ptrSPITObject) {
|
||||
if (p_ptrSPITObject == NULL)
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns a reference to the SPITObject at position p_Index.<br>
|
||||
* Throws an exception if p_Index is out of range.<br>
|
||||
* @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";
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns a reference to the remote SPITObject at position p_Index.<br>
|
||||
* Throws an exception if p_Index is out of range.<br>
|
||||
* @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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#include "esp_log.h"
|
||||
|
||||
/**
|
||||
* clears all unconfirmed SPITObjects not created by this SPIT_Client.
|
||||
*/
|
||||
void SPITObject::clearUnconfirmedSPITObjects() {
|
||||
for (auto i = s_SPITObjects.begin(); i != s_SPITObjects.end(); i++) {
|
||||
SPITObject *ptrSPITObject = i->second;
|
||||
void SPITObject::clearUnconfirmedSPITObjects(SpitRepo<SPITObject> &repo) {
|
||||
auto &entries = repo.getRepo();
|
||||
for (auto i = entries.begin(); i != entries.end();) {
|
||||
SPITObject *ptrSPITObject = i->second.get();
|
||||
if (ptrSPITObject->getCreatedByClient() == false && ptrSPITObject->getConfirmed() == false) {
|
||||
i = s_SPITObjects.erase(i);
|
||||
delete ptrSPITObject;
|
||||
}
|
||||
if (i == s_SPITObjects.end()) {
|
||||
break;
|
||||
i = entries.erase(i);
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SPITObject::eventProjectClosed() {
|
||||
for (auto i = s_SPITObjects.begin(); i != s_SPITObjects.end(); i++) {
|
||||
SPITObject *ptrSPITObject = i->second;
|
||||
void SPITObject::eventProjectClosed(SpitRepo<SPITObject> &repo, SpitRepo<SPITObject> &remoteRepo) {
|
||||
auto &entries = repo.getRepo();
|
||||
for (auto i = entries.begin(); i != entries.end(); ) {
|
||||
SPITObject *ptrSPITObject = i->second.get();
|
||||
if (ptrSPITObject->getCreatedByClient() == true) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
i = s_SPITObjects.erase(i);
|
||||
delete ptrSPITObject;
|
||||
if (i == s_SPITObjects.end()) {
|
||||
break;
|
||||
}
|
||||
i = entries.erase(i);
|
||||
}
|
||||
// Remote
|
||||
for (auto i = s_SPITObjectsRemote.begin(); i != s_SPITObjectsRemote.end(); i++) {
|
||||
SPITObject *ptrSPITObject = i->second;
|
||||
i = s_SPITObjectsRemote.erase(i);
|
||||
delete ptrSPITObject;
|
||||
if (i == s_SPITObjectsRemote.end()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
remoteRepo.clearEntries();
|
||||
}
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
void SPITObject::setConfirmedFalse(SpitRepo<SPITObject> &repo) {
|
||||
auto &entries = repo.getRepo();
|
||||
for (auto i = entries.begin(); i != entries.end(); i++) {
|
||||
i->second->setConfirmed(false);
|
||||
}
|
||||
}
|
||||
|
||||
SPITObject::SPITObject() {
|
||||
initMembers();
|
||||
SPITObject::SPITObject(string p_ID) {
|
||||
m_ID = p_ID;
|
||||
}
|
||||
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;
|
||||
@@ -309,133 +79,142 @@ 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;
|
||||
}
|
||||
return boolChanged;
|
||||
}
|
||||
|
||||
void SPITObject::fillMessageOP(SPIT_Message::ReportSPITObject *p_ReportSPITObject) {
|
||||
p_ReportSPITObject->setActionAssigned(getActionAssigned()); // Action can be assigned to type or to this object
|
||||
p_ReportSPITObject->setConfirmed(m_Confirmed);
|
||||
p_ReportSPITObject->setDelay(m_Delay);
|
||||
p_ReportSPITObject->setDuration(m_Duration);
|
||||
p_ReportSPITObject->setFixed(m_Fixed);
|
||||
p_ReportSPITObject->setFrameFadeInLength(m_FrameFadeInLength);
|
||||
p_ReportSPITObject->setFrameFadeOutLength(m_FrameFadeOutLength);
|
||||
p_ReportSPITObject->setFrameLength(m_FrameLength);
|
||||
p_ReportSPITObject->setFrameStart(m_FrameStart);
|
||||
p_ReportSPITObject->setID(m_ID);
|
||||
p_ReportSPITObject->setName(m_Name);
|
||||
p_ReportSPITObject->setRemark(m_Remark);
|
||||
p_ReportSPITObject->setSPITTypeID(m_SPITTypeID);
|
||||
p_ReportSPITObject->setServerParams(m_ServerParams);
|
||||
p_ReportSPITObject->setServerRemote(m_ServerRemote);
|
||||
p_ReportSPITObject->setTrack(m_Track);
|
||||
p_ReportSPITObject->setValueFactor(m_ValueFactor);
|
||||
p_ReportSPITObject->setValueUse(m_ValueUse);
|
||||
void SPITObject::fillMessageOP(SPIT_Message::ReportSPITObject &p_ReportSPITObject) {
|
||||
p_ReportSPITObject.setActionAssigned(getActionAssigned()); // Action can be assigned to type or to this object
|
||||
p_ReportSPITObject.setConfirmed(m_Confirmed);
|
||||
p_ReportSPITObject.setDelay(m_Delay);
|
||||
p_ReportSPITObject.setDuration(m_Duration);
|
||||
p_ReportSPITObject.setFixed(m_Fixed);
|
||||
p_ReportSPITObject.setFrameFadeInLength(m_FrameFadeInLength);
|
||||
p_ReportSPITObject.setFrameFadeOutLength(m_FrameFadeOutLength);
|
||||
p_ReportSPITObject.setFrameLength(m_FrameLength);
|
||||
p_ReportSPITObject.setFrameStart(m_FrameStart);
|
||||
p_ReportSPITObject.setID(m_ID);
|
||||
p_ReportSPITObject.setName(m_Name);
|
||||
p_ReportSPITObject.setRemark(m_Remark);
|
||||
p_ReportSPITObject.setSPITTypeID(m_SPITTypeID);
|
||||
p_ReportSPITObject.setServerParams(m_ServerParams);
|
||||
p_ReportSPITObject.setServerRemote(m_ServerRemote);
|
||||
p_ReportSPITObject.setTrack(m_Track);
|
||||
p_ReportSPITObject.setValueFactor(m_ValueFactor);
|
||||
p_ReportSPITObject.setValueUse(m_ValueUse);
|
||||
}
|
||||
void SPITObject::fillMessageOP(SPIT_Message::RemoveSPITObject *p_RemoveSPITObject) {
|
||||
p_RemoveSPITObject->setID(m_ID);
|
||||
}
|
||||
|
||||
void SPITObject::setID(string p_ID) {
|
||||
m_ID = p_ID;
|
||||
}
|
||||
void SPITObject::setCreatedByClient(bool p_CreatedByClient) {
|
||||
m_CreatedByClient = p_CreatedByClient;
|
||||
void SPITObject::fillMessageOP(SPIT_Message::RemoveSPITObject &p_RemoveSPITObject) {
|
||||
p_RemoveSPITObject.setID(m_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -486,8 +265,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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user