Continuing destructor code...

This commit is contained in:
Gregg 2022-05-08 11:56:26 -05:00
parent 554cefd3ce
commit 05f1204b4f
2 changed files with 26 additions and 3 deletions

View File

@ -1581,13 +1581,17 @@ SpanService::SpanService(const char *type, const char *hapName, boolean isCustom
SpanService::~SpanService(){
while(Characteristics.rbegin()!=Characteristics.rend()) // delete all Characteristics in this Service
delete *Characteristics.rbegin();
auto svc=accessory->Services.begin(); // find Service in containing Accessory vector and erase entry
while((*svc)!=this)
svc++;
accessory->Services.erase(svc);
for(svc=homeSpan.Loops.begin(); (*svc)!=this && svc!=homeSpan.Loops.end(); svc++); // find and erase entry in Loop vector
if(svc!=homeSpan.Loops.end()){
for(svc=homeSpan.Loops.begin(); svc!=homeSpan.Loops.end() && (*svc)!=this; svc++); // search for entry in Loop vector...
if(svc!=homeSpan.Loops.end()){ // ...if it exists, erase it
homeSpan.Loops.erase(svc);
Serial.printf("Deleted Loop Entry\n");
}
@ -1682,6 +1686,24 @@ SpanCharacteristic::SpanCharacteristic(HapChar *hapChar, boolean isCustom){
///////////////////////////////
SpanCharacteristic::~SpanCharacteristic(){
auto chr=service->Characteristics.begin(); // find Characteristic in containing Service vector and erase entry
while((*chr)!=this)
chr++;
service->Characteristics.erase(chr);
free(ev);
free(desc);
free(unit);
free(validValues);
free(nvsKey);
Serial.printf("Deleted Characteristic AID=%d IID=%d\n",aid,iid);
}
///////////////////////////////
int SpanCharacteristic::sprintfAttributes(char *cBuf, int flags){
int nBytes=0;

View File

@ -282,7 +282,7 @@ struct SpanAccessory{
int iidCount=0; // running count of iid to use for Services and Characteristics associated with this Accessory
vector<SpanService *> Services; // vector of pointers to all Services in this Accessory
SpanAccessory(uint32_t aid=0);
SpanAccessory(uint32_t aid=0); // constructor
~SpanAccessory();
int sprintfAttributes(char *cBuf, int flags); // prints Accessory JSON database into buf, unless buf=NULL; return number of characters printed, excluding null terminator, even if buf=NULL
@ -362,6 +362,7 @@ struct SpanCharacteristic{
SpanService *service=NULL; // pointer to Service containing this Characteristic
SpanCharacteristic(HapChar *hapChar, boolean isCustom=false); // contructor
~SpanCharacteristic();
int sprintfAttributes(char *cBuf, int flags); // prints Characteristic JSON records into buf, according to flags mask; return number of characters printed, excluding null terminator
StatusCode loadUpdate(char *val, char *ev); // load updated val/ev from PUT /characteristic JSON request. Return intiial HAP status code (checks to see if characteristic is found, is writable, etc.)