mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2026-01-28 01:47:18 +01:00
Improve event handling
This commit is contained in:
parent
e4c6e242b6
commit
5aa1298df5
6 changed files with 54 additions and 18 deletions
|
|
@ -165,8 +165,8 @@ static void _bbfdm_task_callback(struct uloop_timeout *t)
|
|||
free(task);
|
||||
}
|
||||
|
||||
int bbfdm_task_schedule(bbfdm_task_callback_t callback, const void *arg1, const void *arg2, int timeout_sec) {
|
||||
|
||||
int bbfdm_task_schedule(bbfdm_task_callback_t callback, const void *arg1, void *arg2, int timeout_sec)
|
||||
{
|
||||
bbfdm_task_data_t *task;
|
||||
|
||||
if (timeout_sec < 0) {
|
||||
|
|
@ -209,7 +209,7 @@ static void _bbfdm_task_finish_callback(struct uloop_process *p, int ret)
|
|||
}
|
||||
|
||||
|
||||
int bbfdm_task_fork(bbfdm_task_callback_t taskcb, bbfdm_task_callback_t finishcb, const void *arg1, const void *arg2)
|
||||
int bbfdm_task_fork(bbfdm_task_callback_t taskcb, bbfdm_task_callback_t finishcb, const void *arg1, void *arg2)
|
||||
{
|
||||
pid_t child;
|
||||
bbfdm_task_data_t *task;
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ struct dmubus_ev_subtask {
|
|||
};
|
||||
|
||||
// bbfdm task related functions
|
||||
typedef void (*bbfdm_task_callback_t)(const void *arg1, const void *arg2);
|
||||
typedef void (*bbfdm_task_callback_t)(const void *arg1, void *arg2);
|
||||
|
||||
typedef struct bbfdm_task_data {
|
||||
struct uloop_process process; // Used for forked task
|
||||
|
|
@ -39,12 +39,12 @@ typedef struct bbfdm_task_data {
|
|||
bbfdm_task_callback_t taskcb;
|
||||
bbfdm_task_callback_t finishcb; // Used for forked task
|
||||
const void *arg1;
|
||||
const void *arg2;
|
||||
void *arg2;
|
||||
} bbfdm_task_data_t;
|
||||
|
||||
int bbfdm_task_schedule(bbfdm_task_callback_t callback, const void *arg1, const void *arg2, int timeout);
|
||||
int bbfdm_task_schedule(bbfdm_task_callback_t callback, const void *arg1, void *arg2, int timeout);
|
||||
|
||||
int bbfdm_task_fork(bbfdm_task_callback_t taskcb, bbfdm_task_callback_t finishcb, const void *arg1, const void *arg2);
|
||||
int bbfdm_task_fork(bbfdm_task_callback_t taskcb, bbfdm_task_callback_t finishcb, const void *arg1, void *arg2);
|
||||
|
||||
typedef void (*CB_FUNC_PTR)(struct ubus_context *ctx, struct ubus_event_handler *ev,
|
||||
const char *type, struct blob_attr *msg);
|
||||
|
|
|
|||
|
|
@ -14,6 +14,11 @@
|
|||
#include "get_helper.h"
|
||||
#include <libubus.h>
|
||||
|
||||
struct event_args {
|
||||
struct blob_attr *blob_data;
|
||||
char method_name[256];
|
||||
};
|
||||
|
||||
static char *get_events_dm_path(struct list_head *ev_list, const char *event)
|
||||
{
|
||||
struct ev_handler_node *iter = NULL;
|
||||
|
|
@ -29,6 +34,28 @@ static char *get_events_dm_path(struct list_head *ev_list, const char *event)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void event_callback(const void *arg1, void *arg2)
|
||||
{
|
||||
struct event_args *e_args = (struct event_args *)arg2;
|
||||
|
||||
if (!e_args || !e_args->blob_data || !DM_STRLEN(e_args->method_name))
|
||||
return;
|
||||
|
||||
struct ubus_context *ctx = ubus_connect(NULL);
|
||||
if (ctx == NULL) {
|
||||
BBF_ERR("Can't create UBUS context for event");
|
||||
return;
|
||||
}
|
||||
|
||||
ubus_send_event(ctx, e_args->method_name, e_args->blob_data);
|
||||
BBF_INFO("Event[%s] sent", e_args->method_name);
|
||||
|
||||
ubus_free(ctx);
|
||||
|
||||
free(e_args->blob_data);
|
||||
free(e_args);
|
||||
}
|
||||
|
||||
static void bbfdm_event_handler(struct ubus_context *ctx, struct ubus_event_handler *ev,
|
||||
const char *type, struct blob_attr *msg)
|
||||
{
|
||||
|
|
@ -73,15 +100,24 @@ static void bbfdm_event_handler(struct ubus_context *ctx, struct ubus_event_hand
|
|||
if (ret)
|
||||
goto end;
|
||||
|
||||
char method_name[256] = {0};
|
||||
|
||||
snprintf(method_name, sizeof(method_name), "%s.%s", DM_STRLEN(u->config.out_root_obj) ? u->config.out_root_obj : u->config.out_name, BBF_EVENT_NAME);
|
||||
|
||||
ubus_send_event(ctx, method_name, bbf_ctx.bb.head);
|
||||
BBF_INFO("Event[%s], for [%s] sent", method_name, dm_path);
|
||||
|
||||
bbfdm_schedule_instance_refresh_timer(ctx, 2);
|
||||
|
||||
size_t blob_data_len = blob_len(bbf_ctx.bb.head);
|
||||
|
||||
if (blob_data_len) {
|
||||
struct event_args *e_args = (struct event_args *)calloc(1, sizeof(struct event_args));
|
||||
if (!e_args)
|
||||
goto end;
|
||||
|
||||
snprintf(e_args->method_name, sizeof(e_args->method_name), "%s.%s", DM_STRLEN(u->config.out_root_obj) ? u->config.out_root_obj : u->config.out_name, BBF_EVENT_NAME);
|
||||
|
||||
e_args->blob_data = (struct blob_attr *)calloc(1, blob_data_len);
|
||||
|
||||
memcpy(e_args->blob_data, bbf_ctx.bb.head, blob_data_len);
|
||||
|
||||
bbfdm_task_schedule(event_callback, NULL, e_args, 6);
|
||||
}
|
||||
|
||||
end:
|
||||
bbf_cleanup(&bbf_ctx);
|
||||
FREE(str);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ static int get_Device_RootDataModelVersion(char *refparam, struct dmctx *ctx, vo
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void _exec_factoryreset(const void *arg1, const void *arg2)
|
||||
static void _exec_factoryreset(const void *arg1, void *arg2)
|
||||
{
|
||||
sleep(2);
|
||||
dmubus_call_set("rpc-sys", "factory", UBUS_ARGS{0}, 0);
|
||||
|
|
|
|||
|
|
@ -1692,9 +1692,9 @@ static int get_operate_args_DeviceInfoFirmwareImage_Activate(char *refparam, str
|
|||
return 0;
|
||||
}
|
||||
|
||||
void _exec_reboot(const void *arg1, const void *arg2)
|
||||
void _exec_reboot(const void *arg1, void *arg2)
|
||||
{
|
||||
sleep(3); // Wait for reboot to happen
|
||||
sleep(3);
|
||||
dmubus_call_set("rpc-sys", "reboot", UBUS_ARGS{0}, 0);
|
||||
sleep(5); // Wait for reboot to happen
|
||||
BBF_ERR("Reboot call failed with rpc-sys, trying again with system");
|
||||
|
|
|
|||
|
|
@ -26,5 +26,5 @@ extern DMLEAF tDeviceInfoProcessorParams[];
|
|||
extern DMLEAF tDeviceInfoSupportedDataModelParams[];
|
||||
extern DMLEAF tDeviceInfoFirmwareImageParams[];
|
||||
|
||||
void _exec_reboot(const void *arg1, const void *arg2);
|
||||
void _exec_reboot(const void *arg1, void *arg2);
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue