bluetooth: Refactor code to helper function

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.
This commit is contained in:
Mikel Astiz 2012-08-31 12:50:55 +02:00 committed by Arun Raghavan
parent 431f56fd68
commit 38de0af64e

View file

@ -280,12 +280,22 @@ static void setup_stream(struct userdata *u) {
TRUE); TRUE);
} }
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) { static void bt_transport_release(struct userdata *u) {
const char *accesstype = "rw"; const char *accesstype = "rw";
const pa_bluetooth_transport *t; const pa_bluetooth_transport *t;
/* Ignore if already released */ /* Ignore if already released */
if (!u->accesstype) if (!bt_transport_is_acquired(u))
return; return;
pa_log_debug("Releasing transport %s", u->transport); pa_log_debug("Releasing transport %s", u->transport);
@ -317,7 +327,7 @@ static int bt_transport_acquire(struct userdata *u, pa_bool_t start) {
const char *accesstype = "rw"; const char *accesstype = "rw";
const pa_bluetooth_transport *t; const pa_bluetooth_transport *t;
if (u->accesstype) { if (bt_transport_is_acquired(u)) {
if (start) if (start)
goto done; goto done;
return 0; return 0;