From 28f575dd0e09b35eb9a9241c69b1898b88c4a282 Mon Sep 17 00:00:00 2001 From: Amin Ben Romdhane <amin.benromdhane@iopsys.eu> Date: Thu, 13 Feb 2025 16:05:15 +0100 Subject: [PATCH] Align with bbfdm new design --- src/configs.c | 12 ++++++------ src/fw_images.c | 6 +++--- src/memory.c | 3 ++- src/processes.c | 3 ++- src/utils.c | 5 +++-- src/utils.h | 2 +- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/configs.c b/src/configs.c index 4bab469..c7f836f 100644 --- a/src/configs.c +++ b/src/configs.c @@ -52,7 +52,7 @@ static int dmmap_synchronizeVcfInst(struct dmctx *dmctx, DMNODE *parent_node, vo return 0; } -static int bbf_config_backup(const char *url, const char *username, const char *password, +static int bbf_config_backup(struct ubus_context *ctx, const char *url, const char *username, const char *password, char *config_name, const char *command, const char *obj_path) { int res = 0; @@ -79,7 +79,7 @@ static int bbf_config_backup(const char *url, const char *username, const char * end: // Send the transfer complete event - send_transfer_complete_event(command, obj_path, url, fault_msg, start_time, complete_time, NULL, "Upload"); + send_transfer_complete_event(ctx, command, obj_path, url, fault_msg, start_time, complete_time, NULL, "Upload"); // Remove temporary file if (file_exists(CONFIG_BACKUP) && remove(CONFIG_BACKUP)) @@ -89,7 +89,7 @@ end: } -static int bbf_config_restore(const char *url, const char *username, const char *password, +static int bbf_config_restore(struct ubus_context *ctx, const char *url, const char *username, const char *password, const char *file_size, const char *checksum_algorithm, const char *checksum, const char *command, const char *obj_path) { @@ -134,7 +134,7 @@ static int bbf_config_restore(const char *url, const char *username, const char end: // Send the transfer complete event - send_transfer_complete_event(command, obj_path, url, fault_msg, start_time, complete_time, NULL, "Download"); + send_transfer_complete_event(ctx, command, obj_path, url, fault_msg, start_time, complete_time, NULL, "Download"); // Remove temporary file if (file_exists(config_restore) && strncmp(url, FILE_URI, strlen(FILE_URI)) && remove(config_restore)) @@ -274,7 +274,7 @@ static int operate_DeviceInfoVendorConfigFile_Backup(char *refparam, struct dmct dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "name", &vcf_name); - int res = bbf_config_backup(url, user, pass, vcf_name, backup_command, backup_path); + int res = bbf_config_backup(ctx->ubus_ctx, url, user, pass, vcf_name, backup_command, backup_path); return res ? USP_FAULT_COMMAND_FAILURE : 0; } @@ -320,7 +320,7 @@ static int operate_DeviceInfoVendorConfigFile_Restore(char *refparam, struct dmc char *checksum_algorithm = dmjson_get_value((json_object *)value, 1, "CheckSumAlgorithm"); char *checksum = dmjson_get_value((json_object *)value, 1, "CheckSum"); - int res = bbf_config_restore(url, user, pass, file_size, checksum_algorithm, checksum, restore_command, restore_path); + int res = bbf_config_restore(ctx->ubus_ctx, url, user, pass, file_size, checksum_algorithm, checksum, restore_command, restore_path); return res ? USP_FAULT_COMMAND_FAILURE : 0; } diff --git a/src/fw_images.c b/src/fw_images.c index 51dcf71..9876928 100644 --- a/src/fw_images.c +++ b/src/fw_images.c @@ -183,7 +183,7 @@ static void dmubus_receive_sysupgrade(struct ubus_context *ctx, struct ubus_even return; } -static int bbf_fw_image_download(const char *url, const char *auto_activate, const char *username, const char *password, +static int bbf_fw_image_download(struct ubus_context *ctx, const char *url, const char *auto_activate, const char *username, const char *password, const char *file_size, const char *checksum_algorithm, const char *checksum, const char *bank_id, const char *command, const char *obj_path, const char *commandKey, const char *keep) { @@ -280,7 +280,7 @@ static int bbf_fw_image_download(const char *url, const char *auto_activate, con end: // Send the transfer complete event - send_transfer_complete_event(command, obj_path, url, fault_msg, start_time, complete_time, commandKey, "Download"); + send_transfer_complete_event(ctx, command, obj_path, url, fault_msg, start_time, complete_time, commandKey, "Download"); // Remove temporary file if ubus upgrade failed and file exists if (file_exists(fw_image_path) && strncmp(url, FILE_URI, strlen(FILE_URI))) @@ -563,7 +563,7 @@ static int operate_DeviceInfoFirmwareImage_Download(char *refparam, struct dmctx #endif char *bank_id = get_fwbank_option_value(data, "id"); - int res = bbf_fw_image_download(url, auto_activate, username, password, file_size, checksum_algorithm, checksum, bank_id, command, obj_path, commandKey, keep_config); + int res = bbf_fw_image_download(ctx->ubus_ctx, url, auto_activate, username, password, file_size, checksum_algorithm, checksum, bank_id, command, obj_path, commandKey, keep_config); if (res == 1) { bbfdm_set_fault_message(ctx, "Firmware validation failed"); diff --git a/src/memory.c b/src/memory.c index 9cbc4be..ef06150 100644 --- a/src/memory.c +++ b/src/memory.c @@ -114,7 +114,8 @@ static void send_memory_critical_state_event(unsigned int mem_utilization) blobmsg_close_array(&bb, arr); - BBFDM_UBUS_INVOKE_SYNC("bbfdm", "notify_event", bb.head, 5000, NULL, NULL); + BBFDM_UBUS_SEND_EVENT("bbfdm.event", bb.head); + BBFDM_DEBUG("'MemoryCriticalState!' event sent successfully with utilization at %u%%.", mem_utilization); blob_buf_free(&bb); diff --git a/src/processes.c b/src/processes.c index f1a1dc0..6ef7ed3 100644 --- a/src/processes.c +++ b/src/processes.c @@ -414,7 +414,8 @@ static void send_cpu_critical_state_event(unsigned int cpu_utilization) blobmsg_close_array(&bb, arr); - BBFDM_UBUS_INVOKE_SYNC("bbfdm", "notify_event", bb.head, 5000, NULL, NULL); + BBFDM_UBUS_SEND_EVENT("bbfdm.event", bb.head); + BBFDM_DEBUG("'CPUCriticalState!' event sent successfully with utilization at %u%%.", cpu_utilization); blob_buf_free(&bb); diff --git a/src/utils.c b/src/utils.c index fb17a4b..4c8afff 100644 --- a/src/utils.c +++ b/src/utils.c @@ -107,7 +107,7 @@ bool validate_file_system_size(const char *file_size) return true; } -void send_transfer_complete_event(const char *command, const char *obj_path, const char *transfer_url, +void send_transfer_complete_event(struct ubus_context *ubus_ctx, const char *command, const char *obj_path, const char *transfer_url, char *fault_string, time_t start_t, time_t complete_t, const char *commandKey, const char *transfer_type) { char start_time[32] = {0}; @@ -145,7 +145,8 @@ void send_transfer_complete_event(const char *command, const char *obj_path, con fill_blob_param(&bb, "FaultString", fault_string, DMT_TYPE[DMT_STRING], 0); blobmsg_close_array(&bb, arr); - dmubus_call_blob_msg_set("bbfdm", "notify_event", &bb); + + ubus_send_event(ubus_ctx, "bbfdm.event", bb.head); blob_buf_free(&bb); } diff --git a/src/utils.h b/src/utils.h index d4ff5e3..22ee3fc 100644 --- a/src/utils.h +++ b/src/utils.h @@ -18,7 +18,7 @@ bool validate_checksum_value(const char *file_path, const char *checksum_algorit bool validate_file_system_size(const char *file_size); bool validate_server_response_code(const char *url, int response_code); -void send_transfer_complete_event(const char *command, const char *obj_path, const char *transfer_url, +void send_transfer_complete_event(struct ubus_context *ubus_ctx, const char *command, const char *obj_path, const char *transfer_url, char *fault_string, time_t start_t, time_t complete_t, const char *commandKey, const char *transfer_type); int sysmngr_get_uptime(void); -- GitLab