Merge branch 'feat/discovery_timeout' into 'main'

Add an API to set Server Init Params

See merge request app-frameworks/esp-matter!1149
This commit is contained in:
Hrishikesh Dhayagude
2025-08-28 18:21:05 +08:00
2 changed files with 46 additions and 4 deletions
+21 -4
View File
@@ -67,6 +67,7 @@ using chip::DeviceLayer::ThreadStackMgr;
static const char *TAG = "esp_matter_core";
static bool esp_matter_started = false;
static chip::CommonCaseDeviceServerInitParams *s_server_init_params = nullptr;
#ifndef CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER
// If Matter Server is disabled, these functions are required by InteractionModelEngine but not linked
@@ -212,12 +213,21 @@ static void deinit_ble_if_commissioned(intptr_t unused)
static void esp_matter_chip_init_task(intptr_t context)
{
TaskHandle_t task_to_notify = reinterpret_cast<TaskHandle_t>(context);
static chip::CommonCaseDeviceServerInitParams initParams;
static chip::CommonCaseDeviceServerInitParams defaultInitParams;
chip::CommonCaseDeviceServerInitParams &initParams =
s_server_init_params ? *s_server_init_params : defaultInitParams;
initParams.InitializeStaticResourcesBeforeServerInit();
initParams.appDelegate = &s_app_delegate;
initParams.testEventTriggerDelegate = test_event_trigger::get_delegate();
initParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate);
if (!initParams.appDelegate) {
initParams.appDelegate = &s_app_delegate;
}
if (!initParams.testEventTriggerDelegate) {
initParams.testEventTriggerDelegate = test_event_trigger::get_delegate();
}
if (!initParams.dataModelProvider) {
initParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate);
}
CHIP_ERROR ret = chip::Server::GetInstance().GetFabricTable().AddFabricDelegate(&s_fabric_delegate);
if (ret != CHIP_NO_ERROR)
@@ -359,6 +369,13 @@ bool is_started()
return esp_matter_started;
}
esp_err_t set_server_init_params(chip::CommonCaseDeviceServerInitParams *server_init_params)
{
VerifyOrReturnError(!esp_matter_started, ESP_ERR_INVALID_STATE, ESP_LOGE(TAG, "esp_matter has started"));
s_server_init_params = server_init_params;
return ESP_OK;
}
esp_err_t start(event_callback_t callback, intptr_t callback_arg)
{
VerifyOrReturnError(!esp_matter_started, ESP_ERR_INVALID_STATE, ESP_LOGE(TAG, "esp_matter has started"));
+25
View File
@@ -23,6 +23,7 @@
#include <app/AttributePathParams.h>
#include <app/CommandPathParams.h>
#include <app/EventPathParams.h>
#include <app/server/Server.h>
using chip::app::ConcreteCommandPath;
using chip::DeviceLayer::ChipDeviceEvent;
@@ -45,6 +46,30 @@ typedef void (*event_callback_t)(const ChipDeviceEvent *event, intptr_t arg);
*/
bool is_started();
/**
* @brief Set the server initialization parameters for Matter.
*
* This function must be called before Matter is started. `esp_matter::start()`
* Calling it after Matter has started will have no effect and will return an error.
*
* @note Starting Matter without valid initialization parameters may lead to undefined behavior or startup failure.
*
* @note The provided pointer is stored internally and used later during Matter initialization.
* It is not copied, so the caller must ensure that the memory pointed to by `server_init_params`
* remains valid and unmodified until Matter is started.
*
* @note If this function is called with a `nullptr`, it will still return ESP_OK. The system
* will proceed with default initialization behavior.
*
* @param[in] server_init_params Pointer to the server initialization parameters. May be nullptr.
*
* @return ESP_OK Successfully set the server initialization parameters.
* @return ESP_ERR_INVALID_STATE If called after Matter has already started.
* @return error in case of failure.
*/
esp_err_t set_server_init_params(chip::CommonCaseDeviceServerInitParams *server_init_params);
/** ESP Matter Start
*
* Initialize and start the matter thread.