[Telepathy-commits] [telepathy-glib/master] TP_ERRORS: when first used, register the error domain with dbus-glib automatically

Simon McVittie simon.mcvittie at collabora.co.uk
Thu Oct 9 06:08:18 PDT 2008


---
 telepathy-glib/errors.c |   24 +++++++++++++++++++-----
 telepathy-glib/run.c    |    2 --
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/telepathy-glib/errors.c b/telepathy-glib/errors.c
index 7bb4033..10c0892 100644
--- a/telepathy-glib/errors.c
+++ b/telepathy-glib/errors.c
@@ -21,6 +21,7 @@
 #include <telepathy-glib/errors.h>
 
 #include <glib.h>
+#include <dbus/dbus-glib.h>
 
 /**
  * TP_ERROR_PREFIX:
@@ -67,15 +68,28 @@ tp_g_set_error_unsupported_handle_type (guint type, GError **error)
 /**
  * tp_errors_quark:
  *
- * <!--no need for more documentation, Returns: says it all-->
+ * Return the Telepathy error domain. Since 0.7.UNRELEASED this function
+ * automatically registers the domain with dbus-glib for server-side use
+ * (using dbus_g_error_domain_register()) when called.
  *
  * Returns: the Telepathy error domain.
  */
 GQuark
 tp_errors_quark (void)
 {
-  static GQuark quark = 0;
-  if (!quark)
-    quark = g_quark_from_static_string ("tp_errors");
-  return quark;
+  static gsize quark = 0;
+
+  if (g_once_init_enter (&quark))
+    {
+      GQuark domain = g_quark_from_static_string ("tp_errors");
+
+      g_assert (sizeof (GQuark) <= sizeof (gsize));
+
+      g_type_init ();
+      dbus_g_error_domain_register (domain, TP_ERROR_PREFIX,
+          TP_TYPE_ERROR);
+      g_once_init_leave (&quark, domain);
+    }
+
+  return (GQuark) quark;
 }
diff --git a/telepathy-glib/run.c b/telepathy-glib/run.c
index f8f5d31..888519e 100644
--- a/telepathy-glib/run.c
+++ b/telepathy-glib/run.c
@@ -233,8 +233,6 @@ tp_run_connection_manager (const char *prog_name,
 
   mainloop = g_main_loop_new (NULL, FALSE);
 
-  dbus_g_error_domain_register (TP_ERRORS, TP_ERROR_PREFIX, TP_TYPE_ERROR);
-
   manager = construct_cm ();
 
   g_signal_connect (manager, "new-connection",
-- 
1.5.6.5




More information about the Telepathy-commits mailing list