Helixis 1.0
Task Programming API
sources/events.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 2009-2011, helixis.org
00003 ** All rights reserved.
00004 **
00005 ** Redistribution and use in source and binary forms, with or without modification, are permitted provided
00006 ** that the following conditions are met:
00007 **
00008 ** Redistributions of source code must retain the above copyright notice, this list of conditions and the
00009 ** following disclaimer.
00010 **
00011 ** Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
00012 ** the following disclaimer in the documentation and/or other materials provided with the distribution.
00013 **
00014 ** Neither the name of the helixis.org nor the names of its contributors may be used to endorse or promote
00015 ** products derived from this software without specific prior written permission.
00016 **
00017 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
00018 ** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00019 ** PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
00020 ** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00021 ** TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00022 ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00023 ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00024 ** POSSIBILITY OF SUCH DAMAGE.
00025 */
00026 
00027 /*
00028 ** INCLUDES
00029 */
00030 
00031 #include "hlx/core.h"
00032 #include "helixis_internal.h"
00033 
00034 #ifdef __cplusplus
00035 extern "C"      {
00036 #endif
00037 
00038 /*
00039 ** EXTERNALS
00040 */
00041 
00042 extern hlx_api gl_api;
00043 
00044 /*
00045 ** GLOBALS
00046 */
00047 
00048 static hlx_event_manager*       gl_event_manager = 0;
00049 
00050 /*
00051 ** FUNCTIONS
00052 */
00053 
00054 void _hlx_event_delete_callback(void *data, void *state)
00055 {
00056         _hlx_event_callback*    callback;
00057 
00058         (void)state;
00059         callback = (_hlx_event_callback*)data;
00060         gl_api.free_entry(callback);
00061 }
00062 
00063 void _hlx_event_default_manager_destroy(void)
00064 {
00065         if (gl_event_manager != 0)
00066                 gl_api.free_entry(gl_event_manager);
00067         gl_event_manager = 0;
00068 }
00069 
00070 hlx_event_manager*              hlx_event_get_default_manager()
00071 {
00072         if (gl_event_manager == 0)
00073                 gl_event_manager = hlx_event_manager_create();
00074         return (gl_event_manager);
00075 }
00076 
00077 hlx_event_errors                hlx_event_handler_create(hlx_event_manager* public_manager, unsigned long id, unsigned int size)
00078 {
00079         return (_hlx_event_handler_create_by_hash((_hlx_event_manager*)public_manager, id, size));
00080 }
00081 
00082 hlx_event_errors                hlx_event_handler_destroy(hlx_event_manager* public_manager, unsigned long id)
00083 {
00084         _hlx_event_handler*     handler;
00085 
00086         if ((handler = _hlx_event_return_handler((_hlx_event_manager*)public_manager, id)) == 0)
00087                 return (EV_ERROR_UNDEFINED);
00088         _hlx_event_handler_destroy(handler);
00089         return (EV_ERROR_SUCCESS);
00090 }
00091 
00092 hlx_event_errors                        hlx_event_register_callback_func_with_group(hlx_event_manager* public_manager, unsigned long id, hlx_event_user_callback user_callback, void* user_data, hlx_group_id group_id)
00093 {
00094         _hlx_event_manager*             manager;
00095         _hlx_event_handler*             handler;
00096         _hlx_event_callback*    callback;
00097 
00098         manager = (_hlx_event_manager*)public_manager;
00099         if ((handler = _hlx_event_return_handler(manager, id)) == 0)
00100                 return (EV_ERROR_UNDEFINED);
00101         if ((callback = gl_api.malloc_entry(sizeof(*callback))) == 0)
00102                 return (EV_ERROR_MEMORY_EXHAUSTED);
00103         callback->func = user_callback;
00104         callback->params.callback = 0;
00105         callback->params.user_data = user_data;
00106         callback->task = 0;
00107         return (_hlx_event_register_callback_with_group(manager, handler, id, callback, group_id));
00108 }
00109 
00110 hlx_event_errors                        hlx_event_register_callback_func(hlx_event_manager* public_manager, unsigned long id, hlx_event_user_callback user_callback, void* user_data)
00111 {
00112         return hlx_event_register_callback_func_with_group(public_manager, id, user_callback, user_data, 0);
00113 }
00114 
00115 hlx_event_errors                        _hlx_event_register_callback_task_with_callback_and_group(hlx_event_manager* public_manager, unsigned long id, hlx_task_func user_callback, void* user_data, hlx_task_callback task_callback, hlx_group_id group_id)
00116 {
00117         _hlx_event_manager*             manager;
00118         _hlx_event_handler*             handler;
00119         _hlx_event_callback*    callback;
00120 
00121         manager = (_hlx_event_manager*)public_manager;
00122         if ((handler = _hlx_event_return_handler(manager, id)) == 0)
00123                 return (EV_ERROR_UNDEFINED);
00124         if ((callback = gl_api.malloc_entry(sizeof(*callback))) == 0)
00125                 return (EV_ERROR_MEMORY_EXHAUSTED);
00126         callback->task = user_callback;
00127         callback->params.callback = task_callback;
00128         callback->params.user_data = user_data;
00129         callback->func = 0;
00130         return (_hlx_event_register_callback_with_group(manager, handler, id, callback, group_id));
00131 }
00132 
00133 hlx_event_errors                        _hlx_event_register_callback_task_with_callback(hlx_event_manager* public_manager, unsigned long id, hlx_task_func task, void* user_data, hlx_task_callback task_callback)
00134 {
00135         return _hlx_event_register_callback_task_with_callback_and_group(public_manager, id, task, user_data, task_callback, 0);
00136 }
00137 
00138 hlx_event_errors                        hlx_event_register_callback_task_with_group(hlx_event_manager* public_manager, unsigned long id, hlx_task_func user_callback, void* user_data, hlx_group_id group_id)
00139 {
00140         return _hlx_event_register_callback_task_with_callback_and_group(public_manager, id, user_callback, user_data, 0, group_id);
00141 }
00142 
00143 hlx_event_errors                        hlx_event_register_callback_task(hlx_event_manager* public_manager, unsigned long id, hlx_task_func user_callback, void* user_data)
00144 {
00145         return _hlx_event_register_callback_task_with_callback_and_group(public_manager, id, user_callback, user_data, 0, 0);
00146 }
00147 
00148 _hlx_event_handler*                     _hlx_event_return_handler(_hlx_event_manager* manager, unsigned long id)
00149 {
00150         return (_hlx_event_return_handler_by_hash(manager, id));
00151 }
00152 
00153 void                                            _hlx_event_task_callback(void* param, hlx_group_id group_id, int status)
00154 {
00155         hlx_event_args* args;
00156 
00157         args = (hlx_event_args*)param;
00158         if (args->callback)
00159                 args->callback(param, group_id, status);
00160         if (args->event_data)
00161                 gl_api.free_entry(args->event_data);
00162         gl_api.free_entry(args);
00163 }
00164 
00165 #ifdef __cplusplus
00166 }
00167 #endif
00168 
00169 /*
00170 ** END OF FILE
00171 */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines