libbonobo closureization



Is there a remote chance of this getting accepted? If yes, I am willing to
modify the other callbacks in libbonobo to use GClosures as well.
The importance of this is that if we don't do this before the API freeze,
language binding authors can get in an awkward situation.


Index: bonobo-event-source.c
===================================================================
RCS file: /cvs/gnome/libbonobo/bonobo/bonobo-event-source.c,v
retrieving revision 1.32
diff -u -u -r1.32 bonobo-event-source.c
--- bonobo-event-source.c	2001/06/26 16:43:32	1.32
+++ bonobo-event-source.c	2001/07/29 22:40:14
@@ -356,11 +356,10 @@
 }
 
 Bonobo_EventSource_ListenerId
-bonobo_event_source_client_add_listener (Bonobo_Unknown object,
-					 BonoboListenerCallbackFn event_callback,
-					 const char *opt_mask,
-					 CORBA_Environment *opt_ev,
-					 gpointer user_data)
+bonobo_event_source_client_add_listener (Bonobo_Unknown     object,
+					 GClosure          *event_callback,
+					 const char        *opt_mask,
+					 CORBA_Environment *opt_ev)
 {
 	CORBA_Environment ev, *my_ev;
 	BonoboListener *listener = NULL;
@@ -368,7 +367,6 @@
 	Bonobo_EventSource_ListenerId id = 0;
 	Bonobo_Unknown es;
 
-	g_return_val_if_fail (object != CORBA_OBJECT_NIL, 0);
 	g_return_val_if_fail (event_callback != NULL, 0);
 	
 	if (!opt_ev) {
@@ -383,7 +381,7 @@
 	if (BONOBO_EX (my_ev) || !es)
 		goto add_listener_end;
 
-	if (!(listener = bonobo_listener_new (event_callback, user_data)))
+	if (!(listener = bonobo_listener_new (event_callback)))
 		goto add_listener_end;
 
 	corba_listener = BONOBO_OBJREF (listener);
Index: bonobo-event-source.h
===================================================================
RCS file: /cvs/gnome/libbonobo/bonobo/bonobo-event-source.h,v
retrieving revision 1.11
diff -u -u -r1.11 bonobo-event-source.h
--- bonobo-event-source.h	2001/04/18 22:09:06	1.11
+++ bonobo-event-source.h	2001/07/29 22:40:14
@@ -13,6 +13,8 @@
 #include <bonobo/bonobo-object.h>
 #include <bonobo/bonobo-listener.h>
 
+#include <gobject/gclosure.h>
+
 G_BEGIN_DECLS
 
 #define BONOBO_EVENT_SOURCE_TYPE        (bonobo_event_source_get_type ())
@@ -53,11 +55,10 @@
 							 CORBA_Environment *opt_ev);
 
 Bonobo_EventSource_ListenerId 
-bonobo_event_source_client_add_listener                 (Bonobo_Unknown           object,
-							 BonoboListenerCallbackFn event_callback,
-							 const char               *opt_mask,
-							 CORBA_Environment        *opt_ev,
-							 gpointer                 user_data); 
+bonobo_event_source_client_add_listener                 (Bonobo_Unknown     object,
+							 GClosure          *callback,
+							 const char        *opt_mask,
+							 CORBA_Environment *opt_ev);
 
 /* You don't want this routine */
 void               bonobo_event_source_ignore_listeners (BonoboEventSource *event_source);
Index: bonobo-generic-factory.c
===================================================================
RCS file: /cvs/gnome/libbonobo/bonobo/bonobo-generic-factory.c,v
retrieving revision 1.33
diff -u -u -r1.33 bonobo-generic-factory.c
--- bonobo-generic-factory.c	2001/07/28 17:53:52	1.33
+++ bonobo-generic-factory.c	2001/07/29 22:40:15
@@ -36,8 +36,7 @@
 struct _BonoboGenericFactoryPrivate
 {	
 	/* The function factory */
-	BonoboFactoryCallback  factory_cb;
-	gpointer               factory_closure;
+	GClosure              *factory_cb;
 
 	/* The CORBA Object */
 	GNOME_ObjectFactory    corba_objref;
@@ -160,8 +159,7 @@
 bonobo_generic_factory_construct (BonoboGenericFactory   *factory,
 				  GNOME_ObjectFactory     corba_factory,
 				  const char             *oaf_iid,
-				  BonoboFactoryCallback   factory_cb,
-				  gpointer                user_data)
+				  GClosure               *factory_cb)
 {
 	CORBA_Environment ev;
 	int ret;
@@ -170,9 +168,13 @@
 	g_return_val_if_fail (BONOBO_IS_GENERIC_FACTORY (factory), NULL);
 	g_return_val_if_fail (corba_factory != CORBA_OBJECT_NIL, NULL);
 
-	factory->priv->factory_cb      = factory_cb;
-	factory->priv->factory_closure = user_data;
-	factory->priv->oaf_iid         = g_strdup (oaf_iid);
+	g_closure_ref (factory_cb);
+	g_closure_sink (factory_cb);
+	if (G_CLOSURE_NEEDS_MARSHAL (factory_cb))
+		g_closure_set_marshal (factory_cb, g_cclosure_marshal_VOID__STRING);
+	
+	factory->priv->factory_cb = factory_cb;
+	factory->priv->oaf_iid    = g_strdup (oaf_iid);
 
 	CORBA_exception_init (&ev);
 	factory->priv->corba_objref  = CORBA_Object_duplicate (corba_factory, &ev);
@@ -210,9 +212,8 @@
  * name server.
  */
 BonoboGenericFactory *
-bonobo_generic_factory_new (const char            *oaf_iid,
-			    BonoboFactoryCallback  factory_cb,
-			    gpointer               data)
+bonobo_generic_factory_new (const char *oaf_iid,
+			    GClosure   *factory_cb)
 {
 	BonoboGenericFactory *factory;
 	GNOME_ObjectFactory corba_factory;
@@ -229,7 +230,7 @@
 	}
 	
 	return bonobo_generic_factory_construct (factory, corba_factory,
-						 oaf_iid, factory_cb, data);
+						 oaf_iid, factory_cb);
 }
 
 
