[telepathy-gabble/master] debug: use TpDebugSender instead of implementing GabbleDebugger

Jonny Lamb jonny.lamb at collabora.co.uk
Fri Nov 13 05:17:51 PST 2009


Signed-off-by: Jonny Lamb <jonny.lamb at collabora.co.uk>
---
 extensions/Debug.xml   |  165 -----------------------------
 extensions/Makefile.am |    1 -
 extensions/all.xml     |    1 -
 src/Makefile.am        |    2 -
 src/debug.c            |   42 ++++----
 src/debugger.c         |  271 ------------------------------------------------
 src/debugger.h         |   88 ----------------
 src/gabble.c           |   30 ++++--
 8 files changed, 44 insertions(+), 556 deletions(-)
 delete mode 100644 extensions/Debug.xml
 delete mode 100644 src/debugger.c
 delete mode 100644 src/debugger.h

diff --git a/extensions/Debug.xml b/extensions/Debug.xml
deleted file mode 100644
index 70a82e9..0000000
--- a/extensions/Debug.xml
+++ /dev/null
@@ -1,165 +0,0 @@
-<?xml version="1.0" ?>
-<node name="/Debug"
-  xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
-  <tp:copyright>Copyright (C) 2009 Collabora Ltd.</tp:copyright>
-  <tp:license xmlns="http://www.w3.org/1999/xhtml">
-    <p>This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public
-License as published by the Free Software Foundation; either
-version 2.1 of the License, or (at your option) any later version.</p>
-
-<p>This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-Lesser General Public License for more details.</p>
-
-<p>You should have received a copy of the GNU Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.</p>
-  </tp:license>
-  <interface name="org.freedesktop.Telepathy.Debug">
-    <tp:added version="0.17.27">(as stable API)</tp:added>
-
-    <tp:docstring xmlns="http://www.w3.org/1999/xhtml">
-      <p>An interface for providing debug messages.</p>
-
-      <p>This interface is primarily provided by one object per
-      service, at the path <tt>/org/freedesktop/Telepathy/debug</tt>.</p>
-    </tp:docstring>
-
-    <property name="Enabled" type="b" access="readwrite"
-      tp:name-for-bindings="Enabled">
-      <tp:docstring>
-        TRUE if the <tp:member-ref>NewDebugMessage</tp:member-ref> signal
-        should be emitted when a new debug message is generated.
-      </tp:docstring>
-    </property>
-
-    <method name="GetMessages" tp:name-for-bindings="Get_Messages">
-      <tp:docstring>
-        Retrieve buffered debug messages. An implementation could have a
-        limit on how many message it keeps and so the array returned from
-        this method should not be assumed to be all of the messages in
-        the lifetime of the service.
-      </tp:docstring>
-
-      <arg direction="out" name="Messages" type="a(dsus)"
-        tp:type="Debug_Message[]">
-        <tp:docstring>
-          A list of debug messages.
-        </tp:docstring>
-      </arg>
-    </method>
-
-    <signal name="NewDebugMessage" tp:name-for-bindings="New_Debug_Message">
-      <tp:docstring>
-        Emitted when a debug messages is generated if the
-        <tp:member-ref>Enabled</tp:member-ref> property is set to TRUE.
-      </tp:docstring>
-
-      <arg name="time" type="d">
-        <tp:docstring>
-          Timestamp of the debug message.
-        </tp:docstring>
-      </arg>
-      <arg name="domain" type="s">
-        <tp:docstring>
-          Domain of the debug message, as described in the Debug_Message struct.
-        </tp:docstring>
-      </arg>
-      <arg name="level" type="u" tp:type="Debug_Level">
-        <tp:docstring>
-          Level of the debug message.
-        </tp:docstring>
-      </arg>
-      <arg name="message" type="s">
-        <tp:docstring>
-          The text of the debug message.
-        </tp:docstring>
-      </arg>
-    </signal>
-
-    <tp:enum name="Debug_Level" type="u">
-      <tp:enumvalue suffix="Error" value="0">
-        <tp:docstring>
-          Log level for errors. Error messages are always fatal, resulting
-          in the service terminating after something completely
-          unexpected occurred.
-        </tp:docstring>
-      </tp:enumvalue>
-      <tp:enumvalue suffix="Critical" value="1">
-        <tp:docstring>
-          Log level for critical messages. Critical messages are messages
-          that the service might predict and it is up to the service itself
-          to decide whether to terminate following a critical message.
-        </tp:docstring>
-      </tp:enumvalue>
-      <tp:enumvalue suffix="Warning" value="2">
-        <tp:docstring>
-          Log level for warnings.
-        </tp:docstring>
-      </tp:enumvalue>
-      <tp:enumvalue suffix="Message" value="3">
-        <tp:docstring>
-          Log level for messages.
-        </tp:docstring>
-      </tp:enumvalue>
-      <tp:enumvalue suffix="Info" value="4">
-        <tp:docstring>
-          Log level for information messages.
-        </tp:docstring>
-      </tp:enumvalue>
-      <tp:enumvalue suffix="Debug" value="5">
-        <tp:docstring>
-          Log level for debug messages.
-        </tp:docstring>
-      </tp:enumvalue>
-    </tp:enum>
-
-    <tp:struct name="Debug_Message" array-name="Debug_Message_List">
-      <tp:docstring>
-        A struct representing a debug message, as returned by
-        <tp:member-ref>GetMessages</tp:member-ref>.
-      </tp:docstring>
-
-      <tp:member type="d" name="Timestamp">
-        <tp:docstring>
-          Timestamp of the debug message. This is a double to allow
-          more accuracy in the time the message was logged.
-        </tp:docstring>
-      </tp:member>
-
-      <tp:member type="s" name="Domain">
-        <tp:docstring xmlns="http://www.w3.org/1999/xhtml">
-          <p>Domain of the debug message. This is used to identify
-          the source of debug messages. For example, debug messages
-          from a connection manager could have this Domain struct
-          member be the name of the connection manager, and logs
-          from any helper library could have the name of the helper
-          library.</p>
-
-          <p>The domain could also contain a category as to where
-          the log message originated separated by a forward-slash.
-          For example, if a debug message was output in a connection
-          manager called "dummy", in the file-transfer code, this
-          Domain struct member might be <tt>dummy/file-transfer</tt>.</p>
-        </tp:docstring>
-      </tp:member>
-
-      <tp:member type="u" tp:type="Debug_Level" name="Level">
-        <tp:docstring>
-          Level of the debug message. This states the severity of the
-          debug message.
-        </tp:docstring>
-      </tp:member>
-
-      <tp:member type="s" name="Message">
-        <tp:docstring>
-          The text of the debug message.
-        </tp:docstring>
-      </tp:member>
-    </tp:struct>
-
-  </interface>
-</node>
-<!-- vim:set sw=2 sts=2 et ft=xml: -->
diff --git a/extensions/Makefile.am b/extensions/Makefile.am
index 087310c..3eace1b 100644
--- a/extensions/Makefile.am
+++ b/extensions/Makefile.am
@@ -6,7 +6,6 @@ EXTRA_DIST = \
     Channel_Future.xml \
     Connection_Interface_Contact_Info.xml \
     Channel_Type_Contact_Search.xml \
