bonobo-listener

Name

bonobo-listener -- An Event Listener (an implementation of Bonobo::Listener)

Synopsis



#define     BONOBO_LISTENER_TYPE
#define     BONOBO_LISTENER                 (o)
#define     BONOBO_IS_LISTENER              (o)
#define     BONOBO_LISTENER_CLASS           (k)
#define     BONOBO_IS_LISTENER_CLASS        (k)
typedef     BonoboListener;
typedef     BonoboListenerClass;
void        (*BonoboListenerCallbackFn)     (BonoboListener *listener,
                                             char *event_name,
                                             CORBA_any *any,
                                             CORBA_Environment *ev,
                                             gpointer user_data);
BonoboListener* bonobo_listener_new         (BonoboListenerCallbackFn event_callback,
                                             gpointer user_data);
char*       bonobo_event_kind               (const char *event_name);
char*       bonobo_event_type               (const char *event_name);
char*       bonobo_event_subtype            (const char *event_name);
char*       bonobo_event_idl_path           (const char *event_name);
char*       bonobo_event_make_name          (const char *idl_path,
                                             const char *kind,
                                             const char *subtype);

Description

The BonoboListener object is a CORBA server used to receive events emitted by a remote Bonobo::EventSource server. The combination EventSource/Listener is used to notify one or more client applications of events that happen in a component. Think of the EventSource/Listener as a notification/callback system that allows multiple clients to be informed of events.

Once created, the BonoboListener object needs to be attached to a remote IDL:Bonobo/EventSource:1.0 server. This is done by passing the CORBA Object reference of the BonoboListener to the addListener method in the IDL:Bonobo/EventSource:1.0.

The BonoboListener object allows the user to specify a callback function to be invoked when an event is emitted by the IDL:Bonobo/EventSource:1.0 server. The BonoboListener object also emits the "event_notify" Gtk+ signal, which allows you to connect multiple code segments to the same event notification.

Here is a sample client application that registers interest in being notified of events from the fictional "Keyboard" event source:

BonoboListener *keyboard_listener;

my_listener_function (BonoboListener *l, char *event_name,
                      CORBA_any value, CORBA_Environment *ev,
                      gpointer user_data)
{
	printf ("Received event named: s\n", event_name);
}

connect_to_keyboard_source (Bonobo_EventSource *keyboard)
{
        Bonobo_Unknown reference;

        /*
         * First, create the listener Bonobo server.
         */
	keyboard_listener = bonobo_listener_new (my_listener_function, NULL);

        /*
         * Now, register our listener with the EventSource
         */
        reference = bonobo_object_corba_objref (keyboard_listener);
        Bonobo_EventSource_addListener (keyboard, reference);
}
      

The CORBA::any value passed to the listener function is defined by the contract between the EventSource's event you are using and you. To manipulate the value, you can use the CORBA DynamicAny interface to introspect the value and extract the information you need.

Details

BONOBO_LISTENER_TYPE

#define BONOBO_LISTENER_TYPE        (bonobo_listener_get_type ())


BONOBO_LISTENER()

#define BONOBO_LISTENER(o)          (GTK_CHECK_CAST ((o), BONOBO_LISTENER_TYPE, BonoboListener))

o : 


BONOBO_IS_LISTENER()

#define BONOBO_IS_LISTENER(o)       (GTK_CHECK_TYPE ((o), BONOBO_LISTENER_TYPE))

o : 


BONOBO_LISTENER_CLASS()

#define BONOBO_LISTENER_CLASS(k)    (GTK_CHECK_CLASS_CAST((k), BONOBO_LISTENER_TYPE, BonoboListenerClass))

k : 


BONOBO_IS_LISTENER_CLASS()

#define BONOBO_IS_LISTENER_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), BONOBO_LISTENER_TYPE))

k : 


BonoboListener

typedef struct {
        BonoboXObject          parent;

	BonoboListenerPrivate *priv;
} BonoboListener;


BonoboListenerClass

typedef struct {
	BonoboXObjectClass     parent_class;

	POA_Bonobo_Listener__epv epv;

	/* Signals */
	void (* event_notify) (BonoboListener    *listener, 
			       char              *event_name,
			       BonoboArg         *event_data, 
			       CORBA_Environment *ev);
} BonoboListenerClass;


BonoboListenerCallbackFn ()

void        (*BonoboListenerCallbackFn)     (BonoboListener *listener,
                                             char *event_name,
                                             CORBA_any *any,
                                             CORBA_Environment *ev,
                                             gpointer user_data);

The signature for the callback function invoked when an event is delivered to the BonoboListener object.

listener :a pointer to the BonoboListener.
event_name :the event name that was emitted.
any :The value (A CORBA Any) that was passed by the EventSource.
ev :Environment for returning CORBA errors.
user_data :the data pointer specified when you called bonobo_listener_new


bonobo_listener_new ()

BonoboListener* bonobo_listener_new         (BonoboListenerCallbackFn event_callback,
                                             gpointer user_data);

Creates a generic event listener. The listener calls the event_callback function and emits an "event_notify" signal when notified of an event. The signal callback should be of the form:

<informalexample> <programlisting> void some_callback (BonoboListener *listener, char *event_name, CORBA_any *any, CORBA_Environment *ev, gpointer user_data); </programlisting> </informalexample>

You will typically pass the CORBA_Object reference in the return value to an EventSource (by invoking EventSource::addListener).

event_callback : function to be invoked when an event is emitted by the EventSource.
user_data : data passed to the functioned pointed by event_call.
Returns : A BonoboListener object.


bonobo_event_kind ()

char*       bonobo_event_kind               (const char *event_name);

event_name : the event name
Returns : The event kind, or NULL on error.


bonobo_event_type ()

char*       bonobo_event_type               (const char *event_name);

event_name : the event name
Returns : The event subtype, or NULL on error.


bonobo_event_subtype ()

char*       bonobo_event_subtype            (const char *event_name);

event_name : 
Returns : 


bonobo_event_idl_path ()

char*       bonobo_event_idl_path           (const char *event_name);

event_name : the event name
Returns : The event idl path, or NULL on error.


bonobo_event_make_name ()

char*       bonobo_event_make_name          (const char *idl_path,
                                             const char *kind,
                                             const char *subtype);

Creates an event name. Event names consist of three parts. The idl_path is mainly to create a unique namespace, and should identify the interface which triggered the event, for example "Bonobo/Property". The kind denotes what happened, for example "change". Finally you can use the optional subtype to make events more specific. All three parts of the name are joined together separated by colons. "Bonobo/Property:change" or "Bonobo/Property:change:autosave" are examples of valid event names.

idl_path : the IDL part of the event name.
kind : the kind of the event
subtype : an optional subtype
Returns : A valid event_name, or NULL on error.

See Also

BonoboEventSource BonoboArg