mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 19:13:13 +00:00
revert commit c91d9d5a components/esp_matter: resize group data provider when ep count change
This commit is contained in:
@@ -31,7 +31,6 @@
|
||||
#include "credentials/GroupDataProviderImpl.h"
|
||||
|
||||
#define ESP_MATTER_MAX_DEVICE_TYPE_COUNT CONFIG_ESP_MATTER_MAX_DEVICE_TYPE_COUNT
|
||||
#define MAX_GROUPS_PER_FABRIC_PER_ENDPOINT CONFIG_MAX_GROUPS_PER_FABRIC_PER_ENDPOINT
|
||||
|
||||
static const char *TAG = "data_model";
|
||||
|
||||
@@ -291,44 +290,6 @@ static int get_next_index()
|
||||
return 0xFFFF;
|
||||
}
|
||||
|
||||
// global instance so that we can reset it when needed.
|
||||
// We may need to reset it when new endpoint is added or existing endpoint is removed.
|
||||
// This is specifically for bridged device.
|
||||
static chip::Credentials::GroupDataProviderImpl *s_group_data_provider = nullptr;
|
||||
static uint16_t s_groups_server_cluster_count = 0;
|
||||
|
||||
static void resize_group_data_provider()
|
||||
{
|
||||
// don't do anything if the count is the same
|
||||
uint16_t groups_server_cluster_count = node::get_server_cluster_endpoint_count(chip::app::Clusters::Groups::Id);
|
||||
if (s_groups_server_cluster_count == groups_server_cluster_count) {
|
||||
return;
|
||||
}
|
||||
|
||||
s_groups_server_cluster_count = groups_server_cluster_count;
|
||||
uint16_t max_groups_per_fabric = s_groups_server_cluster_count * MAX_GROUPS_PER_FABRIC_PER_ENDPOINT;
|
||||
auto group_data_provider = new (std::nothrow) chip::Credentials::GroupDataProviderImpl(max_groups_per_fabric, CHIP_CONFIG_MAX_GROUP_KEYS_PER_FABRIC);
|
||||
if (!group_data_provider) {
|
||||
ESP_LOGE(TAG, "Failed to allocate memory for group data provider");
|
||||
return;
|
||||
}
|
||||
|
||||
group_data_provider->SetStorageDelegate(&chip::Server::GetInstance().GetPersistentStorage());
|
||||
group_data_provider->SetSessionKeystore(chip::Server::GetInstance().GetSessionKeystore());
|
||||
|
||||
// As we are re-using the persistent storage instance from the Server class instance,
|
||||
// which has all the data from the previous endpoints, so no harm in re-sizing.
|
||||
group_data_provider->Init();
|
||||
|
||||
// delete the old one if it exists
|
||||
if (s_group_data_provider) {
|
||||
delete s_group_data_provider;
|
||||
}
|
||||
|
||||
s_group_data_provider = group_data_provider;
|
||||
chip::Credentials::SetGroupDataProvider(s_group_data_provider);
|
||||
}
|
||||
|
||||
static esp_err_t disable(endpoint_t *endpoint)
|
||||
{
|
||||
/* Take lock if not already taken */
|
||||
@@ -568,9 +529,6 @@ esp_err_t enable(endpoint_t *endpoint)
|
||||
}
|
||||
ESP_LOGI(TAG, "Dynamic endpoint %" PRIu16 " added", current_endpoint->endpoint_id);
|
||||
|
||||
// resize the group data provider to match the new endpoint count
|
||||
resize_group_data_provider();
|
||||
|
||||
return err;
|
||||
|
||||
cleanup:
|
||||
@@ -1566,9 +1524,6 @@ esp_err_t destroy(node_t *node, endpoint_t *endpoint)
|
||||
}
|
||||
esp_matter_mem_free(current_endpoint);
|
||||
|
||||
// resize the group data provider to match the new endpoint count
|
||||
resize_group_data_provider();
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,8 @@ using chip::DeviceLayer::GetDiagnosticDataProvider;
|
||||
using chip::DeviceLayer::ThreadStackMgr;
|
||||
#endif
|
||||
|
||||
#define MAX_GROUPS_PER_FABRIC_PER_ENDPOINT CONFIG_MAX_GROUPS_PER_FABRIC_PER_ENDPOINT
|
||||
|
||||
static const char *TAG = "esp_matter_core";
|
||||
static bool esp_matter_started = false;
|
||||
|
||||
@@ -219,6 +221,20 @@ static void esp_matter_chip_init_task(intptr_t context)
|
||||
initParams.testEventTriggerDelegate = test_event_trigger::get_delegate();
|
||||
initParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate);
|
||||
|
||||
#ifdef CONFIG_ESP_MATTER_ENABLE_DATA_MODEL
|
||||
{
|
||||
// We should reserve one endpoint for root node endpoint
|
||||
uint8_t max_groups_server_cluster_count = CONFIG_ESP_MATTER_MAX_DYNAMIC_ENDPOINT_COUNT - 1;
|
||||
uint16_t max_groups_per_fabric = max_groups_server_cluster_count * MAX_GROUPS_PER_FABRIC_PER_ENDPOINT;
|
||||
static chip::Credentials::GroupDataProviderImpl groupDataProvider(max_groups_per_fabric,
|
||||
CHIP_CONFIG_MAX_GROUP_KEYS_PER_FABRIC);
|
||||
groupDataProvider.SetStorageDelegate(initParams.persistentStorageDelegate);
|
||||
groupDataProvider.SetSessionKeystore(initParams.sessionKeystore);
|
||||
groupDataProvider.Init();
|
||||
initParams.groupDataProvider = &groupDataProvider;
|
||||
}
|
||||
#endif // CONFIG_ESP_MATTER_ENABLE_DATA_MODEL
|
||||
|
||||
CHIP_ERROR ret = chip::Server::GetInstance().GetFabricTable().AddFabricDelegate(&s_fabric_delegate);
|
||||
if (ret != CHIP_NO_ERROR)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user