-    Debug.xml \
     OLPC_Activity_Properties.xml \
     OLPC_Buddy_Info.xml \
     OLPC_Gadget.xml \
diff --git a/extensions/all.xml b/extensions/all.xml
index 5127e06..a2055df 100644
--- a/extensions/all.xml
+++ b/extensions/all.xml
@@ -35,7 +35,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA</p>
 
 <xi:include href="Channel_Bundle.xml"/>
 <xi:include href="Channel_Future.xml"/>
-<xi:include href="Debug.xml"/>
 <xi:include href="OLPC_Buddy_Info.xml"/>
 <xi:include href="OLPC_Activity_Properties.xml"/>
 <xi:include href="OLPC_Gadget.xml"/>
diff --git a/src/Makefile.am b/src/Makefile.am
index 142a841..d2b06e3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -47,8 +47,6 @@ libgabble_convenience_la_SOURCES = \
     connection-manager.c \
     debug.h \
     debug.c \
-    debugger.h \
-    debugger.c \
     disco.h \
     disco.c \
     error.c \
diff --git a/src/debug.c b/src/debug.c
index 85aed5a..e2e6894 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -11,8 +11,7 @@
 
 #include <glib/gstdio.h>
 #include <telepathy-glib/debug.h>
-
-#include "debugger.h"
+#include <telepathy-glib/debug-sender.h>
 
 #ifdef ENABLE_DEBUG
 
@@ -70,54 +69,57 @@ gboolean gabble_debug_flag_is_set (GabbleDebugFlags flag)
   return flag & flags;
 }
 
