Skip to content
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

Feature: add callback data to the bridge device type callback (CON-989) #811

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
13 changes: 7 additions & 6 deletions components/esp_matter_bridge/esp_matter_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,15 @@ static esp_err_t plugin_init_callback_endpoint(endpoint_t *endpoint)

static bridge_device_type_callback_t device_type_callback;

esp_err_t set_device_type(device_t *bridged_device, uint32_t device_type_id, void *priv_data)
esp_err_t set_device_type(device_t *bridged_device, uint32_t device_type_id, void *priv_data, void* callback_data)
{
esp_err_t err;

if (!bridged_device) {
ESP_LOGE(TAG, "bridged_device cannot be NULL");
return ESP_ERR_INVALID_ARG;
}
err = device_type_callback(bridged_device->endpoint, device_type_id, priv_data);
err = device_type_callback(bridged_device->endpoint, device_type_id, priv_data, callback_data);
if (err != ESP_OK)
return err;
return plugin_init_callback_endpoint(bridged_device->endpoint);
Expand Down Expand Up @@ -286,7 +286,8 @@ static bool parent_endpoint_is_valid(node_t *node, uint16_t parent_endpoint_id)
return false;
}

device_t *create_device(node_t *node, uint16_t parent_endpoint_id, uint32_t device_type_id, void *priv_data)
device_t *create_device(node_t *node, uint16_t parent_endpoint_id, uint32_t device_type_id,
void *priv_data, void* callback_data)
{
// Check whether the parent endpoint is valid
if (!parent_endpoint_is_valid(node, parent_endpoint_id)) {
Expand All @@ -306,7 +307,7 @@ device_t *create_device(node_t *node, uint16_t parent_endpoint_id, uint32_t devi
esp_matter_mem_free(dev);
return NULL;
}
if (set_device_type(dev, device_type_id, priv_data) != ESP_OK) {
if (set_device_type(dev, device_type_id, priv_data, callback_data) != ESP_OK) {
ESP_LOGE(TAG, "Failed to add the device type for the bridged device");
remove_device(dev);
return NULL;
Expand Down Expand Up @@ -344,7 +345,7 @@ device_t *create_device(node_t *node, uint16_t parent_endpoint_id, uint32_t devi
return dev;
}

device_t *resume_device(node_t *node, uint16_t device_endpoint_id, void *priv_data)
device_t *resume_device(node_t *node, uint16_t device_endpoint_id, void *priv_data, void* callback_data)
{
esp_err_t err = ESP_OK;
device_persistent_info_t persistent_info;
Expand All @@ -369,7 +370,7 @@ device_t *resume_device(node_t *node, uint16_t device_endpoint_id, void *priv_da
erase_bridged_device_info(device_endpoint_id);
return NULL;
}
if (set_device_type(dev, persistent_info.device_type_id, priv_data) != ESP_OK) {
if (set_device_type(dev, persistent_info.device_type_id, priv_data, callback_data) != ESP_OK) {
ESP_LOGE(TAG, "Failed to add the device type for the bridged device");
remove_device(dev);
return NULL;
Expand Down
9 changes: 5 additions & 4 deletions components/esp_matter_bridge/esp_matter_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,19 @@ typedef struct device {
device_persistent_info_t persistent_info;
} device_t;

typedef esp_err_t (*bridge_device_type_callback_t)(esp_matter::endpoint_t *ep, uint32_t device_type_id, void *priv_data);
typedef esp_err_t (*bridge_device_type_callback_t)(esp_matter::endpoint_t *ep, uint32_t device_type_id,
void *priv_data, void* callback_data);

esp_err_t get_bridged_endpoint_ids(uint16_t *matter_endpoint_id_array);

esp_err_t erase_bridged_device_info(uint16_t matter_endpoint_id);

device_t *create_device(esp_matter::node_t *node, uint16_t parent_endpoint_id, uint32_t device_type_id,
void *priv_data);
void *priv_data, void* callback_data);

device_t *resume_device(esp_matter::node_t *node, uint16_t device_endpoint_id, void *priv_data);
device_t *resume_device(esp_matter::node_t *node, uint16_t device_endpoint_id, void *priv_data, void* callback_data);

esp_err_t set_device_type(device_t *bridged_device, uint32_t device_type_id, void *priv_data);
esp_err_t set_device_type(device_t *bridged_device, uint32_t device_type_id, void *priv_data, void* callback_data);

esp_err_t remove_device(device_t *bridged_device);

Expand Down