@@ -245,8 +246,10 @@
 					      factory->priv->corba_objref);
 		CORBA_Object_release (factory->priv->corba_objref, &ev);
 		CORBA_exception_free (&ev);
-		g_free (factory->priv->oaf_iid);
 
+		g_free (factory->priv->oaf_iid);
+		g_closure_unref (factory->priv->factory_cb);
+		
 		g_free (factory->priv);
 		factory->priv = 0;
 	}
@@ -258,11 +261,39 @@
 bonobo_generic_factory_new_generic (BonoboGenericFactory *factory,
 				    const char           *oaf_iid)
 {
+	BonoboObject *ret;
+	GValue        arguments[2] = {{0, }, {0, }};
+	GValue        ret_val = {0, };
+	
 	g_return_val_if_fail (factory != NULL, NULL);
 	g_return_val_if_fail (BONOBO_IS_GENERIC_FACTORY (factory), NULL);
 
+	g_value_init (&arguments[0], BONOBO_GENERIC_FACTORY_TYPE);
+	g_value_set_object (&arguments[0], factory);
+
+	g_value_init (&arguments[1], G_TYPE_STRING);
+	g_value_set_string (&arguments[1], oaf_iid);
+
+	g_value_init (&ret_val, BONOBO_OBJECT_TYPE);
+	
+	g_closure_invoke (factory->priv->factory_cb,
+			  &ret_val,
+			  2,
+			  arguments,
+			  NULL);
+
+	/*
 	return factory->priv->factory_cb (factory, oaf_iid,
 					  factory->priv->factory_closure);
+	*/
+
+	ret = g_value_get_object (&ret_val);
+	g_value_unset (&ret_val);
+
+	g_value_unset (&arguments[0]);
+	g_value_unset (&arguments[1]);
+
+	return ret;
 }
 
 static void
Index: bonobo-generic-factory.h
===================================================================
RCS file: /cvs/gnome/libbonobo/bonobo/bonobo-generic-factory.h,v
retrieving revision 1.28
diff -u -u -r1.28 bonobo-generic-factory.h
--- bonobo-generic-factory.h	2001/07/28 17:44:05	1.28
+++ bonobo-generic-factory.h	2001/07/29 22:40:15
@@ -13,6 +13,7 @@
 
 
 #include <gobject/gobject.h>
+#include <gobject/gclosure.h>
 #include <bonobo/bonobo-object.h>
 #include <bonobo/bonobo-i18n.h>
 #include <liboaf/oaf.h>
