Skip to content

Conversation

Aniket0606
Copy link
Contributor

Reason for change: Implemented the HE bus asynchronous method invoke
API to asynchronously set and get data between a
consumer and a producer.

Test Procedure: 1) Load Linux(RPI) or OpenWRT(BPI) HE bus Build. 2) Trigger "bus_method_async_invoke" API from code to test those changes. 3) Verify device memory.

Risks: Low
Priority: P1

Signed-off-by: [email protected]

@Aniket0606 Aniket0606 requested a review from a team as a code owner August 18, 2025 22:50
@CLAassistant
Copy link

CLAassistant commented Aug 18, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ amarnathhullur
❌ Aniket0606
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

@amarnathhullur amarnathhullur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also please list the testing (various unit test scenarios) addressed as part of this change?

{
bus_data_prop_t *next;

if (p_data_prop->ref_count <= 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be just == 1. If it goes below 1 it should already have been freed right and should not do anything.

free_bus_raw_data(&p_data_prop->value);
p_data_prop->is_data_set = false;
p_data_prop->ref_count = 0;
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should explicitly check for > 1 for this.


while(p_data_prop) {
next = p_data_prop->next_data;
if (p_data_prop->ref_count <= 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above everywhere ref_count is used.

p_data_prop->ref_count--;
}

while(p_data_prop) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont understand what is the usecase of if above and then a while loop

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe above if can be folded in the while loop.

p_data_prop->is_data_set = false;
p_data_prop->ref_count = 0;
} else {
wifi_util_info_print(WIFI_BUS,"%s:%d memory:%p already have some references:%d\r\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
wifi_util_info_print(WIFI_BUS,"%s:%d memory:%p already have some references:%d\r\n",
wifi_util_info_print(WIFI_BUS,"%s:%d memory:%p still have some references:%d\r\n",

Comment on lines 814 to 838
while(p_data_prop) {
next = p_data_prop->next_data;
if (p_data_prop->ref_count <= 1) {
free_bus_raw_data(&p_data_prop->value);
free(p_data_prop);
} else {
wifi_util_info_print(WIFI_BUS,"%s:%d memory:%p already have some references:%d\r\n",
__func__, __LINE__, p_data_prop, p_data_prop->ref_count);
p_data_prop->ref_count--;
}
p_data_prop = next;
}
Copy link
Contributor

@Pavlo-Uvarov Pavlo-Uvarov Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
while(p_data_prop) {
next = p_data_prop->next_data;
if (p_data_prop->ref_count <= 1) {
free_bus_raw_data(&p_data_prop->value);
free(p_data_prop);
} else {
wifi_util_info_print(WIFI_BUS,"%s:%d memory:%p already have some references:%d\r\n",
__func__, __LINE__, p_data_prop, p_data_prop->ref_count);
p_data_prop->ref_count--;
}
p_data_prop = next;
}
next = p_data_prop->next_data;
while(next) {
if (next->ref_count <= 1) {
bus_data_prop_t *temp_next = next;
next = next->next_data;
free_bus_raw_data(&temp_next->value);
free(temp_next);
if (prev) {
prev->next_data = NULL;
}
} else {
wifi_util_info_print(WIFI_BUS,"%s:%d memory:%p still have some references:%d\r\n",
__func__, __LINE__, next, next->ref_count);
next->ref_count--;
if (!first) {
first = next;
}
if (prev) {
prev->next_data = next;
}
prev = next;
next = next->next_data;
++*num_prop;
}
}
return first;

} else {
wifi_util_info_print(WIFI_BUS,"%s:%d memory:%p already have some references:%d\r\n",
__func__, __LINE__, p_data_prop, p_data_prop->ref_count);
p_data_prop->ref_count--;
Copy link
Contributor

@Pavlo-Uvarov Pavlo-Uvarov Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
p_data_prop->ref_count--;
p_data_prop->ref_count--;
first = p_data_prop;
prev = p_data_prop;
++*num_prop;

Comment on lines 800 to 801
void bus_release_data_prop(bus_data_prop_t *p_data_prop)
{
Copy link
Contributor

@Pavlo-Uvarov Pavlo-Uvarov Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void bus_release_data_prop(bus_data_prop_t *p_data_prop)
{
bus_data_prop_t *bus_release_data_prop(bus_data_prop_t *p_data_prop, int *num_prop)
{
*num_prop = 0;
bus_data_prop_t *first = NULL;
bus_data_prop_t *prev = NULL;

Comment on lines 830 to 831
bus_release_data_prop(&p_bus_obj->data_prop);
p_bus_obj->num_prop = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bus_release_data_prop(&p_bus_obj->data_prop);
p_bus_obj->num_prop = 0;
p_bus_obj->data_prop = *bus_release_data_prop(&p_bus_obj->data_prop, &p_bus_obj->num_prop);

return NULL;
}

he_bus_error_t he_bus_async_method_invoke(he_bus_handle_t handle, char const *event_name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add declaration of this function to header file.

@@ -201,6 +201,12 @@ static bus_error_t bus_remove_table_row(bus_handle_t *handle, char const *name)
return bus_error_success;
}

bus_error_t bus_method_async_invoke(bus_handle_t *handle, void *param_name, char *event_name,

This comment was marked as resolved.

@@ -1796,6 +1796,12 @@ static bus_error_t bus_remove_table_row(bus_handle_t *handle, char const *name)
return convert_rbus_to_bus_error_code(rc);
}

bus_error_t bus_method_async_invoke(bus_handle_t *handle, void *param_name, char *event_name,

This comment was marked as resolved.

typedef bus_error_t (* wifi_bus_reg_table_row_t) (bus_handle_t *handle, char const *name, uint32_t row_index, char const *alias);
typedef bus_error_t (* wifi_bus_unreg_table_row_t) (bus_handle_t *handle, char const *name);
typedef bus_error_t (* wifi_bus_add_table_row_t) (bus_handle_t *handle, char const *name, char const *alias, uint32_t *row_index);
typedef bus_error_t (* wifi_bus_remove_table_row_t) (bus_handle_t *handle, char const *name);
typedef bus_error_t (* wifi_bus_unreg_elements_t) (bus_handle_t *handle, uint32_t num_of_element, bus_data_element_t *data_element);
typedef bus_error_t (* wifi_bus_method_invoke_t) (bus_handle_t *handle, void *paramName, char *event, raw_data_t *input_data, raw_data_t *output_data, uint8_t input_bus_data);
typedef bus_error_t (* wifi_bus_method_async_invoke_t) (bus_handle_t *handle, void *param_name, char *event_name,

This comment was marked as resolved.

@@ -218,13 +252,14 @@ typedef bus_error_t (* wifi_bus_event_subscribe_ex_async_t) (bus_handle_t *h
typedef bus_error_t (* wifi_bus_event_unsubscribe_t) (bus_handle_t *handle, char const* event_name);
typedef bus_error_t (* wifi_bus_event_unsubs_ex_t) (bus_handle_t *handle, bus_event_sub_t *l_sub_info_map, int num_sub);
typedef bus_error_t (* wifi_bus_reg_elements_t) (bus_handle_t *handle, bus_data_element_t *data_element, uint32_t num_of_element);
typedef bus_error_t (* wifi_bus_method_invoke_t) (bus_handle_t *handle, void *paramName, char *event, raw_data_t *input_data, raw_data_t *output_data, uint8_t input_bus_data);
typedef bus_error_t (* wifi_bus_method_invoke_t) (bus_handle_t *handle, void *paramName, char *event, bus_data_obj_t *input_data, bus_data_obj_t *output_data, uint8_t input_bus_data);

This comment was marked as resolved.

typedef bus_error_t (*bus_name_sub_handler_t)(char *eventName, bus_event_sub_action_t action, int32_t interval, bool* autoPublish);

typedef bus_error_t (*bus_event_sub_handler_t)(char *event_name, raw_data_t *p_data, void *userData);
typedef bus_error_t (*bus_event_sub_ex_async_handler_t)(char *event_name, bus_error_t ret, void *userData);

typedef void (* wifi_bus_method_async_resp_handler_t) (char const* methodName, bus_error_t error, bus_data_prop_t *params, void *userData);

This comment was marked as resolved.

l_obj = he_bus_calloc(1, sizeof(he_bus_data_object_t));

l_obj = memory_alloc_for_he_bus_data_obj();
HE_BUS_CHECK_NULL_WITH_RC(l_obj, he_bus_error_out_of_resources);
l_obj->next_data = NULL;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is already null, calloc does that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so no need for this line:
l_obj->next_data = NULL;

@@ -486,16 +517,29 @@ void free_raw_data_struct(he_bus_raw_data_t *p_data)

void free_bus_msg_obj_data(he_bus_data_object_t *p_obj_data)
{
free_raw_data_struct(&p_obj_data->data);
if (p_obj_data->ref_count <= 1) {

This comment was marked as resolved.


uint32_t get_max_objs_cnt(he_bus_data_object_t *p_objs)
{
uint32_t total_obj_size = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

total_obj_cnt. variable suggests something other than function name,.

return total_obj_size;
}

int set_obj_status(he_bus_data_object_t *p_objs, he_bus_error_t ret_status)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this will always return OK, void or _Noreturn ( <stdnoreturn.h> from c11) seems more appropriate


while(index < 3) {
payload_data.data_type = he_bus_data_type_uint32;
payload_data.raw_data.u32 = index + 11;

This comment was marked as resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is test code only. So, I added this number for testing.

@Aniket0606 Aniket0606 force-pushed the he_bus_async_method_invoke_api branch from 0043130 to bfd2333 Compare August 22, 2025 12:52
return temp;
}

int bus_data_prop_retain(bus_data_prop_t *p_prop)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, you're not, int bus_set_raw_data_prop(
line 899-900:
p_bus_prop->is_data_set = true;
bus_data_prop_retain(p_bus_prop);

cur->ref_count--;
prev = cur;
} else {
wifi_util_info_print(WIFI_BUS,"%s:%d memory:%p not have some references:%d\r\n",

This comment was marked as resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

} else {
wifi_util_info_print(WIFI_BUS,"%s:%d memory:%p not have some references:%d\r\n",
__func__, __LINE__, cur, cur->ref_count);
prev = cur;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you've checked that 'cur' basically doesnt exist, shouldn't this be prev = next?. if it has ref_count = 0, this is error scenario and other members (such as next_data) might not exactly be whats you expect them to be..

__func__, __LINE__, p_obj_data, p_obj_data->ref_count);
p_obj_data->ref_count--;
} else {
he_bus_core_info_print("%s:%d memory:%p not have some references:%d\r\n",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as in bus_Common.c this is an error scenario, update log level please.

cur->ref_count--;
prev = cur;
} else {
he_bus_core_info_print("%s:%d memory:%p not have some references:%d\r\n",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as in bus_Common.c . Error level + think about rationale of prev = cur.

BUS_CHECK_NULL_WITH_RC(p_bus_prop, RETURN_ERR);
BUS_CHECK_NULL_WITH_RC(p_raw_data, RETURN_ERR);

if (event_name == NULL) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since most of the events will have name (correct me if im wrong), this would benefit from order change. If's are compiled with assumption to be taken, so
if (event_name != NULL) {
....
} else {
*p_raw_data = p_bus_prop->value;
}
will be more optimal here,

Copy link
Contributor Author

@Aniket0606 Aniket0606 Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a name isn't provided, we should return the first element. That's why I did this.

cur->ref_count--;
prev = cur;
} else {
wifi_util_info_print(WIFI_BUS,"%s:%d memory:%p not have some references:%d\r\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of wifi_util_info_print, put this as a wifi_util_error_print

Reason for change: Implemented the HE bus asynchronous method invoke
                   API to asynchronously set and get data between a
                   consumer and a producer.

Test Procedure: 1) Load Linux(RPI) or OpenWRT(BPI) HE bus Build.
2) Trigger "bus_method_async_invoke" API from code to test those changes.
3) Verify device memory.

Risks: Low
Priority: P1

Signed-off-by: [email protected]
@Aniket0606 Aniket0606 force-pushed the he_bus_async_method_invoke_api branch from bfd2333 to de9c544 Compare August 26, 2025 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants