Skip to content

Commit 21c2051

Browse files
committed
Merge branch 'controller/shutdown-all-subss' into 'main'
components/esp_matter_controller: support for shutdown all subscriptions See merge request app-frameworks/esp-matter!944
2 parents 8385f95 + ded2b14 commit 21c2051

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

components/esp_matter_controller/commands/esp_matter_controller_subscribe_command.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -294,5 +294,23 @@ esp_err_t send_shutdown_subscription(uint64_t node_id, uint32_t subscription_id)
294294
return ESP_OK;
295295
}
296296

297+
void send_shutdown_subscriptions(uint64_t node_id)
298+
{
299+
InteractionModelEngine::GetInstance()->ShutdownSubscriptions(
300+
#if CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
301+
matter_controller_client::get_instance().get_commissioner()->GetFabricIndex(),
302+
#else
303+
get_fabric_index(),
304+
#endif
305+
node_id);
306+
ESP_LOGI(TAG, "Shutdown Subscriptions for node:0x%llx", node_id);
307+
}
308+
309+
void send_shutdown_all_subscriptions()
310+
{
311+
InteractionModelEngine::GetInstance()->ShutdownAllSubscriptions();
312+
ESP_LOGI(TAG, "Shutdown all Subscriptions");
313+
}
314+
297315
} // namespace controller
298316
} // namespace esp_matter

components/esp_matter_controller/commands/esp_matter_controller_subscribe_command.h

+23
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ class subscribe_command : public ReadClient::Callback {
118118

119119
CHIP_ERROR OnResubscriptionNeeded(ReadClient *apReadClient, CHIP_ERROR aTerminationCause) override;
120120

121+
uint32_t get_subscription_id() { return m_subscription_id; }
122+
121123
private:
122124
uint64_t m_node_id;
123125
uint16_t m_min_interval;
@@ -222,7 +224,28 @@ esp_err_t send_subscribe_attr_command(uint64_t node_id, uint16_t endpoint_id, ui
222224
esp_err_t send_subscribe_event_command(uint64_t node_id, uint16_t endpoint_id, uint32_t cluster_id, uint32_t event_id,
223225
uint16_t min_interval, uint16_t max_interval, bool auto_resubscribe = true);
224226

227+
/** Shut down a subscription for given node id and subscription id
228+
*
229+
* @param[in] node_id Node id
230+
* @param[in] subscription_id Subscription id
231+
*
232+
* @return ESP_OK on success.
233+
* @return ESP_FAIL in case of failure.
234+
*/
225235
esp_err_t send_shutdown_subscription(uint64_t node_id, uint32_t subscription_id);
226236

237+
/** Shut down all subscriptions for a given node id
238+
*
239+
* @param[in] node_id Node id
240+
* @return None
241+
*/
242+
void send_shutdown_subscriptions(uint64_t node_id);
243+
244+
/** Shut down all subscriptions to all nodes
245+
* @param[in] None
246+
* @return None
247+
*/
248+
void send_shutdown_all_subscriptions();
249+
227250
} // namespace controller
228251
} // namespace esp_matter

components/esp_matter_controller/core/esp_matter_controller_console.cpp

+32-1
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,25 @@ static esp_err_t controller_shutdown_subscription_handler(int argc, char **argv)
534534
return controller::send_shutdown_subscription(node_id, subscription_id);
535535
}
536536

537+
static esp_err_t controller_shutdown_subscriptions_handler(int argc, char **argv)
538+
{
539+
if (argc != 1) {
540+
return ESP_ERR_INVALID_ARG;
541+
}
542+
uint64_t node_id = string_to_uint64(argv[0]);
543+
controller::send_shutdown_subscriptions(node_id);
544+
return ESP_OK;
545+
}
546+
547+
static esp_err_t controller_shutdown_all_subscriptions_handler(int argc, char **argv)
548+
{
549+
if (argc != 0) {
550+
return ESP_ERR_INVALID_ARG;
551+
}
552+
controller::send_shutdown_all_subscriptions();
553+
return ESP_OK;
554+
}
555+
537556
static esp_err_t controller_dispatch(int argc, char **argv)
538557
{
539558
if (argc == 0) {
@@ -648,10 +667,22 @@ esp_err_t controller_register_commands()
648667
},
649668
{
650669
.name = "shutdown-subs",
651-
.description = "Shutdown subscription.\n"
670+
.description = "Shutdown subscription for given node id and subscription id.\n"
652671
"\tUsage: controller shutdown-subs <node-id> <subscription-id>",
653672
.handler = controller_shutdown_subscription_handler,
654673
},
674+
{
675+
.name = "shutdown-subss",
676+
.description = "Shutdown all subscriptions for a given node.\n"
677+
"\tUsage: controller shutdown-subss <node-id>",
678+
.handler = controller_shutdown_subscriptions_handler,
679+
},
680+
{
681+
.name = "shutdown-all-subss",
682+
.description = "Shutdown all subscriptions to all nodes.\n"
683+
"\tUsage: controller shutdown-all-subss",
684+
.handler = controller_shutdown_all_subscriptions_handler,
685+
},
655686
};
656687

657688
const static command_t controller_command = {

0 commit comments

Comments
 (0)