mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 19:13:13 +00:00
Merge branch 'pr_734' into 'main'
[GH_PR] Create user callback on command to allow monitoring in bridge (CON-890) See merge request app-frameworks/esp-matter!585
This commit is contained in:
@@ -49,8 +49,14 @@ void DispatchSingleClusterCommandCommon(const ConcreteCommandPath &command_path,
|
||||
return;
|
||||
}
|
||||
esp_err_t err = ESP_OK;
|
||||
callback_t callback = get_callback(command);
|
||||
TLVReader tlv_reader;
|
||||
tlv_reader.Init(tlv_data);
|
||||
callback_t callback = get_user_callback(command);
|
||||
if (callback) {
|
||||
err = callback(command_path, tlv_reader, opaque_ptr);
|
||||
}
|
||||
callback = get_callback(command);
|
||||
if ((err == ESP_OK) && callback) {
|
||||
err = callback(command_path, tlv_data, opaque_ptr);
|
||||
}
|
||||
int flags = get_flags(command);
|
||||
|
||||
@@ -157,6 +157,7 @@ typedef struct _command {
|
||||
uint32_t command_id;
|
||||
uint16_t flags;
|
||||
command::callback_t callback;
|
||||
command::callback_t user_callback;
|
||||
struct _command *next;
|
||||
} _command_t;
|
||||
|
||||
@@ -1398,6 +1399,7 @@ command_t *create(cluster_t *cluster, uint32_t command_id, uint8_t flags, callba
|
||||
command->command_id = command_id;
|
||||
command->flags = flags;
|
||||
command->callback = callback;
|
||||
command->user_callback = NULL;
|
||||
|
||||
/* Add */
|
||||
_command_t *previous_command = NULL;
|
||||
@@ -1485,6 +1487,25 @@ callback_t get_callback(command_t *command)
|
||||
return current_command->callback;
|
||||
}
|
||||
|
||||
callback_t get_user_callback(command_t *command)
|
||||
{
|
||||
if (!command) {
|
||||
ESP_LOGE(TAG, "Command cannot be NULL");
|
||||
return NULL;
|
||||
}
|
||||
_command_t *current_command = (_command_t *)command;
|
||||
return current_command->user_callback;
|
||||
}
|
||||
|
||||
void set_user_callback(command_t *command, callback_t user_callback)
|
||||
{
|
||||
if (!command) {
|
||||
ESP_LOGE(TAG, "Command cannot be NULL");
|
||||
}
|
||||
_command_t *current_command = (_command_t *)command;
|
||||
current_command->user_callback = user_callback;
|
||||
}
|
||||
|
||||
uint16_t get_flags(command_t *command)
|
||||
{
|
||||
if (!command) {
|
||||
|
||||
@@ -676,6 +676,28 @@ uint32_t get_id(command_t *command);
|
||||
*/
|
||||
callback_t get_callback(command_t *command);
|
||||
|
||||
/** Get command user_callback
|
||||
*
|
||||
* Get the command user_callback for the command.
|
||||
*
|
||||
* @param[in] command Command handle.
|
||||
*
|
||||
* @return Command user_callback on success.
|
||||
* @return NULL in case of failure or if the callback was not set when creating the command.
|
||||
*/
|
||||
callback_t get_user_callback(command_t *command);
|
||||
|
||||
/** Set command user_callback
|
||||
*
|
||||
* Set the user_callback for the command.
|
||||
*
|
||||
* @param[in] command Command handle.
|
||||
* @param[in] user_callback callback_t.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
void set_user_callback(command_t *command, callback_t user_callback);
|
||||
|
||||
/** Get command flags
|
||||
*
|
||||
* Get the command flags for the command.
|
||||
|
||||
Reference in New Issue
Block a user