[rygel-grilo] Implement support for Updated signal



commit ba41f2d2da86640b99ba0c186ebb1fd04d94aeeb
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date:   Thu May 13 11:28:57 2010 +0200

    Implement support for Updated signal

 lib/media-server1-client.c   |   19 +++++-------
 lib/media-server1-observer.c |   62 +++++++++++++++++++++++++++++++++++++++---
 lib/media-server1-private.h  |    2 +
 lib/media-server1-server.c   |    1 -
 src/test-client.c            |   39 +++++++++++++++++++++++++-
 5 files changed, 106 insertions(+), 17 deletions(-)
---
diff --git a/lib/media-server1-client.c b/lib/media-server1-client.c
index 675ac4c..a495180 100644
--- a/lib/media-server1-client.c
+++ b/lib/media-server1-client.c
@@ -62,17 +62,6 @@ G_DEFINE_TYPE (MS1Client, ms1_client, G_TYPE_OBJECT);
 
 /******************** PRIVATE API ********************/
 
-#if 0
-/* Callback invoked when "Updated" dbus signal is received */
-static void
-updated (DBusGProxy *proxy,
-         const gchar *id,
-         MS1Client *client)
-{
-  g_signal_emit (client, signals[UPDATED], 0, id);
-}
-#endif
-
 /* Free gvalue */
 static void
 free_gvalue (GValue *v)
@@ -231,6 +220,14 @@ ms1_client_notify_destroy (MS1Client *client)
   g_signal_emit (client, signals[DESTROY], 0);
 }
 
+/* Notify update of object_path */
+void
+ms1_client_notify_updated (MS1Client *client,
+                           const gchar *object_path)
+{
+  g_signal_emit (client, signals[UPDATED], 0, object_path);
+}
+
 /******************** PUBLIC API ********************/
 
 /**
diff --git a/lib/media-server1-observer.c b/lib/media-server1-observer.c
index ec9865d..1041742 100644
--- a/lib/media-server1-observer.c
+++ b/lib/media-server1-observer.c
@@ -21,6 +21,7 @@
  */
 
 #include <dbus/dbus-glib-bindings.h>
+#include <dbus/dbus-glib-lowlevel.h>
 #include <dbus/dbus-glib.h>
 
 #include "media-server1-private.h"
@@ -85,16 +86,59 @@ name_owner_changed (DBusGProxy *proxy,
   }
 }
 
