Skip to content

Commit

Permalink
Merge branch 'esp_matter/delete_identify' into 'main'
Browse files Browse the repository at this point in the history
components/esp_matter: delete identify when destroy endpoint

See merge request app-frameworks/esp-matter!826
  • Loading branch information
chshu committed Jul 31, 2024
2 parents 2055db1 + cf72dee commit 28ca743
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
25 changes: 25 additions & 0 deletions components/esp_matter/esp_matter_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <app/clusters/network-commissioning/network-commissioning.h>
#include <app/clusters/general-diagnostics-server/general-diagnostics-server.h>
#include <app/clusters/identify-server/identify-server.h>
#include <app/server/Dnssd.h>
#include <app/server/Server.h>
#include <app/util/attribute-storage.h>
Expand Down Expand Up @@ -204,6 +205,7 @@ typedef struct _endpoint {
EmberAfDeviceType *device_types_ptr;
uint16_t parent_endpoint_id;
void *priv_data;
Identify *identify;
struct _endpoint *next;
} _endpoint_t;

Expand Down Expand Up @@ -516,6 +518,12 @@ static esp_err_t disable(endpoint_t *endpoint)
current_endpoint->device_types_ptr = NULL;
}

/* Delete identify */
if (current_endpoint->identify) {
chip::Platform::Delete(current_endpoint->identify);
current_endpoint->identify = NULL;
}

/* Free endpoint type */
esp_matter_mem_free(endpoint_type);
current_endpoint->endpoint_type = NULL;
Expand Down Expand Up @@ -2205,6 +2213,23 @@ esp_err_t set_priv_data(uint16_t endpoint_id, void *priv_data)
return ESP_OK;
}

esp_err_t set_identify(uint16_t endpoint_id, void *identify)
{
node_t *node = node::get();
if (!node) {
ESP_LOGE(TAG, "Node not found");
return ESP_ERR_INVALID_ARG;
}
endpoint_t *endpoint = get(node, endpoint_id);
if (!endpoint) {
ESP_LOGE(TAG, "Endpoint not found");
return ESP_ERR_INVALID_ARG;
}
_endpoint_t *current_endpoint = (_endpoint_t *)endpoint;
current_endpoint->identify = (Identify *)identify;
return ESP_OK;
}

} /* endpoint */

namespace node {
Expand Down
13 changes: 13 additions & 0 deletions components/esp_matter/esp_matter_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,19 @@ void *get_priv_data(uint16_t endpoint_id);
*/
esp_err_t set_priv_data(uint16_t endpoint_id, void *priv_data);

/** Set identify
*
* Set identify to the endpoint. The identify pointer should be dynamically allocated using 'chip::Platform::New<Identify>()',
* and once Matter stack is done using it, it will be freed by 'chip::Platform::Delete()'.
*
* @param[in] endpoint_id Endpoint id.
* @param[in] identify Identify pointer.
*
* @return ESP_OK on success.
* @return error in case of failure.
*/
esp_err_t set_identify(uint16_t endpoint_id, void *identify);

/** Enable endpoint
*
* Enable the endpoint which has been previously created.
Expand Down
7 changes: 4 additions & 3 deletions components/esp_matter/esp_matter_identify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ static void effect_cb(Identify *identify)

esp_err_t init(uint16_t endpoint_id, uint8_t identify_type, uint8_t effect_identifier, uint8_t effect_variant)
{
Identify *identify = new Identify(endpoint_id, start_cb, stop_cb, (chip::app::Clusters::Identify::IdentifyTypeEnum)identify_type,
effect_cb, static_cast<chip::app::Clusters::Identify::EffectIdentifierEnum>(effect_identifier),
static_cast<chip::app::Clusters::Identify::EffectVariantEnum>(effect_variant));
Identify *identify = chip::Platform::New<Identify>(endpoint_id, start_cb, stop_cb, (chip::app::Clusters::Identify::IdentifyTypeEnum)identify_type,
effect_cb, static_cast<chip::app::Clusters::Identify::EffectIdentifierEnum>(effect_identifier),
static_cast<chip::app::Clusters::Identify::EffectVariantEnum>(effect_variant));
if (!identify) {
ESP_LOGE(TAG, "Fail to create identify object");
return ESP_FAIL;
}
endpoint::set_identify(endpoint_id, (void *)identify);
return ESP_OK;
}

Expand Down

0 comments on commit 28ca743

Please sign in to comment.