mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 19:13:13 +00:00
Merge branch 'fix_endpoint_enable' into 'main'
components/esp_matter: call init function in endpoint::enable See merge request app-frameworks/esp-matter!1421
This commit is contained in:
@@ -122,27 +122,6 @@ cluster_t * ABORT_CLUSTER_CREATE(cluster_t *cluster)
|
||||
}
|
||||
} // anonymous namespace
|
||||
|
||||
void plugin_init_callback_common()
|
||||
{
|
||||
ESP_LOGI(TAG, "Cluster plugin init common callback");
|
||||
node_t *node = node::get();
|
||||
/* Skip plugin_init_callback_common when ESP Matter data model is not used */
|
||||
VerifyOrReturn(node);
|
||||
endpoint_t *endpoint = endpoint::get_first(node);
|
||||
while (endpoint) {
|
||||
cluster_t *cluster = get_first(endpoint);
|
||||
while (cluster) {
|
||||
/* Plugin server init callback */
|
||||
plugin_server_init_callback_t plugin_server_init_callback = get_plugin_server_init_callback(cluster);
|
||||
if (plugin_server_init_callback) {
|
||||
plugin_server_init_callback();
|
||||
}
|
||||
cluster = get_next(cluster);
|
||||
}
|
||||
endpoint = endpoint::get_next(endpoint);
|
||||
}
|
||||
}
|
||||
|
||||
void delegate_init_callback_common(endpoint_t *endpoint)
|
||||
{
|
||||
uint16_t endpoint_id = endpoint::get_id(endpoint);
|
||||
@@ -157,24 +136,6 @@ void delegate_init_callback_common(endpoint_t *endpoint)
|
||||
}
|
||||
}
|
||||
|
||||
void add_bounds_callback_common()
|
||||
{
|
||||
node_t *node = node::get();
|
||||
VerifyOrReturn(node);
|
||||
endpoint_t *endpoint = endpoint::get_first(node);
|
||||
while (endpoint) {
|
||||
cluster_t *cluster = get_first(endpoint);
|
||||
while (cluster) {
|
||||
add_bounds_callback_t add_bounds_callback = get_add_bounds_callback(cluster);
|
||||
if (add_bounds_callback) {
|
||||
add_bounds_callback(cluster);
|
||||
}
|
||||
cluster = get_next(cluster);
|
||||
}
|
||||
endpoint = endpoint::get_next(endpoint);
|
||||
}
|
||||
}
|
||||
|
||||
cluster_t *create_default_binding_cluster(endpoint_t *endpoint)
|
||||
{
|
||||
/* Don't create binding cluster if it already exists on the endpoint */
|
||||
|
||||
@@ -26,21 +26,6 @@
|
||||
namespace esp_matter {
|
||||
namespace cluster {
|
||||
|
||||
/** Common cluster plugin init callback
|
||||
*
|
||||
* This is the common plugin init callback which calls the plugin init callbacks in the clusters.
|
||||
*
|
||||
* This common API has been added so that the specific APIs in zap-generated/PluginApplicationCallbacks.h can be
|
||||
* removed.
|
||||
*/
|
||||
void plugin_init_callback_common();
|
||||
|
||||
/** Common cluster add bounds callback
|
||||
*
|
||||
* This is the common add bounds callback which set the bounds to all the attributes of the clusters.
|
||||
*/
|
||||
void add_bounds_callback_common();
|
||||
|
||||
/** Specific cluster create APIs
|
||||
*
|
||||
* These APIs also create the mandatory attributes and commands for the cluster. If the mandatory attribute is not
|
||||
|
||||
@@ -248,6 +248,36 @@ esp_err_t enable(endpoint_t *endpoint)
|
||||
current_endpoint->enabled = true;
|
||||
init_identification(endpoint);
|
||||
esp_matter::cluster::delegate_init_callback_common(endpoint);
|
||||
chip::DeviceLayer::SystemLayer().ScheduleLambda([endpoint] {
|
||||
cluster_t *cluster = cluster::get_first(endpoint);
|
||||
while (cluster) {
|
||||
/* Add bounds callback */
|
||||
cluster::add_bounds_callback_t add_bounds_callback = cluster::get_add_bounds_callback(cluster);
|
||||
if (add_bounds_callback) {
|
||||
add_bounds_callback(cluster);
|
||||
}
|
||||
/* Plugin server init callback */
|
||||
cluster::plugin_server_init_callback_t plugin_server_init_callback =
|
||||
cluster::get_plugin_server_init_callback(cluster);
|
||||
if (plugin_server_init_callback) {
|
||||
plugin_server_init_callback();
|
||||
}
|
||||
/* Initialization callback */
|
||||
uint8_t flags = cluster::get_flags(cluster);
|
||||
cluster::initialization_callback_t init_callback = cluster::get_init_callback(cluster);
|
||||
if (init_callback) {
|
||||
init_callback(endpoint::get_id(endpoint));
|
||||
}
|
||||
if ((flags & CLUSTER_FLAG_SERVER) && (flags & CLUSTER_FLAG_INIT_FUNCTION)) {
|
||||
cluster::function_cluster_init_t init_function =
|
||||
(cluster::function_cluster_init_t)cluster::get_function(cluster, CLUSTER_FLAG_INIT_FUNCTION);
|
||||
if (init_function) {
|
||||
init_function(endpoint::get_id(endpoint));
|
||||
}
|
||||
}
|
||||
cluster = cluster::get_next(cluster);
|
||||
}
|
||||
});
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -256,28 +256,6 @@ CHIP_ERROR provider::Startup(InteractionModelContext context)
|
||||
{
|
||||
ReturnErrorOnFailure(DataModel::Provider::Startup(context));
|
||||
mContext.emplace(context);
|
||||
esp_matter::cluster::add_bounds_callback_common();
|
||||
esp_matter::cluster::plugin_init_callback_common();
|
||||
endpoint_t *ep = endpoint::get_first(node::get());
|
||||
while (ep) {
|
||||
cluster_t *cluster = cluster::get_first(ep);
|
||||
while (cluster) {
|
||||
uint8_t flags = cluster::get_flags(cluster);
|
||||
cluster::initialization_callback_t init_callback = cluster::get_init_callback(cluster);
|
||||
if (init_callback) {
|
||||
init_callback(endpoint::get_id(ep));
|
||||
}
|
||||
if ((flags & CLUSTER_FLAG_SERVER) && (flags & CLUSTER_FLAG_INIT_FUNCTION)) {
|
||||
cluster::function_cluster_init_t init_function =
|
||||
(cluster::function_cluster_init_t)cluster::get_function(cluster, CLUSTER_FLAG_INIT_FUNCTION);
|
||||
if (init_function) {
|
||||
init_function(endpoint::get_id(ep));
|
||||
}
|
||||
}
|
||||
cluster = cluster::get_next(cluster);
|
||||
}
|
||||
ep = endpoint::get_next(ep);
|
||||
}
|
||||
if (GetAttributePersistenceProvider() == nullptr) {
|
||||
ReturnErrorOnFailure(gDefaultAttributePersistence.Init(&Server::GetInstance().GetPersistentStorage()));
|
||||
SetAttributePersistenceProvider(&gDefaultAttributePersistence);
|
||||
|
||||
@@ -245,33 +245,6 @@ static esp_err_t plugin_init_callback_endpoint(endpoint_t *endpoint)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t cluster_server_init(endpoint_t *endpoint)
|
||||
{
|
||||
if (!endpoint) {
|
||||
ESP_LOGE(TAG, "endpoint cannot be NULL");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ESP_LOGI(TAG, "Cluster server init for the new added endpoint");
|
||||
lock::ScopedChipStackLock lock(portMAX_DELAY);
|
||||
cluster_t *cluster = cluster::get_first(endpoint);
|
||||
while (cluster) {
|
||||
uint8_t flags = cluster::get_flags(cluster);
|
||||
cluster::initialization_callback_t init_callback = cluster::get_init_callback(cluster);
|
||||
if (init_callback) {
|
||||
init_callback(endpoint::get_id(endpoint));
|
||||
}
|
||||
if ((flags & CLUSTER_FLAG_SERVER) && (flags & CLUSTER_FLAG_INIT_FUNCTION)) {
|
||||
cluster::function_cluster_init_t init_function =
|
||||
(cluster::function_cluster_init_t)cluster::get_function(cluster, CLUSTER_FLAG_INIT_FUNCTION);
|
||||
if (init_function) {
|
||||
init_function(endpoint::get_id(endpoint));
|
||||
}
|
||||
}
|
||||
cluster = cluster::get_next(cluster);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static bridge_device_type_callback_t device_type_callback;
|
||||
|
||||
esp_err_t set_device_type(device_t *bridged_device, uint32_t device_type_id, void *priv_data)
|
||||
@@ -285,9 +258,6 @@ esp_err_t set_device_type(device_t *bridged_device, uint32_t device_type_id, voi
|
||||
err = device_type_callback(bridged_device->endpoint, device_type_id, priv_data);
|
||||
if (err != ESP_OK)
|
||||
return err;
|
||||
|
||||
cluster_server_init(bridged_device->endpoint);
|
||||
|
||||
return plugin_init_callback_endpoint(bridged_device->endpoint);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user