-GHashTable *flag_to_keys = NULL;
+GHashTable *flag_to_domains = NULL;
 
 static const gchar *
-debug_flag_to_key (GabbleDebugFlags flag)
+debug_flag_to_domain (GabbleDebugFlags flag)
 {
-  if (flag_to_keys == NULL)
+  if (G_UNLIKELY (flag_to_domains == NULL))
     {
       guint i;
 
-      flag_to_keys = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+      flag_to_domains = g_hash_table_new_full (g_direct_hash, g_direct_equal,
           NULL, g_free);
 
       for (i = 0; keys[i].value; i++)
         {
           GDebugKey key = (GDebugKey) keys[i];
-          g_hash_table_insert (flag_to_keys, GUINT_TO_POINTER (key.value),
-              g_strdup (key.key));
+          gchar *val;
+
+          val = g_strdup_printf ("%s/%s", G_LOG_DOMAIN, key.key);
+          g_hash_table_insert (flag_to_domains,
+              GUINT_TO_POINTER (key.value), val);
         }
     }
 
-  return g_hash_table_lookup (flag_to_keys, GUINT_TO_POINTER (flag));
+  return g_hash_table_lookup (flag_to_domains, GUINT_TO_POINTER (flag));
 }
 
 void
 gabble_debug_free (void)
 {
-  if (flag_to_keys == NULL)
+  if (flag_to_domains == NULL)
     return;
 
-  g_hash_table_destroy (flag_to_keys);
-  flag_to_keys = NULL;
+  g_hash_table_destroy (flag_to_domains);
+  flag_to_domains = NULL;
 }
 
 static void
