mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
Api to schedule a task
This commit is contained in:
parent
0a33d96b69
commit
46796a5a47
3 changed files with 55 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -8,3 +8,4 @@ out
|
|||
/build
|
||||
/.repo
|
||||
/utilities/bbf_configd
|
||||
*.swp
|
||||
|
|
|
|||
|
|
@ -153,6 +153,48 @@ static void dmubus_listen_timeout(struct uloop_timeout *timeout)
|
|||
uloop_end();
|
||||
}
|
||||
|
||||
static void _bbfdm_task_callback(struct uloop_timeout *t)
|
||||
{
|
||||
struct bbfdm_task_data *task = container_of(t, struct bbfdm_task_data, timeout);
|
||||
|
||||
if (task == NULL) {
|
||||
BBF_ERR("Failed to decode task");
|
||||
return;
|
||||
}
|
||||
task->callback(task->arg1, task->arg2);
|
||||
free(task);
|
||||
}
|
||||
|
||||
int bbfdm_task_add(bbfdm_task_callback_t callback, const void *arg1, const void *arg2, int timeout_sec) {
|
||||
|
||||
bbfdm_task_data_t *task;
|
||||
|
||||
if (timeout_sec < 0) {
|
||||
BBF_ERR("Can't handler negative timeouts");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// do not use dmalloc here, as this needs to persists beyond session
|
||||
task = (bbfdm_task_data_t *)calloc(sizeof(bbfdm_task_data_t), 1);
|
||||
if (task == NULL) {
|
||||
BBF_ERR("Failed to allocate memory");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
task->callback = callback;
|
||||
task->arg1 = arg1;
|
||||
task->arg2 = arg2;
|
||||
|
||||
task->timeout.cb = _bbfdm_task_callback;
|
||||
|
||||
// Set the initial timeout
|
||||
int ret = uloop_timeout_set(&task->timeout, timeout_sec * 1000);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** dmubus_wait_for_event
|
||||
|
|
|
|||
|
|
@ -30,6 +30,18 @@ struct dmubus_ev_subtask {
|
|||
uint32_t timeout;
|
||||
};
|
||||
|
||||
// bbfdm task related functions
|
||||
typedef void (*bbfdm_task_callback_t)(const void *arg1, const void *arg2);
|
||||
|
||||
typedef struct bbfdm_task_data {
|
||||
struct uloop_timeout timeout;
|
||||
bbfdm_task_callback_t callback;
|
||||
const void *arg1;
|
||||
const void *arg2;
|
||||
} bbfdm_task_data_t;
|
||||
|
||||
int bbfdm_task_add(bbfdm_task_callback_t callback, const void *arg1, const void *arg2, int timeout);
|
||||
|
||||
typedef void (*CB_FUNC_PTR)(struct ubus_context *ctx, struct ubus_event_handler *ev,
|
||||
const char *type, struct blob_attr *msg);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue