365 lines
11 KiB
C++
365 lines
11 KiB
C++
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
|
|
/*
|
|
* SPITObject describes a SPIT Object
|
|
* File: SPITObject.cpp
|
|
* Author: Hagi
|
|
*
|
|
* Created on 9. April 2019, 12:11
|
|
*/
|
|
|
|
#include "SPITObject.h"
|
|
#include "SPITSocket.h"
|
|
#include "esp_log.h"
|
|
|
|
/**
|
|
* clears all unconfirmed SPITObjects not created by this SPIT_Client.
|
|
*/
|
|
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 = entries.erase(i);
|
|
} else {
|
|
i++;
|
|
}
|
|
}
|
|
}
|
|
|
|
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 = entries.erase(i);
|
|
}
|
|
// Remote
|
|
remoteRepo.clearEntries();
|
|
}
|
|
/**
|
|
* sets confirmed = false for all SPITObjects.
|
|
* This should be called when the client has loaded a project.
|
|
*/
|
|
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(string p_ID) {
|
|
m_ID = p_ID;
|
|
}
|
|
|
|
bool SPITObject::setMessageOP(SPIT_Message::ReportSPITObject *p_ReportSPITObject) {
|
|
bool boolChangeAllowed;
|
|
bool boolChanged = false;
|
|
|
|
if (m_CreatedByClient == true && m_Fixed == true) {
|
|
boolChangeAllowed = false;
|
|
} else {
|
|
boolChangeAllowed = true;
|
|
}
|
|
|
|
// Confirmation should be changable
|
|
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_ReportSPITObject->getConfirmed();
|
|
}
|
|
|
|
if (m_Delay != p_ReportSPITObject->getDelay()) {
|
|
if (boolChangeAllowed == false) {
|
|
return false;
|
|
}
|
|
m_Delay = p_ReportSPITObject->getDelay();
|
|
boolChanged = true;
|
|
}
|
|
if (m_Duration != p_ReportSPITObject->getDuration()) {
|
|
if (boolChangeAllowed == false) {
|
|
return false;
|
|
}
|
|
m_Duration = p_ReportSPITObject->getDuration();
|
|
boolChanged = true;
|
|
}
|
|
if (m_Fixed != p_ReportSPITObject->getFixed()) {
|
|
if (boolChangeAllowed == false) {
|
|
return false;
|
|
}
|
|
m_Fixed = p_ReportSPITObject->getFixed();
|
|
boolChanged = true;
|
|
}
|
|
if (m_FrameFadeInLength != p_ReportSPITObject->getFrameFadeInLength()) {
|
|
if (boolChangeAllowed == false) {
|
|
return false;
|
|
}
|
|
m_FrameFadeInLength = p_ReportSPITObject->getFrameFadeInLength();
|
|
boolChanged = true;
|
|
}
|
|
if (m_FrameFadeOutLength != p_ReportSPITObject->getFrameFadeOutLength()) {
|
|
if (boolChangeAllowed == false) {
|
|
return false;
|
|
}
|
|
m_FrameFadeOutLength = p_ReportSPITObject->getFrameFadeOutLength();
|
|
boolChanged = true;
|
|
}
|
|
if (m_FrameLength != p_ReportSPITObject->getFrameLength()) {
|
|
if (boolChangeAllowed == false) {
|
|
return false;
|
|
}
|
|
m_FrameLength = p_ReportSPITObject->getFrameLength();
|
|
boolChanged = true;
|
|
}
|
|
if (m_FrameStart != p_ReportSPITObject->getFrameStart()) {
|
|
if (boolChangeAllowed == false) {
|
|
return false;
|
|
}
|
|
m_FrameStart = p_ReportSPITObject->getFrameStart();
|
|
boolChanged = true;
|
|
}
|
|
if (m_Remark != p_ReportSPITObject->getRemark()) {
|
|
if (boolChangeAllowed == false) {
|
|
return false;
|
|
}
|
|
m_Remark = p_ReportSPITObject->getRemark();
|
|
boolChanged = true;
|
|
}
|
|
if (m_ID != p_ReportSPITObject->getID()) {
|
|
if (boolChangeAllowed == false) {
|
|
return false;
|
|
}
|
|
m_ID = p_ReportSPITObject->getID();
|
|
boolChanged = true;
|
|
}
|
|
if (m_Name != p_ReportSPITObject->getName()) {
|
|
if (boolChangeAllowed == false) {
|
|
return false;
|
|
}
|
|
m_Name = p_ReportSPITObject->getName();
|
|
boolChanged = true;
|
|
}
|
|
if (m_SPITTypeID != p_ReportSPITObject->getSPITTypeID()) {
|
|
if (boolChangeAllowed == false) {
|
|
return false;
|
|
}
|
|
m_SPITTypeID = p_ReportSPITObject->getSPITTypeID();
|
|
boolChanged = true;
|
|
}
|
|
if (m_ServerParams != p_ReportSPITObject->getServerParams()) {
|
|
if (boolChangeAllowed == false) {
|
|
return false;
|
|
}
|
|
m_ServerParams = p_ReportSPITObject->getServerParams();
|
|
boolChanged = true;
|
|
}
|
|
if (m_ServerRemote != p_ReportSPITObject->getServerRemote()) {
|
|
if (boolChangeAllowed == false) {
|
|
return false;
|
|
}
|
|
m_ServerRemote = p_ReportSPITObject->getServerRemote();
|
|
boolChanged = true;
|
|
}
|
|
if (m_Track != p_ReportSPITObject->getTrack()) {
|
|
if (boolChangeAllowed == false) {
|
|
return false;
|
|
}
|
|
m_Track = p_ReportSPITObject->getTrack();
|
|
boolChanged = true;
|
|
}
|
|
if (m_ValueFactor != p_ReportSPITObject->getValueFactor()) {
|
|
if (boolChangeAllowed == false) {
|
|
return false;
|
|
}
|
|
m_ValueFactor = p_ReportSPITObject->getValueFactor();
|
|
boolChanged = true;
|
|
}
|
|
if (m_ValueUse != p_ReportSPITObject->getValueUse()) {
|
|
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::RemoveSPITObject &p_RemoveSPITObject) {
|
|
p_RemoveSPITObject.setID(m_ID);
|
|
}
|
|
|
|
/**
|
|
* This is used by the server and client to tell if the other side has registered the changes.
|
|
* @param p_Confirmed
|
|
* @return if m_Confirmed has changed
|
|
*/
|
|
bool SPITObject::setConfirmed(bool p_Confirmed) {
|
|
if (m_Confirmed == p_Confirmed)
|
|
return false;
|
|
m_Confirmed = p_Confirmed;
|
|
return true;
|
|
}
|
|
|
|
bool SPITObject::setName(string p_Name) {
|
|
if (m_Name == p_Name)
|
|
return false;
|
|
m_Name = p_Name;
|
|
m_Confirmed = false;
|
|
return true;
|
|
}
|
|
bool SPITObject::setRemark(string p_Remark) {
|
|
if (m_Remark == p_Remark)
|
|
return false;
|
|
m_Remark = p_Remark;
|
|
m_Confirmed = false;
|
|
return true;
|
|
}
|
|
bool SPITObject::setServerParams(string p_ServerParams) {
|
|
if (m_ServerParams == p_ServerParams)
|
|
return false;
|
|
m_ServerParams = p_ServerParams;
|
|
m_Confirmed = false;
|
|
return true;
|
|
}
|
|
bool SPITObject::setSPITTypeID(string p_SPITTypeID) {
|
|
if (m_SPITTypeID == p_SPITTypeID)
|
|
return false;
|
|
m_SPITTypeID = p_SPITTypeID;
|
|
m_Confirmed = false;
|
|
return true;
|
|
}
|
|
bool SPITObject::setServerRemote(bool p_BelongstoServer) {
|
|
if (m_ServerRemote == p_BelongstoServer)
|
|
return false;
|
|
m_ServerRemote = p_BelongstoServer;
|
|
m_Confirmed = false;
|
|
return true;
|
|
}
|
|
/**
|
|
* 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 SPITObject::setActionAssignedType(bool p_ActionAssigned) {
|
|
if (m_ActionAssignedType == p_ActionAssigned)
|
|
return false;
|
|
bool boolOldActionAssigend;
|
|
boolOldActionAssigend = getActionAssigned();
|
|
m_ActionAssignedType = p_ActionAssigned;
|
|
if (getActionAssigned() == boolOldActionAssigend)
|
|
return false;
|
|
m_Confirmed = false;
|
|
return true;
|
|
}
|
|
bool SPITObject::setActionAssigned(bool p_ActionAssigned) {
|
|
if (m_ActionAssigned == p_ActionAssigned)
|
|
return false;
|
|
bool boolOldActionAssigend;
|
|
boolOldActionAssigend = getActionAssigned();
|
|
m_ActionAssigned = p_ActionAssigned;
|
|
if (getActionAssigned() == boolOldActionAssigend)
|
|
return false;
|
|
m_Confirmed = false;
|
|
return true;
|
|
}
|
|
bool SPITObject::setFixed(bool p_Fixed) {
|
|
if (m_Fixed == p_Fixed)
|
|
return false;
|
|
m_Fixed = p_Fixed;
|
|
m_Confirmed = false;
|
|
return true;
|
|
}
|
|
bool SPITObject::setFrameStart(long long p_FrameStart) {
|
|
if (m_FrameStart == p_FrameStart)
|
|
return false;
|
|
m_FrameStart = p_FrameStart;
|
|
m_Confirmed = false;
|
|
return true;
|
|
}
|
|
bool SPITObject::setFrameLength(long long p_FrameLength) {
|
|
if (m_FrameLength == p_FrameLength)
|
|
return false;
|
|
m_FrameLength = p_FrameLength;
|
|
m_Confirmed = false;
|
|
return true;
|
|
}
|
|
bool SPITObject::setFrameFadeInLength(long long p_FrameFadeInLength) {
|
|
if (m_FrameFadeInLength == p_FrameFadeInLength)
|
|
return false;
|
|
m_FrameFadeInLength = p_FrameFadeInLength;
|
|
m_Confirmed = false;
|
|
return true;
|
|
}
|
|
bool SPITObject::setFrameFadeOutLength(long long p_FrameFadeOutLength) {
|
|
if (m_FrameFadeOutLength == p_FrameFadeOutLength)
|
|
return false;
|
|
m_FrameFadeOutLength = p_FrameFadeOutLength;
|
|
m_Confirmed = false;
|
|
return true;
|
|
}
|
|
bool SPITObject::setValueUse(char p_ValueUse) {
|
|
if (m_ValueUse == p_ValueUse)
|
|
return false;
|
|
m_ValueUse = p_ValueUse;
|
|
m_Confirmed = false;
|
|
return true;
|
|
}
|
|
bool SPITObject::setValueFactor(int p_ValueFactor) {
|
|
if (m_ValueFactor == p_ValueFactor)
|
|
return false;
|
|
m_ValueFactor = p_ValueFactor;
|
|
m_Confirmed = false;
|
|
return true;
|
|
}
|
|
bool SPITObject::setTrack(int p_Track) {
|
|
if (m_Track == p_Track)
|
|
return false;
|
|
m_Track = p_Track;
|
|
m_Confirmed = false;
|
|
return true;
|
|
}
|
|
bool SPITObject::setDelay(long long p_Delay) {
|
|
if (m_Delay == p_Delay)
|
|
return false;
|
|
m_Delay = p_Delay;
|
|
m_Confirmed = false;
|
|
return true;
|
|
}
|
|
bool SPITObject::setDuration(long long p_Duration) {
|
|
if (m_Duration == p_Duration)
|
|
return false;
|
|
m_Duration = p_Duration;
|
|
m_Confirmed = false;
|
|
return true;
|
|
}
|