linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 02/14] tools: Add implementation of TrackList.GetTracksMetadata to mpris-player
Date: Wed, 15 May 2013 18:31:34 +0300	[thread overview]
Message-ID: <1368631906-15951-2-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1368631906-15951-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 tools/mpris-player.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 84 insertions(+), 2 deletions(-)

diff --git a/tools/mpris-player.c b/tools/mpris-player.c
index 3378227..2e27ee2 100644
--- a/tools/mpris-player.c
+++ b/tools/mpris-player.c
@@ -1511,11 +1511,93 @@ static const GDBusPropertyTable mpris_properties[] = {
 	{ }
 };
 
+static GDBusProxy *find_item(struct player *player, const char *path)
+{
+	struct tracklist *tracklist = player->tracklist;
+	GSList *l;
+
+	for (l = tracklist->items; l; l = l->next) {
+		GDBusProxy *proxy = l->data;
+		const char *p = g_dbus_proxy_get_path(proxy);
+
+		if (g_str_equal(path, p))
+			return proxy;
+	}
+
+	return NULL;
+}
+
+static void append_item_metadata(void *data, void *user_data)
+{
+	GDBusProxy *item = data;
+	DBusMessageIter *iter = user_data;
+	DBusMessageIter var, metadata;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
+			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &metadata);
+
+	if (g_dbus_proxy_get_property(item, "Metadata", &var))
+		parse_metadata(&var, &metadata, parse_track_entry);
+
+	dbus_message_iter_close_container(iter, &metadata);
+
+	return;
+}
+
 static DBusMessage *tracklist_get_metadata(DBusConnection *conn,
 						DBusMessage *msg, void *data)
 {
-	return g_dbus_create_error(msg, ERROR_INTERFACE ".NotImplemented",
-					"Not implemented");
+	struct player *player = data;
+	DBusMessage *reply;
+	DBusMessageIter args, array;
+	GSList *l = NULL;
+
+	dbus_message_iter_init(msg, &args);
+
+	if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_ARRAY)
+		return g_dbus_create_error(msg,
+					ERROR_INTERFACE ".InvalidArguments",
+					"Invalid Arguments");
+
+	dbus_message_iter_recurse(&args, &array);
+
+	while (dbus_message_iter_get_arg_type(&array) ==
+						DBUS_TYPE_OBJECT_PATH) {
+		const char *path;
+		GDBusProxy *item;
+
+		dbus_message_iter_get_basic(&array, &path);
+
+		item = find_item(player, path);
+		if (item == NULL)
+			return g_dbus_create_error(msg,
+					ERROR_INTERFACE ".InvalidArguments",
+					"Invalid Arguments");
+
+		l = g_slist_append(l, item);
+
+		dbus_message_iter_next(&array);
+	}
+
+	reply = dbus_message_new_method_return(msg);
+
+	dbus_message_iter_init_append(reply, &args);
+
+	dbus_message_iter_open_container(&args, DBUS_TYPE_ARRAY,
+					DBUS_TYPE_ARRAY_AS_STRING
+					DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+					DBUS_TYPE_STRING_AS_STRING
+					DBUS_TYPE_VARIANT_AS_STRING
+					DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+					&array);
+
+	g_slist_foreach(l, append_item_metadata, &array);
+
+	dbus_message_iter_close_container(&args, &array);
+
+	return reply;
 }
 
 static DBusMessage *tracklist_goto(DBusConnection *conn,
-- 
1.8.1.4


  reply	other threads:[~2013-05-15 15:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-15 15:31 [PATCH BlueZ 01/14] tools: Add support for MPRIS TrackList interface to mpris-player Luiz Augusto von Dentz
2013-05-15 15:31 ` Luiz Augusto von Dentz [this message]
2013-05-15 15:31 ` [PATCH BlueZ 03/14] tools: Add implementation of TrackList.GoTo " Luiz Augusto von Dentz
2013-05-15 15:31 ` [PATCH BlueZ 04/14] tools: Add support for MPRIS TrackList.TrackAdded signal " Luiz Augusto von Dentz
2013-05-15 15:31 ` [PATCH BlueZ 05/14] tools: Add support for MPRIS TrackList.TrackRemoved " Luiz Augusto von Dentz
2013-05-15 15:31 ` [PATCH BlueZ 06/14] tools: Add support for MPRIS TrackList.TrackMetadataChanged " Luiz Augusto von Dentz
2013-05-15 15:31 ` [PATCH BlueZ 07/14] tools: Add support for MPRIS Playlists interface " Luiz Augusto von Dentz
2013-05-15 15:31 ` [PATCH BlueZ 08/14] tools: Add implementation of Playlists.ActivatePlaylist " Luiz Augusto von Dentz
2013-05-15 15:31 ` [PATCH BlueZ 09/14] tools: Add implementation of Playlists.GetPlaylists " Luiz Augusto von Dentz
2013-05-15 15:31 ` [PATCH BlueZ 10/14] tools: Map mpris:trackid to Item in mpris-player Luiz Augusto von Dentz
2013-05-15 15:31 ` [PATCH BlueZ 11/14] tools: Always register Playlists and TrackList " Luiz Augusto von Dentz
2013-05-15 15:31 ` [PATCH BlueZ 12/14] tools: Wait MediaFolder interface appear to enable " Luiz Augusto von Dentz
2013-05-15 15:31 ` [PATCH BlueZ 13/14] tools: Use playlist proxy instead of object path " Luiz Augusto von Dentz
2013-05-15 15:31 ` [PATCH BlueZ 14/14] tools: Emit changes to HasTrackList " Luiz Augusto von Dentz
2013-05-17  6:46 ` [PATCH BlueZ 01/14] tools: Add support for MPRIS TrackList interface to mpris-player Luiz Augusto von Dentz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1368631906-15951-2-git-send-email-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).