[rygel-grilo] Add support for SearchObjects method
- From: Juan A. Suarez Romero <jasuarez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel-grilo] Add support for SearchObjects method
- Date: Wed, 12 May 2010 16:05:52 +0000 (UTC)
commit ec9889f73502a9f7c756d0ba32acfab8df4fcd19
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date: Wed May 12 12:58:53 2010 +0200
Add support for SearchObjects method
Right now, rygel-grilo is not implementing it.
lib/media-server1-server.c | 102 ++++++++++++++++++++++++++++++++++++++++++--
lib/media-server1-server.h | 12 +++++
2 files changed, 110 insertions(+), 4 deletions(-)
---
diff --git a/lib/media-server1-server.c b/lib/media-server1-server.c
index 7d8e5ed..5078458 100644
--- a/lib/media-server1-server.c
+++ b/lib/media-server1-server.c
@@ -56,15 +56,33 @@ struct _MS1ServerPrivate {
gchar *name;
gpointer *data;
GetChildrenFunc get_children;
+ SearchObjectsFunc search_objects;
GetPropertiesFunc get_properties;
};
/* dbus message signatures */
static const gchar introspect_sgn[] = { DBUS_TYPE_INVALID };
-static const gchar get_sgn[] = { DBUS_TYPE_STRING, DBUS_TYPE_STRING, DBUS_TYPE_INVALID };
-static const gchar getall_sgn[] = { DBUS_TYPE_STRING, DBUS_TYPE_INVALID };
-static const gchar listobjects_sgn[] = { DBUS_TYPE_UINT32, DBUS_TYPE_UINT32, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, DBUS_TYPE_INVALID };
+static const gchar get_sgn[] = { DBUS_TYPE_STRING, /* interface */
+ DBUS_TYPE_STRING, /* property */
+ DBUS_TYPE_INVALID };
+
+static const gchar getall_sgn[] = { DBUS_TYPE_STRING, /* interface */
+ DBUS_TYPE_INVALID };
+
+static const gchar listchildren_sgn[] = { DBUS_TYPE_UINT32, /* offset */
+ DBUS_TYPE_UINT32, /* max */
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, /* filter */
+ DBUS_TYPE_INVALID };
+
+static const gchar searchobjects_sgn[] = { DBUS_TYPE_STRING, /* query */
+ DBUS_TYPE_UINT32, /* offset */
+ DBUS_TYPE_UINT32, /* max */
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, /* filter */
+ DBUS_TYPE_INVALID };
+
+
+/* Properties in interfaces */
static const gchar *mediaobject1_properties[] = { MS1_PROP_PARENT,
MS1_PROP_TYPE,
MS1_PROP_PATH,
@@ -730,7 +748,7 @@ handle_list_children_message (DBusConnection *c,
MS1Server *server = MS1_SERVER (userdata);
/* Check signature */
- if (dbus_message_has_signature (m, listobjects_sgn)) {
+ if (dbus_message_has_signature (m, listchildren_sgn)) {
dbus_message_get_args (m, NULL,
DBUS_TYPE_UINT32, &offset,
DBUS_TYPE_UINT32, &max_count,
@@ -769,6 +787,62 @@ handle_list_children_message (DBusConnection *c,
}
static DBusHandlerResult
+handle_search_objects_message (DBusConnection *c,
+ DBusMessage *m,
+ void *userdata)
+{
+ DBusMessage *r;
+ GList *children;
+ gchar **filter;
+ gchar *id;
+ gchar *query;
+ guint max_count;
+ guint offset;
+ gint nitems;
+ MS1Server *server = MS1_SERVER (userdata);
+
+ /* Check signature */
+ if (dbus_message_has_signature (m, searchobjects_sgn)) {
+ dbus_message_get_args (m, NULL,
+ DBUS_TYPE_STRING, &query,
+ DBUS_TYPE_UINT32, &offset,
+ DBUS_TYPE_UINT32, &max_count,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &filter, &nitems,
+ DBUS_TYPE_INVALID);
+ if (!server->priv->search_objects || nitems == 0) {
+ children = NULL;
+ } else {
+ id = get_id_from_message (m);
+ if (!id) {
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+ children = server->priv->search_objects (server,
+ id,
+ query,
+ offset,
+ max_count? max_count: G_MAXUINT,
+ (const gchar **) filter,
+ server->priv->data,
+ NULL);
+ g_free (id);
+ dbus_free_string_array (filter);
+ }
+
+ r = dbus_message_new_method_return (m);
+ add_glist_as_array (r, NULL, children);
+ dbus_connection_send (c, r, NULL);
+ dbus_message_unref (r);
+ if (children) {
+ g_list_foreach (children, (GFunc) g_hash_table_unref, NULL);
+ g_list_free (children);
+ }
+ return DBUS_HANDLER_RESULT_HANDLED;
+ } else {
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+}
+
+static DBusHandlerResult
items_handler (DBusConnection *c,
DBusMessage *m,
void *userdata)
@@ -813,6 +887,10 @@ containers_handler (DBusConnection *c,
"org.gnome.UPnP.MediaContainer1",
"ListChildren")) {
return handle_list_children_message (c, m, userdata);
+ } else if (dbus_message_is_method_call (m,
+ "org.gnome.UPnP.MediaContainer1",
+ "SearchObjects")) {
+ return handle_search_objects_message (c, m, userdata);
} else {
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
@@ -1034,6 +1112,22 @@ ms1_server_set_get_children_func (MS1Server *server,
}
/**
+ * ms1_server_set_search_objects_func:
+ * @server: a #MS1Server
+ * @search_objects_func: user-defined function to search children
+ *
+ * Defines which function must be used when searching objects
+ **/
+void
+ms1_server_set_search_objects_func (MS1Server *server,
+ SearchObjectsFunc search_objects_func)
+{
+ g_return_if_fail (MS1_IS_SERVER (server));
+
+ server->priv->search_objects = search_objects_func;
+}
+
+/**
* ms1_server_updated:
* @server: a #MS1Server
* @id: item identifier that has changed
diff --git a/lib/media-server1-server.h b/lib/media-server1-server.h
index 0510cba..d76d893 100644
--- a/lib/media-server1-server.h
+++ b/lib/media-server1-server.h
@@ -89,6 +89,15 @@ typedef GList * (*GetChildrenFunc) (MS1Server *server,
gpointer data,
GError **error);
+typedef GList * (*SearchObjectsFunc) (MS1Server *server,
+ const gchar *id,
+ const gchar *query,
+ guint offset,
+ guint max_count,
+ const gchar **properties,
+ gpointer data,
+ GError **error);
+
GType ms1_server_get_type (void);
MS1Server *ms1_server_new (const gchar *name,
@@ -100,6 +109,9 @@ void ms1_server_set_get_properties_func (MS1Server *server,
void ms1_server_set_get_children_func (MS1Server *server,
GetChildrenFunc get_children_func);
+void ms1_server_set_search_objects_func (MS1Server *server,
+ SearchObjectsFunc search_objects_func);
+
void ms1_server_updated (MS1Server *server,
const gchar *id);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]