refactor: Heavy refactoring to modern code style

This commit is contained in:
2025-04-03 21:31:08 +02:00
parent 04a8904cbe
commit 9ebbedb04a
32 changed files with 2360 additions and 4112 deletions
-133
View File
@@ -1,133 +0,0 @@
/*
* 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.
*/
/*
* SAD_DetectedServer holds information about SPIT Server detected by ServerAutoDetection (SAD).
* File: SAD_DetectedServer.cpp
* Author: Hagi
*
* Created on 4. Mai 2019, 13:51
*/
#include "SAD_DetectedServer.hpp"
#include "esp_log.h"
static const char *TAG = "SpitSrv";
unordered_map<string, SAD_DetectedServer *> SAD_DetectedServer::s_DetectedServers;
SAD_DetectedServer::~SAD_DetectedServer() {
}
//----- Detected Server -----
SAD_DetectedServer::SAD_DetectedServer() {
m_ID = "";
m_Name = "";
m_ComputerName = "";
m_ClientIP = "";
m_Port = "";
m_Additions = "";
}
void SAD_DetectedServer::setProjectName(string p_ServerProjectName) {
if (m_ServerProjectName.compare(p_ServerProjectName) != 0) {
if (m_New == false) {
m_Changed = true;
}
}
m_ServerProjectName = p_ServerProjectName;
}
void SAD_DetectedServer::cycleStart() {
for (auto i = s_DetectedServers.begin(); i != s_DetectedServers.end(); i++) {
i->second->startCycleSAD();
}
}
void SAD_DetectedServer::cycleEnd(I_SAD_Client &sadClient) {
for (auto &srv : s_DetectedServers) {
SAD_DetectedServer *ptrDetectedServer = srv.second;
if (ptrDetectedServer->getFoundAgain() == false) {
sadClient.eventServerLost(*ptrDetectedServer);
removeDetectedServer(*ptrDetectedServer);
} else if (ptrDetectedServer->getNew()) {
ptrDetectedServer->setNew(false);
sadClient.eventServerDetected(*ptrDetectedServer);
} else if (ptrDetectedServer->getChanged()) {
sadClient.eventServerChanged(*ptrDetectedServer);
}
}
}
/**
* Used by SAD_Client to add a found SPITServer - don't use this manually
* @param p_IsIP4 true = the server is reached via a IP4 address<br>false = the server is reahed via a IP6 address
* @param p_ServerID the id of the server, every instance of a SPITServer has an own id
* @param p_ServerParams the server's parameter
*/
void SAD_DetectedServer::addDetectedServer(string p_ServerID, string p_ServerParams[]) {
SAD_DetectedServer *ptrDetectedServer;
{
auto i = s_DetectedServers.find(p_ServerID);
if (i != s_DetectedServers.end()) {
ptrDetectedServer = i->second;
} else {
ptrDetectedServer = new SAD_DetectedServer();
ptrDetectedServer->setID(p_ServerParams[PARAMINDEX_ID]);
ptrDetectedServer->setNew(true);
}
ptrDetectedServer->setFoundAgain();
// second prefer IP4
ptrDetectedServer->setIP(p_ServerParams[PARAMINDEX_IP]);
ptrDetectedServer->setClientIP(p_ServerParams[PARAMINDEX_CLIENTIP]);
ptrDetectedServer->setName(p_ServerParams[PARAMINDEX_NAME]);
ptrDetectedServer->setComputerName(p_ServerParams[PARAMINDEX_COMPUTERNAME]);
ptrDetectedServer->setPort(p_ServerParams[PARAMINDEX_PORT]);
ptrDetectedServer->setAdditions(p_ServerParams[PARAMINDEX_ADDITIONS]);
ptrDetectedServer->setProjectName(p_ServerParams[PARAMINDEX_SERVERPROJECTNAME]);
s_DetectedServers[ptrDetectedServer->getID()] = ptrDetectedServer;
}
}
/**
* Used by SAD_Client to remove a SPITServer - don't use this manually
* @param p_DetectedServer
*/
void SAD_DetectedServer::removeDetectedServer(SAD_DetectedServer &server) {
auto i = s_DetectedServers.find(server.getID());
if (i != s_DetectedServers.end()) {
SAD_DetectedServer *o_DetectedServer = i->second;
i = s_DetectedServers.erase(i);
delete o_DetectedServer;
}
}
/**
* Used by SAD_Client to clear all found SPITServers - don't use this manually
*/
void SAD_DetectedServer::clearDetectedServers() {
for (auto i = s_DetectedServers.begin(); i != s_DetectedServers.end(); i++) {
SAD_DetectedServer *ptrDetectedServer = i->second;
i = s_DetectedServers.erase(i);
delete ptrDetectedServer;
if (i == s_DetectedServers.end()) {
break;
}
}
}
const SAD_DetectedServer &SAD_DetectedServer::getRefDetectedServer(string p_ServerID) {
SAD_DetectedServer *ptrDetectedServer = nullptr;
auto i = s_DetectedServers.find(p_ServerID);
if (i != s_DetectedServers.end()) {
ptrDetectedServer = i->second;
}
if (ptrDetectedServer != NULL) {
return *ptrDetectedServer;
}
throw new exception();
}
+94 -315
View File
@@ -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.
*/
+22 -57
View File
@@ -13,57 +13,30 @@
*/
#include "SPITPlayer.h"
#include "esp_log.h"
#include <memory>
#include <vector>
unordered_map<string, SPITPlayer *> SPITPlayer::s_SPITPlayers;
using namespace std;
SPITPlayer *SPITPlayer::getSPITPlayer(string p_PlayerID) {
{
auto i = s_SPITPlayers.find(p_PlayerID);
if (i == s_SPITPlayers.end()) {
s_SPITPlayers[p_PlayerID] = new SPITPlayer(p_PlayerID);
}
i = s_SPITPlayers.find(p_PlayerID);
if (i == s_SPITPlayers.end())
return NULL;
return i->second;
}
}
unordered_map<string, unique_ptr<SPITPlayer>> SPITPlayer::s_SPITPlayers;
void SPITPlayer::clearPlayers() {
;
vector<SPITPlayer *> o_SPITPlayers;
for (auto i = s_SPITPlayers.begin(); i != s_SPITPlayers.end(); i++) {
SPITPlayer *ptrSPITPlayer = i->second;
o_SPITPlayers.push_back(ptrSPITPlayer);
SPITPlayer &SPITPlayer::getSPITPlayer(string p_PlayerID) {
auto i = s_SPITPlayers.find(p_PlayerID);
if (i == s_SPITPlayers.end()) {
s_SPITPlayers[p_PlayerID] = make_unique<SPITPlayer>(p_PlayerID);
}
for (auto i = o_SPITPlayers.begin(); i != o_SPITPlayers.end(); i++) {
SPITPlayer *ptrSPITPlayer = *i;
delete ptrSPITPlayer;
}
o_SPITPlayers.clear();
return *s_SPITPlayers.at(p_PlayerID);
}
SPITPlayer::SPITPlayer(string p_PlayerID) {
m_ID = p_PlayerID;
s_SPITPlayers[p_PlayerID] = this;
}
SPITPlayer::~SPITPlayer() {
PlaySPITType *ptrPlaySPITType;
for (auto i = m_PlaySPITTypes.begin(); i != m_PlaySPITTypes.end(); i++) {
ptrPlaySPITType = i->second;
i = m_PlaySPITTypes.erase(i);
delete ptrPlaySPITType;
if (i == m_PlaySPITTypes.end()) {
break;
}
}
m_PlaySPITTypes.clear();
}
unordered_map<string, SPITPlayer::PlaySPITType *> *SPITPlayer::getPlaySPITTypes() {
return &m_PlaySPITTypes;
}
/**
*
* @param p_SPITObjectID
@@ -72,46 +45,38 @@ unordered_map<string, SPITPlayer::PlaySPITType *> *SPITPlayer::getPlaySPITTypes(
*/
SPITPlayer::PlaySPITType *SPITPlayer::addSPITType_Playing(string p_SPITTypeID) {
PlaySPITType *ptrPlaySPITType;
auto i = m_PlaySPITTypes.find(p_SPITTypeID);
if (i == m_PlaySPITTypes.end()) {
ptrPlaySPITType = new PlaySPITType(this, p_SPITTypeID);
ptrPlaySPITType->setIsPlayed(true);
ptrPlaySPITType->setIsNew(true);
m_PlaySPITTypes[p_SPITTypeID] = ptrPlaySPITType;
auto playSpitType = make_unique<PlaySPITType>(this, p_SPITTypeID);
ptrPlaySPITType = playSpitType.get();
m_PlaySPITTypes[p_SPITTypeID] = move(playSpitType);
} else {
ptrPlaySPITType = i->second;
ptrPlaySPITType->setIsPlayed(true);
ptrPlaySPITType = i->second.get();
}
ptrPlaySPITType->setIsPlayed(true);
return ptrPlaySPITType;
}
void SPITPlayer::startPlaySequence() {
PlaySPITType *ptrPlaySPITType;
for (auto i = m_PlaySPITTypes.begin(); i != m_PlaySPITTypes.end(); i++) {
ptrPlaySPITType = i->second;
PlaySPITType *ptrPlaySPITType = i->second.get();
ptrPlaySPITType->startPlaySequence();
}
}
void SPITPlayer::endPlaySequence() {
PlaySPITType *ptrPlaySPITType;
for (auto i = m_PlaySPITTypes.begin(); i != m_PlaySPITTypes.end(); i++) {
ptrPlaySPITType = i->second;
if (ptrPlaySPITType->getIsPlayed() == false) {
for (auto i = m_PlaySPITTypes.begin(); i != m_PlaySPITTypes.end();) {
if (i->second.get()->getIsPlayed() == false) {
i = m_PlaySPITTypes.erase(i);
delete ptrPlaySPITType;
if (i == m_PlaySPITTypes.end()) {
break;
}
} else {
++i;
}
}
}
SPITPlayer::PlaySPITType::PlaySPITType() {
}
SPITPlayer::PlaySPITType::PlaySPITType(SPITPlayer *p_SPITPlayer, string p_SPITTypeID) {
m_IsNew = true;
m_SPITTypeID = p_SPITTypeID;
m_PlayerID = p_SPITPlayer->getID();
m_PlayerName = p_SPITPlayer->getName();
+83 -148
View File
@@ -27,27 +27,25 @@ using namespace std;
* @return
*/
bool SPITSocket::createSocket_UDP() {
bool boolSuccess = true;
int intResult = -1;
int intOptionValue4 = 1;
// ip4
if (m_UDPSocketIP4 != INVALID_SOCKET) {
close(m_UDPSocketIP4);
m_UDPSocketIP4 = INVALID_SOCKET;
}
m_UDPSocketIP4 = socket(AF_INET, SOCK_DGRAM, 0);
int intResult = -1;
bool success = true;
if (m_UDPSocketIP4 == INVALID_SOCKET) {
boolSuccess = false;
success = false;
} else {
int intOptionValue4 = 1;
intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_REUSEADDR, (void *)&intOptionValue4, sizeof(intOptionValue4));
}
if (intResult < 0) {
boolSuccess = false;
success = false;
}
if (boolSuccess == true) {
if (success == true) {
struct timeval tv;
tv.tv_sec = 1; // seconds
tv.tv_usec = 0; // microseconds (0.0 sec)
@@ -64,138 +62,99 @@ bool SPITSocket::createSocket_UDP() {
// intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_RCVBUF, (void*)&intBufferSize, sizeof(intBufferSize));
// intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_SNDBUF, (void*)&intBufferSize, sizeof(intBufferSize));
}
return boolSuccess;
return success;
}
/**
* Binds the socket to the client's ip address and port. The socket option SO_REUSEADDR is set to true.
* @param p_ClientIP ip address of the client
* @param p_ClientPort port of the client.
* @param clientIp ip address of the client
* @param clientPort port of the client.
* if p_Port == "0" any free port will be used
* @return -1 id bind fails, o if bind is ok
*
*/
int SPITSocket::bindSocket(string p_ServerIP, string p_ClientIP, string p_ClientPort) {
addrinfo *clientAI;
struct sockaddr_in *ptrIP4SocketAddress;
struct sockaddr_in o_IP4SocketAddress;
int intSocklen;
int SPITSocket::bindSocket(string clientIp, string clientPort) {
string stringClientPort;
if (p_ClientPort.length() <= 0)
if (clientPort.length() <= 0)
stringClientPort = "0";
else
stringClientPort = p_ClientPort;
// int intResult = SOCKET_ERROR;
int intResult = 0;
if (getaddrinfo(p_ClientIP.data(), p_ClientPort.data(), NULL, &clientAI) != 0) {
stringClientPort = clientPort;
addrinfo *clientAI;
if (getaddrinfo(clientIp.data(), clientPort.data(), nullptr, &clientAI) != 0) {
return -1;
}
switch (clientAI->ai_family) {
case AF_INET:
if (m_UDPSocketIP4 == INVALID_SOCKET) {
break;
}
ptrIP4SocketAddress = reinterpret_cast<sockaddr_in *>(clientAI->ai_addr);
intSocklen = sizeof(*ptrIP4SocketAddress);
// copy the ptrIP4SocketAddress, may be not filled correct by getaddrinfo
memset(&o_IP4SocketAddress, 0, intSocklen);
o_IP4SocketAddress.sin_addr = ptrIP4SocketAddress->sin_addr;
o_IP4SocketAddress.sin_family = ptrIP4SocketAddress->sin_family;
// o_IP4SocketAddress.sin_zero = ptrIP4SocketAddress->sin_zero;
o_IP4SocketAddress.sin_port = ptrIP4SocketAddress->sin_port;
intResult = bind(m_UDPSocketIP4, (const sockaddr *)(ptrIP4SocketAddress), (socklen_t)intSocklen);
if (intResult < 0) {
break;
}
setBoundClientFamily(AF_INET);
if (intResult == 0) {
if (getsockname(m_UDPSocketIP4, (sockaddr *)ptrIP4SocketAddress, (socklen_t *)&intSocklen) != -1) {
setBoundClientPort(to_string((int)ptrIP4SocketAddress->sin_port));
}
}
break;
default:
setBoundClientFamily(0);
intResult = -1;
break;
if (m_UDPSocketIP4 == INVALID_SOCKET) {
return -1;
}
auto *socketAdr = (sockaddr_in *)(clientAI->ai_addr);
int intSocklen = sizeof(*socketAdr);
// copy the socketAdr, may be not filled correct by getaddrinfo
sockaddr_in o_IP4SocketAddress;
memset(&o_IP4SocketAddress, 0, intSocklen);
o_IP4SocketAddress.sin_addr = socketAdr->sin_addr;
o_IP4SocketAddress.sin_family = socketAdr->sin_family;
o_IP4SocketAddress.sin_port = socketAdr->sin_port;
int intResult = bind(m_UDPSocketIP4, (const sockaddr *)(socketAdr), (socklen_t)intSocklen);
if (intResult < 0) {
return intResult;
}
if ((intResult == 0) &&
(getsockname(m_UDPSocketIP4, (sockaddr *)socketAdr, (socklen_t *)&intSocklen) != -1)) {
setBoundClientPort(to_string((int)socketAdr->sin_port));
}
freeaddrinfo(clientAI);
if (intResult == -1) {
setIsBound(false);
} else {
setIsBound(true);
}
setIsBound(intResult != -1);
return intResult;
}
/**
* Set whether the sockat are brodcast sockets or not. Set the sockopt SO_BROADCAST to 0 or 1
* Set whether the socket are broadcast sockets or not. Set the sockopt SO_BROADCAST to 0 or 1
* @param p_Broadcast true SO_BROADCAST is set
* false = SO_BROADCAST is not set
* @return 0 = ok, -1 = error
*/
int SPITSocket::setBroadcast(bool p_Broadcast) {
int intResult;
int intOptionValue = 1;
u_char charOptionValue = 0x01;
// IP4
if (p_Broadcast) {
intOptionValue = 1;
} else {
intOptionValue = 0;
}
intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_BROADCAST, &intOptionValue, sizeof(int));
// intResult = setsockopt(m_UDPSocketIP4, IPPROTO_IP, IP_MULTICAST_LOOP, (void*)&charOptionValue, sizeof(charOptionValue));
int SPITSocket::setBroadcast(bool broadcast) const {
int intOptionValue = broadcast ? 1 : 0;
int intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_BROADCAST, &intOptionValue, sizeof(int));
return intResult;
}
/**
*
* @param p_InetFamily AF_INET or AF_INET6
* @param p_ServerIP the ip address of the server
* @param p_ServerPort the port of the server
* @param p_MessageBytes buffer containing the message
* @param p_MessageLength the length of the message
* @param ip the ip address of the server
* @param port the port of the server
* @param msg buffer containing the message
* @param msgLength the length of the message
* @return -1 send fails
* 0 send is done
*/
int SPITSocket::sendMessageTo(int p_InetFamily, string p_ServerIP, string p_ServerPort, const char *p_MessageBytes, int p_MessageLength) {
if (m_UDPSocketIP4 == INVALID_SOCKET)
int SPITSocket::sendMessageTo(const string &ip, const string &port, const char *message, int msgLength) {
if (m_UDPSocketIP4 == INVALID_SOCKET) {
return -1;
struct addrinfo *ptrAddressInfo;
struct sockaddr_in *ptrIP4SocketAddress;
struct sockaddr_in o_IP4SocketAddress;
int intSocklen;
int intResult = -1;
}
// prepare AddressInfo
if (getaddrinfo(p_ServerIP.data(), p_ServerPort.data(), NULL, &ptrAddressInfo) != 0) {
return -1;
}
switch (ptrAddressInfo->ai_family) {
case AF_INET:
ptrIP4SocketAddress = reinterpret_cast<sockaddr_in *>(ptrAddressInfo->ai_addr);
intSocklen = sizeof(*ptrIP4SocketAddress);
if (m_UDPSocketIP4 != INVALID_SOCKET) {
// copy the ptrIP4SocketAddress, may be not filled correct by getaddrinfo
memset(&o_IP4SocketAddress, 0, intSocklen);
o_IP4SocketAddress.sin_addr = ptrIP4SocketAddress->sin_addr;
o_IP4SocketAddress.sin_family = ptrIP4SocketAddress->sin_family;
o_IP4SocketAddress.sin_port = ptrIP4SocketAddress->sin_port;
intResult = sendto(m_UDPSocketIP4, p_MessageBytes, p_MessageLength, 0, (const sockaddr *)&o_IP4SocketAddress, (socklen_t)intSocklen);
if (intResult < 0) {
printf("UnixSocket::sendMessageTo IP4 sendto %s FAILED %s\n", p_ServerIP.data(), strerror(errno));
printf("UnixSocket::sendMessageTo ret=%d %s / %s / %d\n", intResult,
p_ServerPort.data(), p_MessageBytes, p_MessageLength);
}
freeaddrinfo(ptrAddressInfo);
}
break;
default:
intResult = -1;
int intResult = -1;
addrinfo *ptrAddressInfo;
if (getaddrinfo(ip.data(), port.data(), nullptr, &ptrAddressInfo) != 0) {
return intResult;
}
auto *ptrIP4SocketAddress = (sockaddr_in *)(ptrAddressInfo->ai_addr);
int intSocklen = sizeof(*ptrIP4SocketAddress);
if (m_UDPSocketIP4 != INVALID_SOCKET) {
// copy the ptrIP4SocketAddress, may be not filled correct by getaddrinfo
sockaddr_in o_IP4SocketAddress;
memset(&o_IP4SocketAddress, 0, intSocklen);
o_IP4SocketAddress.sin_addr = ptrIP4SocketAddress->sin_addr;
o_IP4SocketAddress.sin_family = ptrIP4SocketAddress->sin_family;
o_IP4SocketAddress.sin_port = ptrIP4SocketAddress->sin_port;
intResult = sendto(m_UDPSocketIP4, message, msgLength, 0, (const sockaddr *)&o_IP4SocketAddress, (socklen_t)intSocklen);
if (intResult < 0) {
ESP_LOGE("SPIT", "sendMessageTo IP4 sendto %s FAILED %s\n", ip.data(), strerror(errno));
ESP_LOGE("SPIT", "sendMessageTo ret=%d %s / %s / %d\n", intResult, port.data(), message, msgLength);
}
freeaddrinfo(ptrAddressInfo);
}
if (intResult < 0) {
return -1;
}
@@ -204,52 +163,39 @@ int SPITSocket::sendMessageTo(int p_InetFamily, string p_ServerIP, string p_Serv
/**
* Call this for receiving a message
* This will block until a message is received or the underlying socket is closed
* @param p_InetFamily either AF_INET or AF_INET6<br>
* The SPITSocket creates two udp sockets, one for IP4 and one for IP6
* This parameter decides from which socket should a message recieved
* @param p_Buffer the buffer containing the received message later.
* @param p_BufferLength the size of the buffer
* @param p_ServerIP a pointer to a string, when a messages is received the string will contain the ip address of the sender/server
* if p_ServerIP is NULL - no detection of the server will be done.
* @return
*/
int SPITSocket::receiveMessage(int p_InetFamily, char *p_Buffer, int p_BufferLength, string *p_ServerIP) {
int SPITSocket::receiveMessage(char *p_Buffer, int p_BufferLength, string *serverIp) const {
int intResult = -1;
// ADDRINFO *AI;
struct sockaddr_in o_IP4SocketAddress;
int intSocklen;
switch (p_InetFamily) {
case AF_INET:
if (m_UDPSocketIP4 == INVALID_SOCKET) {
break;
}
intSocklen = sizeof(o_IP4SocketAddress);
memset(&o_IP4SocketAddress, 0, intSocklen);
intResult = recvfrom(m_UDPSocketIP4, (void *)p_Buffer, p_BufferLength, 0, (sockaddr *)&o_IP4SocketAddress, (socklen_t *)&intSocklen);
if (intResult >= 0) {
if (p_ServerIP != NULL) {
char bufferIP4[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &(o_IP4SocketAddress.sin_addr), bufferIP4, intSocklen);
*p_ServerIP = bufferIP4;
}
}
break;
if (m_UDPSocketIP4 == INVALID_SOCKET) {
return intResult;
}
sockaddr_in o_IP4SocketAddress;
int intSocklen = sizeof(o_IP4SocketAddress);
memset(&o_IP4SocketAddress, 0, intSocklen);
intResult = recvfrom(m_UDPSocketIP4, (void *)p_Buffer, p_BufferLength, 0, (sockaddr *)&o_IP4SocketAddress, (socklen_t *)&intSocklen);
if (intResult >= 0 && serverIp != nullptr) {
char bufferIP4[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &(o_IP4SocketAddress.sin_addr), bufferIP4, intSocklen);
*serverIp = bufferIP4;
}
return intResult;
}
SPITSocket::IPAddress SPITSocket::getAdaptersInfo() {
// iterate over active interfaces, and print out IPs
esp_netif_t *netif = NULL;
while ((netif = esp_netif_next_unsafe(netif)) != NULL) {
esp_netif_t *netif = nullptr;
if ((netif = esp_netif_next_unsafe(netif)) != nullptr) {
ESP_LOGI("SPIT", "Connected to %s", esp_netif_get_desc(netif));
esp_netif_ip_info_t ip;
ESP_ERROR_CHECK(esp_netif_get_ip_info(netif, &ip));
ESP_LOGI("SPIT", "- IPv4 address: " IPSTR ",", IP2STR(&ip.ip));
ESP_LOGI("SPIT", "- IPv4 netmask: " IPSTR ",", IP2STR(&ip.netmask));
char buffer[64];
sprintf(buffer, IPSTR, IP2STR(&ip.ip));
string stringIP4 = buffer;
sprintf(buffer, IPSTR, IP2STR(&ip.netmask));
@@ -260,29 +206,18 @@ SPITSocket::IPAddress SPITSocket::getAdaptersInfo() {
}
string createGUID() {
// uuid_t id;
// uuid_generate(id);
// char *guid_string = new char[100];
// uuid_unparse(id, guid_string);
// string stringGUID = guid_string;
// return stringGUID;
uuid_t uu;
char uu_str[UUID_STR_LEN];
uuid_generate(uu);
char uu_str[UUID_STR_LEN];
uuid_unparse(uu, uu_str);
string stringGUID = uu_str;
return stringGUID;
return {uu_str};
}
/** The name of the client's host computer*/
string getClientHostName() {
string stringHostName = "";
const char *hostname;
esp_netif_get_hostname(esp_netif_get_default_netif(), &hostname);
if (hostname != nullptr) {
stringHostName = hostname;
return {hostname};
}
return stringHostName;
;
return "";
}
+85 -306
View File
@@ -17,280 +17,51 @@
static const char *TAG = "SPIT";
unordered_map<string, SPITType *> SPITType::s_SPITTypes;
unordered_map<string, SPITType *> SPITType::s_SPITTypesRemote;
SPITType *SPITType::getSPITType(string p_ID) {
{
auto i = s_SPITTypes.find(p_ID);
if (i == s_SPITTypes.end()) {
return NULL;
}
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
*/
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);
}
}
SPITType *SPITType::getSPITTypeRemote(string p_ID) {
{
auto i = s_SPITTypesRemote.find(p_ID);
if (i == s_SPITTypesRemote.end()) {
return NULL;
}
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
*/
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);
}
}
bool SPITType::addSPITType(SPITType *p_ptrSpitType) {
if (p_ptrSpitType == NULL)
return false;
{
s_SPITTypes[p_ptrSpitType->getID()] = p_ptrSpitType;
return true;
}
}
bool SPITType::addSPITTypeRemote(SPITType *p_ptrSpitType) {
if (p_ptrSpitType == NULL)
return false;
{
s_SPITTypesRemote[p_ptrSpitType->getID()] = p_ptrSpitType;
return true;
}
}
bool SPITType::removeSPITType(SPITType *p_ptrSpitType) {
if (p_ptrSpitType == NULL)
return false;
{
auto i = s_SPITTypes.find(p_ptrSpitType->getID());
if (i == s_SPITTypes.end()) {
return false;
}
i = s_SPITTypes.erase(i);
return true;
}
}
bool SPITType::removeSPITTypeRemote(SPITType *p_ptrSpitType) {
if (p_ptrSpitType == NULL)
return false;
{
auto i = s_SPITTypesRemote.find(p_ptrSpitType->getID());
if (i == s_SPITTypesRemote.end()) {
return false;
}
i = s_SPITTypesRemote.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;
}
}
/**
* Returns a reference to the SPITType 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 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";
}
}
}
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;
}
}
/**
* Returns a reference to the remote SPITType 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 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";
}
}
}
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;
}
}
}
}
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;
}
}
}
}
void SPITType::eventProjectClosed() {
SPITType *ptrSPITType;
for (auto i = s_SPITTypes.begin(); i != s_SPITTypes.end(); i++) {
ptrSPITType = i->second;
void SPITType::eventProjectClosed(SpitRepo<SPITType> &repo, SpitRepo<SPITType> &remoteRepo) {
auto &entries = repo.getRepo();
for (auto i = entries.begin(); i != entries.end();) {
SPITType *ptrSPITType = i->second.get();
if (ptrSPITType->getCreatedByClient() == true) {
i++;
continue;
}
i = s_SPITTypes.erase(i);
delete ptrSPITType;
if (i == s_SPITTypes.end()) {
break;
}
i = entries.erase(i);
}
// Remote
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;
}
}
remoteRepo.clearEntries();
}
/**
* 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);
}
void SPITType::setConfirmedFalse(SpitRepo<SPITType> &repo) {
auto &entries = repo.getRepo();
for (auto i = entries.begin(); i != entries.end(); i++) {
i->second->setConfirmed(false);
}
}
SPITType::SPITType() {
initMembers();
SPITType::SPITType(string p_ID) {
m_ID = p_ID;
}
/*
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_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 +74,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 +125,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 +141,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 +154,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);
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff