[rygel-grilo] Implement get_properties() function



commit bee59afb801c38d7b7fc6a880b2bc41d43119476
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date:   Mon Apr 12 18:19:47 2010 +0200

    Implement get_properties() function
    
    Wrapper around dbus function to get properties of an id.

 lib/media-server2-client.c      |   57 +++++++++++++++++++++++++++++++++++---
 lib/media-server2-client.h      |    2 +
 lib/media-server2-common.h      |    4 ++-
 lib/media-server2-server-glue.h |    4 +-
 src/rygel-grilo.c               |   11 +++----
 src/test-client.c               |   41 ++++++++++++++++++++++++++-
 6 files changed, 103 insertions(+), 16 deletions(-)
---
diff --git a/lib/media-server2-client.c b/lib/media-server2-client.c
index a2323b1..baca8f3 100644
--- a/lib/media-server2-client.c
+++ b/lib/media-server2-client.c
@@ -28,7 +28,7 @@
 #include "media-server2-client.h"
 
 #define MS2_DBUS_SERVICE_PREFIX "org.gnome.UPnP.MediaServer2."
-#define MS2_DBUS_OBJECT         "/org/gnome/UPnP/MediaServer2"
+#define MS2_DBUS_PATH_PREFIX    "/org/gnome/UPnP/MediaServer2/"
 #define MS2_DBUS_IFACE          "org.gnome.UPnP.MediaServer2"
 
 #define ENTRY_POINT_IFACE "/org/gnome/UPnP/MediaServer2/"
@@ -124,7 +124,8 @@ MS2Client *ms2_client_new (const gchar *provider)
   DBusGProxy *gproxy;
   GError *error = NULL;
   MS2Client *client;
-  gchar *dbus_provider;
+  gchar *service_provider;
+  gchar *path_provider;
 
   connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
   if (!connection) {
@@ -133,14 +134,18 @@ MS2Client *ms2_client_new (const gchar *provider)
     return NULL;
   }
 
-  dbus_provider = g_strconcat (MS2_DBUS_SERVICE_PREFIX, provider, NULL);
+  service_provider = g_strconcat (MS2_DBUS_SERVICE_PREFIX, provider, NULL);
+  path_provider = g_strconcat (MS2_DBUS_PATH_PREFIX, provider, NULL);
 
   gproxy = dbus_g_proxy_new_for_name_owner (connection,
-                                            dbus_provider,
-                                            MS2_DBUS_OBJECT,
+                                            service_provider,
+                                            path_provider,
                                             MS2_DBUS_IFACE,
                                             &error);
 
