Skip to content

Create user callback on command to allow monitoring in bridge (CON-890) #734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion components/esp_matter/esp_matter_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions components/esp_matter/esp_matter_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -1397,6 +1398,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;
Expand Down Expand Up @@ -1484,6 +1486,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) {
Expand Down
22 changes: 22 additions & 0 deletions components/esp_matter/esp_matter_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down