[rygel-grilo] Implement SearchObjects in client side
- From: Juan A. Suarez Romero <jasuarez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel-grilo] Implement SearchObjects in client side
- Date: Wed, 12 May 2010 16:06:02 +0000 (UTC)
commit d997c60ebb0b4a3bf1014d226854781605f3e993
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date: Wed May 12 18:05:29 2010 +0200
Implement SearchObjects in client side
lib/media-server1-client.c | 57 ++++++++++++++++++++++++++++++++++++++++++++
lib/media-server1-client.h | 8 ++++++
src/test-client.c | 56 ++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 120 insertions(+), 1 deletions(-)
---
diff --git a/lib/media-server1-client.c b/lib/media-server1-client.c
index da9d921..59d720e 100644
--- a/lib/media-server1-client.c
+++ b/lib/media-server1-client.c
@@ -501,6 +501,63 @@ ms1_client_list_children (MS1Client *client,
return children;
}
+/**
+ * ms1_client_search_objects:
+ * @client: a #MS1Client
+ * @object_path: container identifier to start search from
+ * @offset: number of children to skip
+ * @max_count: maximum number of children to return, or 0 for no limit
+ * @properties: @NULL-terminated array of properties to request for each child
+ * @error: a #GError location to store the error ocurring, or @NULL to ignore
+ *
+ * Searchs for children below this container. Each child consist
+ * of a hash table of <prop_id, prop_gvalue> pairs.
+ *
+ * Returns: a new #GList of #GHashTable. To free it, free first each element
+ * (g_hash_table_unref()) and finally the list itself (g_list_free())
+ **/
+GList *
+ms1_client_search_objects (MS1Client *client,
+ const gchar *object_path,
+ const gchar *query,
+ guint offset,
+ guint max_count,
+ const gchar **properties,
+ GError **error)
+{
+ DBusGProxy *gproxy;
+ GList *children = NULL;
+ GPtrArray *result = NULL;
+
+ g_return_val_if_fail (MS1_IS_CLIENT (client), NULL);
+ g_return_val_if_fail (properties, NULL);
+
+ gproxy = dbus_g_proxy_new_for_name (client->priv->bus,
+ client->priv->fullname,
+ object_path,
+ "org.gnome.UPnP.MediaContainer1");
+
+ if (dbus_g_proxy_call (gproxy,
+ "SearchObjects", error,
+ G_TYPE_STRING, query,
+ G_TYPE_UINT, offset,
+ G_TYPE_UINT, max_count,
+ G_TYPE_STRV, properties,
+ G_TYPE_INVALID,
+ dbus_g_type_get_collection ("GPtrArray",
+ dbus_g_type_get_map ("GHashTable",
+ G_TYPE_STRING,
+ G_TYPE_VALUE)), &result,
+ G_TYPE_INVALID)) {
+ children = gptrarray_to_glist (result);
+ g_ptr_array_free (result, TRUE);
+ }
+
+ g_object_unref (gproxy);
+
+ return children;
+}
+
const gchar *
ms1_client_get_root_path (MS1Client *client)
{
diff --git a/lib/media-server1-client.h b/lib/media-server1-client.h
index fb4a3b6..81fc312 100644
--- a/lib/media-server1-client.h
+++ b/lib/media-server1-client.h
@@ -98,6 +98,14 @@ GList *ms1_client_list_children (MS1Client *client,
const gchar **properties,
GError **error);
+GList *ms1_client_search_objects (MS1Client *client,
+ const gchar *object_path,
+ const gchar *query,
+ guint offset,
+ guint max_count,
+ const gchar **properties,
+ GError **error);
+
const gchar *ms1_client_get_root_path (MS1Client *client);
const gchar *ms1_client_get_path (GHashTable *properties);
diff --git a/src/test-client.c b/src/test-client.c
index dd0a621..c5c464b 100644
--- a/src/test-client.c
+++ b/src/test-client.c
@@ -115,6 +115,59 @@ test_children ()
}
static void
+test_search ()
+{
+ GList *child;
+ GError *error = NULL;
+ GList *result;
+ 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");
+ return;
+ }
+
+ result = ms1_client_search_objects (client,
+ ms1_client_get_root_path (client),
+ "Artist = \"Groove Coverage\"",
+ 0,
+ 10,
+ properties,
+ &error);
+
+ g_print ("\n* Provider '%s'\n", *provider);
+ if (!result) {
+ g_print ("\tDid not get any result, %s\n", error? error->message: "no error");
+ return;
+ }
+
+ for (child = result; child; child = g_list_next (child)) {
+ g_print ("\t* '%s', '%s'\n",
+ ms1_client_get_path (child->data),
+ ms1_client_get_display_name(child->data));
+ }
+
+ g_list_foreach (result, (GFunc) g_hash_table_unref, NULL);
+ g_list_free (result);
+ g_object_unref (client);
+ }
+
+ g_strfreev (providers);
+}
+
+static void
destroy_cb (MS1Client *client, gpointer user_data)
{
g_print ("End of provider %s\n", ms1_client_get_provider_name(client));
@@ -205,7 +258,8 @@ int main (int argc, char **argv)
g_type_init ();
if (0) test_properties ();
- if (1) test_children ();
+ if (0) test_children ();
+ if (1) test_search ();
if (0) test_provider_free ();
if (0) test_dynamic_providers ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]