[rygel-grilo] Fix getting Path property
- From: Juan A. Suarez Romero <jasuarez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel-grilo] Fix getting Path property
- Date: Thu, 13 May 2010 09:57:57 +0000 (UTC)
commit 94ccff3886c357eb37d508e157c4a81af4172105
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date: Wed May 12 20:17:12 2010 +0200
Fix getting Path property
lib/media-server1-server.c | 81 ++++++++++++++++++-------------------------
1 files changed, 34 insertions(+), 47 deletions(-)
---
diff --git a/lib/media-server1-server.c b/lib/media-server1-server.c
index 4261efe..7f10b20 100644
--- a/lib/media-server1-server.c
+++ b/lib/media-server1-server.c
@@ -372,51 +372,69 @@ is_property_valid (const gchar *interface,
return FALSE;
}
+/* Returns the id suitable to be used with server backend */
static gchar *
-get_path_from_id (MS1Server *server,
- const gchar *id)
+get_id_from_message (DBusMessage *m)
{
- gchar *path;
+ gchar **path;
+ gchar *id;
+ gint path_length;
+
+ dbus_message_get_path_decomposed (m, &path);
+
+ /* Path can of type:
+ /org/gnome/UPnP/MediaServer1/<name>
+ /org/gnome/UPnP/MediaServer1/<name>/items/<id>
+ /org/gnome/UPnP/MediaServer1/<name>/containers/<id>
+ */
+ path_length = g_strv_length (path);
+
+ if (path_length == 5) {
+ id = g_strdup (MS1_ROOT);
+ } else if (path_length == 7) {
+ id = g_strdup (g_quark_to_string (atoi (path[6])));
+ } else {
+ id = NULL;
+ }
- path = g_strconcat (MS1_DBUS_PATH_PREFIX,
- server->priv->name,
- NULL);
+ dbus_free_string_array (path);
- return path;
+ return id;
}
+/* Request value of property in the interface */
static GValue *
get_property_value (MS1Server *server,
- const gchar *id,
+ DBusMessage *message,
const gchar *interface,
const gchar *property)
{
GHashTable *propresult;
GValue *v;
const gchar *prop[2] = { NULL };
- gchar *path;
+ gchar *id;
/* Check everything is right */
- if (!id ||
- !property ||
+ if (!property ||
!is_property_valid (interface, property) ||
!server->priv->get_properties) {
return NULL;
}
- /* If asking for Path, we already can use id */
+ /* If asking for Path, we already can use object_path */
if (g_strcmp0 (property, MS1_PROP_PATH) == 0) {
v = g_new0 (GValue, 1);
g_value_init (v, G_TYPE_STRING);
- path = get_path_from_id (server, id);
- g_value_take_string (v, path);
+ g_value_set_string (v, dbus_message_get_path (message));
} else {
+ id = get_id_from_message (message);
prop[0] = property;
propresult = server->priv->get_properties (server,
id,
prop,
server->priv->data,
NULL);
+ g_free (id);
if (!propresult) {
return NULL;
}
@@ -428,35 +446,7 @@ get_property_value (MS1Server *server,
return v;
}
-static gchar *
-get_id_from_message (DBusMessage *m)
-{
- gchar **path;
- gchar *id;
- gint path_length;
-
- dbus_message_get_path_decomposed (m, &path);
-
- /* Path can of type:
- /org/gnome/UPnP/MediaServer1/<name>
- /org/gnome/UPnP/MediaServer1/<name>/items/<id>
- /org/gnome/UPnP/MediaServer1/<name>/containers/<id>
- */
- path_length = g_strv_length (path);
-
- if (path_length == 5) {
- id = g_strdup (MS1_ROOT);
- } else if (path_length == 7) {
- id = g_strdup (g_quark_to_string (atoi (path[6])));
- } else {
- id = NULL;
- }
-
- dbus_free_string_array (path);
-
- return id;
-}
-
+/* Adds a GPtrArray as an array of strings to dbus message */
static void
add_gptrarray_as_as (DBusMessage *m,
DBusMessageIter *iter,
@@ -649,7 +639,6 @@ handle_get_message (DBusConnection *c,
DBusMessage *r;
gchar *interface = NULL;
gchar *property = NULL;
- gchar *id;
MS1Server *server = MS1_SERVER (userdata);
/* Check signature */
@@ -658,9 +647,7 @@ handle_get_message (DBusConnection *c,
DBUS_TYPE_STRING, &interface,
DBUS_TYPE_STRING, &property,
DBUS_TYPE_INVALID);
- id = get_id_from_message (m);
- value = get_property_value (server, id, interface, property);
- g_free (id);
+ value = get_property_value (server, m, interface, property);
if (!value) {
g_printerr ("Invalid property %s in interface %s\n",
property,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]