-log_to_debugger (GabbleDebugFlags flag,
+log_to_debug_sender (GabbleDebugFlags flag,
     const gchar *message)
 {
-  GabbleDebugger *dbg = gabble_debugger_get_singleton ();
-  gchar *domain;
+  TpDebugSender *dbg;
   GTimeVal now;
 
-  g_get_current_time (&now);
+  dbg = tp_debug_sender_dup ();
 
-  domain = g_strdup_printf ("%s/%s", G_LOG_DOMAIN, debug_flag_to_key (flag));
+  g_get_current_time (&now);
 
-  gabble_debugger_add_message (dbg, &now, domain, G_LOG_LEVEL_DEBUG, message);
+  tp_debug_sender_add_message (dbg, &now, debug_flag_to_domain (flag),
+      G_LOG_LEVEL_DEBUG, message);
 
-  g_free (domain);
+  g_object_unref (dbg);
 }
 
 void gabble_debug (GabbleDebugFlags flag,
@@ -131,7 +133,7 @@ void gabble_debug (GabbleDebugFlags flag,
   message = g_strdup_vprintf (format, args);
   va_end (args);
 
-  log_to_debugger (flag, message);
+  log_to_debug_sender (flag, message);
 
   if (flag & flags)
     g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "%s", message);
diff --git a/src/debugger.c b/src/debugger.c
deleted file mode 100644
index 4ee2ab6..0000000
--- a/src/debugger.c
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
- * debugger.h - Telepathy debug interface implementation
- * Copyright (C) 2009 Collabora Ltd.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#include "debugger.h"
-#include "config.h"
-
-#include <telepathy-glib/dbus.h>
-
-#include "extensions/extensions.h"
-#include "gabble-signals-marshal.h"
-
-static GabbleDebugger *singleton = NULL;
-
-static void
-debug_iface_init (gpointer g_iface, gpointer iface_data);
-
-G_DEFINE_TYPE_WITH_CODE (GabbleDebugger, gabble_debugger, G_TYPE_OBJECT,
-    G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES,
-        tp_dbus_properties_mixin_iface_init);
-    G_IMPLEMENT_INTERFACE (GABBLE_TYPE_SVC_DEBUG, debug_iface_init));
-
-/* properties */
-enum
-{
-  PROP_ENABLED = 1,
-  NUM_PROPERTIES
-};
-
-static GabbleDebugLevel
-log_level_flags_to_debug_level (GLogLevelFlags level)
-{
-  if (level & G_LOG_LEVEL_ERROR)
-    return GABBLE_DEBUG_LEVEL_ERROR;
-  else if (level & G_LOG_LEVEL_CRITICAL)
-    return GABBLE_DEBUG_LEVEL_CRITICAL;
-  else if (level & G_LOG_LEVEL_WARNING)
-    return GABBLE_DEBUG_LEVEL_WARNING;
-  else if (level & G_LOG_LEVEL_MESSAGE)
-    return GABBLE_DEBUG_LEVEL_MESSAGE;
-  else if (level & G_LOG_LEVEL_INFO)
-    return GABBLE_DEBUG_LEVEL_INFO;
-  else if (level & G_LOG_LEVEL_DEBUG)
-    return GABBLE_DEBUG_LEVEL_DEBUG;
-  else
-    /* Fall back to DEBUG if all else fails */
-    return GABBLE_DEBUG_LEVEL_DEBUG;
-}
-
-static GabbleDebugMessage *
-debug_message_new (GTimeVal *timestamp,
-    const gchar *domain,
-    GLogLevelFlags level,
-    const gchar *string)
-{
-  GabbleDebugMessage *msg;
-
-  msg = g_slice_new0 (GabbleDebugMessage);
-  msg->timestamp = timestamp->tv_sec + timestamp->tv_usec / 1e6;
-  msg->domain = g_strdup (domain);
-  msg->level = log_level_flags_to_debug_level (level);
-  msg->string = g_strdup (string);
-  return msg;
-}
-
-static void
-debug_message_free (GabbleDebugMessage *msg)
-{
-  g_free (msg->domain);
-  g_free (msg->string);
-  g_slice_free (GabbleDebugMessage, msg);
-}
-
-static void
-gabble_debugger_get_property (GObject *object,
-    guint property_id,
-    GValue *value,
-    GParamSpec *pspec)
-{
-  GabbleDebugger *self = GABBLE_DEBUGGER (object);
-
-  switch (property_id)
-    {
-      case PROP_ENABLED:
-        g_value_set_boolean (value, self->enabled);
-        break;
-
-      default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-    }
-}
-
-static void
-gabble_debugger_set_property (GObject *object,
-    guint property_id,
-    const GValue *value,
-    GParamSpec *pspec)
-{
-  GabbleDebugger *self = GABBLE_DEBUGGER (object);
-
-  switch (property_id)
-    {
-      case PROP_ENABLED:
-        self->enabled = g_value_get_boolean (value);
-        break;
-
-     default:
-       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-  }
-}
-
-static void
-gabble_debugger_finalize (GObject *object)
-{
-  GabbleDebugger *self = GABBLE_DEBUGGER (object);
-
-  g_queue_foreach (self->messages, (GFunc) debug_message_free, NULL);
-  g_queue_free (self->messages);
-  self->messages = NULL;
-
-  G_OBJECT_CLASS (gabble_debugger_parent_class)->finalize (object);
-}
-
-static void
-gabble_debugger_class_init (GabbleDebuggerClass *klass)
-{
-  GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  static TpDBusPropertiesMixinPropImpl debug_props[] = {
-      { "Enabled", "enabled", "enabled" },
-      { NULL }
-  };
-  static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = {
-      { GABBLE_IFACE_DEBUG,
-        tp_dbus_properties_mixin_getter_gobject_properties,
-        tp_dbus_properties_mixin_setter_gobject_properties,
-        debug_props,
-      },
-      { NULL }
-  };
-
-  object_class->get_property = gabble_debugger_get_property;
-  object_class->set_property = gabble_debugger_set_property;
-  object_class->finalize = gabble_debugger_finalize;
-
-  g_object_class_install_property (object_class, PROP_ENABLED,
-      g_param_spec_boolean ("enabled", "Enabled?",
-          "True if the new-debug-message signal is enabled.",
-          FALSE,
-          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-
-  klass->dbus_props_class.interfaces = prop_interfaces;
-  tp_dbus_properties_mixin_class_init (object_class,
-      G_STRUCT_OFFSET (GabbleDebuggerClass, dbus_props_class));
-}
-
-static void
-get_messages (GabbleSvcDebug *self,
-    DBusGMethodInvocation *context)
-{
-  GabbleDebugger *dbg = GABBLE_DEBUGGER (self);
-  GPtrArray *messages;
-  static GType struct_type = 0;
-  GList *i;
-  guint j;
-
-  if (G_UNLIKELY (struct_type == 0))
-    {
-      struct_type = dbus_g_type_get_struct (
-          "GValueArray", G_TYPE_DOUBLE, G_TYPE_STRING, G_TYPE_UINT,
-          G_TYPE_STRING, G_TYPE_INVALID);
-    }
-
-  messages = g_ptr_array_sized_new (g_queue_get_length (dbg->messages));
-
-  for (i = dbg->messages->head; i; i = i->next)
-    {
-      GValue gvalue = { 0 };
-      GabbleDebugMessage *message = (GabbleDebugMessage *) i->data;
-
-      g_value_init (&gvalue, struct_type);
-      g_value_take_boxed (&gvalue,
-          dbus_g_type_specialized_construct (struct_type));
-      dbus_g_type_struct_set (&gvalue,
-          0, message->timestamp,
-          1, message->domain,
-          2, message->level,
-          3, message->string,
-          G_MAXUINT);
-      g_ptr_array_add (messages, g_value_get_boxed (&gvalue));
-    }
-
-  gabble_svc_debug_return_from_get_messages (context, messages);
-
-  for (j = 0; j < messages->len; j++)
-    g_boxed_free (struct_type, messages->pdata[j]);
-
-  g_ptr_array_free (messages, TRUE);
-}
-
-static void
-debug_iface_init (gpointer g_iface,
-    gpointer iface_data)
-{
-  GabbleSvcDebugClass *klass = (GabbleSvcDebugClass *) g_iface;
-
-  gabble_svc_debug_implement_get_messages (klass, get_messages);
-}
-
-static void
-gabble_debugger_init (GabbleDebugger *self)
-{
-  self->messages = g_queue_new ();
-}
-
-GabbleDebugger *
-gabble_debugger_get_singleton (void)
-{
-  if (G_UNLIKELY (singleton == NULL))
-    {
-      DBusGConnection *bus;
-
-      singleton = g_object_new (GABBLE_TYPE_DEBUGGER, NULL);
-      bus = tp_get_bus ();
-      dbus_g_connection_register_g_object (bus,
-          "/org/freedesktop/Telepathy/debug", (GObject *) singleton);
-    }
-
-  return singleton;
-}
-
-void
-gabble_debugger_add_message (GabbleDebugger *self,
-    GTimeVal *timestamp,
-    const gchar *domain,
-    GLogLevelFlags level,
-    const gchar *string)
-{
-  GabbleDebugMessage *new_msg;
-
-  if (g_queue_get_length (self->messages) >= DEBUG_MESSAGE_LIMIT)
-    {
-      GabbleDebugMessage *old_head =
-        (GabbleDebugMessage *) g_queue_pop_head (self->messages);
-
-      debug_message_free (old_head);
-    }
-
-  new_msg = debug_message_new (timestamp, domain, level, string);
-  g_queue_push_tail (self->messages, new_msg);
-
-  if (self->enabled)
-    {
-      gabble_svc_debug_emit_new_debug_message (self, new_msg->timestamp,
-          domain, new_msg->level, string);
-    }
-}
diff --git a/src/debugger.h b/src/debugger.h
deleted file mode 100644
index a6d41cf..0000000
--- a/src/debugger.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * debugger.h - header for Telepathy debug interface implementation
- * Copyright (C) 2009 Collabora Ltd.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#ifndef _GABBLE_DEBUGGER
-#define _GABBLE_DEBUGGER
-
-#include <glib-object.h>
-
-#include <telepathy-glib/properties-mixin.h>
-#include <telepathy-glib/dbus-properties-mixin.h>
-
-#include "extensions/extensions.h"
-
-G_BEGIN_DECLS
-
-#define GABBLE_TYPE_DEBUGGER gabble_debugger_get_type()
-
-#define GABBLE_DEBUGGER(obj) \
-  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GABBLE_TYPE_DEBUGGER, GabbleDebugger))
-
-#define GABBLE_DEBUGGER_CLASS(klass) \
-  (G_TYPE_CHECK_CLASS_CAST ((klass), GABBLE_TYPE_DEBUGGER, GabbleDebuggerClass))
-
-#define GABBLE_IS_DEBUGGER(obj) \
-  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GABBLE_TYPE_DEBUGGER))
-
-#define GABBLE_IS_DEBUGGER_CLASS(klass) \
-  (G_TYPE_CHECK_CLASS_TYPE ((klass), GABBLE_TYPE_DEBUGGER))
-
-#define GABBLE_DEBUGGER_GET_CLASS(obj) \
-  (G_TYPE_INSTANCE_GET_CLASS ((obj), GABBLE_TYPE_DEBUGGER, GabbleDebuggerClass))
-
-/* On the basis that messages are around 60 bytes on average, and that 50kb is
- * a reasonable maximum size for a frame buffer.
- */
-
-#define DEBUG_MESSAGE_LIMIT 800
-
-typedef struct {
-  gdouble timestamp;
-  gchar *domain;
-  GabbleDebugLevel level;
-  gchar *string;
-} GabbleDebugMessage;
-
-typedef struct {
-  GObject parent;
-
-  gboolean enabled;
-  GQueue *messages;
-} GabbleDebugger;
-
-typedef struct {
-  GObjectClass parent_class;
-  TpDBusPropertiesMixinClass dbus_props_class;
-} GabbleDebuggerClass;
-
-GType gabble_debugger_get_type (void);
-
-GabbleDebugger *
-gabble_debugger_get_singleton (void);
-
-void
-gabble_debugger_add_message (GabbleDebugger *self,
-    GTimeVal *timestamp,
-    const gchar *domain,
-    GLogLevelFlags level,
-    const gchar *string);
-
-G_END_DECLS
-
-#endif /* _GABBLE_DEBUGGER */
diff --git a/src/gabble.c b/src/gabble.c
index cce1dca..992d12e 100644
--- a/src/gabble.c
+++ b/src/gabble.c
@@ -24,12 +24,13 @@
 #include <unistd.h>
 
 #include <telepathy-glib/debug.h>
