Compare commits
2 Commits
331258692b
...
tooFar
| Author | SHA1 | Date | |
|---|---|---|---|
| 6fa1d9639a | |||
| 7edc57784c |
@@ -11,7 +11,6 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include "syslog.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -80,11 +79,6 @@ class SClient : ISadClient {
|
||||
string mServerComputerName{};
|
||||
int mServerStepTime{-1};
|
||||
|
||||
//--- Server Project ---
|
||||
string mServerProjectID;
|
||||
string mServerProjectName;
|
||||
int mServerFramesPerSecond;
|
||||
|
||||
public:
|
||||
/** The ID of the client.<br>Every client instance should set an unique id*/
|
||||
string getID() { return mID; }
|
||||
@@ -129,7 +123,7 @@ class SClient : ISadClient {
|
||||
// Reconnect to the server when connection is lost see eventConnectionStatus and eventServerDetected
|
||||
bool _doReconnect{}; // true = on eventServerDetected connect to the server identified by mServerID
|
||||
public:
|
||||
int sendSPITMessage(Message::OPPart & spitMessageOPPart);
|
||||
int sendMessage(Message::OPPart & spitMessageOPPart);
|
||||
|
||||
//--------------- ServerAutoDetection SAD ---------------
|
||||
public:
|
||||
@@ -179,11 +173,7 @@ class SClient : ISadClient {
|
||||
/** Used internally. When the connection to the SPITServer is lost an eventConnectionStatus will occur*/
|
||||
void eventWatchdogLost();
|
||||
//--------------- SPIT Project ---------------
|
||||
private:
|
||||
void parseReportProject(Message::ReportProject &message);
|
||||
void parseCloseProject(Message::CloseProject &message);
|
||||
|
||||
public:
|
||||
/** Returns the SPITServer's project ID - may be the same as the project's name*/
|
||||
string getServerProjectID();
|
||||
/** Returns the SPITServer's project name*/
|
||||
@@ -191,11 +181,6 @@ class SClient : ISadClient {
|
||||
/** Returns frame rate per second. This is the time resolution in which the server transmits time data. The unit of time data is always frames.*/
|
||||
int getServerFramesPerSecond();
|
||||
|
||||
private:
|
||||
void parseRequestProjectTransfer(Message::RequestProjectTransfer &message);
|
||||
void parseStartProjectTransfer(Message::StartProjectTransfer &message);
|
||||
void parseEndProjectTransfer(Message::EndProjectTransfer &message);
|
||||
|
||||
public:
|
||||
static void sendProject(SClient *p_PtrSClient);
|
||||
|
||||
@@ -231,31 +216,16 @@ class SClient : ISadClient {
|
||||
private:
|
||||
// receive SPIT-Types
|
||||
void parseReportType(Message::ReportType &message);
|
||||
void parseRemoveSPITType(Message::RemoveType &message);
|
||||
int sendSPITTypeInternal(SType &spitType);
|
||||
int sendTypeInternal(SType &spitType);
|
||||
|
||||
public:
|
||||
/**
|
||||
* If a client wants to change a SPITType, he should send it to the server.<br>
|
||||
* If the SPITTye is a fixed one and not created by the client himself, then an eventSPITType can be sent from the server, which cancels the change.<br>
|
||||
* @param spitypeID the id of the SPITType to remove.
|
||||
* @return 0 = is sended, -1 = is not sended
|
||||
*/
|
||||
bool changeSPITType(SType *spitType);
|
||||
/**
|
||||
* If a client wants to remove a SPITType, he should send it to the server.<br>
|
||||
* If the SPITTye is a fixed one and not created by the client himself, then an eventSPITType can be sent from the server, which cancels the deletion.<br>
|
||||
* @param spitypeID the id of the SPITType to remove.
|
||||
* @return 0 = is sended, -1 = is not sended
|
||||
*/
|
||||
int removeSPITType(string spitypeID);
|
||||
bool changeType(SType *spitType) { return mProcessor.changeType(spitType); }
|
||||
int removeType(string spitypeID) { return mProcessor.removeType(spitypeID); }
|
||||
|
||||
public:
|
||||
//--------------- SPIT Objects ---------------
|
||||
private:
|
||||
void parseReportSPITObject(Message::ReportObject &message);
|
||||
void parseRemoveSPITObject(Message::RemoveObject &message);
|
||||
int sendSPITObjectInternal(SObject *ptrObject);
|
||||
int sendObjectInternal(SObject *sObject);
|
||||
|
||||
public:
|
||||
/**
|
||||
@@ -265,21 +235,6 @@ class SClient : ISadClient {
|
||||
* @return 0 = sended, -1 = not sended
|
||||
*/
|
||||
bool changeSPITObject(SObject *spitObject);
|
||||
/**
|
||||
* When the client removes a SPITObject (normally the client should not do this), then he should send it to the SPITServer.<br>
|
||||
* The SPITServer may discard the deletion and an eventSPITObject occurs.<br>
|
||||
* @param objectID the id of the SPITObject to remove.
|
||||
* @return 0 = sended, -1 = not sended
|
||||
*/
|
||||
int removeSPITObject(string objectID);
|
||||
|
||||
public:
|
||||
//--------------- Play SPIT Objects ---------------
|
||||
private:
|
||||
void parsePlaySPITStart(Message::PlayStart &message);
|
||||
void parsePlaySPITObject(Message::PlayObject &message);
|
||||
void parsePlaySPITEnd(Message::PlayEnd &message);
|
||||
void parseReportPlayStatus(Message::ReportPlayStatus &message);
|
||||
|
||||
public:
|
||||
//--------- Remote ----------
|
||||
@@ -295,9 +250,6 @@ class SClient : ISadClient {
|
||||
void answerWatchdog() {
|
||||
sAnswered = true;
|
||||
}
|
||||
|
||||
SpitRepo<SObject> mSpitObjects;
|
||||
SpitRepo<SObject> mRemoteSpitObjects;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -57,7 +57,10 @@ class SProcessor {
|
||||
};
|
||||
|
||||
struct InternalCallbacks {
|
||||
function<int(SType &sType)> sendSpitTypeInternal;
|
||||
function<void(int ms)> delay;
|
||||
function<int(Message::OPPart &msg)> sendMessage;
|
||||
function<int(SType &sType)> sendTypeInternal;
|
||||
function<int(SObject *sObject)> sendObjectInternal;
|
||||
};
|
||||
|
||||
// //------ PlayerType ------
|
||||
@@ -99,20 +102,20 @@ class SProcessor {
|
||||
|
||||
// string mClientProjectName;
|
||||
|
||||
// uint8_t mMessageNumberSend{1};
|
||||
// int mMessageNumberReceived{-1}; // set to -1 because the first received message will set the number (1..255)
|
||||
// vector<unique_ptr<Message>> mOvertakingMessages;
|
||||
uint8_t mMessageNumberSend{1};
|
||||
int mMessageNumberReceived{-1}; // set to -1 because the first received message will set the number (1..255)
|
||||
vector<unique_ptr<Message>> mOvertakingMessages;
|
||||
|
||||
// // Server's info filled by parseConnectAnswer
|
||||
// string mServerID{};
|
||||
string mServerID{};
|
||||
// string mServerName{};
|
||||
// string mServerComputerName{};
|
||||
// int mServerStepTime{-1};
|
||||
|
||||
// //--- Server Project ---
|
||||
// string mServerProjectID;
|
||||
// string mServerProjectName;
|
||||
// int mServerFramesPerSecond;
|
||||
string mServerProjectID;
|
||||
string mServerProjectName;
|
||||
int mServerFramesPerSecond;
|
||||
|
||||
// public:
|
||||
// /** The ID of the client.<br>Every client instance should set an unique id*/
|
||||
@@ -153,9 +156,9 @@ class SProcessor {
|
||||
// private:
|
||||
// // Reconnect to the server when connection is lost see eventConnectionStatus and eventServerDetected
|
||||
// bool _doReconnect{}; // true = on eventServerDetected connect to the server identified by mServerID
|
||||
// public:
|
||||
// std::vector<char> createMessage(Message::OPPart & spitMessageOPPart);
|
||||
// void checkParseMessageData(vector<char> data);
|
||||
public:
|
||||
std::vector<char> createMessage(Message::OPPart & spitMessageOPPart);
|
||||
void checkParseMessageData(vector<char> data);
|
||||
|
||||
// //--------------- ServerAutoDetection SAD ---------------
|
||||
// public:
|
||||
@@ -191,7 +194,7 @@ class SProcessor {
|
||||
// private:
|
||||
// void disconnectInternal(Connection cause);
|
||||
// void resetMessageNumberReceived();
|
||||
// void parseMessage(Message& message);
|
||||
void parseMessage(Message& message);
|
||||
// void addOvertakingMessage(unique_ptr<Message> message);
|
||||
// void parseConnectAnswer(Message::ConnectAnswer &message);
|
||||
// void parseDisconnect(Message::Disconnect &message);
|
||||
@@ -205,24 +208,23 @@ class SProcessor {
|
||||
// void eventWatchdogLost();
|
||||
// //--------------- SPIT Project ---------------
|
||||
// private:
|
||||
// void parseReportProject(Message::ReportProject &message);
|
||||
// void parseCloseProject(Message::CloseProject &message);
|
||||
public: // tood remove
|
||||
void parseReportProject(Message::ReportProject &message);
|
||||
void parseCloseProject(Message::CloseProject &message);
|
||||
|
||||
// public:
|
||||
// /** Returns the SPITServer's project ID - may be the same as the project's name*/
|
||||
// string getServerProjectID();
|
||||
// /** Returns the SPITServer's project name*/
|
||||
// string getServerProjectName();
|
||||
// /** Returns frame rate per second. This is the time resolution in which the server transmits time data. The unit of time data is always frames.*/
|
||||
// int getServerFramesPerSecond();
|
||||
public:
|
||||
/** Returns the SPITServer's project ID - may be the same as the project's name*/
|
||||
string getServerProjectID();
|
||||
/** Returns the SPITServer's project name*/
|
||||
string getServerProjectName();
|
||||
/** Returns frame rate per second. This is the time resolution in which the server transmits time data. The unit of time data is always frames.*/
|
||||
int getServerFramesPerSecond();
|
||||
|
||||
// private:
|
||||
// void parseRequestProjectTransfer(Message::RequestProjectTransfer &message);
|
||||
// void parseStartProjectTransfer(Message::StartProjectTransfer &message);
|
||||
// void parseEndProjectTransfer(Message::EndProjectTransfer &message);
|
||||
|
||||
// public:
|
||||
// // static void sendProject(SClient *p_PtrSProcessor);
|
||||
public: // todo remove
|
||||
void parseRequestProjectTransfer(Message::RequestProjectTransfer &message);
|
||||
void parseStartProjectTransfer(Message::StartProjectTransfer &message);
|
||||
void parseEndProjectTransfer(Message::EndProjectTransfer &message);
|
||||
|
||||
// // --------------- SPIT Types ---------------
|
||||
// public:
|
||||
@@ -255,55 +257,43 @@ class SProcessor {
|
||||
private:
|
||||
public: // @todo delete
|
||||
void parseReportType(Message::ReportType &message);
|
||||
// void parseRemoveSPITType(Message::RemoveType &message);
|
||||
// int sendSPITTypeInternal(SType &sType);
|
||||
void parseRemoveType(Message::RemoveType &message);
|
||||
|
||||
// public:
|
||||
// /**
|
||||
// * If a client wants to change a SPITType, he should send it to the server.<br>
|
||||
// * If the SPITTye is a fixed one and not created by the client himself, then an eventSPITType can be sent from the server, which cancels the change.<br>
|
||||
// * @param spitypeID the id of the SPITType to remove.
|
||||
// * @return 0 = is sended, -1 = is not sended
|
||||
// */
|
||||
// bool changeSPITType(SType *spitType);
|
||||
// /**
|
||||
// * If a client wants to remove a SPITType, he should send it to the server.<br>
|
||||
// * If the SPITTye is a fixed one and not created by the client himself, then an eventSPITType can be sent from the server, which cancels the deletion.<br>
|
||||
// * @param spitypeID the id of the SPITType to remove.
|
||||
// * @return 0 = is sended, -1 = is not sended
|
||||
// */
|
||||
// int removeSPITType(string spitypeID);
|
||||
public:
|
||||
/**
|
||||
* If a client wants to change a SPITType, he should send it to the server.<br>
|
||||
* If the SPITTye is a fixed one and not created by the client himself, then an eventSPITType can be sent from the server, which cancels the change.<br>
|
||||
* @param spitypeID the id of the SPITType to remove.
|
||||
* @return 0 = is sended, -1 = is not sended
|
||||
*/
|
||||
bool changeType(SType *spitType);
|
||||
/**
|
||||
* If a client wants to remove a SPITType, he should send it to the server.<br>
|
||||
* If the SPITTye is a fixed one and not created by the client himself, then an eventSPITType can be sent from the server, which cancels the deletion.<br>
|
||||
* @param spitypeID the id of the SPITType to remove.
|
||||
* @return 0 = is sended, -1 = is not sended
|
||||
*/
|
||||
int removeType(string spitypeID);
|
||||
|
||||
// public:
|
||||
// //--------------- SPIT Objects ---------------
|
||||
// private:
|
||||
// void parseReportSPITObject(Message::ReportObject &message);
|
||||
// void parseRemoveSPITObject(Message::RemoveObject &message);
|
||||
public:
|
||||
void parseReportObject(Message::ReportObject &message);
|
||||
void parseRemoveObject(Message::RemoveObject &message);
|
||||
// int sendSPITObjectInternal(SObject *ptrObject);
|
||||
|
||||
// public:
|
||||
// /**
|
||||
// * When the client changes a SPITObject (normally the client should not do this), then it should send the changes to the SPITServer.<br>
|
||||
// * The SPITServer may discard the changes and an eventSPITObject occurs.<br>
|
||||
// * @param spitObject the pointer to the changed SPITObject.
|
||||
// * @return 0 = sended, -1 = not sended
|
||||
// */
|
||||
// bool changeSPITObject(SObject *spitObject);
|
||||
// /**
|
||||
// * When the client removes a SPITObject (normally the client should not do this), then he should send it to the SPITServer.<br>
|
||||
// * The SPITServer may discard the deletion and an eventSPITObject occurs.<br>
|
||||
// * @param objectID the id of the SPITObject to remove.
|
||||
// * @return 0 = sended, -1 = not sended
|
||||
// */
|
||||
// int removeSPITObject(string objectID);
|
||||
int removeObject(string objectID);
|
||||
|
||||
// public:
|
||||
// //--------------- Play SPIT Objects ---------------
|
||||
// private:
|
||||
// void parsePlaySPITStart(Message::PlayStart &message);
|
||||
// void parsePlaySPITObject(Message::PlayObject &message);
|
||||
// void parsePlaySPITEnd(Message::PlayEnd &message);
|
||||
// void parseReportPlayStatus(Message::ReportPlayStatus &message);
|
||||
public:
|
||||
void parsePlayStart(Message::PlayStart &message);
|
||||
void parsePlayObject(Message::PlayObject &message);
|
||||
void parsePlayEnd(Message::PlayEnd &message);
|
||||
void parseReportPlayStatus(Message::ReportPlayStatus &message);
|
||||
|
||||
// public:
|
||||
// //--------- Remote ----------
|
||||
@@ -316,9 +306,9 @@ public: // @todo delete
|
||||
// sAnswered = true;
|
||||
// }
|
||||
|
||||
// SpitRepo<SObject> mSpitObjects;
|
||||
// SpitRepo<SObject> mRemoteSpitObjects;
|
||||
public: // @todo remove
|
||||
public: // @todo remove
|
||||
SpitRepo<SObject> mSpitObjects;
|
||||
SpitRepo<SObject> mRemoteSpitObjects;
|
||||
SpitRepo<SType> mSpitTypes;
|
||||
SpitRepo<SType> mRemoteSpitTypes;
|
||||
};
|
||||
|
||||
@@ -20,7 +20,10 @@ SClient::SClient(string name, string projName, ISocket &socket, Callbacks calls)
|
||||
mProjName(projName),
|
||||
mProcessor(name, projName, getClientHostName(), createGUID(), calls,
|
||||
{
|
||||
.sendSpitTypeInternal = [&](SType &sType) { return sendSPITTypeInternal(sType);}
|
||||
.delay = [&](int ms){ return fos::Task::delayMs(ms); },
|
||||
.sendMessage = [&](Message::OPPart &msg){ return sendMessage(msg); },
|
||||
.sendTypeInternal = [&](SType &sType) { return sendTypeInternal(sType);},
|
||||
.sendObjectInternal = [&](SObject *sObject) { return sendObjectInternal(sObject);}
|
||||
}
|
||||
),
|
||||
mSocket(socket) {
|
||||
@@ -37,7 +40,7 @@ void SClient::clientProjectClose() {
|
||||
if (mConnectionStatus == Connection::Ok) {
|
||||
ESP_LOGI(TAG, " ... tidy up ressources");
|
||||
Message::CloseProject closeSPITProject(mProjName);
|
||||
if (sendSPITMessage(closeSPITProject) < 0) {
|
||||
if (sendMessage(closeSPITProject) < 0) {
|
||||
ESP_LOGD(TAG, "Client could not send Client's ReportProject");
|
||||
}
|
||||
}
|
||||
@@ -46,19 +49,19 @@ void SClient::clientProjectClose() {
|
||||
void SClient::clientProjectLoaded() {
|
||||
// set confirmed = false for all SPITTypes and SPITObjects
|
||||
SType::setConfirmedFalse(mProcessor.mSpitTypes);
|
||||
SObject::setConfirmedFalse(mSpitObjects);
|
||||
SObject::setConfirmedFalse(mProcessor.mSpitObjects);
|
||||
|
||||
if (mConnectionStatus == Connection::Ok) {
|
||||
// send ReportProject to the server
|
||||
Message::ReportProject reportSPITProject(mProjName, mProjName);
|
||||
reportSPITProject.setFramesPerSecond(0);
|
||||
if (sendSPITMessage(reportSPITProject) < 0) {
|
||||
if (sendMessage(reportSPITProject) < 0) {
|
||||
ESP_LOGD(TAG, "SPIT_CLient::clientProjectLoaded could not send Client's ReportProject");
|
||||
}
|
||||
|
||||
// send RequestProjectTransfer
|
||||
Message::RequestProjectTransfer sMRequestProjectTransfer;
|
||||
if (sendSPITMessage(sMRequestProjectTransfer) < 0) {
|
||||
if (sendMessage(sMRequestProjectTransfer) < 0) {
|
||||
ESP_LOGD(TAG, "SPIT_CLient::clientProjectLoaded could not send RequestProjectTransfer");
|
||||
}
|
||||
}
|
||||
@@ -77,11 +80,11 @@ void SClient::setActionSPITType(string typeId, bool actionAssigned) {
|
||||
if (spitType == nullptr)
|
||||
return;
|
||||
if (spitType->ActionAssigned.set(actionAssigned)) {
|
||||
sendSPITTypeInternal(*spitType);
|
||||
for (auto& [key, value] : mSpitObjects.getRepo()) {
|
||||
sendTypeInternal(*spitType);
|
||||
for (auto& [key, value] : mProcessor.mSpitObjects.getRepo()) {
|
||||
if (value->SPITTypeID.get() == spitType->getID()) {
|
||||
if (value->setActionAssignedType(actionAssigned) == true) {
|
||||
sendSPITObjectInternal(value.get());
|
||||
sendObjectInternal(value.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,11 +93,11 @@ void SClient::setActionSPITType(string typeId, bool actionAssigned) {
|
||||
|
||||
/** This should be called if the user wants to associate/remove an action with a SPITObject. */
|
||||
void SClient::setActionSPITObject(string spitObjId, bool actionAssigned) {
|
||||
SObject *spitObject = mSpitObjects.getEntry(spitObjId);
|
||||
SObject *spitObject = mProcessor.mSpitObjects.getEntry(spitObjId);
|
||||
if (spitObject == nullptr)
|
||||
return;
|
||||
if (spitObject->setActionAssigned(actionAssigned) == true) {
|
||||
sendSPITObjectInternal(spitObject);
|
||||
sendObjectInternal(spitObject);
|
||||
}
|
||||
}
|
||||
//---------- ServerAutoDetection SAD -----------
|
||||
@@ -205,7 +208,7 @@ void SClient::eventServerChanged(SadDetectedServer &server) {
|
||||
// // } //Excample
|
||||
// }
|
||||
|
||||
int SClient::sendSPITMessage(Message::OPPart &opPart) {
|
||||
int SClient::sendMessage(Message::OPPart &opPart) {
|
||||
if (mMessageNumberSend == 255)
|
||||
mMessageNumberSend = 1;
|
||||
else
|
||||
@@ -281,14 +284,14 @@ void SClient::checkParseMessage(unique_ptr<Message> p_SPITMessage) {
|
||||
return;
|
||||
}
|
||||
|
||||
int intActualMessageNumber = (int)(p_SPITMessage->getHeader()->getMessageNumber() & 0xFF);
|
||||
int msgNum = (int)(p_SPITMessage->getHeader()->getMessageNumber() & 0xFF);
|
||||
|
||||
if (intActualMessageNumber == 0) {
|
||||
if (msgNum == 0) {
|
||||
parseMessage(std::move(p_SPITMessage));
|
||||
return;
|
||||
}
|
||||
if (mMessageNumberReceived < 0) {
|
||||
mMessageNumberReceived = intActualMessageNumber;
|
||||
mMessageNumberReceived = msgNum;
|
||||
parseMessage(std::move(p_SPITMessage));
|
||||
return;
|
||||
}
|
||||
@@ -297,8 +300,8 @@ void SClient::checkParseMessage(unique_ptr<Message> p_SPITMessage) {
|
||||
if (intNextMessageNumber > 255 || intNextMessageNumber < 1)
|
||||
intNextMessageNumber = 1;
|
||||
|
||||
if (intActualMessageNumber == intNextMessageNumber) {
|
||||
mMessageNumberReceived = intActualMessageNumber;
|
||||
if (msgNum == intNextMessageNumber) {
|
||||
mMessageNumberReceived = msgNum;
|
||||
parseMessage(std::move(p_SPITMessage));
|
||||
|
||||
// check overtaking messages
|
||||
@@ -310,10 +313,10 @@ void SClient::checkParseMessage(unique_ptr<Message> p_SPITMessage) {
|
||||
intNextMessageNumber = 1;
|
||||
|
||||
auto &ptrOvertakingSPIT_Message = *it;
|
||||
intActualMessageNumber = (int)(ptrOvertakingSPIT_Message->getHeader()->getMessageNumber() & 0xFF);
|
||||
msgNum = (int)(ptrOvertakingSPIT_Message->getHeader()->getMessageNumber() & 0xFF);
|
||||
|
||||
if (intActualMessageNumber == intNextMessageNumber) {
|
||||
mMessageNumberReceived = intActualMessageNumber;
|
||||
if (msgNum == intNextMessageNumber) {
|
||||
mMessageNumberReceived = msgNum;
|
||||
parseMessage(move(ptrOvertakingSPIT_Message));
|
||||
mOvertakingMessages.erase(it);
|
||||
|
||||
@@ -365,7 +368,7 @@ void SClient::parseMessage(unique_ptr<Message> message) {
|
||||
parseDisconnect(message->getAs<Message::Disconnect>());
|
||||
break;
|
||||
case Message::ReportProject::OPFLAG:
|
||||
parseReportProject(message->getAs<Message::ReportProject>());
|
||||
mProcessor.parseReportProject(message->getAs<Message::ReportProject>());
|
||||
break;
|
||||
case Message::Watchdog::OPFLAG:
|
||||
parseWatchdog(message->getAs<Message::Watchdog>());
|
||||
@@ -375,43 +378,43 @@ void SClient::parseMessage(unique_ptr<Message> message) {
|
||||
break;
|
||||
//----- SPIT Project -----
|
||||
case Message::StartProjectTransfer::OPFLAG:
|
||||
parseStartProjectTransfer(message->getAs<Message::StartProjectTransfer>());
|
||||
mProcessor.parseStartProjectTransfer(message->getAs<Message::StartProjectTransfer>());
|
||||
break;
|
||||
case Message::CloseProject::OPFLAG:
|
||||
parseCloseProject(message->getAs<Message::CloseProject>());
|
||||
mProcessor.parseCloseProject(message->getAs<Message::CloseProject>());
|
||||
break;
|
||||
case Message::RequestProjectTransfer::OPFLAG:
|
||||
parseRequestProjectTransfer(message->getAs<Message::RequestProjectTransfer>());
|
||||
mProcessor.parseRequestProjectTransfer(message->getAs<Message::RequestProjectTransfer>());
|
||||
break;
|
||||
case Message::EndProjectTransfer::OPFLAG:
|
||||
parseEndProjectTransfer(message->getAs<Message::EndProjectTransfer>());
|
||||
mProcessor.parseEndProjectTransfer(message->getAs<Message::EndProjectTransfer>());
|
||||
break;
|
||||
//----- SPIT Types ------
|
||||
case Message::ReportType::OPFLAG:
|
||||
mProcessor.parseReportType(message->getAs<Message::ReportType>());
|
||||
break;
|
||||
case Message::RemoveType::OPFLAG:
|
||||
parseRemoveSPITType(message->getAs<Message::RemoveType>());
|
||||
mProcessor. parseRemoveType(message->getAs<Message::RemoveType>());
|
||||
//----- SPIT Objects ------
|
||||
break;
|
||||
case Message::ReportObject::OPFLAG:
|
||||
parseReportSPITObject(message->getAs<Message::ReportObject>());
|
||||
mProcessor.parseReportObject(message->getAs<Message::ReportObject>());
|
||||
break;
|
||||
case Message::RemoveObject::OPFLAG:
|
||||
parseRemoveSPITObject(message->getAs<Message::RemoveObject>());
|
||||
mProcessor.parseRemoveObject(message->getAs<Message::RemoveObject>());
|
||||
break;
|
||||
//----- Play SPIT Objects ------
|
||||
case Message::PlayStart::OPFLAG:
|
||||
parsePlaySPITStart(message->getAs<Message::PlayStart>());
|
||||
mProcessor.parsePlayStart(message->getAs<Message::PlayStart>());
|
||||
break;
|
||||
case Message::PlayObject::OPFLAG:
|
||||
parsePlaySPITObject(message->getAs<Message::PlayObject>());
|
||||
mProcessor.parsePlayObject(message->getAs<Message::PlayObject>());
|
||||
break;
|
||||
case Message::PlayEnd::OPFLAG:
|
||||
parsePlaySPITEnd(message->getAs<Message::PlayEnd>());
|
||||
mProcessor.parsePlayEnd(message->getAs<Message::PlayEnd>());
|
||||
break;
|
||||
case Message::ReportPlayStatus::OPFLAG:
|
||||
parseReportPlayStatus(message->getAs<Message::ReportPlayStatus>());
|
||||
mProcessor.parseReportPlayStatus(message->getAs<Message::ReportPlayStatus>());
|
||||
break;
|
||||
default:
|
||||
ESP_LOGD(TAG, "Client::parseMessage: Unknown Message");
|
||||
@@ -459,7 +462,7 @@ bool SClient::connect(string serverIP, string serverPort, string clientIP, strin
|
||||
|
||||
// sleep a little to make sure that the reception of the messages is started
|
||||
fos::Task::delayMs(500);
|
||||
if (sendSPITMessage(sMConnect) < 0) {
|
||||
if (sendMessage(sMConnect) < 0) {
|
||||
mConnectionStatus = Connection::None;
|
||||
mStopReceiveMessages = true;
|
||||
return false;
|
||||
@@ -483,7 +486,7 @@ void SClient::disconnectInternal(Connection cause) {
|
||||
break;
|
||||
case Connection::None: {
|
||||
Message::Disconnect sMDisconnect;
|
||||
sendSPITMessage(sMDisconnect);
|
||||
sendMessage(sMDisconnect);
|
||||
} break;
|
||||
case Connection::NoneServer:
|
||||
break;
|
||||
@@ -505,7 +508,7 @@ void SClient::disconnectInternal(Connection cause) {
|
||||
ESP_LOGD(TAG, "connection terminated by server");
|
||||
// call eventProjectClosed because this may not be sended by the server,
|
||||
// when the connection is closed
|
||||
mCallbacks.onProjectUpdate(ProjUpdate::ServerClosed, mServerProjectID);
|
||||
mCallbacks.onProjectUpdate(ProjUpdate::ServerClosed, mProcessor.getServerProjectID());
|
||||
|
||||
// Server has terminated the connection -> start a new game
|
||||
// _doReconnect = false;
|
||||
@@ -574,7 +577,7 @@ void SClient::parseDisconnect(Message::Disconnect &message) {
|
||||
void SClient::parseWatchdog(Message::Watchdog &message) {
|
||||
// ESP_LOGD(TAG, "parse Watchdog ");
|
||||
Message::WatchdogAnswer o_WatchdogAnswer;
|
||||
sendSPITMessage(o_WatchdogAnswer);
|
||||
sendMessage(o_WatchdogAnswer);
|
||||
}
|
||||
/**
|
||||
* The SPIT server sends a watchdog message at regular intervals. The client responds immediately with WatchdogAnswer
|
||||
@@ -588,7 +591,7 @@ void SClient::parseWatchdogAnswer(Message::WatchdogAnswer &message) {
|
||||
void SClient::sendWatchdog() {
|
||||
int intResult;
|
||||
Message::Watchdog message;
|
||||
intResult = sendSPITMessage(message);
|
||||
intResult = sendMessage(message);
|
||||
if (intResult < 0) {
|
||||
ESP_LOGW("WDT", "Failed to send Watchdog msg");
|
||||
}
|
||||
@@ -601,130 +604,9 @@ void SClient::eventWatchdogLost() {
|
||||
}
|
||||
}
|
||||
|
||||
//----- SPIT Project ------
|
||||
void SClient::parseReportProject(Message::ReportProject &message) {
|
||||
ESP_LOGD(TAG, "parse ReportProject");
|
||||
mServerProjectID = message.getProjectID();
|
||||
mServerProjectName = message.getProjectName();
|
||||
mServerFramesPerSecond = message.getFramesPerSecond();
|
||||
mCallbacks.onProjectUpdate(ProjUpdate::ServerLoaded, mServerProjectID);
|
||||
|
||||
// Set all SPITTypes and SPITObjects confirmed = false
|
||||
SType::setConfirmedFalse(mProcessor.mSpitTypes);
|
||||
SObject::setConfirmedFalse(mSpitObjects);
|
||||
|
||||
// Send RequestProjectTransfer
|
||||
Message::RequestProjectTransfer sMRequestProjectTransfer;
|
||||
if (sendSPITMessage(sMRequestProjectTransfer) < 0) {
|
||||
ESP_LOGD(TAG, "Client::parseReportProject could not send RequestProjectTransfer");
|
||||
}
|
||||
|
||||
// todo Don't send the ReportProject here it should be sended after parseEndProjectTransfer
|
||||
// Send client's ReportProject
|
||||
Message::ReportProject reportProject(mProjName, mProjName);
|
||||
reportProject.setFramesPerSecond(0);
|
||||
if (sendSPITMessage(reportProject) < 0) {
|
||||
ESP_LOGD(TAG, "Client::parseReportProject could not send Client's ReportProject");
|
||||
}
|
||||
}
|
||||
void SClient::parseCloseProject(Message::CloseProject &p_CloseSPITProject) {
|
||||
ESP_LOGD(TAG, "parse CloseProject");
|
||||
string stringProjectID;
|
||||
mCallbacks.onProjectUpdate(ProjUpdate::ServerClosed, p_CloseSPITProject.getProjectID());
|
||||
SPlayer::clearPlayers();
|
||||
}
|
||||
|
||||
string SClient::getServerProjectID() { return mServerProjectID; }
|
||||
string SClient::getServerProjectName() { return mServerProjectName; }
|
||||
int SClient::getServerFramesPerSecond() { return mServerFramesPerSecond; }
|
||||
|
||||
void SClient::parseRequestProjectTransfer(Message::RequestProjectTransfer &message) {
|
||||
ESP_LOGD(TAG, "parse RequestProjectTransfer");
|
||||
// StartProjectTransfer
|
||||
Message::StartProjectTransfer sMStartProjectTransfer;
|
||||
if (sendSPITMessage(sMStartProjectTransfer) < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// send all listes SPITTypes
|
||||
for (const auto& [key, value] : mProcessor.mSpitTypes.getRepo()) {
|
||||
sendSPITTypeInternal(*value);
|
||||
fos::Task::delayMs(10);
|
||||
}
|
||||
for (auto& [key, value] : mSpitObjects.getRepo()) {
|
||||
sendSPITObjectInternal(value.get());
|
||||
fos::Task::delayMs(10);
|
||||
}
|
||||
|
||||
// EndProjectTransfer
|
||||
Message::EndProjectTransfer sMEndProjectTransfer;
|
||||
sendSPITMessage(sMEndProjectTransfer);
|
||||
}
|
||||
|
||||
/* NEW IMPLEMENTATION
|
||||
|
||||
void SClient::parseRequestProjectTransfer(Message::RequestProjectTransfer* message) {
|
||||
// ESP_LOGD(TAG, "parse RequestProjectTransfer");
|
||||
thread* o_ThreadSend;
|
||||
o_ThreadSend = new thread(&this->sendProject, this);
|
||||
// int intResult;
|
||||
// Message::StartProjectTransfer* ptrSMStartProjectTransfer;
|
||||
// Message::EndProjectTransfer* ptrSMEndProjectTransfer;
|
||||
// int intCount;
|
||||
// SPITType* ptrSPITType;
|
||||
// SObject* ptrSPITObject;
|
||||
|
||||
|
||||
// //StartProjectTransfer
|
||||
// NotifyStartProjectTransfer_Client* o_RunnableStart = new NotifyStartProjectTransfer_Client(mSPITClientInterface);
|
||||
// SPIT_Handler::addRunnable(o_RunnableStart);
|
||||
|
||||
// ptrSMStartProjectTransfer = new Message::StartProjectTransfer();
|
||||
// intResult = sendSPITMessage(ptrSMStartProjectTransfer);
|
||||
// if (intResult < 0) {
|
||||
// return;
|
||||
// }
|
||||
// mWatchdog->answerWatchdog();
|
||||
// {
|
||||
// //send all listes SPITTypes
|
||||
// unique_lock<recursive_mutex> o_LockType(*SPITType::getMutex());
|
||||
// intCount = SPITType::getSPITTypeCount();
|
||||
// for (int i = 0; i < intCount; i++) {
|
||||
// ptrSPITType = mSpitTypes.getEntry(i);
|
||||
// if (ptrSPITType == nullptr) continue;
|
||||
// intResult = sendSPITTypeInternal(ptrSPITType);
|
||||
// if (intResult < 0) return;
|
||||
// mWatchdog->answerWatchdog();
|
||||
// this_thread::sleep_for(chrono::milliseconds(7));
|
||||
// }
|
||||
// }
|
||||
|
||||
// {
|
||||
// unique_lock<recursive_mutex> o_LockObject(*SObject::getMutex());
|
||||
// intCount = mSpitObjects.getEntryCount();
|
||||
// for (int i = 0; i < intCount; i++) {
|
||||
// ptrSPITObject = mSpitObjects.getEntry(i);
|
||||
// if (ptrSPITObject == nullptr) continue;
|
||||
// intResult = sendSPITObjectInternal(ptrSPITObject);
|
||||
// if (intResult < 0) return;
|
||||
// mWatchdog->answerWatchdog();
|
||||
// this_thread::sleep_for(chrono::milliseconds(7));
|
||||
// }
|
||||
// }
|
||||
|
||||
// //EndProjectTransfer
|
||||
// ptrSMEndProjectTransfer = new Message::EndProjectTransfer();
|
||||
// intResult = sendSPITMessage(ptrSMEndProjectTransfer);
|
||||
// if (intResult < 0) {
|
||||
// return;
|
||||
// }
|
||||
// mWatchdog->answerWatchdog();
|
||||
// NotifyEndProjectTransfer_Client* o_RunnableEnd = new NotifyEndProjectTransfer_Client(mSPITClientInterface);
|
||||
// SPIT_Handler::addRunnable(o_RunnableEnd);
|
||||
|
||||
// //Send act
|
||||
}
|
||||
*/
|
||||
string SClient::getServerProjectID() { return mProcessor.getServerProjectID(); }
|
||||
string SClient::getServerProjectName() { return mProcessor.getServerProjectName(); }
|
||||
int SClient::getServerFramesPerSecond() { return mProcessor.getServerFramesPerSecond(); }
|
||||
|
||||
void SClient::sendProject(SClient *p_PtrSPIT_Client) {
|
||||
// int intResult;
|
||||
@@ -739,7 +621,7 @@ void SClient::sendProject(SClient *p_PtrSPIT_Client) {
|
||||
// SPIT_Handler::addRunnable(o_RunnableStart);
|
||||
|
||||
// ptrSMStartProjectTransfer = new Message::StartProjectTransfer();
|
||||
// intResult = p_PtrSPIT_Client->sendSPITMessage(ptrSMStartProjectTransfer);
|
||||
// intResult = p_PtrSPIT_Client->sendMessage(ptrSMStartProjectTransfer);
|
||||
// if (intResult < 0) {
|
||||
// return;
|
||||
// }
|
||||
@@ -753,7 +635,7 @@ void SClient::sendProject(SClient *p_PtrSPIT_Client) {
|
||||
// ptrSPITType = mSpitTypes.getEntry(i);
|
||||
// if (ptrSPITType == nullptr) continue;
|
||||
// if (ptrSPITType->getCreatedByClient() == false) continue;
|
||||
// intResult = p_PtrSPIT_Client->sendSPITTypeInternal(ptrSPITType);
|
||||
// intResult = p_PtrSPIT_Client->sendTypeInternal(ptrSPITType);
|
||||
// if (intResult < 0) return;
|
||||
// // mWatchdog->answerWatchdog();
|
||||
// this_thread::sleep_for(chrono::milliseconds(7));
|
||||
@@ -767,7 +649,7 @@ void SClient::sendProject(SClient *p_PtrSPIT_Client) {
|
||||
// ptrSPITObject = mSpitObjects.getEntry(i);
|
||||
// if (ptrSPITObject == nullptr) continue;
|
||||
// if (ptrSPITObject->getCreatedByClient() == false) continue;
|
||||
// intResult = p_PtrSPIT_Client->sendSPITObjectInternal(ptrSPITObject);
|
||||
// intResult = p_PtrSPIT_Client->sendObjectInternal(ptrSPITObject);
|
||||
// if (intResult < 0) return;
|
||||
// // mWatchdog->answerWatchdog();
|
||||
// this_thread::sleep_for(chrono::milliseconds(7));
|
||||
@@ -776,7 +658,7 @@ void SClient::sendProject(SClient *p_PtrSPIT_Client) {
|
||||
|
||||
// //EndProjectTransfer
|
||||
// ptrSMEndProjectTransfer = new Message::EndProjectTransfer();
|
||||
// intResult = p_PtrSPIT_Client->sendSPITMessage(ptrSMEndProjectTransfer);
|
||||
// intResult = p_PtrSPIT_Client->sendMessage(ptrSMEndProjectTransfer);
|
||||
// if (intResult < 0) {
|
||||
// return;
|
||||
// }
|
||||
@@ -787,115 +669,16 @@ void SClient::sendProject(SClient *p_PtrSPIT_Client) {
|
||||
// //Send act
|
||||
}
|
||||
|
||||
void SClient::parseStartProjectTransfer(Message::StartProjectTransfer &message) {
|
||||
mCallbacks.onProjectUpdate(ProjUpdate::StartTransfer, mServerProjectID);
|
||||
}
|
||||
void SClient::parseEndProjectTransfer(Message::EndProjectTransfer &message) {
|
||||
SObject::clearUnconfirmedObjects(mSpitObjects);
|
||||
mCallbacks.onProjectUpdate(ProjUpdate::EndTransfer, mServerProjectID);
|
||||
|
||||
// Send Message::ReportProject after the mSPITClientInterface is notfied of EndProjectTransfer
|
||||
Message::ReportProject reportSPITProject(mProjName, mProjName);
|
||||
reportSPITProject.setFramesPerSecond(0);
|
||||
if (sendSPITMessage(reportSPITProject) < 0) {
|
||||
ESP_LOGD(TAG, "Client::parseReportProject could not send Client's ReportProject");
|
||||
}
|
||||
}
|
||||
|
||||
void SClient::parseRemoveSPITType(Message::RemoveType &message) {
|
||||
ESP_LOGD(TAG, "parse RemoveType %s", message.getID().c_str());
|
||||
bool boolRemote = false;
|
||||
string stringSPITTypeID = message.getID();
|
||||
|
||||
SType *ptrSPITType = mProcessor.mRemoteSpitTypes.getEntry(stringSPITTypeID);
|
||||
if (!ptrSPITType) {
|
||||
boolRemote = true;
|
||||
} else {
|
||||
ptrSPITType = mProcessor.mSpitTypes.getEntry(stringSPITTypeID);
|
||||
if (!ptrSPITType) {
|
||||
boolRemote = false;
|
||||
} else {
|
||||
// No SPITType with stringSPITTypeID is listet
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (ptrSPITType->getCreatedByClient() && ptrSPITType->Fixed.get()) {
|
||||
// the SPITyte is created by client himself and it is fixed -> don't remove the SPITType!!
|
||||
// Send the SPITTyp back to the server
|
||||
sendSPITTypeInternal(*ptrSPITType);
|
||||
return;
|
||||
}
|
||||
|
||||
mCallbacks.onSpitType(ObjectEvent::Deleted, boolRemote, *ptrSPITType);
|
||||
if (boolRemote == false) {
|
||||
mProcessor.mSpitTypes.removeEntry(*ptrSPITType);
|
||||
} else {
|
||||
mProcessor.mRemoteSpitTypes.removeEntry(*ptrSPITType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If a client has changed a SPITType, it should send it to the server to transmit the changes.
|
||||
* If the SPITType is a fixed one and not created by the client himself, then an eventSPITType can be sent from the server, which cancels the changes.
|
||||
* @param p_SPITType the pointer to the changed SPITType
|
||||
* @return 0 = is sended, -1 = is not sended
|
||||
*/
|
||||
int SClient::sendSPITTypeInternal(SType &p_SPITType) {
|
||||
int SClient::sendTypeInternal(SType &p_SPITType) {
|
||||
Message::ReportType sMReportSPITType;
|
||||
p_SPITType.fillMessageOP(sMReportSPITType);
|
||||
return sendSPITMessage(sMReportSPITType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change an existing SPIT_Type.
|
||||
* @param p_SPITType the SPITType vont
|
||||
* @return true = changed, false = not changed maybe p_SPITType is NULL or the SPITType doesn't exists
|
||||
*/
|
||||
bool SClient::changeSPITType(SType *p_SPITType) {
|
||||
if (p_SPITType == nullptr)
|
||||
return false;
|
||||
SType *ptrSPITType = mProcessor.mSpitTypes.getEntry(p_SPITType->getID());
|
||||
if (ptrSPITType == nullptr)
|
||||
return false;
|
||||
|
||||
ptrSPITType->DefaultDelay.set(p_SPITType->DefaultDelay.get());
|
||||
ptrSPITType->DefaultDuration.set(p_SPITType->DefaultDuration.get());
|
||||
ptrSPITType->Fixed.set(p_SPITType->Fixed.get());
|
||||
ptrSPITType->GroupName.set(p_SPITType->GroupName.get());
|
||||
ptrSPITType->Name.set(p_SPITType->Name.get());
|
||||
ptrSPITType->ProjectIndepended.set(p_SPITType->ProjectIndepended.get());
|
||||
|
||||
mCallbacks.onSpitType(ObjectEvent::Changed, false, *ptrSPITType);
|
||||
sendSPITTypeInternal(*ptrSPITType);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a client has removed a SPITType where id == p_SPITTypeID, it should send it to the server.
|
||||
* The corresponding SPITType if listet in SPITType will be deleted.
|
||||
* An eventRemoveSPITType will occur.
|
||||
* If a connection to a SPITServer is established, the SPITServer may dicard the deletion an an eventSPITType will occur
|
||||
* -> the SPITType will be listet again.
|
||||
* @param p_SPITType the id of the SPITType ro remove
|
||||
* @return 0 = is sended, -1 = is not sended
|
||||
*/
|
||||
int SClient::removeSPITType(string p_SPITTypeID) {
|
||||
if (p_SPITTypeID.length() <= 0)
|
||||
return -1;
|
||||
SType *ptrSPITType;
|
||||
{
|
||||
ptrSPITType = mProcessor.mSpitTypes.getEntry(p_SPITTypeID);
|
||||
if (ptrSPITType == nullptr)
|
||||
return -1;
|
||||
Message::RemoveType sMRemoveSPITType;
|
||||
ptrSPITType->fillMessageOP(sMRemoveSPITType);
|
||||
mCallbacks.onSpitType(ObjectEvent::Deleted, false, *ptrSPITType);
|
||||
mProcessor.mSpitTypes.removeEntry(*ptrSPITType);
|
||||
return sendSPITMessage(sMRemoveSPITType);
|
||||
}
|
||||
return -1;
|
||||
return sendMessage(sMReportSPITType);
|
||||
}
|
||||
|
||||
SType *SClient::createTypeFixed(string iD, string p_GroupName, string p_Name, uint64_t p_DefaultDelay, uint64_t p_DefaultDuration) {
|
||||
@@ -923,113 +706,17 @@ SType *SClient::createType(string p_ID, string p_GroupName, string p_Name, uint6
|
||||
|
||||
auto eventType = boolNew ? ObjectEvent::Created : ObjectEvent::Changed;
|
||||
mCallbacks.onSpitType(eventType, false, *ptrSPITType);
|
||||
sendSPITTypeInternal(*ptrSPITType);
|
||||
sendTypeInternal(*ptrSPITType);
|
||||
return ptrSPITType;
|
||||
}
|
||||
|
||||
//----- SPIT Objects ------
|
||||
void SClient::parseReportSPITObject(Message::ReportObject &message) {
|
||||
ESP_LOGD(TAG, "parse ReportObject %s", message.getID().c_str());
|
||||
SObject *ptrSPITObject;
|
||||
SType *ptrSPITType;
|
||||
bool boolNew = false;
|
||||
bool boolRemote = false;
|
||||
bool boolChanged = false;
|
||||
{
|
||||
ESP_LOGD(TAG, "parse ReportObject %s / %s", message.getID().c_str(), message.getName().c_str());
|
||||
if (message.getServerRemote() == false) {
|
||||
boolRemote = false;
|
||||
ptrSPITObject = mSpitObjects.getEntry(message.getID());
|
||||
ptrSPITType = mProcessor.mSpitTypes.getEntry(message.getSPITTypeID());
|
||||
|
||||
if (ptrSPITType == nullptr) {
|
||||
// No associated SPITType found
|
||||
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
|
||||
mSpitObjects.removeEntry(*ptrSPITObject);
|
||||
}
|
||||
return;
|
||||
}
|
||||
bool isKnownType = ptrSPITType != nullptr;
|
||||
if (ptrSPITObject == nullptr) {
|
||||
// The user's app my veto the SPITType
|
||||
if (mCallbacks.onCheckSpitObjectVeto(isKnownType) == false) {
|
||||
ESP_LOGW(TAG, "ObjectVeto %s / %s", message.getID().c_str(), message.getName().c_str());
|
||||
return;
|
||||
}
|
||||
auto spitObj = make_unique<SObject>(message.getID());
|
||||
ptrSPITObject = spitObj.get();
|
||||
mSpitObjects.addEntry(move(spitObj));
|
||||
boolNew = true;
|
||||
} else {
|
||||
// The user's app my veto the SPITType
|
||||
if (mCallbacks.onCheckSpitObjectVeto(isKnownType) == false) {
|
||||
// SpitObject exists and User APp denied the SPITObject -> remove the SPITObject without sending a message
|
||||
mSpitObjects.removeEntry(*ptrSPITObject);
|
||||
ESP_LOGW(TAG, "TypeVeto %s / %s", message.getID().c_str(), message.getName().c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
boolRemote = true;
|
||||
ptrSPITObject = mRemoteSpitObjects.getEntry(message.getID());
|
||||
ptrSPITType = mProcessor.mRemoteSpitTypes.getEntry(message.getSPITTypeID());
|
||||
if (ptrSPITType == nullptr) {
|
||||
// No associated SPITType found
|
||||
return;
|
||||
}
|
||||
if (ptrSPITObject == nullptr) {
|
||||
auto spitObj = make_unique<SObject>(message.getID());
|
||||
ptrSPITObject = spitObj.get();
|
||||
mRemoteSpitObjects.addEntry(move(spitObj));
|
||||
boolNew = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ptrSPITObject->setMessageOP(&message)) {
|
||||
ESP_LOGE(TAG, "Change not allowed");
|
||||
// setMessageOP error - the SPITObject can't be changed, it may be fixed and crated by this client
|
||||
sendSPITObjectInternal(ptrSPITObject);
|
||||
return;
|
||||
}
|
||||
|
||||
if (boolRemote == false) {
|
||||
// set the virtual action assignment
|
||||
ptrSPITObject->setActionAssignedType(ptrSPITType->ActionAssigned.get());
|
||||
}
|
||||
|
||||
auto eventType = boolNew ? ObjectEvent::Created : ObjectEvent::Changed;
|
||||
mCallbacks.onSpitObject(eventType, boolRemote, *ptrSPITType, *ptrSPITObject);
|
||||
|
||||
if (ptrSPITObject->setConfirmed(true) == true || boolChanged == true) {
|
||||
// Confirmation has changed
|
||||
sendSPITObjectInternal(ptrSPITObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
void SClient::parseRemoveSPITObject(Message::RemoveObject &message) {
|
||||
ESP_LOGD(TAG, "parse RemoveObject %s", message.getID().c_str());
|
||||
SObject *ptrSPITObject = mRemoteSpitObjects.getEntry(message.getID());
|
||||
if (ptrSPITObject != nullptr) {
|
||||
SType *ptrSPITType = mProcessor.mRemoteSpitTypes.getEntry(ptrSPITObject->SPITTypeID.get());
|
||||
if (ptrSPITType != nullptr) {
|
||||
mCallbacks.onSpitObject(ObjectEvent::Deleted, true, *ptrSPITType, *ptrSPITObject);
|
||||
}
|
||||
mRemoteSpitObjects.removeEntry(*ptrSPITObject);
|
||||
} else {
|
||||
// call removeSPITObject, this will notify the server that the object is removed
|
||||
removeSPITObject(message.getID());
|
||||
}
|
||||
}
|
||||
|
||||
int SClient::sendSPITObjectInternal(SObject *ptrSPITObject) {
|
||||
int SClient::sendObjectInternal(SObject *ptrSPITObject) {
|
||||
if (ptrSPITObject == nullptr)
|
||||
return -1;
|
||||
Message::ReportObject sMReportSPITObject;
|
||||
ptrSPITObject->fillMessageOP(sMReportSPITObject);
|
||||
|
||||
return sendSPITMessage(sMReportSPITObject);
|
||||
return sendMessage(sMReportSPITObject);
|
||||
}
|
||||
/**
|
||||
* When the client changes an existing SPITObject (normally the client should not do this), then he should send the changes to the SPITServer.
|
||||
@@ -1045,7 +732,7 @@ bool SClient::changeSPITObject(SObject *obj) {
|
||||
SObject *ptrSPITObject;
|
||||
SType *ptrSPITType;
|
||||
{
|
||||
ptrSPITObject = mSpitObjects.getEntry(obj->getID());
|
||||
ptrSPITObject = mProcessor.mSpitObjects.getEntry(obj->getID());
|
||||
if (ptrSPITObject == nullptr)
|
||||
return false;
|
||||
ptrSPITType = mProcessor.mSpitTypes.getEntry(obj->getID());
|
||||
@@ -1070,112 +757,11 @@ bool SClient::changeSPITObject(SObject *obj) {
|
||||
ptrSPITObject->ValueUse.set(obj->ValueUse.get());
|
||||
|
||||
mCallbacks.onSpitObject(ObjectEvent::Changed, false, *ptrSPITType, *ptrSPITObject);
|
||||
sendSPITObjectInternal(ptrSPITObject);
|
||||
sendObjectInternal(ptrSPITObject);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* When the client wants to remove a SPITObject with id == p_SPITObjectID (normally the client should not do this), then he should send it to the SPITServer.
|
||||
* The corresponding SPITObject if listet in SPITObject will be deleted.
|
||||
* An eventRemoveSPITType will occur.
|
||||
* If an connection to a SPITServer is established, the SPITServer may discard the deletion and an eventSPITObject occurs
|
||||
* -> the SPITObject is listet again.
|
||||
* @param objId the id of the SPITObject to remove.
|
||||
* @return 0 = sended to the SPITServer, -1 = not sended to the SPITServer or nos SPITObject with id == objId exists.
|
||||
*/
|
||||
int SClient::removeSPITObject(string objId) {
|
||||
if (objId.length() <= 0)
|
||||
return -1;
|
||||
SType *ptrSPITType;
|
||||
SObject *ptrSPITObject;
|
||||
{
|
||||
Message::RemoveObject sMRemoveSPITObject;
|
||||
|
||||
ptrSPITObject = mSpitObjects.getEntry(objId);
|
||||
if (ptrSPITObject == nullptr)
|
||||
return -1;
|
||||
ptrSPITType = mProcessor.mSpitTypes.getEntry(ptrSPITObject->SPITTypeID.get());
|
||||
if (ptrSPITType == nullptr)
|
||||
return -1;
|
||||
ptrSPITObject->fillMessageOP(sMRemoveSPITObject);
|
||||
mCallbacks.onSpitObject(ObjectEvent::Deleted, false, *ptrSPITType, *ptrSPITObject);
|
||||
mSpitObjects.removeEntry(*ptrSPITObject);
|
||||
return sendSPITMessage(sMRemoveSPITObject);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
//----- Play SPIT Objects ------
|
||||
|
||||
void SClient::parsePlaySPITStart(Message::PlayStart &message) {
|
||||
ESP_LOGD(TAG, "parse PlayStart ID: %s Name: %s Running: %d", message.getPlayerID().c_str(), message.getPlayerName().c_str(), (int)message.getPlayerIsRunning());
|
||||
SPlayer &spitPlayer = SPlayer::getSPITPlayer(message.getPlayerID());
|
||||
spitPlayer.setIsRunning(message.getPlayerIsRunning());
|
||||
spitPlayer.setName(message.getPlayerName());
|
||||
spitPlayer.setType(message.getPlayerType());
|
||||
spitPlayer.setTime(message.getTime());
|
||||
spitPlayer.startPlaySequence();
|
||||
|
||||
mCallbacks.onPlay(spitPlayer.getID(), spitPlayer.getName(), spitPlayer.getType(), spitPlayer.getIsRunning(), spitPlayer.getTime());
|
||||
}
|
||||
void SClient::parsePlaySPITObject(Message::PlayObject &message) {
|
||||
|
||||
SPlayer &ptrSPITPlayer = SPlayer::getSPITPlayer(message.getPlayerID());
|
||||
SObject *ptrSPITObject = mSpitObjects.getEntry(message.getSPITObjectID());
|
||||
|
||||
if (ptrSPITObject == nullptr) {
|
||||
return;
|
||||
}
|
||||
SPlayer::PlayType *ptrPlaySPITType = ptrSPITPlayer.addTypePlaying(ptrSPITObject->SPITTypeID.get());
|
||||
if (ptrPlaySPITType == nullptr) {
|
||||
return;
|
||||
}
|
||||
ptrPlaySPITType->setPlayerIsRunning(ptrSPITPlayer.getIsRunning());
|
||||
ptrPlaySPITType->addValue(((double)message.getValue() / 1000000), ((double)ptrSPITObject->ValueFactor.get() / 1000000));
|
||||
}
|
||||
|
||||
void SClient::parsePlaySPITEnd(Message::PlayEnd &message) {
|
||||
SPlayer &ptrSPITPlayer = SPlayer::getSPITPlayer(message.getPlayerID());
|
||||
|
||||
auto &ptrPlaySPITTypes = ptrSPITPlayer.getPlaySPITTypes();
|
||||
for (auto i = ptrPlaySPITTypes.begin(); i != ptrPlaySPITTypes.end(); i++) {
|
||||
SPlayer::PlayType *ptrPlaySPITType = i->second.get();
|
||||
bool boolStarted = ptrPlaySPITType->getIsNew();
|
||||
bool boolStopped = (ptrPlaySPITType->getIsPlayed() == false);
|
||||
SType *ptrSPITType = mProcessor.mSpitTypes.getEntry(ptrPlaySPITType->getSPITTypeID());
|
||||
if (ptrSPITType == nullptr) {
|
||||
// set isplayed to false, the ptrPlayObject will be removed by ptrSPITPlayer.endPlaySequence()
|
||||
ptrPlaySPITType->setIsPlayed(false);
|
||||
continue;
|
||||
}
|
||||
mCallbacks.onPlaySpitType(ptrPlaySPITType->getPlayerID(), ptrPlaySPITType->getSPITTypeID(), ptrPlaySPITType->getPlayerIsRunning(), boolStarted, boolStopped, ptrPlaySPITType->getValue());
|
||||
}
|
||||
ptrSPITPlayer.endPlaySequence();
|
||||
}
|
||||
|
||||
void SClient::parseReportPlayStatus(Message::ReportPlayStatus &message) {
|
||||
SType *ptrSPITType = NULL;
|
||||
|
||||
SObject *ptrSPITObject = mRemoteSpitObjects.getEntry(message.getID());
|
||||
if (ptrSPITObject == nullptr) {
|
||||
ptrSPITObject = mSpitObjects.getEntry(message.getID());
|
||||
if (ptrSPITObject == nullptr) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (ptrSPITObject->ServerRemote.get() == false) {
|
||||
ptrSPITType = mProcessor.mSpitTypes.getEntry(ptrSPITObject->SPITTypeID.get());
|
||||
} else {
|
||||
ptrSPITType = mProcessor.mRemoteSpitTypes.getEntry(ptrSPITObject->SPITTypeID.get());
|
||||
}
|
||||
|
||||
if (ptrSPITType == nullptr) {
|
||||
return;
|
||||
}
|
||||
mCallbacks.onPlayRemoteObjectStatus(*ptrSPITType, *ptrSPITObject, message.getFrameInsideObject(), message.getValue());
|
||||
}
|
||||
|
||||
//--------- Remote ----------
|
||||
|
||||
/**
|
||||
@@ -1193,14 +779,14 @@ void SClient::parseReportPlayStatus(Message::ReportPlayStatus &message) {
|
||||
* VALUEFLAG_DECREASE (0x01) The server decreases his existing value by valuePpm
|
||||
*/
|
||||
void SClient::sendRemoteObject(string p_SPITObjectID, int valuePpm, char valueFlag) {
|
||||
SObject *ptrRemoteSPITObject = mRemoteSpitObjects.getEntry(p_SPITObjectID);
|
||||
SObject *ptrRemoteSPITObject = mProcessor.mRemoteSpitObjects.getEntry(p_SPITObjectID);
|
||||
if (ptrRemoteSPITObject == nullptr)
|
||||
return;
|
||||
|
||||
Message::PlayStart playSPITStart(mID, mProjName, PLAYERTYPE_DISCRETE);
|
||||
playSPITStart.setPlayerIsRunning(false);
|
||||
playSPITStart.setTime(0);
|
||||
sendSPITMessage(playSPITStart);
|
||||
sendMessage(playSPITStart);
|
||||
|
||||
Message::PlayObject playSPITObject;
|
||||
playSPITObject.setID(ptrRemoteSPITObject->getID());
|
||||
@@ -1208,10 +794,10 @@ void SClient::sendRemoteObject(string p_SPITObjectID, int valuePpm, char valueFl
|
||||
playSPITObject.setPlayerID(mID);
|
||||
playSPITObject.setValue(valuePpm);
|
||||
playSPITObject.setValueFlag(valueFlag);
|
||||
sendSPITMessage(playSPITObject);
|
||||
sendMessage(playSPITObject);
|
||||
|
||||
Message::PlayEnd playSPITEnd(mID);
|
||||
sendSPITMessage(playSPITEnd);
|
||||
sendMessage(playSPITEnd);
|
||||
}
|
||||
|
||||
fos::Semaphore SClient::sStartSad;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -58,7 +58,13 @@ class SpitClientFix {
|
||||
.onPlayRemoteObjectStatus = [&](const SType &t, const SObject &o, uint64_t p_FrameInsideObject, int value) { client.onPlayRemoteObjectStatus(t, o, p_FrameInsideObject, value); },
|
||||
.onCheckSpitTypeVeto = [&](bool knownType, bool createdByClient) { return client.onCheckSpitTypeVeto(knownType, createdByClient); },
|
||||
.onCheckSpitObjectVeto = [&](bool knownType) { return client.onCheckSpitObjectVeto(knownType); }};
|
||||
SProcessor sut{"sut", "sutProj", "dev", "##GUID##", callbacks};
|
||||
SProcessor::InternalCallbacks intCallbacks {
|
||||
.delay = [&](int ms){ return ; },
|
||||
.sendMessage = [&](Message::OPPart &msg){ return 0; },
|
||||
.sendTypeInternal = [&](SType &sType) { return 0; },
|
||||
.sendObjectInternal = [&](SObject *sObject) { return 0; }
|
||||
};
|
||||
SProcessor sut{"sut", "sutProj", "dev", "##GUID##", callbacks, intCallbacks};
|
||||
};
|
||||
|
||||
TEST_CASE_FIXTURE(SpitClientFix, "Spit types") {
|
||||
|
||||
@@ -58,7 +58,13 @@ class SpitClientCmplsFix {
|
||||
.onPlayRemoteObjectStatus = [&](const SType &t, const SObject &o, uint64_t p_FrameInsideObject, int value) { client.onPlayRemoteObjectStatus(t, o, p_FrameInsideObject, value); },
|
||||
.onCheckSpitTypeVeto = [&](bool knownType, bool createdByClient) { return client.onCheckSpitTypeVeto(knownType, createdByClient); },
|
||||
.onCheckSpitObjectVeto = [&](bool knownType) { return client.onCheckSpitObjectVeto(knownType); }};
|
||||
SProcessor sut{"sut", "sutProj", "dev", "##GUID##", callbacks};
|
||||
SProcessor::InternalCallbacks intCallbacks {
|
||||
.delay = [&](int ms){ return ; },
|
||||
.sendMessage = [&](Message::OPPart &msg){ return 0; },
|
||||
.sendTypeInternal = [&](SType &sType) { return 0; },
|
||||
.sendObjectInternal = [&](SObject *sObject) { return 0; }
|
||||
};
|
||||
SProcessor sut{"sut", "sutProj", "dev", "##GUID##", callbacks, intCallbacks};
|
||||
};
|
||||
|
||||
static void spoofMsgCounter(std::vector<uint8_t> &msg, uint8_t cnt) {
|
||||
|
||||
Reference in New Issue
Block a user