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:
parent
05f1204b4f
commit
058d6b0c96
13
src/HAP.cpp
13
src/HAP.cpp
|
|
@ -141,23 +141,14 @@ void HAPClient::init(){
|
||||||
if(!nvs_get_blob(hapNVS,"HAPHASH",NULL,&len)){ // if found HAP HASH structure
|
if(!nvs_get_blob(hapNVS,"HAPHASH",NULL,&len)){ // if found HAP HASH structure
|
||||||
nvs_get_blob(hapNVS,"HAPHASH",&homeSpan.hapConfig,&len); // retrieve data
|
nvs_get_blob(hapNVS,"HAPHASH",&homeSpan.hapConfig,&len); // retrieve data
|
||||||
} else {
|
} 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_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
|
nvs_commit(hapNVS); // commit to NVS
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.print("\n");
|
Serial.print("\n");
|
||||||
|
|
||||||
homeSpan.updateConfigNum();
|
homeSpan.updateConfigNum(); // create Configuration Cumber and Loop vector
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
|
|
||||||
|
|
@ -1492,6 +1492,15 @@ boolean Span::updateConfigNum(){
|
||||||
Serial.print("\n\n");
|
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);
|
return(changed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1574,7 +1583,7 @@ SpanService::SpanService(const char *type, const char *hapName, boolean isCustom
|
||||||
|
|
||||||
homeSpan.Accessories.back()->Services.push_back(this);
|
homeSpan.Accessories.back()->Services.push_back(this);
|
||||||
accessory=homeSpan.Accessories.back();
|
accessory=homeSpan.Accessories.back();
|
||||||
iid=++(homeSpan.Accessories.back()->iidCount);
|
iid=++(homeSpan.Accessories.back()->iidCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
@ -1595,7 +1604,7 @@ SpanService::~SpanService(){
|
||||||
homeSpan.Loops.erase(svc);
|
homeSpan.Loops.erase(svc);
|
||||||
Serial.printf("Deleted Loop Entry\n");
|
Serial.printf("Deleted Loop Entry\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.printf("Deleted Service AID=%d IID=%d\n",accessory->aid,iid);
|
Serial.printf("Deleted Service AID=%d IID=%d\n",accessory->aid,iid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1698,6 +1707,11 @@ SpanCharacteristic::~SpanCharacteristic(){
|
||||||
free(unit);
|
free(unit);
|
||||||
free(validValues);
|
free(validValues);
|
||||||
free(nvsKey);
|
free(nvsKey);
|
||||||
|
|
||||||
|
if(format==FORMAT::STRING){
|
||||||
|
free(value.STRING);
|
||||||
|
free(newValue.STRING);
|
||||||
|
}
|
||||||
|
|
||||||
Serial.printf("Deleted Characteristic AID=%d IID=%d\n",aid,iid);
|
Serial.printf("Deleted Characteristic AID=%d IID=%d\n",aid,iid);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
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 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
|
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
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue