summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2009-08-24 12:37:26 +0100
committerJonny Lamb <jonny.lamb@collabora.co.uk>2009-09-04 16:05:28 +0100
commit6a68f130e45fc92da62d2e9d1e9ca123d4cd251e (patch)
treeed448fc21c7c65448cb1d14afe3958dd4c1d2433
parenta7a5cf31d8e8fd3a4991133c6755ad12890d32b6 (diff)
downloadtelepathy-salut-6a68f130e45fc92da62d2e9d1e9ca123d4cd251e.tar.gz
Add support for TpDebugSender.
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r--configure.ac2
-rw-r--r--src/Makefile.am3
-rw-r--r--src/debug.c72
-rw-r--r--src/debug.h3
-rw-r--r--src/salut-connection-manager.c22
5 files changed, 94 insertions, 8 deletions
diff --git a/configure.ac b/configure.ac
index 66d44661..ac880c5a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -175,7 +175,7 @@ AC_SUBST(LIBXML2_CFLAGS)
AC_SUBST(LIBXML2_LIBS)
dnl Check for telepathy-glib
-PKG_CHECK_MODULES(TELEPATHY_GLIB, [telepathy-glib >= 0.7.31])
+PKG_CHECK_MODULES(TELEPATHY_GLIB, [telepathy-glib >= 0.7.36])
AC_SUBST(TELEPATHY_GLIB_CFLAGS)
AC_SUBST(TELEPATHY_GLIB_LIBS)
diff --git a/src/Makefile.am b/src/Makefile.am
index 4e58b4fe..8302180e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -162,7 +162,8 @@ AM_CFLAGS = $(ERROR_CFLAGS) $(GCOV_CFLAGS) @DBUS_CFLAGS@ \
@TELEPATHY_GLIB_CFLAGS@ \
@AVAHI_CFLAGS@ \
-I $(top_srcdir) -I $(top_builddir) \
- -I $(top_srcdir)/lib -I $(top_builddir)/lib
+ -I $(top_srcdir)/lib -I $(top_builddir)/lib \
+ -DG_LOG_DOMAIN=\"salut\"
AM_LDFLAGS = $(GCOV_LIBS) @DBUS_LIBS@ \
@TELEPATHY_GLIB_LIBS@ \
diff --git a/src/debug.c b/src/debug.c
index b43eb345..9227dc45 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -10,6 +10,7 @@
#include <glib/gstdio.h>
#include <telepathy-glib/debug.h>
+#include <telepathy-glib/debug-sender.h>
#include "debug.h"
@@ -67,17 +68,76 @@ gboolean debug_flag_is_set (DebugFlags flag)
return flag & flags;
}
+static GHashTable *flag_to_keys = NULL;
+
+static const gchar *
+debug_flag_to_domain (DebugFlags flag)
+{
+ if (G_UNLIKELY (flag_to_keys == NULL))
+ {
+ guint i;
+
+ flag_to_keys = 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];
+ gchar *val;
+
+ val = g_strdup_printf ("%s/%s", G_LOG_DOMAIN, key.key);
+ g_hash_table_insert (flag_to_keys,
+ GUINT_TO_POINTER (key.value), val);
+ }
+ }
+
+ return g_hash_table_lookup (flag_to_keys, GUINT_TO_POINTER (flag));
+}
+
+void
+debug_free (void)
+{
+ if (flag_to_keys == NULL)
+ return;
+
+ g_hash_table_destroy (flag_to_keys);
+ flag_to_keys = NULL;
+}
+
+static void
+log_to_debug_sender (DebugFlags flag,
+ const gchar *message)
+{
+ TpDebugSender *dbg;
+ GTimeVal now;
+
+ dbg = tp_debug_sender_dup ();
+
+ g_get_current_time (&now);
+
+ tp_debug_sender_add_message (dbg, &now, debug_flag_to_domain (flag),
+ G_LOG_LEVEL_DEBUG, message);
+
+ g_object_unref (dbg);
+}
+
void debug (DebugFlags flag,
const gchar *format,
...)
{
+ gchar *message;
+ va_list args;
+
+ va_start (args, format);
+ message = g_strdup_vprintf (format, args);
+ va_end (args);
+
+ log_to_debug_sender (flag, message);
+
if (flag & flags)
- {
- va_list args;
- va_start (args, format);
- g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, args);
- va_end (args);
- }
+ g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "%s", message);
+
+ g_free (message);
}
#endif /* ENABLE_DEBUG */
diff --git a/src/debug.h b/src/debug.h
index ede6484d..cc28fcc5 100644
--- a/src/debug.h
+++ b/src/debug.h
@@ -40,6 +40,7 @@ void debug_set_flags (DebugFlags flags);
gboolean debug_flag_is_set (DebugFlags flag);
void debug (DebugFlags flag, const gchar *format, ...)
G_GNUC_PRINTF (2, 3);
+void debug_free (void);
#ifdef DEBUG_FLAG
@@ -64,6 +65,8 @@ void debug (DebugFlags flag, const gchar *format, ...)
#endif /* DEBUG_FLAG */
+#define debug_free() G_STMT_START { } G_STMT_END
+
#endif /* ENABLE_DEBUG */
G_END_DECLS
diff --git a/src/salut-connection-manager.c b/src/salut-connection-manager.c
index 9d912d38..666ffed1 100644
--- a/src/salut-connection-manager.c
+++ b/src/salut-connection-manager.c
@@ -24,9 +24,11 @@
#include <dbus/dbus-protocol.h>
#include <telepathy-glib/util.h>
+#include <telepathy-glib/debug-sender.h>
#include "salut-connection-manager.h"
#include "salut-connection.h"
+#include "debug.h"
/* properties */
enum
@@ -39,6 +41,7 @@ typedef struct _SalutConnectionManagerPrivate SalutConnectionManagerPrivate;
struct _SalutConnectionManagerPrivate
{
GType backend_type;
+ TpDebugSender *debug_sender;
};
#define SALUT_CONNECTION_MANAGER_GET_PRIVATE(obj) \
@@ -112,6 +115,9 @@ salut_connection_manager_init (SalutConnectionManager *self)
SalutConnectionManagerPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
SALUT_TYPE_CONNECTION_MANAGER, SalutConnectionManagerPrivate);
+ priv->debug_sender = tp_debug_sender_dup ();
+ g_log_set_default_handler (tp_debug_sender_log_handler, G_LOG_DOMAIN);
+
self->priv = priv;
}
@@ -158,6 +164,21 @@ salut_connection_manager_set_property (GObject *object,
}
static void
+salut_connection_manager_finalize (GObject *object)
+{
+ SalutConnectionManagerPrivate *priv = SALUT_CONNECTION_MANAGER_GET_PRIVATE (
+ object);
+
+ if (priv->debug_sender != NULL)
+ {
+ g_object_unref (priv->debug_sender);
+ priv->debug_sender = NULL;
+ }
+
+ debug_free ();
+}
+
+static void
salut_connection_manager_class_init (
SalutConnectionManagerClass *salut_connection_manager_class)
{
@@ -171,6 +192,7 @@ salut_connection_manager_class_init (
object_class->get_property = salut_connection_manager_get_property;
object_class->set_property = salut_connection_manager_set_property;
+ object_class->finalize = salut_connection_manager_finalize;
param_spec = g_param_spec_gtype (
"backend-type",