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

listener.h File Reference


Detailed Description

Needs brief description here.

Author:
Richard Eckart
Date:
2001-2003

#include <glib.h>

Go to the source code of this file.

Defines

#define LISTENER_ADD(signal, callback)
#define LISTENER_REMOVE(signal, callback)
#define LISTENER_EMIT(signal, params)

Typedefs

typedef GSList * listeners_t
 To use the macros below with a "node_added" signal for example, you need to have a storage stucture to hold the listeners list This needs to be defined in the following fashion.


Define Documentation

#define LISTENER_ADD signal,
callback   ) 
 

Value:

G_STMT_START {                                                              \
    gpointer p = cast_func_to_gpointer((func_ptr_t) (callback));            \
    g_assert(NULL != p);                                                    \
    CAT2(signal,_listeners) = g_slist_append(CAT2(signal,_listeners), p);   \
} G_STMT_END

#define LISTENER_EMIT signal,
params   ) 
 

Value:

G_STMT_START {                                                              \
    GSList *sl;                                                             \
    for (sl = CAT2(signal,_listeners); sl != NULL; sl = g_slist_next(sl)) { \
        CAT2(signal,_listener_t) fn;                                        \
        g_assert(NULL != sl->data);                                         \
        fn = (CAT2(signal,_listener_t)) cast_gpointer_to_func(sl->data);    \
        fn params;                                                          \
    }                                                                       \
} G_STMT_END

#define LISTENER_REMOVE signal,
callback   ) 
 

Value:

G_STMT_START {                                                              \
    gpointer p = cast_func_to_gpointer((func_ptr_t) (callback));            \
    g_assert(NULL != p);                                                    \
    CAT2(signal,_listeners) = g_slist_remove(CAT2(signal,_listeners), p);   \
} G_STMT_END


Typedef Documentation

typedef GSList* listeners_t
 

To use the macros below with a "node_added" signal for example, you need to have a storage stucture to hold the listeners list This needs to be defined in the following fashion.

The name is important for the macros to access the structure. For a "node_removed" signal replace node_added_listeners with node_removed_listeners.

listeners_t node_added_listeners = NULL;

You also need a special type defined which holds the signature of the callback function. For example:

typedef void (*node_added_listener_t) (gnutella_node_t *, const gchar *);

Again the name is important (like above).


Generated on Sun Feb 12 10:50:04 2006 for Gtk-Gnutella by doxygen 1.3.6