[next] telepathy-glib: add new-debug-message signal

Simon McVittie smcv at kemper.freedesktop.org
Wed Apr 25 07:26:08 PDT 2012


Module: telepathy-glib
Branch: next
Commit: 0bbef6a26f050571c93a7df02bcc6e9cabab9f27
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=0bbef6a26f050571c93a7df02bcc6e9cabab9f27

Author: Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
Date:   Fri Apr 13 15:08:11 2012 +0200

add new-debug-message signal

---

 telepathy-glib/debug-client.c |   49 +++++++++++++++++++++++++++++++++++++++++
 tests/dbus/debug-client.c     |   44 ++++++++++++++++++++++++++++++++++++
 2 files changed, 93 insertions(+), 0 deletions(-)

diff --git a/telepathy-glib/debug-client.c b/telepathy-glib/debug-client.c
index 1fcf257..8376f52 100644
--- a/telepathy-glib/debug-client.c
+++ b/telepathy-glib/debug-client.c
@@ -90,6 +90,13 @@ enum
   PROP_ENABLED = 1
 };
 
+enum {
+  SIG_NEW_DEBUG_MESSAGE,
+  LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+
 static void
 tp_debug_client_init (TpDebugClient *self)
 {
@@ -117,11 +124,29 @@ tp_debug_client_get_property (GObject *object,
 }
 
 static void
+new_debug_message_cb (TpDebugClient *self,
+    gdouble timestamp,
+    const gchar *domain,
+    TpDebugLevel level,
+    const gchar *message,
+    gpointer user_data,
+    GObject *weak_object)
+{
+  TpDebugMessage *msg;
+
+  msg = _tp_debug_message_new (timestamp, domain, level, message);
+
+  g_signal_emit (self, signals[SIG_NEW_DEBUG_MESSAGE], 0, msg);
+  g_object_unref (msg);
+}
+
+static void
 tp_debug_client_constructed (GObject *object)
 {
   TpDebugClient *self = TP_DEBUG_CLIENT (object);
   TpProxy *proxy = TP_PROXY (object);
   GObjectClass *parent_class = G_OBJECT_CLASS (tp_debug_client_parent_class);
+  GError *error = NULL;
 
   if (parent_class->constructed != NULL)
     parent_class->constructed (object);
@@ -130,6 +155,13 @@ tp_debug_client_constructed (GObject *object)
       tp_proxy_get_dbus_daemon (proxy), tp_proxy_get_bus_name (proxy),
       name_owner_changed_cb, object, NULL);
   tp_debug_client_prepare_core (self);
+
+  if (!tp_cli_debug_connect_to_new_debug_message (self, new_debug_message_cb,
+        NULL, NULL, NULL, &error))
+    {
+      WARNING ("Failed to connect to NewDebugMessage: %s", error->message);
+      g_error_free (error);
+    }
 }
 
 static void
@@ -177,6 +209,23 @@ tp_debug_client_class_init (TpDebugClientClass *klass)
       G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
   g_object_class_install_property (object_class, PROP_ENABLED, spec);
 
+  /**
+   * TpDebugClient::new-debug-message:
+   * @self: a #TpDebugClient
+   * @message: a #TpDebugMessage
+   *
+   * Emitted when a #TpDebugMessage is generated if the TpDebugMessage:enabled
+   * property is set to %TRUE.
+   *
+   * Since: UNRELEASED
+   */
+  signals[SIG_NEW_DEBUG_MESSAGE] = g_signal_new ("new-debug-message",
+      G_OBJECT_CLASS_TYPE (klass),
+      G_SIGNAL_RUN_LAST,
+      0, NULL, NULL, NULL,
+      G_TYPE_NONE,
+      1, TP_TYPE_DEBUG_MESSAGE);
+
   g_type_class_add_private (klass, sizeof (TpDebugClientPrivate));
   tp_debug_client_init_known_interfaces ();
 }
diff --git a/tests/dbus/debug-client.c b/tests/dbus/debug-client.c
index c528e61..3c3e865 100644
--- a/tests/dbus/debug-client.c
+++ b/tests/dbus/debug-client.c
@@ -27,6 +27,7 @@ typedef struct {
     TpDebugClient *client;
 
     GPtrArray *messages;
+    TpDebugMessage *message;
     GError *error /* initialized where needed */;
     gint wait;
 } Test;
@@ -62,6 +63,7 @@ teardown (Test *test,
   tp_clear_object (&test->client);
 
   tp_clear_pointer (&test->messages, g_ptr_array_unref);
+  tp_clear_object (&test->message);
 }
 
 static void
@@ -237,6 +239,46 @@ test_get_messages (Test *test,
   g_assert_cmpstr (tp_debug_message_get_message (msg), ==, "message1");
 }
 
+static void
+new_debug_message_cb (TpDebugClient *client,
+    TpDebugMessage *message,
+    Test *test)
+{
+  tp_clear_object (&test->message);
+
+  test->message = g_object_ref (message);
+
+  test->wait--;
+  if (test->wait <= 0)
+    g_main_loop_quit (test->mainloop);
+
+}
+
+static void
+test_new_debug_message (Test *test,
+    gconstpointer data G_GNUC_UNUSED)
+{
+  g_signal_connect (test->client, "new-debug-message",
+      G_CALLBACK (new_debug_message_cb), test);
+
+  g_object_set (test->sender, "enabled", TRUE, NULL);
+
+  tp_debug_sender_add_message (test->sender, NULL, "domain",
+      G_LOG_LEVEL_DEBUG, "new message");
+
+  test->wait = 1;
+  g_main_loop_run (test->mainloop);
+  g_assert_no_error (test->error);
+
+  g_assert (TP_IS_DEBUG_MESSAGE (test->message));
+
+  g_assert_cmpstr (tp_debug_message_get_domain (test->message), ==, "domain");
+  g_assert_cmpuint (tp_debug_message_get_level (test->message), ==,
+      G_LOG_LEVEL_DEBUG);
+  g_assert_cmpstr (tp_debug_message_get_message (test->message), ==,
+      "new message");
+}
+
 int
 main (int argc,
       char **argv)
@@ -254,6 +296,8 @@ main (int argc,
       test_set_enabled, teardown);
   g_test_add ("/debug-client/get-messages", Test, NULL, setup,
       test_get_messages, teardown);
+  g_test_add ("/debug-client/new-debug-message", Test, NULL, setup,
+      test_new_debug_message, teardown);
 
   return g_test_run ();
 }



More information about the telepathy-commits mailing list