00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00036 #ifndef _listener_h_
00037 #define _listener_h_
00038
00039 #include <glib.h>
00040
00058 typedef GSList *listeners_t;
00059
00060 #define LISTENER_ADD(signal, callback) \
00061 G_STMT_START { \
00062 gpointer p = cast_func_to_gpointer((func_ptr_t) (callback)); \
00063 g_assert(NULL != p); \
00064 CAT2(signal,_listeners) = g_slist_append(CAT2(signal,_listeners), p); \
00065 } G_STMT_END
00066
00067 #define LISTENER_REMOVE(signal, callback) \
00068 G_STMT_START { \
00069 gpointer p = cast_func_to_gpointer((func_ptr_t) (callback)); \
00070 g_assert(NULL != p); \
00071 CAT2(signal,_listeners) = g_slist_remove(CAT2(signal,_listeners), p); \
00072 } G_STMT_END
00073
00074 #define LISTENER_EMIT(signal, params) \
00075 G_STMT_START { \
00076 GSList *sl; \
00077 for (sl = CAT2(signal,_listeners); sl != NULL; sl = g_slist_next(sl)) { \
00078 CAT2(signal,_listener_t) fn; \
00079 g_assert(NULL != sl->data); \
00080 fn = (CAT2(signal,_listener_t)) cast_gpointer_to_func(sl->data); \
00081 fn params; \
00082 } \
00083 } G_STMT_END
00084
00085 #endif
00086
00087