[Pkg-telepathy-commits] [telepathy-glib-1] 45/212: Debug sender: avoid using codegen for signal emission

Simon McVittie smcv at debian.org
Wed May 14 12:08:49 UTC 2014


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch debian
in repository telepathy-glib-1.

commit c3a2706dc9fecc41734dd1b96c3993080c446b7b
Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date:   Mon Mar 24 19:21:32 2014 +0000

    Debug sender: avoid using codegen for signal emission
    
    At the moment telepathy-glib has a lot of g_debug() while we're
    debugging the new GDBus-based implementations, so the codegen's signal
    emissions do a g_debug(), which triggers a g_debug(), and so on.
---
 telepathy-glib/debug-sender.c | 39 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/telepathy-glib/debug-sender.c b/telepathy-glib/debug-sender.c
index bcb8d3e..1df70ba 100644
--- a/telepathy-glib/debug-sender.c
+++ b/telepathy-glib/debug-sender.c
@@ -80,6 +80,7 @@ static void debug_iface_init (gpointer g_iface, gpointer iface_data);
 
 struct _TpDebugSenderPrivate
 {
+  GDBusConnection *conn;
   gboolean enabled;
   gboolean timestamps;
   GQueue *messages;
@@ -189,6 +190,16 @@ tp_debug_sender_set_property (GObject *object,
 }
 
 static void
+tp_debug_sender_dispose (GObject *object)
+{
+  TpDebugSender *self = TP_DEBUG_SENDER (object);
+
+  g_clear_object (&self->priv->conn);
+
+  G_OBJECT_CLASS (tp_debug_sender_parent_class)->dispose (object);
+}
+
+static void
 tp_debug_sender_finalize (GObject *object)
 {
   TpDebugSender *self = TP_DEBUG_SENDER (object);
@@ -225,6 +236,7 @@ tp_debug_sender_constructor (GType type,
 static void
 tp_debug_sender_constructed (GObject *object)
 {
+  TpDebugSender *self = TP_DEBUG_SENDER (object);
   TpDBusDaemon *dbus_daemon;
 
   dbus_daemon = tp_dbus_daemon_dup (NULL);
@@ -234,6 +246,9 @@ tp_debug_sender_constructed (GObject *object)
       tp_dbus_daemon_register_object (dbus_daemon,
           TP_DEBUG_OBJECT_PATH, debug_sender);
 
+      self->priv->conn = g_object_ref (tp_proxy_get_dbus_connection (
+            dbus_daemon));
+
       g_object_unref (dbus_daemon);
     }
 }
@@ -259,6 +274,7 @@ tp_debug_sender_class_init (TpDebugSenderClass *klass)
 
   object_class->get_property = tp_debug_sender_get_property;
   object_class->set_property = tp_debug_sender_set_property;
+  object_class->dispose = tp_debug_sender_dispose;
   object_class->finalize = tp_debug_sender_finalize;
   object_class->constructor = tp_debug_sender_constructor;
   object_class->constructed = tp_debug_sender_constructed;
@@ -354,6 +370,13 @@ tp_debug_sender_dup (void)
   return g_object_new (TP_TYPE_DEBUG_SENDER, NULL);
 }
 
+/* GDBus is less tolerant of NULL than dbus-glib */
+static inline const gchar *
+nonnull (const gchar *s)
+{
+  return (s == NULL ? "" : s);
+}
+
 static void
 _tp_debug_sender_take (TpDebugSender *self,
     DebugMessage *new_msg)
@@ -372,8 +395,18 @@ _tp_debug_sender_take (TpDebugSender *self,
 
   if (self->priv->enabled)
     {
-      tp_svc_debug1_emit_new_debug_message (self, new_msg->timestamp,
-          new_msg->domain, new_msg->level, new_msg->string);
+      /* don't use tp_svc_debug1_emit_new_debug_message
+       * to avoid triggering another g_debug(), which triggers
+       * another g_debug(), etc., forever */
+      g_dbus_connection_emit_signal (self->priv->conn,
+          NULL, /* broadcast */
+          TP_DEBUG_OBJECT_PATH,
+          TP_IFACE_DEBUG1,
+          "NewDebugMessage",
+          g_variant_new ("(dsus)", new_msg->timestamp,
+            nonnull (new_msg->domain),
+            new_msg->level, nonnull (new_msg->string)),
+          NULL);
     }
 
 #ifndef ENABLE_DEBUG_CACHE
@@ -591,6 +624,8 @@ tp_debug_sender_log_handler (const gchar *log_domain,
       if (now.tv_sec == 0)
         g_get_current_time (&now);
 
+      /* We could probably make this object thread-safe now that
+       * we're using GDBus, but for now, use an idle. */
       g_idle_add_full (G_PRIORITY_HIGH, tp_debug_sender_idle,
           debug_message_new (&now, log_domain, log_level, message),
           NULL);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-telepathy/telepathy-glib-1.git



More information about the Pkg-telepathy-commits mailing list