components/esp_matter: call init callbacks for endpoints created before esp_matter::start

This commit is contained in:
chendejin
2026-03-27 10:34:36 +08:00
parent 5fdbda7880
commit cade5352c4
3 changed files with 14 additions and 2 deletions
@@ -266,7 +266,7 @@ static esp_err_t init_identification(endpoint_t *endpoint)
return ESP_OK; return ESP_OK;
} }
static void invoke_init_callbacks_internal(endpoint_t *endpoint) void invoke_init_callbacks_internal(endpoint_t *endpoint)
{ {
cluster_t *cluster = cluster::get_first(endpoint); cluster_t *cluster = cluster::get_first(endpoint);
while (cluster) { while (cluster) {
@@ -314,7 +314,8 @@ esp_err_t enable(endpoint_t *endpoint)
_endpoint_t *current_endpoint = (_endpoint_t *)endpoint; _endpoint_t *current_endpoint = (_endpoint_t *)endpoint;
current_endpoint->enabled = true; current_endpoint->enabled = true;
init_identification(endpoint); init_identification(endpoint);
{ /* Call the init callbacks for the endpoints which are created after esp_matter::start(). (e.g. for bridged endpoints) */
if (esp_matter::is_started()) {
// Use the lock instead of schedule lambda to ensure the callbacks are invoked before esp_matter::start() returns. // Use the lock instead of schedule lambda to ensure the callbacks are invoked before esp_matter::start() returns.
esp_matter::lock::ScopedChipStackLock lock(portMAX_DELAY); esp_matter::lock::ScopedChipStackLock lock(portMAX_DELAY);
invoke_init_callbacks_internal(endpoint); invoke_init_callbacks_internal(endpoint);
@@ -38,6 +38,11 @@ namespace endpoint {
esp_err_t enable_all(); esp_err_t enable_all();
/** Invoke the init callbacks for the clusters on the endpoint
*
* @param[in] endpoint Endpoint handle.
*/
void invoke_init_callbacks_internal(endpoint_t *endpoint);
} }
namespace attribute { namespace attribute {
@@ -466,6 +466,12 @@ CHIP_ERROR provider::Startup(InteractionModelContext context)
ReturnErrorOnFailure(gDefaultAttributePersistence.Init(&Server::GetInstance().GetPersistentStorage())); ReturnErrorOnFailure(gDefaultAttributePersistence.Init(&Server::GetInstance().GetPersistentStorage()));
SetAttributePersistenceProvider(&gDefaultAttributePersistence); SetAttributePersistenceProvider(&gDefaultAttributePersistence);
} }
/* Call the init callbacks for the endpoints which are created before esp_matter::start() */
endpoint_t *ep = endpoint::get_first(node::get());
while (ep) {
endpoint::invoke_init_callbacks_internal(ep);
ep = endpoint::get_next(ep);
}
return mRegistry.SetContext(ServerClusterContext{ return mRegistry.SetContext(ServerClusterContext{
.provider = *this, .provider = *this,
.storage = Server::GetInstance().GetPersistentStorage(), .storage = Server::GetInstance().GetPersistentStorage(),