Added logic to delete PushButtons when Service is deleted

This completes all code for the ~SpanService() destructor.

To do: create tutorial example demonstrating a Dynamic Bridge
This commit is contained in:
Gregg 2022-05-09 21:27:18 -05:00
parent dc11c59a00
commit d326ae1abf
1 changed files with 12 additions and 2 deletions

View File

@ -1588,12 +1588,22 @@ SpanService::~SpanService(){
accessory->Services.erase(svc); accessory->Services.erase(svc);
for(svc=homeSpan.Loops.begin(); svc!=homeSpan.Loops.end() && (*svc)!=this; svc++); // search for entry in Loop vector... 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 if(svc!=homeSpan.Loops.end()){ // ...if it exists, erase it
homeSpan.Loops.erase(svc); homeSpan.Loops.erase(svc);
LOG1("Deleted Loop Entry\n"); LOG1("Deleted Loop Entry\n");
} }
auto pb=homeSpan.PushButtons.begin(); // loop through PushButton vector and delete ALL PushButtons associated with this Service
while(pb!=homeSpan.PushButtons.end()){
if((*pb)->service==this){
pb=homeSpan.PushButtons.erase(pb);
LOG1("Deleted PushButton on Pin=%d\n",(*pb)->pin);
}
else {
pb++;
}
}
LOG1("Deleted Service AID=%d IID=%d\n",accessory->aid,iid); LOG1("Deleted Service AID=%d IID=%d\n",accessory->aid,iid);
} }