-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/rrd prof #181
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/rrd prof #181
Changes from all commits
86b503b
c9587f0
8b712e9
28ba654
2a7dcba
81cc501
bb266ac
48f1a70
588db7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -33,6 +33,72 @@ key_t key = 1234; | |||||||||||||||||||||||||||||||||||||||||||||
| uint32_t gWebCfgBloBVersion = 0; | ||||||||||||||||||||||||||||||||||||||||||||||
| rbusHandle_t rrdRbusHandle; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Global storage for profile category | ||||||||||||||||||||||||||||||||||||||||||||||
| char RRDProfileCategory[256] = "all"; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Helper functions for profile category file-based storage | ||||||||||||||||||||||||||||||||||||||||||||||
| int load_profile_category(void) { | ||||||||||||||||||||||||||||||||||||||||||||||
| FILE *fp = fopen(RRD_PROFILE_CATEGORY_FILE, "r"); | ||||||||||||||||||||||||||||||||||||||||||||||
| if (fp) { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (fgets(RRDProfileCategory, sizeof(RRDProfileCategory), fp)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| // Remove trailing newline | ||||||||||||||||||||||||||||||||||||||||||||||
| char *newline = strchr(RRDProfileCategory, '\n'); | ||||||||||||||||||||||||||||||||||||||||||||||
| if (newline) *newline = '\0'; | ||||||||||||||||||||||||||||||||||||||||||||||
| fclose(fp); | ||||||||||||||||||||||||||||||||||||||||||||||
| return 0; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| fclose(fp); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| // Default to "all" if file doesn't exist or read fails | ||||||||||||||||||||||||||||||||||||||||||||||
| strncpy(RRDProfileCategory, "all", sizeof(RRDProfileCategory) - 1); | ||||||||||||||||||||||||||||||||||||||||||||||
| RRDProfileCategory[sizeof(RRDProfileCategory) - 1] = '\0'; | ||||||||||||||||||||||||||||||||||||||||||||||
| return -1; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| int save_profile_category(void) { | ||||||||||||||||||||||||||||||||||||||||||||||
| FILE *fp = fopen(RRD_PROFILE_CATEGORY_FILE, "w"); | ||||||||||||||||||||||||||||||||||||||||||||||
| if (fp) { | ||||||||||||||||||||||||||||||||||||||||||||||
| fprintf(fp, "%s\n", RRDProfileCategory); | ||||||||||||||||||||||||||||||||||||||||||||||
| fclose(fp); | ||||||||||||||||||||||||||||||||||||||||||||||
| return 0; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| return -1; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+58
to
+65
|
||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| #define DATA_HANDLER_SET_MACRO \ | ||||||||||||||||||||||||||||||||||||||||||||||
| { \ | ||||||||||||||||||||||||||||||||||||||||||||||
| NULL, \ | ||||||||||||||||||||||||||||||||||||||||||||||
| rrd_SetHandler, \ | ||||||||||||||||||||||||||||||||||||||||||||||
| NULL, \ | ||||||||||||||||||||||||||||||||||||||||||||||
| NULL, \ | ||||||||||||||||||||||||||||||||||||||||||||||
| NULL, \ | ||||||||||||||||||||||||||||||||||||||||||||||
| NULL \ | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| #define DATA_HANDLER_GET_MACRO \ | ||||||||||||||||||||||||||||||||||||||||||||||
| { \ | ||||||||||||||||||||||||||||||||||||||||||||||
| rrd_GetHandler, \ | ||||||||||||||||||||||||||||||||||||||||||||||
| NULL, \ | ||||||||||||||||||||||||||||||||||||||||||||||
| NULL, \ | ||||||||||||||||||||||||||||||||||||||||||||||
| NULL, \ | ||||||||||||||||||||||||||||||||||||||||||||||
| NULL, \ | ||||||||||||||||||||||||||||||||||||||||||||||
| NULL \ | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Data elements for profile data RBUS provider | ||||||||||||||||||||||||||||||||||||||||||||||
| rbusDataElement_t profileDataElements[2] = { | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| RRD_SET_PROFILE_EVENT, | ||||||||||||||||||||||||||||||||||||||||||||||
| RBUS_ELEMENT_TYPE_PROPERTY, | ||||||||||||||||||||||||||||||||||||||||||||||
| DATA_HANDLER_SET_MACRO | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+88
to
+94
|
||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| RRD_GET_PROFILE_EVENT, | ||||||||||||||||||||||||||||||||||||||||||||||
| RBUS_ELEMENT_TYPE_PROPERTY, | ||||||||||||||||||||||||||||||||||||||||||||||
| DATA_HANDLER_GET_MACRO | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /*Function: RRD_subscribe | ||||||||||||||||||||||||||||||||||||||||||||||
| *Details: This helps to perform Bus init/connect and event handler registration for receiving | ||||||||||||||||||||||||||||||||||||||||||||||
| *events from the TR181 parameter. | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -103,6 +169,21 @@ int RRD_subscribe() | |||||||||||||||||||||||||||||||||||||||||||||
| RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: SUCCESS: RBUS Event Subscribe for RRD done! \n", __FUNCTION__, __LINE__); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Load profile category from file | ||||||||||||||||||||||||||||||||||||||||||||||
| if (load_profile_category() == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||
| RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Loaded profile category: %s\n", __FUNCTION__, __LINE__, RRDProfileCategory); | ||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: No stored profile category, defaulting to 'all'\n", __FUNCTION__, __LINE__); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Register RBUS data elements for profile data provider | ||||||||||||||||||||||||||||||||||||||||||||||
| ret = rbus_regDataElements(rrdRbusHandle, 2, profileDataElements); | ||||||||||||||||||||||||||||||||||||||||||||||
| if (ret != RBUS_ERROR_SUCCESS) { | ||||||||||||||||||||||||||||||||||||||||||||||
| RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: RBUS regDataElements failed with error: %d\n", __FUNCTION__, __LINE__, ret); | ||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: SUCCESS: RBUS profile data elements registered\n", __FUNCTION__, __LINE__); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+180
to
+184
|
||||||||||||||||||||||||||||||||||||||||||||||
| ret = rbus_regDataElements(rrdRbusHandle, 2, profileDataElements); | |
| if (ret != RBUS_ERROR_SUCCESS) { | |
| RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: RBUS regDataElements failed with error: %d\n", __FUNCTION__, __LINE__, ret); | |
| } else { | |
| RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: SUCCESS: RBUS profile data elements registered\n", __FUNCTION__, __LINE__); | |
| { | |
| rbusError_t regRet = rbus_regDataElements(rrdRbusHandle, 2, profileDataElements); | |
| if (regRet != RBUS_ERROR_SUCCESS) { | |
| RDK_LOG(RDK_LOG_ERROR, LOG_REMDEBUG, "[%s:%d]: RBUS regDataElements failed with error: %d\n", __FUNCTION__, __LINE__, regRet); | |
| } else { | |
| RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: SUCCESS: RBUS profile data elements registered\n", __FUNCTION__, __LINE__); | |
| } | |
| if (ret == RBUS_ERROR_SUCCESS) { | |
| ret = regRet; | |
| } |
Copilot
AI
Apr 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RRD_unsubscribe assigns ret from rbus_unregDataElements and then immediately overwrites it with rbus_close’s result, so unregistration failures can be lost (function may return success even though unreg failed). Consider preserving the first failure and/or returning a combined error status.
Copilot
AI
Apr 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new RBUS set/get handler behavior (category persistence and JSON response construction) isn’t covered by the existing gtest suite that includes rrdInterface.c. Add unit tests for rrd_SetHandler/rrd_GetHandler covering valid category set, invalid type/oversize input, missing/unreadable JSON file, and category-not-found/nested-category cases.
Copilot
AI
Apr 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rrd_GetHandler returns RBUS_ERROR_SUCCESS even when file size is out of bounds, malloc fails, fread is short, or JSON parsing fails (and may leave the property unset). Return an appropriate RBUS error and/or set a deterministic empty JSON value on these failure paths.
Copilot
AI
Apr 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memory leak: cJSON_Print(cJSON_CreateArray()) allocates a cJSON array that is never freed (same pattern appears in both the nested-structure and not-found branches). Create the array in a variable, print it, then cJSON_Delete it after printing.
| RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Category %s has nested structure, returning empty\n", | |
| __FUNCTION__, __LINE__, RRDProfileCategory); | |
| result_str = cJSON_Print(cJSON_CreateArray()); | |
| } | |
| } else { | |
| RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Category %s not found\n", | |
| __FUNCTION__, __LINE__, RRDProfileCategory); | |
| result_str = cJSON_Print(cJSON_CreateArray()); | |
| cJSON *emptyArray = NULL; | |
| RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Category %s has nested structure, returning empty\n", | |
| __FUNCTION__, __LINE__, RRDProfileCategory); | |
| emptyArray = cJSON_CreateArray(); | |
| result_str = cJSON_Print(emptyArray); | |
| cJSON_Delete(emptyArray); | |
| } | |
| } else { | |
| cJSON *emptyArray = NULL; | |
| RDK_LOG(RDK_LOG_DEBUG, LOG_REMDEBUG, "[%s:%d]: Category %s not found\n", | |
| __FUNCTION__, __LINE__, RRDProfileCategory); | |
| emptyArray = cJSON_CreateArray(); | |
| result_str = cJSON_Print(emptyArray); | |
| cJSON_Delete(emptyArray); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -29,6 +29,7 @@ extern "C" | |||||
| #include "rrdCommon.h" | ||||||
| #if !defined(GTEST_ENABLE) | ||||||
| #include "rbus.h" | ||||||
| #include <cjson/cJSON.h> | ||||||
|
||||||
| #include <cjson/cJSON.h> | |
| #include "cJSON.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RRDProfileCategory and the helper functions load_profile_category/save_profile_category are not file-local, so they export new global symbols from rrdInterface.c. Make these
static(and consider making the bufferstatictoo) to avoid symbol collisions and accidental external use.