Final bonobo-types patch



Hi,

just committed my bonobo-types to libbonobo:

====
2001-07-18  Martin Baulig  <baulig suse de>

	* bonobo/bonobo-types.[ch]: New files.

	* bonobo/bonobo-object.h (BonoboObjectClass): Made "query_interface"
	a virtual method, not a signal.

====

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/libbonobo/ChangeLog,v
retrieving revision 1.72
diff -u -u -r1.72 ChangeLog
--- ChangeLog	2001/07/17 17:08:23	1.72
+++ ChangeLog	2001/07/18 22:07:45
@@ -1,3 +1,10 @@
+2001-07-18  Martin Baulig  <baulig suse de>
+
+	* bonobo/bonobo-types.[ch]: New files.
+
+	* bonobo/bonobo-object.h (BonoboObjectClass): Made "query_interface"
+	a virtual method, not a signal.
+
 2001-07-17  Michael Meeks  <michael ximian com>
 
 	* bonobo/Makefile.am (libbonoboinclude_HEADERS): don't install
Index: changes.txt
===================================================================
RCS file: /cvs/gnome/libbonobo/changes.txt,v
retrieving revision 1.10
diff -u -u -r1.10 changes.txt
--- changes.txt	2001/07/10 12:30:36	1.10
+++ changes.txt	2001/07/18 22:07:45
@@ -38,6 +38,7 @@
 		removed bonobo_object_bind_to_servant
 		removed bonobo_object_activate_servant
 		removed bonobo_object_activate_servant_full
+	"query_interface" is a virtual method and no long a signal.
 
 bonobo-generic-factory.[ch]:
 	A very broken module
Index: bonobo/Makefile.am
===================================================================
RCS file: /cvs/gnome/libbonobo/bonobo/Makefile.am,v
retrieving revision 1.28
diff -u -u -r1.28 Makefile.am
--- bonobo/Makefile.am	2001/07/17 17:08:23	1.28
+++ bonobo/Makefile.am	2001/07/18 22:07:45
@@ -88,7 +88,8 @@
 	bonobo-stream-memory.h		\
 	bonobo-xobject.h		\
 	bonobo-i18n.h			\
-	bonobo-marshal.h
+	bonobo-marshal.h		\
+	bonobo-types.h
 
 noinst_HEADERS =			\
 	bonobo-activation-context.h	\
@@ -122,7 +123,8 @@
 	bonobo-storage.c		\
 	bonobo-stream-client.c		\
 	bonobo-stream-memory.c		\
-	bonobo-running-context.c
+	bonobo-running-context.c	\
+	bonobo-types.c
 
 $(libbonobo_src) : $(CORBA_SOURCE)
 
Index: bonobo/bonobo-object.c
===================================================================
RCS file: /cvs/gnome/libbonobo/bonobo/bonobo-object.c,v
retrieving revision 1.113
diff -u -u -r1.113 bonobo-object.c
--- bonobo/bonobo-object.c	2001/07/16 23:42:23	1.113
+++ bonobo/bonobo-object.c	2001/07/18 22:07:46
@@ -26,6 +26,7 @@
 #include "bonobo-running-context.h"
 #include "bonobo-object-directory.h"
 #include "bonobo-marshal.h"
+#include "bonobo-types.h"
 
 #ifdef BONOBO_OBJECT_DEBUG
 #	define BONOBO_REF_HOOKS
@@ -60,7 +61,6 @@
 
 enum {
 	DESTROY,
-	QUERY_INTERFACE,
 	SYSTEM_EXCEPTION,
 	LAST_SIGNAL
 };
@@ -513,7 +513,8 @@
 {
 	CORBA_Environment  ev;
 	BonoboObject      *retval;
-	CORBA_Object       corba_retval;
+	BonoboObjectClass *klass;
+	CORBA_Object       corba_retval = CORBA_OBJECT_NIL;
 	GType              type;
 	GList             *l;
 
@@ -522,9 +523,9 @@
 	retval       = NULL;
 	corba_retval = CORBA_OBJECT_NIL;
 
-	g_signal_emit (
-		G_OBJECT (object), bonobo_object_signals [QUERY_INTERFACE],
-		0, repo_id, &corba_retval);
+	klass = BONOBO_OBJECT_GET_CLASS (object);
+	if (klass->query_interface)
+		corba_retval = klass->query_interface (object, repo_id);
 
 	CORBA_exception_init (&ev);
 
@@ -640,14 +641,6 @@
 			      NULL, NULL,
 			      g_cclosure_marshal_VOID__VOID,
 			      G_TYPE_NONE, 0);