+#include <telepathy-glib/debug-sender.h>
 #include <telepathy-glib/run.h>
+#include <telepathy-glib/util.h>
 #include <wocky/wocky.h>
 #include <wocky/wocky-debug.h>
 
 #include "debug.h"
-#include "debugger.h"
 #include "connection-manager.h"
 
 static TpBaseConnectionManager *
@@ -40,20 +41,24 @@ construct_cm (void)
 }
 
 #ifdef ENABLE_DEBUG
+static TpDebugSender *debug_sender = NULL;
+
 static void
-log_to_debugger (const gchar *log_domain,
+log_to_debug_sender (const gchar *log_domain,
     GLogLevelFlags log_level,
     const gchar *string)
 {
-  GabbleDebugger *dbg = gabble_debugger_get_singleton ();
   GTimeVal now;
 
+  g_return_if_fail (TP_IS_DEBUG_SENDER (debug_sender));
+
   g_get_current_time (&now);
 
-  gabble_debugger_add_message (dbg, &now, log_domain, log_level, string);
+  tp_debug_sender_add_message (debug_sender, &now, log_domain, log_level,
+      string);
 }
 
-/* Whether we redirect all wocky log message purely to the debugger */
+/* Whether we redirect all wocky log message purely to the debug sender */
 static gboolean redirect_wocky = FALSE;
 /* Whether to add a timestamp to the output messages */
 static gboolean stamp_logs = FALSE;
@@ -89,9 +94,9 @@ log_handler (const gchar *log_domain,
         }
     }
 
