Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

listener.h

Go to the documentation of this file.
00001 /*
00002  * $Id: listener.h,v 1.8 2005/09/10 08:58:40 daichik Exp $
00003  *
00004  * Copyright (c) 2001-2003, Richard Eckart
00005  *
00006  *----------------------------------------------------------------------
00007  * This file is part of gtk-gnutella.
00008  *
00009  *  gtk-gnutella is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  gtk-gnutella is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with gtk-gnutella; if not, write to the Free Software
00021  *  Foundation, Inc.:
00022  *      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 /* _listener_h_ */
00086 
00087 /* vi: set ts=4 sw=4 cindent: */

Generated on Sun Feb 12 10:49:56 2006 for Gtk-Gnutella by doxygen 1.3.6