refactor: Heavy refactoring of SPIT
This commit is contained in:
@@ -0,0 +1,202 @@
|
||||
|
||||
#include "spit_object.hpp"
|
||||
#include "spit_socket.hpp"
|
||||
#include "esp_log.h"
|
||||
|
||||
namespace spit {
|
||||
|
||||
/**
|
||||
* clears all unconfirmed SObjects not created by this SPIT_Client.
|
||||
*/
|
||||
void SObject::clearUnconfirmedObjects(SpitRepo<SObject> &repo) {
|
||||
auto &entries = repo.getRepo();
|
||||
for (auto i = entries.begin(); i != entries.end();) {
|
||||
SObject *ptrSObject = i->second.get();
|
||||
if (ptrSObject->getCreatedByClient() == false && ptrSObject->getConfirmed() == false) {
|
||||
i = entries.erase(i);
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SObject::eventProjectClosed(SpitRepo<SObject> &repo, SpitRepo<SObject> &remoteRepo) {
|
||||
auto &entries = repo.getRepo();
|
||||
for (auto i = entries.begin(); i != entries.end(); ) {
|
||||
SObject *ptrSObject = i->second.get();
|
||||
if (ptrSObject->getCreatedByClient() == true) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
i = entries.erase(i);
|
||||
}
|
||||
// Remote
|
||||
remoteRepo.clearEntries();
|
||||
}
|
||||
|
||||
/**
|
||||
* sets confirmed = false for all SObjects.
|
||||
* This should be called when the client has loaded a project.
|
||||
*/
|
||||
void SObject::setConfirmedFalse(SpitRepo<SObject> &repo) {
|
||||
auto &entries = repo.getRepo();
|
||||
for (auto i = entries.begin(); i != entries.end(); i++) {
|
||||
i->second->setConfirmed(false);
|
||||
}
|
||||
}
|
||||
|
||||
bool SObject::setMessageOP(Message::ReportObject *message) {
|
||||
bool changeAllowed;
|
||||
|
||||
if ((mCreatedByClient == true) && (Fixed.mValue == true)) {
|
||||
changeAllowed = false;
|
||||
} else {
|
||||
changeAllowed = true;
|
||||
}
|
||||
|
||||
// Confirmation should be changable
|
||||
if (mCreatedByClient) {
|
||||
// Server reports a client created SPITType -> the type is confirmed
|
||||
mConfirmed = true;
|
||||
} else {
|
||||
// type is NOT client created -> the client has to confirm the SPITtype
|
||||
mConfirmed = message->getConfirmed();
|
||||
}
|
||||
|
||||
if (changeAllowed == false) {
|
||||
return false;
|
||||
}
|
||||
bool changed = false;
|
||||
if (Delay.mValue != message->getDelay()) {
|
||||
Delay.mValue = message->getDelay();
|
||||
changed = true;
|
||||
}
|
||||
if (Duration.mValue != message->getDuration()) {
|
||||
Duration.mValue = message->getDuration();
|
||||
changed = true;
|
||||
}
|
||||
if (Fixed.mValue != message->getFixed()) {
|
||||
Fixed.mValue = message->getFixed();
|
||||
changed = true;
|
||||
}
|
||||
if (FrameFadeInLength.mValue != message->getFrameFadeInLength()) {
|
||||
FrameFadeInLength.mValue = message->getFrameFadeInLength();
|
||||
changed = true;
|
||||
}
|
||||
if (FrameFadeOutLength.mValue != message->getFrameFadeOutLength()) {
|
||||
FrameFadeOutLength.mValue = message->getFrameFadeOutLength();
|
||||
changed = true;
|
||||
}
|
||||
if (FrameLength.mValue != message->getFrameLength()) {
|
||||
FrameLength.mValue = message->getFrameLength();
|
||||
changed = true;
|
||||
}
|
||||
if (FrameStart.mValue != message->getFrameStart()) {
|
||||
FrameStart.mValue = message->getFrameStart();
|
||||
changed = true;
|
||||
}
|
||||
if (Remark.mValue != message->getRemark()) {
|
||||
Remark.mValue = message->getRemark();
|
||||
changed = true;
|
||||
}
|
||||
if (mID != message->getID()) {
|
||||
mID = message->getID();
|
||||
changed = true;
|
||||
}
|
||||
if (Name.mValue != message->getName()) {
|
||||
Name.mValue = message->getName();
|
||||
changed = true;
|
||||
}
|
||||
if (SPITTypeID.mValue != message->getSPITTypeID()) {
|
||||
SPITTypeID.mValue = message->getSPITTypeID();
|
||||
changed = true;
|
||||
}
|
||||
if (ServerParams.mValue != message->getServerParams()) {
|
||||
ServerParams.mValue = message->getServerParams();
|
||||
changed = true;
|
||||
}
|
||||
if (ServerRemote.mValue != message->getServerRemote()) {
|
||||
ServerRemote.mValue = message->getServerRemote();
|
||||
changed = true;
|
||||
}
|
||||
if (Track.mValue != message->getTrack()) {
|
||||
Track.mValue = message->getTrack();
|
||||
changed = true;
|
||||
}
|
||||
if (mValueFactor != message->getValueFactor()) {
|
||||
mValueFactor = message->getValueFactor();
|
||||
changed = true;
|
||||
}
|
||||
if (mValueUse != message->getValueUse()) {
|
||||
mValueUse = message->getValueUse();
|
||||
changed = true;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
void SObject::fillMessageOP(Message::ReportObject &message) {
|
||||
message.setActionAssigned(getActionAssigned()); // Action can be assigned to type or to this object
|
||||
message.setConfirmed(mConfirmed);
|
||||
message.setDelay(Delay.mValue);
|
||||
message.setDuration(Duration.mValue);
|
||||
message.setFixed(Fixed.mValue);
|
||||
message.setFrameFadeInLength(FrameFadeInLength.mValue);
|
||||
message.setFrameFadeOutLength(FrameFadeOutLength.mValue);
|
||||
message.setFrameLength(FrameLength.mValue);
|
||||
message.setFrameStart(FrameStart.mValue);
|
||||
message.setID(mID);
|
||||
message.setName(Name.mValue);
|
||||
message.setRemark(Remark.mValue);
|
||||
message.setSPITTypeID(SPITTypeID.mValue);
|
||||
message.setServerParams(ServerParams.mValue);
|
||||
message.setServerRemote(ServerRemote.mValue);
|
||||
message.setTrack(Track.mValue);
|
||||
message.setValueFactor(mValueFactor);
|
||||
message.setValueUse(mValueUse);
|
||||
}
|
||||
|
||||
void SObject::fillMessageOP(Message::RemoveObject &message) {
|
||||
message.setID(mID);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used by the server and client to tell if the other side has registered the changes.
|
||||
* @param p_Confirmed
|
||||
* @return if mConfirmed has changed
|
||||
*/
|
||||
bool SObject::setConfirmed(bool p_Confirmed) {
|
||||
if (mConfirmed == p_Confirmed)
|
||||
return false;
|
||||
mConfirmed = p_Confirmed;
|
||||
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 SObject with the SPITType.
|
||||
* @return true = an action is assigned for the SPITType.
|
||||
*/
|
||||
bool SObject::setActionAssignedType(bool p_ActionAssigned) {
|
||||
if (mActionAssignedType == p_ActionAssigned)
|
||||
return false;
|
||||
bool oldActionAssigend = getActionAssigned();
|
||||
mActionAssignedType = p_ActionAssigned;
|
||||
if (getActionAssigned() == oldActionAssigend)
|
||||
return false;
|
||||
mConfirmed = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SObject::setActionAssigned(bool p_ActionAssigned) {
|
||||
if (mActionAssigned == p_ActionAssigned)
|
||||
return false;
|
||||
bool oldActionAssigend = getActionAssigned();
|
||||
mActionAssigned = p_ActionAssigned;
|
||||
if (getActionAssigned() == oldActionAssigend)
|
||||
return false;
|
||||
mConfirmed = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user