![]() |
Helixis 1.0
Task Programming API
|
Go to the source code of this file.
| typedef void(* hlx_event_user_callback)(hlx_event_args *) |
| enum hlx_event_errors |
| EV_ERROR_SUCCESS | |
| EV_ERROR_INTERNAL_ERROR | |
| EV_ERROR_MEMORY_EXHAUSTED | |
| EV_ERROR_ALREADY_EXISTS | |
| EV_ERROR_UNDEFINED | |
| EV_ERROR_NO_EVENT_DATA |
Definition at line 52 of file events.h.
{
EV_ERROR_SUCCESS = 0,
EV_ERROR_INTERNAL_ERROR = 1,
EV_ERROR_MEMORY_EXHAUSTED = 2,
EV_ERROR_ALREADY_EXISTS = 3,
EV_ERROR_UNDEFINED = 4,
EV_ERROR_NO_EVENT_DATA = 5
} hlx_event_errors;
| hlx_event_manager* hlx_event_get_default_manager | ( | void | ) |
Get the default event manager (Never call hlx_event_manager_destroy() for this manager)
Definition at line 70 of file events.c.
References hlx_event_manager_create().
Referenced by hlx_scheduler_destruct().
{
if (gl_event_manager == 0)
gl_event_manager = hlx_event_manager_create();
return (gl_event_manager);
}
| hlx_event_errors hlx_event_handler_create | ( | hlx_event_manager * | manager, |
| unsigned long | id, | ||
| unsigned int | size | ||
| ) |
Create a new event in the given manager
| manager | The event manager where the event will be attached |
| id | The event Id (you can use hlx_hash) |
| size | The size of the user data (for hlx_event_notify). HLX_EVENT_NO_ARGS for no user arg. |
Definition at line 77 of file events.c.
References _hlx_event_handler_create_by_hash().
{
return (_hlx_event_handler_create_by_hash((_hlx_event_manager*)public_manager, id, size));
}
| hlx_event_errors hlx_event_handler_destroy | ( | hlx_event_manager * | manager, |
| unsigned long | id | ||
| ) |
Destroy The given event
| manager | The event manager where the event is attached |
| id | The event Id (you can use hlx_hash) |
Definition at line 82 of file events.c.
References _hlx_event_handler_destroy(), _hlx_event_return_handler(), EV_ERROR_SUCCESS, and EV_ERROR_UNDEFINED.
{
_hlx_event_handler* handler;
if ((handler = _hlx_event_return_handler((_hlx_event_manager*)public_manager, id)) == 0)
return (EV_ERROR_UNDEFINED);
_hlx_event_handler_destroy(handler);
return (EV_ERROR_SUCCESS);
}
| hlx_event_manager* hlx_event_manager_create | ( | void | ) |
Create a new event manager
Definition at line 52 of file parallel_events.c.
References _hlx_event_manager::handlers, hlx_api::malloc_entry, and slist_new().
Referenced by hlx_event_get_default_manager().
{
_hlx_event_manager* manager;
if ((manager = gl_api.malloc_entry(sizeof(*manager))) == 0)
return 0;
slist_new(&manager->handlers, 0, 0);
return ((hlx_event_manager*)manager);
}
| void hlx_event_manager_destroy | ( | hlx_event_manager * | manager | ) |
Destroy the event manager
Definition at line 62 of file parallel_events.c.
References _hlx_event_default_manager_destroy(), _hlx_event_handler_destroy(), hlx_api::free_entry, slist_delete(), slist_get_head_and_then_next(), and slist_get_user_data_from_element().
Referenced by hlx_scheduler_destruct().
{
struct slist_element* it;
_hlx_event_handler* handler;
it = 0;
while (slist_get_head_and_then_next(((_hlx_event_manager*)manager)->handlers, &it))
{
slist_get_user_data_from_element(it, (void **)&handler);
_hlx_event_handler_destroy(handler);
gl_api.free_entry(handler);
}
slist_delete(((_hlx_event_manager*)manager)->handlers);
_hlx_event_default_manager_destroy();
}
| hlx_event_errors hlx_event_notify | ( | hlx_event_manager * | manager, |
| unsigned long | id, | ||
| void * | event_data | ||
| ) |
Raise an event
| manager | The event manager where the event is attached |
| id | The event Id (you can use hlx_hash) |
| task | The user task. |
| event_data | User event data (the size of the content must be equal to the size specified in hlx_event_handler_create()). You can pass NULL if you use HLX_EVENT_NO_ARGS Important : This method create internally a copy of the parameter. |
Definition at line 123 of file parallel_events.c.
References _hlx_event_return_handler(), _hlx_event_task_callback(), hlx_event_args::callback, _hlx_event_handler::callbacks, EV_ERROR_MEMORY_EXHAUSTED, EV_ERROR_NO_EVENT_DATA, EV_ERROR_SUCCESS, EV_ERROR_UNDEFINED, hlx_event_args::event_data, hlx_core_add_task_callback(), hlx_core_add_task_in_group_callback(), hlx_api::malloc_entry, hlx_api::memcpy_entry, _hlx_event_handler::param_size, slist_get_head_and_then_next(), slist_get_user_data_from_element(), and hlx_event_args::user_data.
{
_hlx_event_handler* handler;
_hlx_event_callback* callback;
hlx_event_args* task_args;
hlx_event_args func_args;
struct slist_element* it;
if ((handler = _hlx_event_return_handler((_hlx_event_manager*)manager, id)) == 0)
return (EV_ERROR_UNDEFINED);
if (handler->param_size && event_data == 0)
return (EV_ERROR_NO_EVENT_DATA);
func_args.event_data = event_data;
func_args.callback = 0;
it = 0;
while (slist_get_head_and_then_next(handler->callbacks, &it))
{
slist_get_user_data_from_element(it, (void **)&callback);
if (callback->func)
{
func_args.user_data = callback->params.user_data;
callback->func(&func_args);
}
if (callback->task)
{
if ((task_args = gl_api.malloc_entry(sizeof(hlx_event_args))) == 0)
return (EV_ERROR_MEMORY_EXHAUSTED);
task_args->user_data = callback->params.user_data;
task_args->callback = callback->params.callback;
if (handler->param_size)
{
if ((task_args->event_data = gl_api.malloc_entry(handler->param_size)) == 0)
return (EV_ERROR_MEMORY_EXHAUSTED);
gl_api.memcpy_entry(task_args->event_data, event_data, handler->param_size);
}
else
task_args->event_data = 0;
if (callback->group_id > 0)
hlx_core_add_task_in_group_callback(callback->task, task_args, callback->group_id, 0, _hlx_event_task_callback);
else
hlx_core_add_task_callback(callback->task, task_args, 0, _hlx_event_task_callback);
}
}
return (EV_ERROR_SUCCESS);
}
| hlx_event_errors hlx_event_register_callback_func | ( | hlx_event_manager * | manager, |
| unsigned long | id, | ||
| hlx_event_user_callback | func, | ||
| void * | user_data | ||
| ) |
Attach a callback to the given event
| manager | The event manager where the event is attached |
| id | The event Id (you can use hlx_hash) |
| func | The user callback. |
| user_data | User data in addition to the event data. |
Definition at line 110 of file events.c.
References hlx_event_register_callback_func_with_group().
{
return hlx_event_register_callback_func_with_group(public_manager, id, user_callback, user_data, 0);
}
| hlx_event_errors hlx_event_register_callback_func_with_group | ( | hlx_event_manager * | manager, |
| unsigned long | id, | ||
| hlx_event_user_callback | func, | ||
| void * | user_data, | ||
| hlx_group_id | group_id | ||
| ) |
Attach a callback to the given event. the callback will be called from the given group
| manager | The event manager where the event is attached |
| id | The event Id (you can use hlx_hash) |
| func | The user callback. |
| user_data | User data in addition to the event data. |
| group_id | The group where the callback will be called |
Definition at line 92 of file events.c.
References _hlx_event_register_callback_with_group(), _hlx_event_return_handler(), _hlx_event_params::callback, EV_ERROR_MEMORY_EXHAUSTED, EV_ERROR_UNDEFINED, _hlx_event_callback::func, hlx_api::malloc_entry, _hlx_event_callback::params, _hlx_event_callback::task, and _hlx_event_params::user_data.
Referenced by hlx_event_register_callback_func().
{
_hlx_event_manager* manager;
_hlx_event_handler* handler;
_hlx_event_callback* callback;
manager = (_hlx_event_manager*)public_manager;
if ((handler = _hlx_event_return_handler(manager, id)) == 0)
return (EV_ERROR_UNDEFINED);
if ((callback = gl_api.malloc_entry(sizeof(*callback))) == 0)
return (EV_ERROR_MEMORY_EXHAUSTED);
callback->func = user_callback;
callback->params.callback = 0;
callback->params.user_data = user_data;
callback->task = 0;
return (_hlx_event_register_callback_with_group(manager, handler, id, callback, group_id));
}
| hlx_event_errors hlx_event_register_callback_task | ( | hlx_event_manager * | manager, |
| unsigned long | id, | ||
| hlx_task_func | task, | ||
| void * | user_data | ||
| ) |
Attach a task to the given event
| manager | The event manager where the event is attached |
| id | The event Id (you can use hlx_hash) |
| task | The user task. |
| user_data | User data in addition to the event data. |
Definition at line 143 of file events.c.
References _hlx_event_register_callback_task_with_callback_and_group().
{
return _hlx_event_register_callback_task_with_callback_and_group(public_manager, id, user_callback, user_data, 0, 0);
}
| hlx_event_errors hlx_event_register_callback_task_with_group | ( | hlx_event_manager * | manager, |
| unsigned long | id, | ||
| hlx_task_func | task, | ||
| void * | user_data, | ||
| hlx_group_id | group_id | ||
| ) |
Attach a task to the given event. the task will be pushed in the given group
| manager | The event manager where the event is attached |
| id | The event Id (you can use hlx_hash) |
| task | The user task. |
| user_data | User data in addition to the event data. |
| group_id | The group where the task will be pushed |
Definition at line 138 of file events.c.
References _hlx_event_register_callback_task_with_callback_and_group().
{
return _hlx_event_register_callback_task_with_callback_and_group(public_manager, id, user_callback, user_data, 0, group_id);
}
1.7.4