Skip to content

Commit b92d52a

Browse files
committed
Merge branch 'use-id-based-getter' into 'main'
Use id based getter APIs to get endpoint, cluster, and attribute handle See merge request app-frameworks/esp-matter!1012
2 parents 68a489b + 9d11f25 commit b92d52a

File tree

7 files changed

+29
-68
lines changed

7 files changed

+29
-68
lines changed

components/esp_matter/esp_matter_attribute_utils.cpp

+5-14
Original file line numberDiff line numberDiff line change
@@ -2104,10 +2104,7 @@ esp_err_t report(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_i
21042104
VerifyOrReturnError(lock_status != lock::FAILED, ESP_FAIL, ESP_LOGE(TAG, "Could not get task context"));
21052105

21062106
/* Get attribute */
2107-
node_t *node = node::get();
2108-
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
2109-
cluster_t *cluster = cluster::get(endpoint, cluster_id);
2110-
attribute_t *attribute = attribute::get(cluster, attribute_id);
2107+
attribute_t *attribute = attribute::get(endpoint_id, cluster_id, attribute_id);
21112108
if (!attribute) {
21122109
ESP_LOGE(TAG, "Could not find Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32, endpoint_id, cluster_id,
21132110
attribute_id);
@@ -2183,11 +2180,8 @@ Status emberAfExternalAttributeReadCallback(EndpointId endpoint_id, ClusterId cl
21832180
{
21842181
/* Get value */
21852182
uint32_t attribute_id = matter_attribute->attributeId;
2186-
node_t *node = node::get();
2187-
VerifyOrReturnError(node, Status::Failure);
2188-
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
2189-
cluster_t *cluster = cluster::get(endpoint, cluster_id);
2190-
attribute_t *attribute = attribute::get(cluster, attribute_id);
2183+
attribute_t *attribute = attribute::get(endpoint_id, cluster_id, attribute_id);
2184+
VerifyOrReturnError(attribute, Status::Failure);
21912185
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
21922186

21932187
int flags = attribute::get_flags(attribute);
@@ -2218,11 +2212,8 @@ Status emberAfExternalAttributeWriteCallback(EndpointId endpoint_id, ClusterId c
22182212
{
22192213
/* Get value */
22202214
uint32_t attribute_id = matter_attribute->attributeId;
2221-
node_t *node = node::get();
2222-
VerifyOrReturnError(node, Status::Failure);
2223-
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
2224-
cluster_t *cluster = cluster::get(endpoint, cluster_id);
2225-
attribute_t *attribute = attribute::get(cluster, attribute_id);
2215+
attribute_t *attribute = attribute::get(endpoint_id, cluster_id, attribute_id);
2216+
VerifyOrReturnError(attribute, Status::Failure);
22262217

22272218
/* Get val */
22282219
/* This creates a new variable val, and stores the new attribute value in the new variable.

components/esp_matter/esp_matter_core.cpp

+3-12
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,6 @@ static int get_next_index()
414414

415415
static esp_err_t disable(endpoint_t *endpoint)
416416
{
417-
VerifyOrReturnError(endpoint, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Endpoint cannot be NULL"));
418-
419417
/* Take lock if not already taken */
420418
lock::status_t lock_status = lock::chip_stack_lock(portMAX_DELAY);
421419

@@ -1912,20 +1910,15 @@ esp_err_t set_parent_endpoint(endpoint_t *endpoint, endpoint_t *parent_endpoint)
19121910

19131911
void *get_priv_data(uint16_t endpoint_id)
19141912
{
1915-
node_t *node = node::get();
1916-
/* This is not an error, since the node will not be initialized for application using the data model from zap */
1917-
VerifyOrReturnValue(node, NULL, ESP_LOGE(TAG, "Node not found"));
1918-
endpoint_t *endpoint = get(node, endpoint_id);
1913+
endpoint_t *endpoint = get(endpoint_id);
19191914
VerifyOrReturnValue(endpoint, NULL, ESP_LOGE(TAG, "Endpoint not found"));
19201915
_endpoint_t *current_endpoint = (_endpoint_t *)endpoint;
19211916
return current_endpoint->priv_data;
19221917
}
19231918

19241919
esp_err_t set_priv_data(uint16_t endpoint_id, void *priv_data)
19251920
{
1926-
node_t *node = node::get();
1927-
VerifyOrReturnError(node, ESP_ERR_INVALID_STATE, ESP_LOGE(TAG, "Node is not initialized"));
1928-
endpoint_t *endpoint = get(node, endpoint_id);
1921+
endpoint_t *endpoint = get(endpoint_id);
19291922
VerifyOrReturnError(endpoint, ESP_ERR_NOT_FOUND, ESP_LOGE(TAG, "Endpoint not found"));
19301923
_endpoint_t *current_endpoint = (_endpoint_t *)endpoint;
19311924
current_endpoint->priv_data = priv_data;
@@ -1934,9 +1927,7 @@ esp_err_t set_priv_data(uint16_t endpoint_id, void *priv_data)
19341927

19351928
esp_err_t set_identify(uint16_t endpoint_id, void *identify)
19361929
{
1937-
node_t *node = node::get();
1938-
VerifyOrReturnError(node, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Node not found"));
1939-
endpoint_t *endpoint = get(node, endpoint_id);
1930+
endpoint_t *endpoint = get(endpoint_id);
19401931
VerifyOrReturnError(endpoint, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Endpoint not found"));
19411932
_endpoint_t *current_endpoint = (_endpoint_t *)endpoint;
19421933
current_endpoint->identify = (Identify *)identify;

components/esp_matter/esp_matter_delegate_callbacks.cpp

+4-11
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,8 @@ namespace cluster {
4848

4949
static uint32_t get_feature_map_value(uint16_t endpoint_id, uint32_t cluster_id)
5050
{
51-
node_t *node = node::get();
52-
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
53-
cluster_t *cluster = cluster::get(endpoint, cluster_id);
5451
uint32_t attribute_id = Globals::Attributes::FeatureMap::Id;
55-
attribute_t *attribute = attribute::get(cluster, attribute_id);
52+
attribute_t *attribute = attribute::get(endpoint_id, cluster_id, attribute_id);
5653

5754
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
5855
attribute::get_val(attribute, &val);
@@ -130,11 +127,9 @@ void EnergyEvseDelegateInitCB(void *delegate, uint16_t endpoint_id)
130127
void MicrowaveOvenControlDelegateInitCB(void *delegate, uint16_t endpoint_id)
131128
{
132129
// Get delegates of MicrowaveOvenMode and OperationalState clusters.
133-
node_t *node = node::get();
134-
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
135-
cluster_t *cluster = cluster::get(endpoint, MicrowaveOvenMode::Id);
130+
cluster_t *cluster = cluster::get(endpoint_id, MicrowaveOvenMode::Id);
136131
ModeBase::Delegate *microwave_oven_mode_delegate = static_cast<ModeBase::Delegate*>(get_delegate_impl(cluster));
137-
cluster = cluster::get(endpoint, OperationalState::Id);
132+
cluster = cluster::get(endpoint_id, OperationalState::Id);
138133
OperationalState::Delegate *operational_state_delegate = static_cast<OperationalState::Delegate*>(get_delegate_impl(cluster));
139134
VerifyOrReturn(delegate != nullptr && microwave_oven_mode_delegate != nullptr && operational_state_delegate != nullptr);
140135
// Create instances of clusters.
@@ -304,10 +299,8 @@ void ModeSelectDelegateInitCB(void *delegate, uint16_t endpoint_id)
304299
void ThreadBorderRouterManagementDelegateInitCB(void *delegate, uint16_t endpoint_id)
305300
{
306301
assert(delegate != nullptr);
307-
esp_matter::cluster_t *cluster = esp_matter::cluster::get(endpoint_id, ThreadBorderRouterManagement::Id);
308-
assert(cluster != nullptr);
309302
/* Get the attribute */
310-
attribute_t *attribute = attribute::get(cluster, Globals::Attributes::FeatureMap::Id);
303+
attribute_t *attribute = attribute::get(endpoint_id, ThreadBorderRouterManagement::Id, Globals::Attributes::FeatureMap::Id);
311304
assert(attribute != nullptr);
312305
/* Update the value if the attribute already exists */
313306
esp_matter_attr_val_t val = esp_matter_invalid(NULL);

components/esp_matter_rainmaker/esp_matter_rainmaker.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,7 @@ static esp_err_t sign_data_command_callback(const ConcreteCommandPath &command_p
363363
static esp_err_t custom_cluster_create()
364364
{
365365
/* Get the endpoint */
366-
node_t *node = node::get();
367-
endpoint_t *endpoint = endpoint::get(node, cluster::rainmaker::endpoint_id);
366+
endpoint_t *endpoint = endpoint::get(cluster::rainmaker::endpoint_id);
368367

369368
/* Create custom rainmaker cluster */
370369
cluster_t *cluster = esp_matter::cluster::create(endpoint, cluster::rainmaker::Id, CLUSTER_FLAG_SERVER);

examples/light/main/app_main.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,14 @@ extern "C" void app_main()
180180
ESP_LOGI(TAG, "Light created with endpoint_id %d", light_endpoint_id);
181181

182182
/* Mark deferred persistence for some attributes that might be changed rapidly */
183-
cluster_t *level_control_cluster = cluster::get(endpoint, LevelControl::Id);
184-
attribute_t *current_level_attribute = attribute::get(level_control_cluster, LevelControl::Attributes::CurrentLevel::Id);
183+
attribute_t *current_level_attribute = attribute::get(light_endpoint_id, LevelControl::Id, LevelControl::Attributes::CurrentLevel::Id);
185184
attribute::set_deferred_persistence(current_level_attribute);
186185

187-
cluster_t *color_control_cluster = cluster::get(endpoint, ColorControl::Id);
188-
attribute_t *current_x_attribute = attribute::get(color_control_cluster, ColorControl::Attributes::CurrentX::Id);
186+
attribute_t *current_x_attribute = attribute::get(light_endpoint_id, ColorControl::Id, ColorControl::Attributes::CurrentX::Id);
189187
attribute::set_deferred_persistence(current_x_attribute);
190-
attribute_t *current_y_attribute = attribute::get(color_control_cluster, ColorControl::Attributes::CurrentY::Id);
188+
attribute_t *current_y_attribute = attribute::get(light_endpoint_id, ColorControl::Id, ColorControl::Attributes::CurrentY::Id);
191189
attribute::set_deferred_persistence(current_y_attribute);
192-
attribute_t *color_temp_attribute = attribute::get(color_control_cluster, ColorControl::Attributes::ColorTemperatureMireds::Id);
190+
attribute_t *color_temp_attribute = attribute::get(light_endpoint_id, ColorControl::Id, ColorControl::Attributes::ColorTemperatureMireds::Id);
193191
attribute::set_deferred_persistence(color_temp_attribute);
194192

195193
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION

examples/light_wifi_prov/main/app_driver.cpp

+8-17
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,7 @@ static void app_driver_button_toggle_cb(void *arg, void *data)
9696
uint32_t cluster_id = OnOff::Id;
9797
uint32_t attribute_id = OnOff::Attributes::OnOff::Id;
9898

99-
node_t *node = node::get();
100-
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
101-
cluster_t *cluster = cluster::get(endpoint, cluster_id);
102-
attribute_t *attribute = attribute::get(cluster, attribute_id);
99+
attribute_t *attribute = attribute::get(endpoint_id, cluster_id, attribute_id);
103100

104101
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
105102
attribute::get_val(attribute, &val);
@@ -139,43 +136,37 @@ esp_err_t app_driver_light_set_defaults(uint16_t endpoint_id)
139136
esp_err_t err = ESP_OK;
140137
void *priv_data = endpoint::get_priv_data(endpoint_id);
141138
led_indicator_handle_t handle = (led_indicator_handle_t)priv_data;
142-
node_t *node = node::get();
143-
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
144-
cluster_t *cluster = NULL;
145139
attribute_t *attribute = NULL;
146140
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
147141

148142
/* Setting brightness */
149-
cluster = cluster::get(endpoint, LevelControl::Id);
150-
attribute = attribute::get(cluster, LevelControl::Attributes::CurrentLevel::Id);
143+
attribute = attribute::get(endpoint_id, LevelControl::Id, LevelControl::Attributes::CurrentLevel::Id);
151144
attribute::get_val(attribute, &val);
152145
err |= app_driver_light_set_brightness(handle, &val);
153146

154147
/* Setting color */
155-
cluster = cluster::get(endpoint, ColorControl::Id);
156-
attribute = attribute::get(cluster, ColorControl::Attributes::ColorMode::Id);
148+
attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::ColorMode::Id);
157149
attribute::get_val(attribute, &val);
158150
if (val.val.u8 == (uint8_t)ColorControl::ColorMode::kCurrentHueAndCurrentSaturation) {
159151
/* Setting hue */
160-
attribute = attribute::get(cluster, ColorControl::Attributes::CurrentHue::Id);
152+
attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::CurrentHue::Id);
161153
attribute::get_val(attribute, &val);
162154
err |= app_driver_light_set_hue(handle, &val);
163155
/* Setting saturation */
164-
attribute = attribute::get(cluster, ColorControl::Attributes::CurrentSaturation::Id);
156+
attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::CurrentSaturation::Id);
165157
attribute::get_val(attribute, &val);
166158
err |= app_driver_light_set_saturation(handle, &val);
167159
} else if (val.val.u8 == (uint8_t)ColorControl::ColorMode::kColorTemperature) {
168160
/* Setting temperature */
169-
attribute = attribute::get(cluster, ColorControl::Attributes::ColorTemperatureMireds::Id);
161+
attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::ColorTemperatureMireds::Id);
170162
attribute::get_val(attribute, &val);
171163
err |= app_driver_light_set_temperature(handle, &val);
172164
} else {
173165
ESP_LOGE(TAG, "Color mode not supported");
174166
}
175167

176168
/* Setting power */
177-
cluster = cluster::get(endpoint, OnOff::Id);
178-
attribute = attribute::get(cluster, OnOff::Attributes::OnOff::Id);
169+
attribute = attribute::get(endpoint_id, OnOff::Id, OnOff::Attributes::OnOff::Id);
179170
attribute::get_val(attribute, &val);
180171
err |= app_driver_light_set_power(handle, &val);
181172

@@ -189,7 +180,7 @@ app_driver_handle_t app_driver_light_init()
189180
led_indicator_handle_t leds[CONFIG_BSP_LEDS_NUM];
190181
ESP_ERROR_CHECK(bsp_led_indicator_create(leds, NULL, CONFIG_BSP_LEDS_NUM));
191182
led_indicator_set_hsv(leds[0], SET_HSV(DEFAULT_HUE, DEFAULT_SATURATION, DEFAULT_BRIGHTNESS));
192-
183+
193184
return (app_driver_handle_t)leds[0];
194185
#else
195186
return NULL;

examples/light_wifi_prov/main/app_main.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,16 @@ extern "C" void app_main()
240240
ESP_LOGI(TAG, "Light created with endpoint_id %d", light_endpoint_id);
241241

242242
/* Mark deferred persistence for some attributes that might be changed rapidly */
243-
cluster_t *level_control_cluster = cluster::get(endpoint, LevelControl::Id);
244243
attribute_t *current_level_attribute =
245-
attribute::get(level_control_cluster, LevelControl::Attributes::CurrentLevel::Id);
244+
attribute::get(light_endpoint_id, LevelControl::Id, LevelControl::Attributes::CurrentLevel::Id);
246245
attribute::set_deferred_persistence(current_level_attribute);
247246

248-
cluster_t *color_control_cluster = cluster::get(endpoint, ColorControl::Id);
249-
attribute_t *current_x_attribute = attribute::get(color_control_cluster, ColorControl::Attributes::CurrentX::Id);
247+
attribute_t *current_x_attribute = attribute::get(light_endpoint_id, ColorControl::Id, ColorControl::Attributes::CurrentX::Id);
250248
attribute::set_deferred_persistence(current_x_attribute);
251-
attribute_t *current_y_attribute = attribute::get(color_control_cluster, ColorControl::Attributes::CurrentY::Id);
249+
attribute_t *current_y_attribute = attribute::get(light_endpoint_id, ColorControl::Id, ColorControl::Attributes::CurrentY::Id);
252250
attribute::set_deferred_persistence(current_y_attribute);
253251
attribute_t *color_temp_attribute =
254-
attribute::get(color_control_cluster, ColorControl::Attributes::ColorTemperatureMireds::Id);
252+
attribute::get(light_endpoint_id, ColorControl::Id, ColorControl::Attributes::ColorTemperatureMireds::Id);
255253
attribute::set_deferred_persistence(color_temp_attribute);
256254

257255
err = esp_event_loop_create_default();

0 commit comments

Comments
 (0)