[pulseaudio-discuss] [PATCH v1 02/18] bluetooth: Refactor code to helper function
Mikel Astiz
mikel.astiz.oss at gmail.com
Mon Aug 27 08:23:57 PDT 2012
From: Mikel Astiz <mikel.astiz at bmw-carit.de>
Make code more readable by introducing the helper function
bt_transport_is_acquired(). This also adds assertions to check whether
the internal state is consistent.
---
src/modules/bluetooth/module-bluetooth-device.c | 14 ++++++++++++--
1 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index 07f97fa..c9fad26 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -281,12 +281,22 @@ static int setup_stream(struct userdata *u) {
return 0;
}
+static bool bt_transport_is_acquired(struct userdata *u) {
+ if (u->accesstype == NULL) {
+ pa_assert(u->stream_fd < 0);
+ return FALSE;
+ } else {
+ pa_assert(u->stream_fd >= 0);
+ return TRUE;
+ }
+}
+
static void bt_transport_release(struct userdata *u) {
const char *accesstype = "rw";
const pa_bluetooth_transport *t;
/* Ignore if already released */
- if (!u->accesstype)
+ if (!bt_transport_is_acquired(u))
return;
pa_log_debug("Releasing transport %s", u->transport);
@@ -318,7 +328,7 @@ static int bt_transport_acquire(struct userdata *u, pa_bool_t start) {
const char *accesstype = "rw";
const pa_bluetooth_transport *t;
- if (u->accesstype) {
+ if (bt_transport_is_acquired(u)) {
if (start)
goto done;
return 0;
--
1.7.7.6
More information about the pulseaudio-discuss
mailing list