dbus/glib dbus-gproxy.c, 1.32, 1.33 dbus-gparser.c, 1.15,
1.16 dbus-gobject.c, 1.37, 1.38 dbus-gmain.c, 1.43,
1.44 dbus-glib.c, 1.6, 1.7
Colin Walters
walters at freedesktop.org
Thu Jun 30 11:22:15 PDT 2005
- Previous message: dbus/test/glib test-service-glib.xml, 1.7, 1.8 test-service-glib.c,
1.17, 1.18 test-dbus-glib.c, 1.23, 1.24 Makefile.am, 1.14, 1.15
- Next message: dbus/dbus dbus-glib.h,1.16,1.17
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvs/dbus/dbus/glib
In directory gabe:/tmp/cvs-serv29039/glib
Modified Files:
dbus-gproxy.c dbus-gparser.c dbus-gobject.c dbus-gmain.c
dbus-glib.c
Log Message:
2005-06-30 Colin Walters <walters at verbum.org>
* test/glib/test-dbus-glib.c:
* test/glib/test-service-glib.c:
* test/glib/test-service-glib.xml: Update tests for new error
setting bits, also add async tests (patch from Ross Burton).
* test/glib/Makefile.am (test_service_glib_LDADD): Add
DBUS_GLIB_THREADS_LIBS.
* glib/dbus-gproxy.c (get_name_owner)
(dbus_g_pending_call_end_valist): Ditto.
* glib/dbus-gobject.c (error_metadata): New mapping from GError
domain (GQuark) to DBusGErrorInfo.
(gerror_domaincode_to_dbus_error_name): Attempt to look up error
quark in error_metadata. Take message interface as default
error message interface.
(gerror_to_dbus_error_message): Pass message interface.
(dbus_set_g_error): Resurrected.
(dbus_g_error_info_free): New function.
(dbus_g_object_type_install_info): Use g_type_class_ref instead
of _peek to actually create the object class if it hasn't been
created yet.
(dbus_g_error_domain_register): New function.
* glib/dbus-gmain.c (dbus_g_bus_get): Switch to dbus_set_g_error.
* glib/dbus-gparser.c (validate_signature): Ditto.
* dbus/dbus-glib.h (dbus_g_error_set): Delete.
(dbus_g_error_domain_register): Prototype.
* glib/dbus-glib.c (dbus_g_error_set): Delete.
Update tests.
Index: dbus-gproxy.c
===================================================================
RCS file: /cvs/dbus/dbus/glib/dbus-gproxy.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- dbus-gproxy.c 29 Jun 2005 16:58:59 -0000 1.32
+++ dbus-gproxy.c 30 Jun 2005 18:22:10 -0000 1.33
@@ -818,7 +818,7 @@
error:
g_assert (dbus_error_is_set (&derror));
- dbus_g_error_set (error, derror.name, derror.message);
+ dbus_set_g_error (error, &derror);
dbus_error_free (&derror);
out:
@@ -2009,14 +2009,14 @@
break;
case DBUS_MESSAGE_TYPE_ERROR:
dbus_set_error_from_message (&derror, reply);
- dbus_g_error_set (error, derror.name, derror.message);
+ dbus_set_g_error (error, &derror);
dbus_error_free (&derror);
goto out;
break;
default:
dbus_set_error (&derror, DBUS_ERROR_FAILED,
"Reply was neither a method return nor an exception");
- dbus_g_error_set (error, derror.name, derror.message);
+ dbus_set_g_error (error, &derror);
dbus_error_free (&derror);
goto out;
break;
Index: dbus-gparser.c
===================================================================
RCS file: /cvs/dbus/dbus/glib/dbus-gparser.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- dbus-gparser.c 26 Jun 2005 17:02:09 -0000 1.15
+++ dbus-gparser.c 30 Jun 2005 18:22:10 -0000 1.16
@@ -23,6 +23,7 @@
#include "dbus-gparser.h"
#include "dbus/dbus-glib-lowlevel.h"
#include "dbus-gidl.h"
+#include "dbus-gobject.h"
#include "dbus/dbus-signature.h"
#include <string.h>
@@ -474,7 +475,7 @@
if (!dbus_signature_validate (str, &derror))
{
- dbus_g_error_set (error, derror.name, derror.message);
+ dbus_set_g_error (&derror, error);
return FALSE;
}
return TRUE;
Index: dbus-gobject.c
===================================================================
RCS file: /cvs/dbus/dbus/glib/dbus-gobject.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- dbus-gobject.c 29 Jun 2005 17:02:33 -0000 1.37
+++ dbus-gobject.c 30 Jun 2005 18:22:10 -0000 1.38
@@ -39,9 +39,16 @@
* @{
*/
+typedef struct
+{
+ char *default_iface;
+ GType code_enum;
+} DBusGErrorInfo;
+
static GStaticRWLock globals_lock = G_STATIC_RW_LOCK_INIT;
static GHashTable *info_hash = NULL;
static GHashTable *marshal_table = NULL;
+static GData *error_metadata = NULL;
static char*
uscore_to_wincaps (const char *uscore)
@@ -696,6 +703,7 @@
static char *
gerror_domaincode_to_dbus_error_name (const DBusGObjectInfo *object_info,
+ const char *msg_interface,
GQuark domain, gint code)
{
const char *domain_str;
@@ -707,6 +715,36 @@
if (!domain_str || !code_str)
{
+ DBusGErrorInfo *info;
+
+ g_static_rw_lock_reader_lock (&globals_lock);
+
+ if (error_metadata != NULL)
+ info = g_datalist_id_get_data (&error_metadata, domain);
+ else
+ info = NULL;
+
+ g_static_rw_lock_reader_unlock (&globals_lock);
+
+ if (info)
+ {
+ GEnumValue *value;
+ GEnumClass *klass;
+
+ klass = g_type_class_ref (info->code_enum);
+ value = g_enum_get_value (klass, code);
+ g_type_class_unref (klass);
+
+ domain_str = info->default_iface;
+ code_str = value->value_nick;
+ }
+ }
+
+ if (!domain_str)
+ domain_str = msg_interface;
+
+ if (!domain_str || !code_str)
+ {
/* If we can't map it sensibly, make up an error name */
char *domain_from_quark;
@@ -752,7 +790,9 @@
else
{
char *error_name;
- error_name = gerror_domaincode_to_dbus_error_name (object_info, error->domain, error->code);
+ error_name = gerror_domaincode_to_dbus_error_name (object_info,
+ dbus_message_get_interface (message),
+ error->domain, error->code);
reply = dbus_message_new_error (message, error_name, error->message);
g_free (error_name);
}
@@ -1256,6 +1296,40 @@
}
}
+#include "dbus-glib-error-switch.h"
+
+void
+dbus_set_g_error (GError **gerror,
+ DBusError *error)
+{
+ int code;
+
+ code = dbus_error_to_gerror_code (error->name);
+ if (code != DBUS_GERROR_REMOTE_EXCEPTION)
+ g_set_error (gerror, DBUS_GERROR,
+ code,
+ "%s",
+ error->message);
+ else
+ g_set_error (gerror, DBUS_GERROR,
+ code,
+ "%s%c%s",
+ error->message,
+ '\0',
+ error->name);
+}
+
+static void
+dbus_g_error_info_free (gpointer p)
+{
+ DBusGErrorInfo *info;
+
+ info = p;
+
+ g_free (info->default_iface);
+ g_free (info);
+}
+
/** @} */ /* end of internals */
/**
@@ -1287,7 +1361,7 @@
dbus_g_value_types_init ();
- object_class = g_type_class_peek (object_type);
+ object_class = g_type_class_ref (object_type);
g_return_if_fail (G_IS_OBJECT_CLASS (object_class));
@@ -1301,6 +1375,55 @@
g_hash_table_replace (info_hash, object_class, (void*) info);
g_static_rw_lock_writer_unlock (&globals_lock);
+
+ g_type_class_unref (object_class);
+}
+
+/**
+ * Register a GError domain and set of codes with D-BUS. You must
+ * have created a GEnum for the error codes. This function will not
+ * be needed with an introspection-capable GLib.
+ *
+ * @param domain the GError domain
+ * @param default_iface the D-BUS interface used for error values by default, or #NULL
+ * @param code_enum a GType for a GEnum of the error codes
+ */
+void
+dbus_g_error_domain_register (GQuark domain,
+ const char *default_iface,
+ GType code_enum)
+{
+ DBusGErrorInfo *info;
+
+ g_return_if_fail (g_quark_to_string (domain) != NULL);
+ g_return_if_fail (code_enum != G_TYPE_INVALID);
+ g_return_if_fail (G_TYPE_FUNDAMENTAL (code_enum) == G_TYPE_ENUM);
+
+ g_static_rw_lock_writer_lock (&globals_lock);
+
+ if (error_metadata == NULL)
+ g_datalist_init (&error_metadata);
+
+ info = g_datalist_id_get_data (&error_metadata, domain);
+
+ if (info != NULL)
+ {
+ g_warning ("Metadata for error domain \"%s\" already registered\n",
+ g_quark_to_string (domain));
+ }
+ else
+ {
+ info = g_new0 (DBusGErrorInfo, 1);
+ info->default_iface = g_strdup (default_iface);
+ info->code_enum = code_enum;
+
+ g_datalist_id_set_data_full (&error_metadata,
+ domain,
+ info,
+ dbus_g_error_info_free);
+ }
+
+ g_static_rw_lock_writer_unlock (&globals_lock);
}
static void
Index: dbus-gmain.c
===================================================================
RCS file: /cvs/dbus/dbus/glib/dbus-gmain.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- dbus-gmain.c 26 Jun 2005 17:02:09 -0000 1.43
+++ dbus-gmain.c 30 Jun 2005 18:22:10 -0000 1.44
@@ -28,6 +28,7 @@
#include "dbus-gtest.h"
#include "dbus-gutils.h"
#include "dbus-gvalue.h"
+#include "dbus-gobject.h"
#include "dbus-gvalue-utils.h"
#include <string.h>
@@ -720,7 +721,7 @@
connection = dbus_bus_get (type, &derror);
if (connection == NULL)
{
- dbus_g_error_set (error, derror.name, derror.message);
+ dbus_set_g_error (error, &derror);
dbus_error_free (&derror);
return NULL;
}
Index: dbus-glib.c
===================================================================
RCS file: /cvs/dbus/dbus/glib/dbus-glib.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- dbus-glib.c 26 Jun 2005 17:02:09 -0000 1.6
+++ dbus-glib.c 30 Jun 2005 18:22:10 -0000 1.7
@@ -26,6 +26,7 @@
#include <dbus/dbus-glib-lowlevel.h>
#include "dbus-gtest.h"
#include "dbus-gutils.h"
+#include "dbus-gobject.h"
#include <string.h>
#include <libintl.h>
@@ -149,41 +150,6 @@
return quark;
}
-#include "dbus-glib-error-switch.h"
-
-/**
- * Set a GError return location from a D-BUS error name and message.
- * This function should only be used in the implementation of service
- * methods.
- *
- * @param gerror location to store a GError, or #NULL
- * @param name the D-BUS error name
- * @param msg the D-BUS error detailed message
- */
-void
-dbus_g_error_set (GError **gerror,
- const char *name,
- const char *msg)
-{
- int code;
- g_return_if_fail (name != NULL);
- g_return_if_fail (msg != NULL);
-
- code = dbus_error_to_gerror_code (name);
- if (code == DBUS_GERROR_REMOTE_EXCEPTION)
- g_set_error (gerror, DBUS_GERROR,
- code,
- "%s%c%s",
- msg,
- '\0',
- name);
- else
- g_set_error (gerror, DBUS_GERROR,
- code,
- "%s",
- msg);
-}
-
/**
* Determine whether D-BUS error name for a remote exception matches
* the given name. This function is intended to be invoked on a
@@ -463,7 +429,7 @@
dbus_error_init (&err);
dbus_set_error_const (&err, DBUS_ERROR_NO_MEMORY, "Out of memory!");
- dbus_g_error_set (&gerror, err.name, err.message);
+ dbus_set_g_error (&gerror, &err);
g_assert (gerror != NULL);
g_assert (gerror->domain == DBUS_GERROR);
g_assert (gerror->code == DBUS_GERROR_NO_MEMORY);
@@ -472,13 +438,6 @@
dbus_error_init (&err);
g_clear_error (&gerror);
- dbus_g_error_set (&gerror, "com.example.Foo.BlahFailed", "blah failed");
- g_assert (gerror != NULL);
- g_assert (gerror->domain == DBUS_GERROR);
- g_assert (gerror->code == DBUS_GERROR_REMOTE_EXCEPTION);
- g_assert (dbus_g_error_has_name (gerror, "com.example.Foo.BlahFailed"));
- g_assert (!strcmp (gerror->message, "blah failed"));
-
return TRUE;
}
- Previous message: dbus/test/glib test-service-glib.xml, 1.7, 1.8 test-service-glib.c,
1.17, 1.18 test-dbus-glib.c, 1.23, 1.24 Makefile.am, 1.14, 1.15
- Next message: dbus/dbus dbus-glib.h,1.16,1.17
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the dbus-commit
mailing list