Linux bluetooth development
 help / color / mirror / Atom feed
From: Mikel Astiz <mikel.astiz.oss@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Mikel Astiz <mikel.astiz@bmw-carit.de>
Subject: [PATCH v1 4/6] media: Add MediaTransport.TryAcquire()
Date: Wed,  5 Dec 2012 17:15:32 +0100	[thread overview]
Message-ID: <1354724134-7354-5-git-send-email-mikel.astiz.oss@gmail.com> (raw)
In-Reply-To: <1354724134-7354-1-git-send-email-mikel.astiz.oss@gmail.com>

From: Mikel Astiz <mikel.astiz@bmw-carit.de>

Split the Acquire() method in two parts so that the optional acquires,
formerly represented as a "?" flag in the accesstype parameter of
Acquire(), are now implemented in TryAcquire().
---
 doc/media-api.txt          |  7 +++++++
 profiles/audio/transport.c | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/doc/media-api.txt b/doc/media-api.txt
index b15ad61..5e052b4 100644
--- a/doc/media-api.txt
+++ b/doc/media-api.txt
@@ -266,6 +266,13 @@ Methods		fd, uint16, uint16 Acquire()
 			Acquire transport file descriptor and the MTU for read
 			and write respectively.
 
+		fd, uint16, uint16 TryAcquire()
+
+			Acquire transport file descriptor only if the transport
+			is in "pending" state at the time the message is
+			received by BlueZ. Otherwise no request will be sent
+			to the remote device and the function will just fail.
+
 		void Release()
 
 			Releases file descriptor.
diff --git a/profiles/audio/transport.c b/profiles/audio/transport.c
index 1064098..0fd2469 100644
--- a/profiles/audio/transport.c
+++ b/profiles/audio/transport.c
@@ -463,6 +463,37 @@ static DBusMessage *acquire(DBusConnection *conn, DBusMessage *msg,
 	return NULL;
 }
 
+static DBusMessage *try_acquire(DBusConnection *conn, DBusMessage *msg,
+								void *data)
+{
+	struct media_transport *transport = data;
+	struct media_owner *owner;
+	struct media_request *req;
+	guint id;
+
+	if (transport->owner != NULL)
+		return btd_error_not_authorized(msg);
+
+	if (transport->state >= TRANSPORT_STATE_REQUESTING)
+		return btd_error_not_authorized(msg);
+
+	if (transport->state != TRANSPORT_STATE_PENDING)
+		return btd_error_failed(msg, "Transport not playing");
+
+	owner = media_owner_create(msg);
+	id = transport->resume(transport, owner);
+	if (id == 0) {
+		media_owner_free(owner);
+		return btd_error_not_authorized(msg);
+	}
+
+	req = media_request_create(msg, id);
+	media_owner_add(owner, req);
+	media_transport_set_owner(transport, owner);
+
+	return NULL;
+}
+
 static DBusMessage *release(DBusConnection *conn, DBusMessage *msg,
 					void *data)
 {
@@ -634,6 +665,11 @@ static const GDBusMethodTable transport_methods[] = {
 			GDBUS_ARGS({ "fd", "h" }, { "mtu_r", "q" },
 							{ "mtu_w", "q" } ),
 			acquire) },
+	{ GDBUS_ASYNC_METHOD("TryAcquire",
+			NULL,
+			GDBUS_ARGS({ "fd", "h" }, { "mtu_r", "q" },
+							{ "mtu_w", "q" }),
+			try_acquire) },
 	{ GDBUS_ASYNC_METHOD("Release", NULL, NULL, release) },
 	{ },
 };
-- 
1.7.11.7


  parent reply	other threads:[~2012-12-05 16:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-05 16:15 [PATCH v1 0/6] Remove access rights from MediaTransport Mikel Astiz
2012-12-05 16:15 ` [PATCH v1 1/6] media: Remove transport access type from D-Bus API Mikel Astiz
2012-12-05 16:15 ` [PATCH v1 2/6] media: Remove internal transport locks Mikel Astiz
2012-12-05 16:15 ` [PATCH v1 3/6] media: Remove transport owner list Mikel Astiz
2012-12-05 16:15 ` Mikel Astiz [this message]
2012-12-05 16:15 ` [PATCH v1 5/6] media: Trivial style fix Mikel Astiz
2012-12-05 16:15 ` [PATCH v1 6/6] media: Add version suffix to all media interfaces Mikel Astiz
2012-12-05 17:25 ` [PATCH v1 0/6] Remove access rights from MediaTransport Johan Hedberg

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=1354724134-7354-5-git-send-email-mikel.astiz.oss@gmail.com \
    --to=mikel.astiz.oss@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=mikel.astiz@bmw-carit.de \
    /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