@@ -555,7 +555,7 @@ attribute_t *create(cluster_t *cluster, uint32_t attribute_id, uint16_t flags, e
555555 return (attribute_t *)attribute;
556556}
557557
558- static esp_err_t destroy (attribute_t *attribute)
558+ static esp_err_t free_attribute (attribute_t *attribute)
559559{
560560 VerifyOrReturnError (attribute, ESP_ERR_INVALID_ARG, ESP_LOGE (TAG, " Attribute cannot be NULL" ));
561561 _attribute_t *current_attribute = (_attribute_t *)attribute;
@@ -587,6 +587,22 @@ static esp_err_t destroy(attribute_t *attribute)
587587 return ESP_OK;
588588}
589589
590+ esp_err_t destroy (cluster_t *cluster, attribute_t *attribute)
591+ {
592+ VerifyOrReturnError (cluster && attribute, ESP_ERR_INVALID_ARG, ESP_LOGE (TAG, " Cluster or attribute cannot be NULL" ));
593+ _cluster_t *current_cluster = (_cluster_t *)cluster;
594+ _attribute_base_t *target_attribute = (_attribute_base_t *)attribute;
595+
596+ _attribute_base_t **current_attribute = ¤t_cluster->attribute_list ;
597+ while (*current_attribute && *current_attribute != target_attribute) {
598+ current_attribute = &(*current_attribute)->next ;
599+ }
600+
601+ VerifyOrReturnError (*current_attribute, ESP_ERR_NOT_FOUND, ESP_LOGE (TAG, " Attribute not found in the cluster" ));
602+ *current_attribute = target_attribute->next ;
603+ return free_attribute (attribute);
604+ }
605+
590606attribute_t *get (cluster_t *cluster, uint32_t attribute_id)
591607{
592608 VerifyOrReturnValue (cluster, NULL , ESP_LOGE (TAG, " Cluster cannot be NULL." ));
@@ -1179,6 +1195,15 @@ command_t *create(cluster_t *cluster, uint32_t command_id, uint8_t flags, callba
11791195 return (command_t *)command;
11801196}
11811197
1198+ esp_err_t destroy (cluster_t *cluster, command_t *command)
1199+ {
1200+ VerifyOrReturnError (cluster && command, ESP_ERR_INVALID_ARG, ESP_LOGE (TAG, " Cluster or command cannot be NULL" ));
1201+ _cluster_t *current_cluster = (_cluster_t *)cluster;
1202+ _command_t *current_command = (_command_t *)command;
1203+ SinglyLinkedList<_command_t >::remove (¤t_cluster->command_list , current_command);
1204+ return ESP_OK;
1205+ }
1206+
11821207command_t *get (uint16_t endpoint_id, uint32_t cluster_id, uint32_t command_id)
11831208{
11841209 _cluster_t *current_cluster = (_cluster_t *)cluster::get (endpoint_id, cluster_id);
@@ -1287,6 +1312,15 @@ event_t *create(cluster_t *cluster, uint32_t event_id)
12871312 return (event_t *)event;
12881313}
12891314
1315+ esp_err_t destroy (cluster_t *cluster, event_t *event)
1316+ {
1317+ VerifyOrReturnError (cluster && event, ESP_ERR_INVALID_ARG, ESP_LOGE (TAG, " Cluster or event cannot be NULL" ));
1318+ _cluster_t *current_cluster = (_cluster_t *)cluster;
1319+ _event_t *current_event = (_event_t *)event;
1320+ SinglyLinkedList<_event_t >::remove (¤t_cluster->event_list , current_event);
1321+ return ESP_OK;
1322+ }
1323+
12901324event_t *get (cluster_t *cluster, uint32_t event_id)
12911325{
12921326 VerifyOrReturnValue (cluster, NULL , ESP_LOGE (TAG, " Cluster cannot be NULL." ));
@@ -1377,7 +1411,7 @@ esp_err_t destroy(cluster_t *cluster)
13771411 _attribute_base_t *attribute = current_cluster->attribute_list ;
13781412 while (attribute) {
13791413 _attribute_base_t *next_attribute = attribute->next ;
1380- attribute::destroy ((attribute_t *)attribute);
1414+ attribute::free_attribute ((attribute_t *)attribute);
13811415 attribute = next_attribute;
13821416 }
13831417
0 commit comments