Completed destructors for SpanAccessory, SpanService, and SpanCharacteristics

Tested to ensure any combination can be deleted.

To do: must add logic to destruct any PushButtons that were added to a Service
This commit is contained in:
Gregg 2022-05-08 15:27:50 -05:00
parent 05f1204b4f
commit 058d6b0c96
3 changed files with 19 additions and 14 deletions

View File

@ -141,23 +141,14 @@ void HAPClient::init(){
if(!nvs_get_blob(hapNVS,"HAPHASH",NULL,&len)){ // if found HAP HASH structure
nvs_get_blob(hapNVS,"HAPHASH",&homeSpan.hapConfig,&len); // retrieve data
} else {
Serial.print("Resetting Accessory Configuration number...\n");
Serial.print("Resetting Database Hash...\n");
nvs_set_blob(hapNVS,"HAPHASH",&homeSpan.hapConfig,sizeof(homeSpan.hapConfig)); // save data (will default to all zero values, which will then be updated below)
nvs_commit(hapNVS); // commit to NVS
}
Serial.print("\n");
homeSpan.updateConfigNum();
for(int i=0;i<homeSpan.Accessories.size();i++){ // identify all services with over-ridden loop() methods
for(int j=0;j<homeSpan.Accessories[i]->Services.size();j++){
SpanService *s=homeSpan.Accessories[i]->Services[j];
if((void(*)())(s->*(&SpanService::loop)) != (void(*)())(&SpanService::loop)) // save pointers to services in Loops vector
homeSpan.Loops.push_back(s);
}
}
homeSpan.updateConfigNum(); // create Configuration Cumber and Loop vector
}
//////////////////////////////////////

View File

@ -1492,6 +1492,15 @@ boolean Span::updateConfigNum(){
Serial.print("\n\n");
}
Loops.clear();
for(auto acc=Accessories.begin(); acc!=Accessories.end(); acc++){ // identify all services with over-ridden loop() methods
for(auto svc=(*acc)->Services.begin(); svc!=(*acc)->Services.end(); svc++){
if((void(*)())((*svc)->*(&SpanService::loop)) != (void(*)())(&SpanService::loop)) // save pointers to services in Loops vector
homeSpan.Loops.push_back((*svc));
}
}
return(changed);
}
@ -1699,6 +1708,11 @@ SpanCharacteristic::~SpanCharacteristic(){
free(validValues);
free(nvsKey);
if(format==FORMAT::STRING){
free(value.STRING);
free(newValue.STRING);
}
Serial.printf("Deleted Characteristic AID=%d IID=%d\n",aid,iid);
}

View File

@ -315,7 +315,7 @@ struct SpanService{
int sprintfAttributes(char *cBuf, int flags); // prints Service JSON records into buf; return number of characters printed, excluding null terminator
virtual boolean update() {return(true);} // placeholder for code that is called when a Service is updated via a Controller. Must return true/false depending on success of update
virtual void loop(){} // loops for each Service - called every cycle and can be over-ridden with user-defined code
virtual void loop(){} // loops for each Service - called every cycle if over-ridden with user-defined code
virtual void button(int pin, int pressType){} // method called for a Service when a button attached to "pin" has a Single, Double, or Long Press, according to pressType
};