-  /* Gabble messages are already sent to the debugger in gabble_debug. */
+  /* Gabble messages are already sent to the debug sender in gabble_debug. */
   if (log_level != G_LOG_LEVEL_DEBUG || tp_strdiff (log_domain, G_LOG_DOMAIN))
-    log_to_debugger (log_domain, log_level, message);
+    log_to_debug_sender (log_domain, log_level, message);
 }
 
 #endif
@@ -113,6 +118,7 @@ int
 gabble_main (int argc,
     char **argv)
 {
+  int out;
   tp_debug_divert_messages (g_getenv ("GABBLE_LOGFILE"));
 
 #ifdef ENABLE_DEBUG
@@ -126,12 +132,20 @@ gabble_main (int argc,
       wocky_debug_set_flags (DEBUG_XMPP | DEBUG_SASL | DEBUG_PORTER);
     }
 
+  debug_sender = tp_debug_sender_dup ();
+
   g_log_set_default_handler (log_handler, NULL);
 
   if (g_getenv ("GABBLE_PERSIST") != NULL)
     tp_debug_set_persistent (TRUE);
 #endif
 
-  return tp_run_connection_manager ("telepathy-gabble", VERSION,
+  out = tp_run_connection_manager ("telepathy-gabble", VERSION,
       construct_cm, argc, argv);
+
+#ifdef ENABLE_DEBUG
+  g_object_unref (debug_sender);
+#endif
+
+  return out;
 }
-- 
1.5.6.5



More information about the telepathy-commits mailing list