Skip to content
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
18 changes: 10 additions & 8 deletions source/platform/common/bus_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ elem_node_map_t* bus_insert_elem_node(elem_node_map_t* root, bus_mux_data_elem_t
elem_node_map_t* current_node = root;
elem_node_map_t* temp_node = NULL;
elem_node_map_t* next_node = NULL;
int ret = 0, create_child = 0;
int create_child = 0;
char buff[256];

if(current_node == NULL || elem == NULL)
Expand Down Expand Up @@ -343,15 +343,14 @@ elem_node_map_t* bus_insert_elem_node(elem_node_map_t* root, bus_mux_data_elem_t
}
token = strtok_r(NULL, ".", &saveptr);
}
if(ret != 0)
{

BUS_MUX_UNLOCK(get_bus_mux_mutex());
return NULL;
}

current_node->type = elem->type;
current_node->node_data_type = elem->node_data_type;
if (current_node->node_elem_data != NULL) {
free(current_node->node_elem_data);
current_node->node_elem_data = NULL;
current_node->node_elem_data_len = 0;
}
current_node->node_elem_data = malloc(elem->cfg_data_len);
if(current_node->node_elem_data == NULL)
{
Expand All @@ -362,13 +361,16 @@ elem_node_map_t* bus_insert_elem_node(elem_node_map_t* root, bus_mux_data_elem_t
memcpy(current_node->node_elem_data, elem->cfg_data, elem->cfg_data_len);
current_node->node_elem_data_len = elem->cfg_data_len;

if(elem->type == bus_element_type_table)
if(elem->type == bus_element_type_table && current_node->child == NULL)
{
elem_node_map_t* rowTemplate = get_empty_elem_node();
if(rowTemplate == NULL)
{
wifi_util_error_print(WIFI_BUS, "Failed to create node [%s]\n",
elem->full_name);
free(current_node->node_elem_data);
current_node->node_elem_data = NULL;
current_node->node_elem_data_len = 0;
BUS_MUX_UNLOCK(get_bus_mux_mutex());
return NULL;
}
Expand Down
56 changes: 56 additions & 0 deletions source/platform/rdkb/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,28 @@ bus_error_t bus_method_invoke(bus_handle_t *handle, void *paramName, char *event
return convert_rbus_to_bus_error_code(rc);
}

static rbusError_t bus_discover_component(rbusHandle_t handle, char const *element_name)
{
rbusError_t rc;
int component_cnt = 0;
char **component_names = NULL;
char const *element_list[1];

element_list[0] = element_name;
rc = rbus_discoverComponentName(handle, 1, element_list, &component_cnt,
&component_names);
if (rc != RBUS_ERROR_SUCCESS) {
return rc;
}

for (int i = 0; i < component_cnt; i++) {
free(component_names[i]);
}
free(component_names);

return (component_cnt > 0) ? RBUS_ERROR_SUCCESS : RBUS_ERROR_DESTINATION_NOT_FOUND;
}

bus_error_t bus_event_subscribe(bus_handle_t *handle, char const *event_name, void *cb,
void *userData, int timeout)
{
Expand All @@ -1740,6 +1762,14 @@ bus_error_t bus_event_subscribe(bus_handle_t *handle, char const *event_name, vo
rbus_sub_callback_table_t rbus_cb = { 0 };
bus_sub_callback_table_t user_cb;

rc = bus_discover_component(p_rbus_handle, event_name);
if (rc != RBUS_ERROR_SUCCESS) {
wifi_util_dbg_print(WIFI_BUS,
"%s:%d bus: provider not found for [%s], rc: %d\n",
__func__, __LINE__, event_name, rc);
return convert_rbus_to_bus_error_code(rc);
}

user_cb.sub_handler = cb;
user_cb.sub_ex_async_handler = NULL;

Expand Down Expand Up @@ -1820,6 +1850,14 @@ bus_error_t bus_event_subscribe_async(bus_handle_t *handle, char const *event_na
rbus_sub_callback_table_t rbus_cb = { 0 };
bus_sub_callback_table_t user_cb;

rc = bus_discover_component(p_rbus_handle, event_name);
if (rc != RBUS_ERROR_SUCCESS) {
wifi_util_dbg_print(WIFI_BUS,
"%s:%d bus: provider not found for [%s], rc: %d\n",
__func__, __LINE__, event_name, rc);
return convert_rbus_to_bus_error_code(rc);
}

user_cb.sub_handler = cb;
user_cb.sub_ex_async_handler = async_cb;

Expand All @@ -1845,6 +1883,15 @@ bus_error_t bus_event_subscribe_ex(bus_handle_t *handle, bus_event_sub_t *l_sub_
return bus_error_invalid_input;
}

for (int index = 0; index < num_sub; index++) {
ret = bus_discover_component(p_rbus_handle, l_sub_info_map[index].event_name);
if (ret != RBUS_ERROR_SUCCESS) {
wifi_util_dbg_print(WIFI_BUS, "%s:%d bus: provider not found for [%s], rc: %d\n",
__func__, __LINE__, l_sub_info_map[index].event_name, ret);
return convert_rbus_to_bus_error_code(ret);
}
}

sub_info_map = calloc(1, num_sub * sizeof(rbusEventSubscription_t));
if (sub_info_map == NULL) {
wifi_util_error_print(WIFI_BUS, "%s:%d bus: bus_event_subscribe_ex() calloc is failed\n",
Expand Down Expand Up @@ -1892,6 +1939,15 @@ bus_error_t bus_event_subscribe_ex_async(bus_handle_t *handle, bus_event_sub_t *
return bus_error_invalid_input;
}

for (int index = 0; index < num_sub; index++) {
ret = bus_discover_component(p_rbus_handle, l_sub_info_map[index].event_name);
if (ret != RBUS_ERROR_SUCCESS) {
wifi_util_dbg_print(WIFI_BUS, "%s:%d bus: provider not found for [%s], rc: %d\n",
__func__, __LINE__, l_sub_info_map[index].event_name, ret);
return convert_rbus_to_bus_error_code(ret);
}
}

sub_info_map = calloc(1, num_sub * sizeof(rbusEventSubscription_t));
if (sub_info_map == NULL) {
wifi_util_error_print(WIFI_BUS, "%s:%d bus: bus_event_subscribe_ex() calloc is failed\n",
Expand Down
Loading