@@ -29,7 +30,9 @@
 typedef struct _BonoboGenericFactoryPrivate BonoboGenericFactoryPrivate;
 typedef struct _BonoboGenericFactory        BonoboGenericFactory;
 
-typedef BonoboObject * (*BonoboFactoryCallback) (BonoboGenericFactory *factory, const char *component_id, gpointer closure);
+typedef BonoboObject * (*BonoboFactoryCallback) (BonoboGenericFactory *factory,
+						 const char           *component_id,
+						 gpointer              closure);
 					
 struct _BonoboGenericFactory {
 	GObject                      base;
@@ -53,14 +56,12 @@
 								  gpointer              shlib_id);
 
 BonoboGenericFactory *bonobo_generic_factory_new (const char            *oaf_iid,
-						  BonoboFactoryCallback  factory_cb,
-						  gpointer               user_data);
+						  GClosure              *factory_cb);
 
 BonoboGenericFactory *bonobo_generic_factory_construct (BonoboGenericFactory  *factory,
 							GNOME_ObjectFactory    corba_factory,
 							const char            *oaf_iid,
-							BonoboFactoryCallback  factory_cb,
-							gpointer               user_data);
+							GClosure              *factory_cb);
 
 POA_GNOME_ObjectFactory__epv *bonobo_generic_factory_get_epv (void);
 
@@ -74,15 +75,17 @@
 		g_error (_("Could not initialize Bonobo"));
 #endif
 