+/* Check for Updated signal and notify appropriate MS1Client, which will send a
+   signal */
+static DBusHandlerResult
+listen_updated_signal (DBusConnection *connection,
+                       DBusMessage *message,
+                       void *user_data)
+{
+  GList *clients;
+  MS1Observer *observer = MS1_OBSERVER (user_data);
+  gchar **path;
+
+  g_print ("# Iface %s\n", dbus_message_get_interface(message));
+  g_print ("# Path %s\n", dbus_message_get_path (message));
+  g_print ("# Method %s\n", dbus_message_get_member (message));
+  g_print ("\n\n\n");
+
+  if (dbus_message_is_signal (message,
+                              "org.gnome.UPnP.MediaContainer1",
+                              "Updated")) {
+    dbus_message_get_path_decomposed (message, &path);
+
+    if (g_strv_length (path) < 5) {
+      g_printerr ("Wrong object path %s\n", dbus_message_get_path (message));
+      dbus_free_string_array (path);
+      return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+    }
+
+    /* Check if there is a client for this provider; if so, then notify all of
+       them */
+    clients = g_hash_table_lookup (observer->priv->clients, path[4]);
+    dbus_free_string_array (path);
+
+    g_list_foreach (clients,
+                    (GFunc) ms1_client_notify_updated,
+                    (gpointer) dbus_message_get_path (message));
+
+    return DBUS_HANDLER_RESULT_HANDLED;
+  }
+
+  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
 /* Creates an instance of observer */
 static MS1Observer *
 create_instance ()
 {
-  DBusGConnection *connection;
+  DBusConnection *connection;
+  DBusGConnection *gconnection;
   GError *error = NULL;
   MS1Observer *observer;
 
-  connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
-  if (!connection) {
+  gconnection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+  if (!gconnection) {
     g_printerr ("Could not connect to session bus, %s\n", error->message);
     g_error_free (error);
     return NULL;
@@ -102,7 +146,7 @@ create_instance ()
 
   observer = g_object_new (MS1_TYPE_OBSERVER, NULL);
 
-  observer->priv->proxy = dbus_g_proxy_new_for_name (connection,
+  observer->priv->proxy = dbus_g_proxy_new_for_name (gconnection,
                                                      DBUS_SERVICE_DBUS,
                                                      DBUS_PATH_DBUS,
                                                      DBUS_INTERFACE_DBUS);
@@ -120,6 +164,16 @@ create_instance ()
                                observer,
                                NULL);
 
+  /* Listen for Updated signal */
+  connection = dbus_g_connection_get_connection (gconnection);
+  dbus_bus_add_match (connection,
+                      "interface='org.gnome.UPnP.MediaContainer1',"
+                      "member='Updated'",
+                      NULL);
+  dbus_connection_add_filter (connection,
+                              listen_updated_signal,
+                              observer,
+                              NULL);
   return observer;
 }
 
diff --git a/lib/media-server1-private.h b/lib/media-server1-private.h
index b335c4f..d216db6 100644
--- a/lib/media-server1-private.h
+++ b/lib/media-server1-private.h
@@ -33,6 +33,8 @@
 
 void ms1_client_notify_destroy (MS1Client *client);
 
+void ms1_client_notify_updated (MS1Client *client, const gchar *object_path);
+
 void ms1_observer_add_client (MS1Client *client, const gchar *provider);
 
 void ms1_observer_remove_client (MS1Client *client, const gchar *provider);
diff --git a/lib/media-server1-server.c b/lib/media-server1-server.c
index 09ff600..b086c2b 100644
--- a/lib/media-server1-server.c
+++ b/lib/media-server1-server.c
@@ -1165,7 +1165,6 @@ ms1_server_updated (MS1Server *server,
   message = dbus_message_new_signal (object_path,
                                      "org.gnome.UPnP.MediaContainer1",
                                      "Updated");
-
   dbus_connection_send (connection, message, NULL);
   dbus_message_unref (message);
 
diff --git a/src/test-client.c b/src/test-client.c
index c5c464b..ff878b5 100644
--- a/src/test-client.c
+++ b/src/test-client.c
@@ -174,6 +174,14 @@ destroy_cb (MS1Client *client, gpointer user_data)
 }
 
 static void
+updated_cb (MS1Client *client, const gchar *object_path, gpointer user_data)
+{
+  g_print ("Provider %s: %s updated\n",
+           ms1_client_get_provider_name (client),
+           object_path);
+}
+
+static void
 new_cb (MS1Observer *observer, const gchar *provider, gpointer user_data)
 {
   MS1Client *client;
@@ -216,6 +224,34 @@ test_provider_free ()
 }
 
 static void
+test_updated ()
+{
+  MS1Client *client;
+  gchar **provider;
+  gchar **providers;
+
+  providers = ms1_client_get_providers ();
+
+  if (!providers) {
+    g_print ("There is no MediaServer1 provider\n");
+    return;
+  }
+
+  for (provider = providers; *provider; provider++) {
+    client = ms1_client_new (*provider);
+    if (!client) {
+      g_printerr ("Unable to create a client\n");
+      continue;
+    }
+
+    g_print ("Provider %s\n", *provider);
+    g_signal_connect (G_OBJECT (client), "updated", G_CALLBACK (updated_cb), NULL);
+  }
+
+  g_strfreev (providers);
+}
+
+static void
 test_dynamic_providers ()
 {
   MS1Client *client;
@@ -259,8 +295,9 @@ int main (int argc, char **argv)
 
   if (0) test_properties ();
   if (0) test_children ();
-  if (1) test_search ();
+  if (0) test_search ();
   if (0) test_provider_free ();
+  if (1) test_updated ();
   if (0) test_dynamic_providers ();
 
   mainloop = g_main_loop_new (NULL, FALSE);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]