00001 /* template header file */ 00002 /* Copyright (C) 2010 Holger Dietze 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) version 3. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License along 00015 * with this program; if not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #ifndef CB_LIST_H 00019 #define CB_LIST_H 00020 00021 #ifdef HAVE_STDLIB_H 00022 #include <stdlib.h> 00023 #endif 00024 00025 00033 typedef uint16_t (* cb_function_t)(void *); 00034 00039 typedef struct cb_list_entry_s { 00041 struct cb_list_entry_s * next_entry; 00043 cb_function_t pTargetFkt; 00045 void * FktArg; 00046 } cb_list_entry_t; 00047 00050 typedef cb_list_entry_t *cb_list_t; 00051 00057 inline void callback_iterate (cb_list_t list) 00058 { 00059 cb_list_entry_t * p; 00060 for (p = list; p; p = p->next_entry) { 00061 (*p->pTargetFkt) (p->FktArg); 00062 } 00063 } 00064 00067 inline uint16_t callback_iterate_and_until0 (cb_list_t list) 00068 { 00069 cb_list_entry_t * p; 00070 uint16_t result = 0xffff; 00071 for (p = list; result && p; p = p->next_entry) { 00072 result &= (*p->pTargetFkt) (p->FktArg); 00073 } 00074 return result; 00075 } 00076 00087 inline void cb_register_call(cb_list_t * list, 00088 cb_function_t fkt2call, void *arg) 00089 { 00090 cb_list_entry_t * n; 00091 00092 // create new element 00093 n = malloc(sizeof(cb_list_entry_t)); 00094 // link in current start element 00095 n->next_entry = *list; 00096 // initialize 00097 n->pTargetFkt = fkt2call; 00098 n->FktArg = arg; 00099 00100 // store new element into first 00101 *list = n; 00102 } 00103 00104 #endif