Api to schedule a task

This commit is contained in:
Vivek Kumar Dutta 2024-10-04 18:45:12 +05:30
parent 0a33d96b69
commit 46796a5a47
3 changed files with 55 additions and 0 deletions

1
.gitignore vendored
View file

@ -8,3 +8,4 @@ out
/build
/.repo
/utilities/bbf_configd
*.swp

View file

@ -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

View file

@ -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);