-	bonobo_object_signals [QUERY_INTERFACE] =
-		g_signal_new ("query_interface",
-			      G_TYPE_FROM_CLASS (object_class),
-			      G_SIGNAL_RUN_LAST,
-			      G_STRUCT_OFFSET (BonoboObjectClass,query_interface),
-			      NULL, NULL,
-			      bonobo_marshal_VOID__POINTER_POINTER,
-			      G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER);
 	bonobo_object_signals [SYSTEM_EXCEPTION] =
 		g_signal_new ("system_exception",
 			      G_TYPE_FROM_CLASS (object_class),
Index: bonobo/bonobo-object.h
===================================================================
RCS file: /cvs/gnome/libbonobo/bonobo/bonobo-object.h,v
retrieving revision 1.63
diff -u -u -r1.63 bonobo-object.h
--- bonobo/bonobo-object.h	2001/06/27 23:40:03	1.63
+++ bonobo/bonobo-object.h	2001/07/18 22:07:47
@@ -24,6 +24,7 @@
 #define BONOBO_OBJECT_CLASS(k)    (G_TYPE_CHECK_CLASS_CAST((k), BONOBO_OBJECT_TYPE, BonoboObjectClass))
 #define BONOBO_IS_OBJECT(o)       (G_TYPE_CHECK_INSTANCE_TYPE ((o), BONOBO_OBJECT_TYPE))
 #define BONOBO_IS_OBJECT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), BONOBO_OBJECT_TYPE))
+#define BONOBO_OBJECT_GET_CLASS(o)(G_TYPE_INSTANCE_GET_CLASS ((o), BONOBO_OBJECT_TYPE, BonoboObjectClass))
 
 #define BONOBO_OBJREF(o)          (bonobo_object_corba_objref(BONOBO_OBJECT(o)))
 
@@ -58,10 +59,12 @@
 typedef struct {
 	GObjectClass parent_class;
 
+	/* virtual methods. */
+	CORBA_Object (*query_interface)  (BonoboObject *object, const char *repo_id);
+
 	/* signals. */
-	void  (*destroy)          (BonoboObject *object);
-	void  (*query_interface)  (BonoboObject *object, const char *repo_id,  CORBA_Object      *retval);
-	void  (*system_exception) (BonoboObject *object, CORBA_Object cobject, CORBA_Environment *ev);
+	void         (*destroy)          (BonoboObject *object);
+	void         (*system_exception) (BonoboObject *object, CORBA_Object cobject, CORBA_Environment *ev);
 
 	BonoboObjectPOAFn          poa_init_fn;
 	BonoboObjectPOAFn          poa_fini_fn;
Index: bonobo/bonobo-types.c
===================================================================
RCS file: bonobo-types.c
diff -N bonobo-types.c
--- /dev/null	Tue May  5 16:32:27 1998
+++ bonobo-types.c	Wed Jul 18 18:07:47 2001
@@ -0,0 +1,245 @@
+#include <config.h>
+#include <gobject/gbsearcharray.h>
+#include <gobject/gvalue.h>
+#include <gobject/gvaluearray.h>
+#include <gobject/gvaluecollector.h>
+#include <bonobo/bonobo-types.h>
+#include <bonobo/bonobo-arg.h>
+
+typedef struct
+{
+	GType            type;
+	CORBA_TypeCode   tc;
+	gboolean         is_bonobo_unknown;
+} CorbaObjectProxy;
+
+static gint corba_object_proxy_cmp (gconstpointer p1, gconstpointer p2);
+
+static GBSearchArray corba_object_proxy_bsa = G_STATIC_BSEARCH_ARRAY_INIT (sizeof (CorbaObjectProxy), corba_object_proxy_cmp, 0);
+
+static gint
+corba_object_proxy_cmp (gconstpointer p1, gconstpointer p2)
+{
+	const CorbaObjectProxy *node1 = p1, *node2 = p2;
+
+	return G_BSEARCH_ARRAY_CMP (node1->type, node2->type);
+}
+
+static void
+corba_object_proxy_value_init (GValue *value)
+{
+	CorbaObjectProxy key, *node;
+
+	key.type = G_VALUE_TYPE (value);
+	node = g_bsearch_array_lookup (&corba_object_proxy_bsa, &key);
+	// value->data[0].v_pointer = node->init ? node->init () : NULL;
+}
+
+static void
+corba_object_proxy_value_free (GValue *value)
+{
+	if (value->data[0].v_pointer) {
+		CorbaObjectProxy key, *node;
+		CORBA_Environment ev;
+
+		key.type = G_VALUE_TYPE (value);
+		node = g_bsearch_array_lookup (&corba_object_proxy_bsa, &key);
+
+		CORBA_exception_init (&ev);
+		if (node->is_bonobo_unknown)
+			bonobo_object_release_unref (value->data[0].v_pointer, &ev);
+		else
+			CORBA_Object_release (value->data[0].v_pointer, &ev);
+		CORBA_exception_free (&ev);
+	}
+}
+
+static void
+corba_object_proxy_value_copy (const GValue *src_value,
+			       GValue       *dest_value)
+{
+	if (src_value->data[0].v_pointer) {
+		CorbaObjectProxy key, *node;
+		CORBA_Environment ev;
+
+		key.type = G_VALUE_TYPE (src_value);
+		node = g_bsearch_array_lookup (&corba_object_proxy_bsa, &key);
+
+		CORBA_exception_init (&ev);
+		if (node->is_bonobo_unknown)
+			dest_value->data[0].v_pointer = bonobo_object_dup_ref (
+				src_value->data[0].v_pointer, &ev);
+		else
+			dest_value->data[0].v_pointer = CORBA_Object_duplicate (
+				src_value->data[0].v_pointer, &ev);
+		CORBA_exception_free (&ev);
+	} else
+		dest_value->data[0].v_pointer = NULL;
+}
+
+static gpointer
+corba_object_proxy_value_peek_pointer (const GValue *value)
+{
+	return value->data[0].v_pointer;
+}
+
+static gchar*
+corba_object_proxy_collect_value (GValue      *value,
+				  guint        n_collect_values,
+				  GTypeCValue *collect_values,
+				  guint        collect_flags)
+{
+	CorbaObjectProxy key, *node;
+
+	key.type = G_VALUE_TYPE (value);
+	node = g_bsearch_array_lookup (&corba_object_proxy_bsa, &key);
+
+	if (!collect_values[0].v_pointer)
+		value->data[0].v_pointer = NULL;
+	else {
+		CORBA_Environment ev;
+		CORBA_Object corba_objref;
+
+		corba_objref = collect_values[0].v_pointer;
+
+		CORBA_exception_init (&ev);
+		if (!CORBA_Object_is_a (corba_objref, node->tc->repo_id, &ev))
+		    return g_strdup_printf ("CORBA Object %p is not a `%s'.",
+					    corba_objref, node->tc->repo_id);
+
+		if (node->is_bonobo_unknown)
+			value->data[0].v_pointer = bonobo_object_dup_ref (corba_objref, &ev);
+		else
+			value->data[0].v_pointer = CORBA_Object_duplicate (corba_objref, &ev);
+		CORBA_exception_free (&ev);
+	}
+
+	return NULL;
+}
+
+static gchar*
+corba_object_proxy_lcopy_value (const GValue *value,
+				guint         n_collect_values,
+				GTypeCValue  *collect_values,
+				guint         collect_flags)
+{
+	gpointer *corba_p = collect_values[0].v_pointer;
+
+	if (!corba_p)
+		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
+
+	if (!value->data[0].v_pointer)
+		*corba_p = NULL;
+	else {
+		CorbaObjectProxy key, *node;
+		CORBA_Environment ev;
+
+		key.type = G_VALUE_TYPE (value);
+		node = g_bsearch_array_lookup (&corba_object_proxy_bsa, &key);
+
+		CORBA_exception_init (&ev);
+		if (node->is_bonobo_unknown)
+			*corba_p = bonobo_object_dup_ref (value->data[0].v_pointer, &ev);
+		else
+			*corba_p = CORBA_Object_duplicate (value->data[0].v_pointer, &ev);
+		CORBA_exception_free (&ev);
+	}
+
+  return NULL;
+}
+
+GType
+bonobo_corba_object_type_register_static (const gchar *name, const CORBA_TypeCode tc,
+					  gboolean is_bonobo_unknown)
+{
+	static const GTypeValueTable vtable = {
+		corba_object_proxy_value_init,
+		corba_object_proxy_value_free,
+		corba_object_proxy_value_copy,
+		corba_object_proxy_value_peek_pointer,
+		"p",
+		corba_object_proxy_collect_value,
+		"p",
+		corba_object_proxy_lcopy_value,
+	};
+	static const GTypeInfo type_info = {
+		0,		/* class_size */
+		NULL,		/* base_init */
+		NULL,		/* base_finalize */
+		NULL,		/* class_init */
+		NULL,		/* class_finalize */
+		NULL,		/* class_data */
+		0,		/* instance_size */
+		0,		/* n_preallocs */
+		NULL,		/* instance_init */
+		&vtable,	/* value_table */
+	};
+	GType type;
+
+	g_return_val_if_fail (tc != NULL, 0);
+	g_return_val_if_fail (name != NULL, 0);
+	g_return_val_if_fail (g_type_from_name (name) == 0, 0);
+
+	type = g_type_register_static (G_TYPE_BOXED, name, &type_info, 0);
+
+	/* install proxy functions upon successfull registration */
+	if (type) {
+		CorbaObjectProxy key;
+		CORBA_Environment ev;
+
+		key.type = type;
+		CORBA_exception_init (&ev);
+		key.tc = (CORBA_TypeCode) CORBA_Object_duplicate ((CORBA_Object) tc, &ev);
+		CORBA_exception_init (&ev);
+		key.is_bonobo_unknown = is_bonobo_unknown;
+		g_bsearch_array_insert (&corba_object_proxy_bsa, &key, TRUE);
+		CORBA_exception_free (&ev);
+	}
+	
+	return type;
+}
+
+#define BONOBO_TYPE_CORBA_OBJECT_IMPL(name,typename,tc,is_bonobo_unknown)	\
+GType										\
+bonobo_ ## name ## _get_type (void)						\
+{										\
+	static GType type = 0;							\
+	if (!type)								\
+		type = bonobo_corba_object_type_register_static (		\
+			## typename, ## tc, is_bonobo_unknown);			\
+	return type;								\
+}
+
+BONOBO_TYPE_CORBA_OBJECT_IMPL (corba_object, "CorbaObject", TC_CORBA_Object, FALSE);
+BONOBO_TYPE_CORBA_OBJECT_IMPL (corba_exception, "CorbaException", TC_CORBA_exception_type, FALSE);
+BONOBO_TYPE_CORBA_OBJECT_IMPL (unknown, "BonoboUnknown", TC_Bonobo_Unknown, TRUE);
+
+static gpointer
+corba_any_init (void)
+{
+	return CORBA_any__alloc ();
+}
+
+static gpointer
+corba_any_copy (gpointer any)
+{
+	return bonobo_arg_copy (any);
+}
+
+static void
+corba_any_free (gpointer any)
+{
+	bonobo_arg_release (any);
+}
+
+GType
+bonobo_corba_any_get_type (void)
+{
+	static GType type = 0;
+	if (!type)
+		type = g_boxed_type_register_static ("BonoboCorbaAny", corba_any_init,
+						     corba_any_copy, corba_any_free, TRUE);
+	return type;
+}
+
+
Index: bonobo/bonobo-types.h
===================================================================
RCS file: bonobo-types.h
diff -N bonobo-types.h
--- /dev/null	Tue May  5 16:32:27 1998
+++ bonobo-types.h	Wed Jul 18 18:07:47 2001
@@ -0,0 +1,37 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/**
+ * GRuntime types for CORBA Objects.
+ *
+ * Authors:
+ *   Martin Baulig (baulig suse de)
+ *
+ * Copyright 2001 SuSE Linux AG.
+ */
+#ifndef _BONOBO_TYPES_H_
+#define _BONOBO_TYPES_H_
+
+#include <glib/gmacros.h>
+#include <gobject/gobject.h>
+#include <bonobo/bonobo-object.h>
+
+G_BEGIN_DECLS
+
+GType  bonobo_corba_object_type_register_static     (const gchar           *name,
+                                                     const CORBA_TypeCode   tc,
+						     gboolean               is_bonobo_unknown);
+
+#define BONOBO_TYPE_CORBA_OBJECT                    (bonobo_corba_object_get_type ())
+GType bonobo_corba_object_get_type                  (void);
+
+#define BONOBO_TYPE_CORBA_EXCEPTION                 (bonobo_corba_exception_get_type ())
+GType bonobo_corba_exception_get_type               (void);
+
+#define BONOBO_TYPE_UNKNOWN                         (bonobo_unknown_get_type ())
+GType bonobo_unknown_get_type                       (void);
+
+#define BONOBO_TYPE_CORBA_ANY                       (bonobo_corba_any_get_type ())
+GType bonobo_corba_any_get_type                     (void);
+
+G_END_DECLS
+
+#endif
-- 
Martin Baulig
martin gnome org (private)
baulig suse de (work)


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