mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 19:13:13 +00:00
Merge branch 'cherry-pick/v1_1_delete_identify' into 'release/v1.1'
components/esp_matter: delete identify when destroy endpoint (backport v1.1) See merge request app-frameworks/esp-matter!878
This commit is contained in:
@@ -29,6 +29,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>
|
||||
@@ -191,6 +192,7 @@ typedef struct _endpoint {
|
||||
EmberAfDeviceType *device_types_ptr;
|
||||
uint16_t parent_endpoint_id;
|
||||
void *priv_data;
|
||||
Identify *identify;
|
||||
struct _endpoint *next;
|
||||
} _endpoint_t;
|
||||
|
||||
@@ -497,6 +499,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;
|
||||
@@ -606,7 +614,7 @@ esp_err_t enable(endpoint_t *endpoint)
|
||||
attribute::get_data_from_attr_val(&attribute->val, &matter_attributes[attribute_index].attributeType,
|
||||
&matter_attributes[attribute_index].size, NULL);
|
||||
|
||||
/* The length is not fixed for string attribute, so set it to the max size (32) to avoid overflow issue
|
||||
/* The length is not fixed for string attribute, so set it to the max size (32) to avoid overflow issue
|
||||
* when writing a longer string.
|
||||
*/
|
||||
if (attribute->val.type == ESP_MATTER_VAL_TYPE_CHAR_STRING) {
|
||||
@@ -1020,8 +1028,8 @@ esp_err_t start(event_callback_t callback, intptr_t callback_arg)
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
esp_err_t err = esp_event_loop_create_default();
|
||||
|
||||
// In case create event loop returns ESP_ERR_INVALID_STATE it is not necessary to fail startup
|
||||
|
||||
// In case create event loop returns ESP_ERR_INVALID_STATE it is not necessary to fail startup
|
||||
// as of it means that default event loop is already initialized and no additional actions should be done.
|
||||
if (err != ESP_OK && err != ESP_ERR_INVALID_STATE) {
|
||||
ESP_LOGE(TAG, "Error create default event loop");
|
||||
@@ -1133,7 +1141,7 @@ attribute_t *create(cluster_t *cluster, uint32_t attribute_id, uint8_t flags, es
|
||||
attribute_updated = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!attribute_updated) {
|
||||
set_val((attribute_t *)attribute, &val);
|
||||
}
|
||||
@@ -2351,6 +2359,23 @@ void *get_priv_data(uint16_t endpoint_id)
|
||||
return current_endpoint->priv_data;
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
@@ -275,6 +275,19 @@ esp_err_t set_parent_endpoint(endpoint_t *endpoint, endpoint_t *parent_endpoint)
|
||||
*/
|
||||
void *get_priv_data(uint16_t endpoint_id);
|
||||
|
||||
/** 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.
|
||||
|
||||
@@ -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, (EmberAfIdentifyIdentifyType)identify_type,
|
||||
effect_cb, static_cast<EmberAfIdentifyEffectIdentifier>(effect_identifier),
|
||||
static_cast<EmberAfIdentifyEffectVariant>(effect_variant));
|
||||
Identify *identify = chip::Platform::New<Identify>(endpoint_id, start_cb, stop_cb, (EmberAfIdentifyIdentifyType)identify_type,
|
||||
effect_cb, static_cast<EmberAfIdentifyEffectIdentifier>(effect_identifier),
|
||||
static_cast<EmberAfIdentifyEffectVariant>(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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user