aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonny Lamb <jonnylamb@gnome.org>2010-02-17 00:38:21 +0800
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2010-02-17 01:47:13 +0800
commit37aabc6b1e5b97747da6bb1b3070fa2fdaffa530 (patch)
tree1f37308a4e39967ca2d970f7e7fe5c6b8295d107
parentfd49fd64d74d56ae4e1cf514edfb1aec348832a4 (diff)
downloadgsoc2013-empathy-37aabc6b1e5b97747da6bb1b3070fa2fdaffa530.tar
gsoc2013-empathy-37aabc6b1e5b97747da6bb1b3070fa2fdaffa530.tar.gz
gsoc2013-empathy-37aabc6b1e5b97747da6bb1b3070fa2fdaffa530.tar.bz2
gsoc2013-empathy-37aabc6b1e5b97747da6bb1b3070fa2fdaffa530.tar.lz
gsoc2013-empathy-37aabc6b1e5b97747da6bb1b3070fa2fdaffa530.tar.xz
gsoc2013-empathy-37aabc6b1e5b97747da6bb1b3070fa2fdaffa530.tar.zst
gsoc2013-empathy-37aabc6b1e5b97747da6bb1b3070fa2fdaffa530.zip
Use TpDebugSender to publish debug messages (#607330)
-rw-r--r--libempathy/Makefile.am2
-rw-r--r--libempathy/empathy-debug.c14
-rw-r--r--libempathy/empathy-debugger.c270
-rw-r--r--libempathy/empathy-debugger.h88
-rw-r--r--src/empathy-debug-window.c27
-rw-r--r--src/empathy.c41
6 files changed, 34 insertions, 408 deletions
diff --git a/libempathy/Makefile.am b/libempathy/Makefile.am
index fa62d0cd7..f6f0c0a23 100644
--- a/libempathy/Makefile.am
+++ b/libempathy/Makefile.am
@@ -38,7 +38,6 @@ libempathy_headers = \
empathy-contact-monitor.h \
empathy-contact.h \
empathy-debug.h \
- empathy-debugger.h \
empathy-dispatch-operation.h \
empathy-dispatcher.h \
empathy-ft-factory.h \
@@ -79,7 +78,6 @@ libempathy_la_SOURCES = \
empathy-contact-monitor.c \
empathy-contact.c \
empathy-debug.c \
- empathy-debugger.c \
empathy-dispatch-operation.c \
empathy-dispatcher.c \
empathy-ft-factory.c \
diff --git a/libempathy/empathy-debug.c b/libempathy/empathy-debug.c
index 487827791..1f29259fd 100644
--- a/libempathy/empathy-debug.c
+++ b/libempathy/empathy-debug.c
@@ -30,11 +30,10 @@
#include <glib/gstdio.h>
#include <telepathy-glib/debug.h>
+#include <telepathy-glib/debug-sender.h>
#include "empathy-debug.h"
-#include "empathy-debugger.h"
-
#ifdef ENABLE_DEBUG
static EmpathyDebugFlags flags = 0;
@@ -115,20 +114,23 @@ empathy_debug_free (void)
}
static void
-log_to_debugger (EmpathyDebugFlags flag,
+log_to_debug_sender (EmpathyDebugFlags flag,
const gchar *message)
{
- EmpathyDebugger *dbg = empathy_debugger_get_singleton ();
+ TpDebugSender *sender;
gchar *domain;
GTimeVal now;
+ sender = tp_debug_sender_dup ();
+
g_get_current_time (&now);
domain = g_strdup_printf ("%s/%s", G_LOG_DOMAIN, debug_flag_to_key (flag));
- empathy_debugger_add_message (dbg, &now, domain, G_LOG_LEVEL_DEBUG, message);
+ tp_debug_sender_add_message (sender, &now, domain, G_LOG_LEVEL_DEBUG, message);
g_free (domain);
+ g_object_unref (sender);
}
void
@@ -143,7 +145,7 @@ empathy_debug (EmpathyDebugFlags 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/libempathy/empathy-debugger.c b/libempathy/empathy-debugger.c
deleted file mode 100644
index 04873120c..000000000
--- a/libempathy/empathy-debugger.c
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- * 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 "empathy-debugger.h"
-#include "config.h"
-
-#include <telepathy-glib/dbus.h>
-
-#include "extensions/extensions.h"
-
-static EmpathyDebugger *singleton = NULL;
-
-static void
-debug_iface_init (gpointer g_iface, gpointer iface_data);
-
-G_DEFINE_TYPE_WITH_CODE (EmpathyDebugger, empathy_debugger, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES,
- tp_dbus_properties_mixin_iface_init);
- G_IMPLEMENT_INTERFACE (EMP_TYPE_SVC_DEBUG, debug_iface_init));
-
-/* properties */
-enum
-{
- PROP_ENABLED = 1,
- NUM_PROPERTIES
-};
-
-static EmpDebugLevel
-log_level_flags_to_debug_level (GLogLevelFlags level)
-{
- if (level & G_LOG_LEVEL_ERROR)
- return EMP_DEBUG_LEVEL_ERROR;
- else if (level & G_LOG_LEVEL_CRITICAL)
- return EMP_DEBUG_LEVEL_CRITICAL;
- else if (level & G_LOG_LEVEL_WARNING)
- return EMP_DEBUG_LEVEL_WARNING;
- else if (level & G_LOG_LEVEL_MESSAGE)
- return EMP_DEBUG_LEVEL_MESSAGE;
- else if (level & G_LOG_LEVEL_INFO)
- return EMP_DEBUG_LEVEL_INFO;
- else if (level & G_LOG_LEVEL_DEBUG)
- return EMP_DEBUG_LEVEL_DEBUG;
- else
- /* Fall back to DEBUG if all else fails */
- return EMP_DEBUG_LEVEL_DEBUG;
-}
-
-static EmpathyDebugMessage *
-debug_message_new (GTimeVal *timestamp,
- const gchar *domain,
- GLogLevelFlags level,
- const gchar *string)
-{
- EmpathyDebugMessage *msg;
-
- msg = g_slice_new0 (EmpathyDebugMessage);
- 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 (EmpathyDebugMessage *msg)
-{
- g_free (msg->domain);
- g_free (msg->string);
- g_slice_free (EmpathyDebugMessage, msg);
-}
-
-static void
-empathy_debugger_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
-{
- EmpathyDebugger *self = EMPATHY_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
-empathy_debugger_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- EmpathyDebugger *self = EMPATHY_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
-empathy_debugger_finalize (GObject *object)
-{
- EmpathyDebugger *self = EMPATHY_DEBUGGER (object);
-
- g_queue_foreach (self->messages, (GFunc) debug_message_free, NULL);
- g_queue_free (self->messages);
- self->messages = NULL;
-
- G_OBJECT_CLASS (empathy_debugger_parent_class)->finalize (object);
-}
-
-static void
-empathy_debugger_class_init (EmpathyDebuggerClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- static TpDBusPropertiesMixinPropImpl debug_props[] = {
- { "Enabled", "enabled", "enabled" },
- { NULL }
- };
- static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = {
- { EMP_IFACE_DEBUG,
- tp_dbus_properties_mixin_getter_gobject_properties,
- tp_dbus_properties_mixin_setter_gobject_properties,
- debug_props,
- },
- { NULL }
- };
-
- object_class->get_property = empathy_debugger_get_property;
- object_class->set_property = empathy_debugger_set_property;
- object_class->finalize = empathy_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 (EmpathyDebuggerClass, dbus_props_class));
-}
-
-static void
-get_messages (EmpSvcDebug *self,
- DBusGMethodInvocation *context)
-{
- EmpathyDebugger *dbg = EMPATHY_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 };
- EmpathyDebugMessage *message = (EmpathyDebugMessage *) 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));
- }
-
- emp_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)
-{
- EmpSvcDebugClass *klass = (EmpSvcDebugClass *) g_iface;
-
- emp_svc_debug_implement_get_messages (klass, get_messages);
-}
-
-static void
-empathy_debugger_init (EmpathyDebugger *self)
-{
- self->messages = g_queue_new ();
-}
-
-EmpathyDebugger *
-empathy_debugger_get_singleton (void)
-{
- if (G_UNLIKELY (singleton == NULL))
- {
- DBusGConnection *bus;
-
- singleton = g_object_new (EMPATHY_TYPE_DEBUGGER, NULL);
- bus = tp_get_bus ();
- dbus_g_connection_register_g_object (bus,
- "/org/freedesktop/Telepathy/debug", (GObject *) singleton);
- }
-
- return singleton;
-}
-
-void
-empathy_debugger_add_message (EmpathyDebugger *self,
- GTimeVal *timestamp,
- const gchar *domain,
- GLogLevelFlags level,
- const gchar *string)
-{
- EmpathyDebugMessage *new_msg;
-
- if (g_queue_get_length (self->messages) >= DEBUG_MESSAGE_LIMIT)
- {
- EmpathyDebugMessage *old_head =
- (EmpathyDebugMessage *) 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)
- {
- emp_svc_debug_emit_new_debug_message (self, new_msg->timestamp,
- domain, new_msg->level, string);
- }
-}
diff --git a/libempathy/empathy-debugger.h b/libempathy/empathy-debugger.h
deleted file mode 100644
index f3fdc7070..000000000
--- a/libempathy/empathy-debugger.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * 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 _EMPATHY_DEBUGGER
-#define _EMPATHY_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 EMPATHY_TYPE_DEBUGGER empathy_debugger_get_type()
-
-#define EMPATHY_DEBUGGER(obj) \
- (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_DEBUGGER, EmpathyDebugger))
-
-#define EMPATHY_DEBUGGER_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_CAST ((klass), EMPATHY_TYPE_DEBUGGER, EmpathyDebuggerClass))
-
-#define EMPATHY_IS_DEBUGGER(obj) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_DEBUGGER))
-
-#define EMPATHY_IS_DEBUGGER_CLASS(klass) \
- (G_TYPE_CHECK_CLASS_TYPE ((klass), EMPATHY_TYPE_DEBUGGER))
-
-#define EMPATHY_DEBUGGER_GET_CLASS(obj) \
- (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_DEBUGGER, EmpathyDebuggerClass))
-
-/* 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;
- EmpDebugLevel level;
- gchar *string;
-} EmpathyDebugMessage;
-
-typedef struct {
- GObject parent;
-
- gboolean enabled;
- GQueue *messages;
-} EmpathyDebugger;
-
-typedef struct {
- GObjectClass parent_class;
- TpDBusPropertiesMixinClass dbus_props_class;
-} EmpathyDebuggerClass;
-
-GType empathy_debugger_get_type (void);
-
-EmpathyDebugger *
-empathy_debugger_get_singleton (void);
-
-void
-empathy_debugger_add_message (EmpathyDebugger *self,
- GTimeVal *timestamp,
- const gchar *domain,
- GLogLevelFlags level,
- const gchar *string);
-
-G_END_DECLS
-
-#endif /* _EMPATHY_DEBUGGER */
diff --git a/src/empathy-debug-window.c b/src/empathy-debug-window.c
index da2c0e079..b8b34b273 100644
--- a/src/empathy-debug-window.c
+++ b/src/empathy-debug-window.c
@@ -34,6 +34,7 @@
#include <libempathy-gtk/empathy-geometry.h>
#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/interfaces.h>
#include <telepathy-glib/util.h>
#include <telepathy-glib/proxy-subclass.h>
@@ -115,22 +116,22 @@ log_level_to_string (guint level)
{
switch (level)
{
- case EMP_DEBUG_LEVEL_ERROR:
+ case TP_DEBUG_LEVEL_ERROR:
return "Error";
break;
- case EMP_DEBUG_LEVEL_CRITICAL:
+ case TP_DEBUG_LEVEL_CRITICAL:
return "Critical";
break;
- case EMP_DEBUG_LEVEL_WARNING:
+ case TP_DEBUG_LEVEL_WARNING:
return "Warning";
break;
- case EMP_DEBUG_LEVEL_MESSAGE:
+ case TP_DEBUG_LEVEL_MESSAGE:
return "Message";
break;
- case EMP_DEBUG_LEVEL_INFO:
+ case TP_DEBUG_LEVEL_INFO:
return "Info";
break;
- case EMP_DEBUG_LEVEL_DEBUG:
+ case TP_DEBUG_LEVEL_DEBUG:
return "Debug";
break;
default:
@@ -281,7 +282,7 @@ debug_window_set_enabled (EmpathyDebugWindow *debug_window,
val = tp_g_value_slice_new_boolean (enabled);
- tp_cli_dbus_properties_call_set (priv->proxy, -1, EMP_IFACE_DEBUG,
+ tp_cli_dbus_properties_call_set (priv->proxy, -1, TP_IFACE_DEBUG,
"Enabled", val, NULL, NULL, NULL, NULL);
tp_g_value_slice_free (val);
@@ -1297,37 +1298,37 @@ debug_window_constructor (GType type,
gtk_list_store_append (level_store, &iter);
gtk_list_store_set (level_store, &iter,
COL_LEVEL_NAME, _("Debug"),
- COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_DEBUG,
+ COL_LEVEL_VALUE, TP_DEBUG_LEVEL_DEBUG,
-1);
gtk_list_store_append (level_store, &iter);
gtk_list_store_set (level_store, &iter,
COL_LEVEL_NAME, _("Info"),
- COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_INFO,
+ COL_LEVEL_VALUE, TP_DEBUG_LEVEL_INFO,
-1);
gtk_list_store_append (level_store, &iter);
gtk_list_store_set (level_store, &iter,
COL_LEVEL_NAME, _("Message"),
- COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_MESSAGE,
+ COL_LEVEL_VALUE, TP_DEBUG_LEVEL_MESSAGE,
-1);
gtk_list_store_append (level_store, &iter);
gtk_list_store_set (level_store, &iter,
COL_LEVEL_NAME, _("Warning"),
- COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_WARNING,
+ COL_LEVEL_VALUE, TP_DEBUG_LEVEL_WARNING,
-1);
gtk_list_store_append (level_store, &iter);
gtk_list_store_set (level_store, &iter,
COL_LEVEL_NAME, _("Critical"),
- COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_CRITICAL,
+ COL_LEVEL_VALUE, TP_DEBUG_LEVEL_CRITICAL,
-1);
gtk_list_store_append (level_store, &iter);
gtk_list_store_set (level_store, &iter,
COL_LEVEL_NAME, _("Error"),
- COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_ERROR,
+ COL_LEVEL_VALUE, TP_DEBUG_LEVEL_ERROR,
-1);
gtk_combo_box_set_active (GTK_COMBO_BOX (priv->level_filter), 0);
diff --git a/src/empathy.c b/src/empathy.c
index be95d6dd0..33c05dc81 100644
--- a/src/empathy.c
+++ b/src/empathy.c
@@ -39,6 +39,7 @@
#include <telepathy-glib/account-manager.h>
#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/debug-sender.h>
#include <telepathy-glib/util.h>
#include <telepathy-glib/connection-manager.h>
#include <telepathy-glib/interfaces.h>
@@ -50,7 +51,6 @@
#include <libempathy/empathy-account-settings.h>
#include <libempathy/empathy-connectivity.h>
#include <libempathy/empathy-connection-managers.h>
-#include <libempathy/empathy-debugger.h>
#include <libempathy/empathy-dispatcher.h>
#include <libempathy/empathy-dispatch-operation.h>
#include <libempathy/empathy-log-manager.h>
@@ -341,32 +341,6 @@ new_call_handler_cb (EmpathyCallFactory *factory,
gtk_widget_show (GTK_WIDGET (window));
}
-#ifdef ENABLE_DEBUG
-static void
-default_log_handler (const gchar *log_domain,
- GLogLevelFlags log_level,
- const gchar *message,
- gpointer user_data)
-{
- g_log_default_handler (log_domain, log_level, message, NULL);
-
- /* G_LOG_DOMAIN = "empathy". No need to send empathy messages to the
- * debugger as they already have in empathy_debug. */
- if (log_level != G_LOG_LEVEL_DEBUG
- || tp_strdiff (log_domain, G_LOG_DOMAIN))
- {
- EmpathyDebugger *dbg;
- GTimeVal now;
-
- dbg = empathy_debugger_get_singleton ();
- g_get_current_time (&now);
-
- empathy_debugger_add_message (dbg, &now, log_domain,
- log_level, message);
- }
-}
-#endif /* ENABLE_DEBUG */
-
static void
account_manager_ready_cb (GObject *source_object,
GAsyncResult *result,
@@ -598,6 +572,10 @@ main (int argc, char *argv[])
UniqueApp *unique_app;
gboolean chatroom_manager_ready;
+#ifdef ENABLE_DEBUG
+ TpDebugSender *debug_sender;
+#endif
+
GOptionContext *optcontext;
GOptionEntry options[] = {
{ "no-connect", 'n',
@@ -647,8 +625,9 @@ main (int argc, char *argv[])
textdomain (GETTEXT_PACKAGE);
#ifdef ENABLE_DEBUG
- /* Set up debugger */
- g_log_set_default_handler (default_log_handler, NULL);
+ /* Set up debug sender */
+ debug_sender = tp_debug_sender_dup ();
+ g_log_set_default_handler (tp_debug_sender_log_handler, G_LOG_DOMAIN);
#endif
unique_app = unique_app_new_with_commands ("org.gnome.Empathy",
@@ -763,6 +742,10 @@ main (int argc, char *argv[])
empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
+#ifdef ENABLE_DEBUG
+ g_object_unref (debug_sender);
+#endif
+
g_object_unref (idle);
g_object_unref (connectivity);
g_object_unref (icon);