+  g_free (service_provider);
+  g_free (path_provider);
+
   if (!gproxy) {
     g_printerr ("Could not connect to %s provider, %s\n",
                 provider,
@@ -154,3 +159,45 @@ MS2Client *ms2_client_new (const gchar *provider)
 
   return client;
 }
+
+static void
+free_gvalue (GValue *v)
+{
+  g_value_unset (v);
+  g_free (v);
+}
+
+GHashTable *
+ms2_client_get_properties (MS2Client *client,
+                           const gchar *id,
+                           const gchar **properties,
+                           GError **error)
+{
+  GHashTable *prop_result;
+  GPtrArray *result = NULL;
+  gint i;
+
+  g_return_val_if_fail (MS2_IS_CLIENT (client), NULL);
+
+  if (!org_gnome_UPnP_MediaServer2_get_properties (client->priv->proxy_provider,
+                                                   id,
+                                                   properties,
+                                                   &result,
+                                                   error)) {
+    return NULL;
+  }
+
+  prop_result = g_hash_table_new_full (g_str_hash,
+                                       g_str_equal,
+                                       (GDestroyNotify) g_free,
+                                       (GDestroyNotify) free_gvalue);
+  for (i = 0; i < result->len; i++) {
+    g_hash_table_insert (prop_result,
+                         g_strdup (properties[i]),
+                         g_ptr_array_index (result, i));
+  }
+
+  g_ptr_array_free (result, TRUE);
+
+  return prop_result;
+}
diff --git a/lib/media-server2-client.h b/lib/media-server2-client.h
index 40ce3fd..b4801d6 100644
--- a/lib/media-server2-client.h
+++ b/lib/media-server2-client.h
@@ -78,4 +78,6 @@ gchar **ms2_client_get_providers (void);
 
 MS2Client *ms2_client_new (const gchar *provider);
 
+GHashTable *ms2_client_get_properties (MS2Client *client, const gchar *id, const gchar **properties, GError **error);
+
 #endif /* _MEDIA_SERVER2_CLIENT_H_ */
diff --git a/lib/media-server2-common.h b/lib/media-server2-common.h
index ea51d10..c5198e0 100644
--- a/lib/media-server2-common.h
+++ b/lib/media-server2-common.h
@@ -75,10 +75,12 @@
 #define MS2_UNKNOWN_INT -1
 #define MS2_UNKNOWN_STR ""
 
+/* Root category */
+#define MS2_ROOT "0"
+
 typedef enum {
   MS2_ERROR_GENERAL = 1
 } MS2Error;
 
 #endif /* _MEDIA_SERVER2_COMMON_H_ */
 
-
diff --git a/lib/media-server2-server-glue.h b/lib/media-server2-server-glue.h
index 921eb18..58f9a58 100644
--- a/lib/media-server2-server-glue.h
+++ b/lib/media-server2-server-glue.h
@@ -53,7 +53,7 @@ G_BEGIN_DECLS
 #endif /* !G_ENABLE_DEBUG */
 
 
-/* NONE:STRING,UINT,INT,BOXED,POINTER (/tmp/dbus-binding-tool-c-marshallers.9MVLAV:1) */
+/* NONE:STRING,UINT,INT,BOXED,POINTER (/tmp/dbus-binding-tool-c-marshallers.O4F0AV:1) */
 extern void dbus_glib_marshal_ms2_server_VOID__STRING_UINT_INT_BOXED_POINTER (GClosure     *closure,
                                                                               GValue       *return_value,
                                                                               guint         n_param_values,
@@ -103,7 +103,7 @@ dbus_glib_marshal_ms2_server_VOID__STRING_UINT_INT_BOXED_POINTER (GClosure     *
 }
 #define dbus_glib_marshal_ms2_server_NONE__STRING_UINT_INT_BOXED_POINTER	dbus_glib_marshal_ms2_server_VOID__STRING_UINT_INT_BOXED_POINTER
 
-/* NONE:STRING,BOXED,POINTER (/tmp/dbus-binding-tool-c-marshallers.9MVLAV:2) */
+/* NONE:STRING,BOXED,POINTER (/tmp/dbus-binding-tool-c-marshallers.O4F0AV:2) */
 extern void dbus_glib_marshal_ms2_server_VOID__STRING_BOXED_POINTER (GClosure     *closure,
                                                                      GValue       *return_value,
                                                                      guint         n_param_values,
diff --git a/src/rygel-grilo.c b/src/rygel-grilo.c
index 35683c9..49c5724 100644
--- a/src/rygel-grilo.c
+++ b/src/rygel-grilo.c
@@ -31,7 +31,6 @@
 #define ID_PREFIX_CONTAINER "grc://"
 #define ID_PREFIX_IMAGE     "gri://"
 #define ID_PREFIX_VIDEO     "grv://"
-#define ID_ROOT             "0"
 #define ID_SEPARATOR        "/"
 
 static gchar **args;
@@ -81,7 +80,7 @@ get_parent_id (const gchar *child_id)
   gchar *parent_id;
   gsize bytes_to_copy;
 
-  if (g_strcmp0 (child_id, ID_ROOT) == 0) {
+  if (g_strcmp0 (child_id, MS2_ROOT) == 0) {
     return NULL;
   }
 
@@ -90,7 +89,7 @@ get_parent_id (const gchar *child_id)
 
   /* Check if parent is a root */
   if (bytes_to_copy < 6) {
-    return g_strdup (ID_ROOT);
+    return g_strdup (MS2_ROOT);
   }
 
   /* Save parent id */
@@ -108,7 +107,7 @@ get_grl_id (const gchar *ms_id)
   gchar **offspring;
   gchar *grl_id;
 
-  if (g_strcmp0 (ms_id, ID_ROOT) == 0) {
+  if (g_strcmp0 (ms_id, MS2_ROOT) == 0) {
     return NULL;
   }
 
@@ -135,7 +134,7 @@ serialize_media (const gchar *parent_id,
 
   escaped_id = g_uri_escape_string (grl_media_get_id (media), NULL, TRUE);
 
-  if (g_strcmp0 (parent_id, ID_ROOT) == 0) {
+  if (g_strcmp0 (parent_id, MS2_ROOT) == 0) {
     ms_id = g_strconcat (ID_PREFIX_CONTAINER, escaped_id, NULL);
   } else {
     ms_id = g_strconcat (parent_id, ID_SEPARATOR, escaped_id, NULL);
@@ -161,7 +160,7 @@ unserialize_media (GrlMetadataSource *source, const gchar *id)
   GrlMedia *media = NULL;
   gchar *grl_id;
 
-  if (g_strcmp0 (id, ID_ROOT) == 0 ||
+  if (g_strcmp0 (id, MS2_ROOT) == 0 ||
       g_str_has_prefix (id, ID_PREFIX_CONTAINER)) {
     media = grl_media_box_new ();
   } else if (g_str_has_prefix (id, ID_PREFIX_AUDIO)) {
diff --git a/src/test-client.c b/src/test-client.c
index bf5484f..b836ae7 100644
--- a/src/test-client.c
+++ b/src/test-client.c
@@ -4,8 +4,17 @@
 
 int main (int argc, char **argv)
 {
-  gchar **providers;
+  GError *error = NULL;
+  GHashTable *result;
+  GValue *v;
   MS2Client *client;
+  const gchar **p;
+  const gchar *properties[] = { MS2_PROP_DISPLAY_NAME,
+                                MS2_PROP_PARENT,
+                                MS2_PROP_CHILD_COUNT,
+                                NULL };
+  gchar **provider;
+  gchar **providers;
 
   g_type_init ();
 
@@ -15,5 +24,33 @@ int main (int argc, char **argv)
     return 0;
   }
 
-  client = ms2_client_new (providers[0]);
+  for (provider = providers; *provider; provider++) {
+    client = ms2_client_new (*provider);
+
+    if (!client) {
+      g_printerr ("Unable to create a client\n");
+      return 0;
+    }
+
+    result = ms2_client_get_properties (client, MS2_ROOT, properties, &error);
+
+    if (!result) {
+      g_print ("Did not get any property, %s\n", error->message);
+      return 0;
+    }
+
+    g_print ("\n* Provider '%s'\n", *provider);
+    for (p = properties; *p; p++) {
+      v = g_hash_table_lookup (result, *p);
+      if (v && G_VALUE_HOLDS_INT (v)) {
+        g_print ("\t* '%s' value: '%d'\n", *p, g_value_get_int (v));
+      } else if (v && G_VALUE_HOLDS_STRING (v)) {
+        g_print ("\t* '%s' value: '%s'\n", *p, g_value_get_string (v));
+      } else {
+        g_print ("\t* '%s' value: ---\n", *p);
+      }
+    }
+  }
+
+  g_hash_table_unref (result);
 }



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