-#define BONOBO_OAF_FACTORY(oafiid, descr, version, callback, data)            \
-int main (int argc, char *argv [])                                            \
-{                                                                             \
-	BonoboGenericFactory *factory;                                        \
-                                                                              \
-	BONOBO_FACTORY_INIT (descr, version, &argc, argv);                    \
-	factory = bonobo_generic_factory_new (oafiid, callback, data);        \
-	bonobo_main ();                                                       \
-	return 0;                                                             \
+#define BONOBO_OAF_FACTORY(oafiid, descr, version, callback, data)		\
+int main (int argc, char *argv [])						\
+{										\
+	BonoboGenericFactory *factory;						\
+										\
+	BONOBO_FACTORY_INIT (descr, version, &argc, argv);			\
+										\
+	factory = bonobo_generic_factory_new					\
+		(oafiid, g_cclosure_new (callback, data, NULL));		\
+	bonobo_main ();								\
+	return 0;								\
 }                                                                             
 
 #define BONOBO_OAF_FACTORY_MULTI(oafiid, descr, version, callback, data)      \
Index: bonobo-listener.c
===================================================================
RCS file: /cvs/gnome/libbonobo/bonobo/bonobo-listener.c,v
retrieving revision 1.22
diff -u -u -r1.22 bonobo-listener.c
--- bonobo-listener.c	2001/07/07 14:10:48	1.22
+++ bonobo-listener.c	2001/07/29 22:40:18
@@ -10,18 +10,21 @@
  */
 #include <config.h>
 #include <string.h>
+
 #include <gobject/gsignal.h>
+#include <gobject/gvaluetypes.h>
+
 #include <bonobo/bonobo-exception.h>
 #include <bonobo/bonobo-listener.h>
 #include <bonobo/bonobo-marshal.h>
+#include <bonobo/bonobo-types.h>
 
 #define PARENT_TYPE BONOBO_OBJECT_TYPE
 
 static GObjectClass *bonobo_listener_parent_class;
 
 struct _BonoboListenerPrivate {
-	BonoboListenerCallbackFn event_callback;
-	gpointer                 user_data;
+	GClosure *event_callback;
 };
 
 enum SIGNALS {
@@ -41,12 +44,33 @@
 	listener = BONOBO_LISTENER (bonobo_object_from_servant (servant));
 
 	bonobo_object_ref (BONOBO_OBJECT (listener));
-	if (listener->priv->event_callback) 
-		listener->priv->event_callback (
-			listener, (CORBA_char *) event_name, 
-			(CORBA_any *) args, ev,
-			listener->priv->user_data);
-
+	if (listener->priv->event_callback) {
+		GValue arguments[4] = {{0, }, {0, }, {0, }, {0, }};
+		
+		g_value_init (&arguments[0], BONOBO_LISTENER_TYPE);
+		g_value_set_object (&arguments[0], listener);
+
+		g_value_init (&arguments[1], G_TYPE_STRING);
+		g_value_set_string (&arguments[1], event_name);
+
+		g_value_init (&arguments[2], BONOBO_TYPE_CORBA_ANY);
+		g_value_set_boxed (&arguments[2], args);
+
+		g_value_init (&arguments[3], G_TYPE_POINTER);
+		g_value_set_pointer (&arguments[3], ev);
+
+		g_closure_invoke (listener->priv->event_callback,
+				  NULL,
+				  4,
+				  arguments,
+				  NULL);
+
+		g_value_unset (&arguments[0]);
+		g_value_unset (&arguments[1]);
+		g_value_unset (&arguments[2]);
+		g_value_unset (&arguments[3]);
+	}
+		
 	g_signal_emit (G_OBJECT (listener),
 		       signals [EVENT_NOTIFY], 0,
 		       event_name, args, ev);
@@ -59,8 +83,14 @@
 	BonoboListener *listener;
 
 	listener = BONOBO_LISTENER (object);
-	g_free (listener->priv);
 
+	if (listener->priv)
+	{
+		g_closure_unref (listener->priv->event_callback);
+		g_free (listener->priv);
+		listener->priv = 0;
+	}
+
 	bonobo_listener_parent_class->finalize (object);
 }
 
@@ -92,8 +122,7 @@
 
 	listener = BONOBO_LISTENER(object);
 	listener->priv = g_new (BonoboListenerPrivate, 1);
-	listener->priv->event_callback = NULL;
-	listener->priv->user_data = NULL;
+	listener->priv->event_callback = 0;
 }
 
 BONOBO_TYPE_FUNC_FULL (BonoboListener, 
@@ -126,15 +155,19 @@
  * Returns: A BonoboListener object.
  */
 BonoboListener*
-bonobo_listener_new (BonoboListenerCallbackFn event_callback, 
-		     gpointer                 user_data)
+bonobo_listener_new (GClosure *event_cb)
 {
 	BonoboListener *listener;
 
 	listener = g_object_new (BONOBO_LISTENER_TYPE, NULL);
 	
-	listener->priv->event_callback = event_callback;
-	listener->priv->user_data = user_data;
+	g_closure_ref (event_cb);
+	g_closure_sink (event_cb);
+	if (G_CLOSURE_NEEDS_MARSHAL (event_cb))
+		g_closure_set_marshal (event_cb,
+				       bonobo_marshal_VOID__STRING_BOXED_POINTER);
+
+	listener->priv->event_callback = event_cb;
 
 	return listener;
 }
Index: bonobo-listener.h
===================================================================
RCS file: /cvs/gnome/libbonobo/bonobo/bonobo-listener.h,v
retrieving revision 1.11
diff -u -u -r1.11 bonobo-listener.h
--- bonobo-listener.h	2001/04/18 22:09:06	1.11
+++ bonobo-listener.h	2001/07/29 22:40:18
@@ -14,6 +14,8 @@
 #include <bonobo/bonobo-arg.h>
 #include <bonobo/bonobo-object.h>
 
+#include <gobject/gclosure.h>
+
 G_BEGIN_DECLS
 
 #define BONOBO_LISTENER_TYPE        (bonobo_listener_get_type ())
@@ -51,8 +53,7 @@
 
 GType         bonobo_listener_get_type  (void);
 
-BonoboListener *bonobo_listener_new       (BonoboListenerCallbackFn event_callback, 
-					   gpointer                 user_data);
+BonoboListener *bonobo_listener_new       (GClosure *event_callback);
 
 char           *bonobo_event_make_name    (const char *idl_path, 
 					   const char *kind,
Index: bonobo-marshal.list
===================================================================
RCS file: /cvs/gnome/libbonobo/bonobo/bonobo-marshal.list,v
retrieving revision 1.4
diff -u -u -r1.4 bonobo-marshal.list
--- bonobo-marshal.list	2001/07/12 15:57:35	1.4
+++ bonobo-marshal.list	2001/07/29 22:40:18
@@ -6,3 +6,4 @@
 VOID:STRING,INT,STRING
 POINTER:POINTER,BOOLEAN,POINTER
 BOOLEAN:POINTER
+VOID:STRING,BOXED,POINTER
Index: bonobo-shlib-factory.c
===================================================================
RCS file: /cvs/gnome/libbonobo/bonobo/bonobo-shlib-factory.c,v
retrieving revision 1.10
diff -u -u -r1.10 bonobo-shlib-factory.c
--- bonobo-shlib-factory.c	2001/07/28 17:44:05	1.10
+++ bonobo-shlib-factory.c	2001/07/29 22:40:18
@@ -55,8 +55,7 @@
 				const char            *oaf_iid,
 				PortableServer_POA     poa,
 				gpointer               oaf_impl_ptr,
-				BonoboFactoryCallback  factory_cb,
-				gpointer               user_data)
+				GClosure              *closure)
 {
 	g_return_val_if_fail (factory != NULL, NULL);
 	g_return_val_if_fail (BONOBO_IS_SHLIB_FACTORY (factory), NULL);
@@ -71,7 +70,7 @@
 		bonobo_generic_factory_construct (BONOBO_GENERIC_FACTORY (factory),
 						  corba_factory,
 						  oaf_iid,
-						  factory_cb, user_data));
+						  closure));
 }
 
 /**
@@ -96,19 +95,18 @@
 BonoboShlibFactory *bonobo_shlib_factory_new (const char           *oaf_iid,
 					      PortableServer_POA    poa,
 					      gpointer              oaf_impl_ptr,
-					      BonoboFactoryCallback factory_cb,
-					      gpointer              user_data)
+					      GClosure             *closure)
 {
 	BonoboShlibFactory *factory;
 	GNOME_ObjectFactory corba_factory;
 
-	g_return_val_if_fail (factory_cb != NULL, NULL);
+	g_return_val_if_fail (closure != NULL, NULL);
 	g_return_val_if_fail (oaf_iid != NULL, NULL);
 	
 	factory = g_object_new (bonobo_shlib_factory_get_type (), NULL);
 
 	corba_factory = bonobo_generic_factory_corba_object_create (
-		BONOBO_GENERIC_FACTORY (factory), factory_cb);
+		BONOBO_GENERIC_FACTORY (factory), closure);
 
 	if (corba_factory == CORBA_OBJECT_NIL) {
 		g_object_unref (G_OBJECT (factory));
@@ -117,7 +115,7 @@
 	
 	return bonobo_shlib_factory_construct (factory, corba_factory,
 					       oaf_iid, poa, oaf_impl_ptr,
-					       factory_cb, user_data);
+					       closure);
 }
 
 static void
Index: bonobo-shlib-factory.h
===================================================================
RCS file: /cvs/gnome/libbonobo/bonobo/bonobo-shlib-factory.h,v
retrieving revision 1.8
diff -u -u -r1.8 bonobo-shlib-factory.h
--- bonobo-shlib-factory.h	2001/07/28 17:44:05	1.8
+++ bonobo-shlib-factory.h	2001/07/29 22:40:18
@@ -33,7 +33,8 @@
 {                                                                             \
 	BonoboShlibFactory *f;                                                \
         CORBA_Object object_ref;                                              \
-	f = bonobo_shlib_factory_new (oafiid, poa, impl_ptr, fn, data);       \
+	f = bonobo_shlib_factory_new (oafiid, poa, impl_ptr,		      \
+					g_cclosure_new (G_CALLBACK (fn), data, NULL)); \
         object_ref = bonobo_generic_factory_corba_objref (BONOBO_GENERIC_FACTORY (f)); \
         if (BONOBO_EX (ev) || !object_ref) {                                  \
 		g_warning ("cannot get objref: '%s'",                         \
@@ -67,14 +68,12 @@
 						    const char            *component_id,
 						    PortableServer_POA     poa,
 						    gpointer               oaf_impl_ptr,
-						    BonoboFactoryCallback  factory_cb,
-						    gpointer               user_data);
+						    GClosure              *closure);
 
 BonoboShlibFactory *bonobo_shlib_factory_new (const char            *component_id,
 					      PortableServer_POA     poa,
 					      gpointer               oaf_impl_ptr,
-					      BonoboFactoryCallback  factory_cb,
-					      gpointer               user_data);
+					      GClosure              *closure);
 
 void                bonobo_shlib_factory_track_object (BonoboShlibFactory    *factory,
 						       BonoboObject          *object);

-- 
   .--= ULLA! =---------------------.   `We are not here to give users what
   \     http://cactus.rulez.org     \   they want'  -- RMS, at GUADEC 2001
    `---= cactus cactus rulez org =---'
Saint:  A dead sinner revised and edited.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]