fixing memory leaks and Veto mechanics

This commit is contained in:
2025-04-08 23:34:07 +02:00
parent 858b7d81cc
commit 2397789047
9 changed files with 212 additions and 353 deletions
+2 -1
View File
@@ -13,6 +13,7 @@
*/
#include "SPITPlayer.h"
#include "esp_log.h"
#include <memory>
#include <vector>
@@ -64,7 +65,7 @@ void SPITPlayer::startPlaySequence() {
}
void SPITPlayer::endPlaySequence() {
for (auto i = m_PlaySPITTypes.begin(); i != m_PlaySPITTypes.end(); ) {
for (auto i = m_PlaySPITTypes.begin(); i != m_PlaySPITTypes.end();) {
if (i->second.get()->getIsPlayed() == false) {
i = m_PlaySPITTypes.erase(i);
} else {
+12 -5
View File
@@ -823,7 +823,13 @@ void SPIT_Client::parseReportSPITType(SPIT_Message::ReportSPITType &p_ReportSPIT
ptrSPITType = mSpitTypes.getEntry(p_ReportSPITType.getID());
if (ptrSPITType == nullptr) {
// The user's app my veto the SPITType
if (mCallbacks.onCheckSpitTypeVeto(&p_ReportSPITType) == false) {
bool createdByClient = false;
if (ptrSPITType) {
createdByClient = ptrSPITType->getCreatedByClient();
}
if (mCallbacks.onCheckSpitTypeVeto(false, createdByClient) == false) {
ESP_LOGW(TAG, "TypeVeto %s / %s", p_ReportSPITType.getID().c_str(), p_ReportSPITType.getName().c_str());
return;
}
auto spitType = make_unique<SPITType>(p_ReportSPITType.getID());
@@ -1005,10 +1011,11 @@ void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject &p_Report
}
return;
}
bool isKnownType = ptrSPITType != nullptr;
if (ptrSPITObject == nullptr) {
// The user's app my veto the SPITType
if (mCallbacks.onCheckSpitObjectVeto(&p_ReportSPITObject) == false) {
ESP_LOGD(TAG, "ObjectVeto %s / %s", p_ReportSPITObject.getID().c_str(), p_ReportSPITObject.getName().c_str());
if (mCallbacks.onCheckSpitObjectVeto(isKnownType) == false) {
ESP_LOGW(TAG, "ObjectVeto %s / %s", p_ReportSPITObject.getID().c_str(), p_ReportSPITObject.getName().c_str());
return;
}
auto spitObj = make_unique<SPITObject>(p_ReportSPITObject.getID());
@@ -1017,10 +1024,10 @@ void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject &p_Report
boolNew = true;
} else {
// The user's app my veto the SPITType
if (mCallbacks.onCheckSpitObjectVeto(&p_ReportSPITObject) == false) {
if (mCallbacks.onCheckSpitObjectVeto(isKnownType) == false) {
// SpitObject exists and User APp denied the SPITObject -> remove the SPITObject without sending a message
mSpitObjects.removeEntry(*ptrSPITObject);
ESP_LOGD(TAG, "TypeVeto %s / %s", p_ReportSPITObject.getID().c_str(), p_ReportSPITObject.getName().c_str());
ESP_LOGW(TAG, "TypeVeto %s / %s", p_ReportSPITObject.getID().c_str(), p_ReportSPITObject.getName().c_str());
return;
}
}
+3 -1
View File
@@ -128,7 +128,6 @@ std::vector<char> SPIT_Message::createMessage(OPPart &p_OPPart) {
return {};
}
//----------- Header -----------
SPIT_Message::Header::Header(const Header &orig) {
m_SPITID = &SPITID[0];
@@ -193,6 +192,9 @@ bool SPIT_Message::Header::fillBytes(std::vector<char> &message) {
//----------- OPPart -----------
SPIT_Message::OPPart::~OPPart() {
}
// Receive
SPIT_Message::OPPart::OPPart(unique_ptr<Header> p_Header, int p_OPFlag, int size)
: m_Header(move(p_Header)),