[pulseaudio-commits] src/modules
Tanu Kaskinen
tanuk at kemper.freedesktop.org
Sun Oct 19 04:05:03 PDT 2014
src/modules/bluetooth/backend-ofono.c | 3 ---
src/modules/bluetooth/bluez5-util.c | 19 ++++++++++---------
2 files changed, 10 insertions(+), 12 deletions(-)
New commits:
commit 0df4d56cf8129c4cdb9797d505e59954f6f01fea
Author: Tanu Kaskinen <tanu.kaskinen at linux.intel.com>
Date: Tue Oct 7 14:50:21 2014 +0300
bluetooth: Move stuff to pa_bluetooth_transport_put/unlink()
This should not have any effect on behaviour. The goal is to align
with the pattern that I think we should follow:
Object initialization:
- put() is the place to create references from other objects to the
newly created object. In this case, adding the transport to
discovery->transports was moved from new() to put, and adding the
transport to device->transports was moved from set_state() to
put().
Object destruction:
- unlink() undoes put() and removes all references from other objects
to the object being unlinked. In this case setting the
device->transports pointer to NULL was moved from set_state() to
unlink(), and setting the discovery->transports pointer to NULL was
moved from free() to unlink().
- free() undoes new(), but also calls unlink() so that object owners
don't need to remember to call unlink() before free().
diff --git a/src/modules/bluetooth/backend-ofono.c b/src/modules/bluetooth/backend-ofono.c
index d1ee146..ba10ed6 100644
--- a/src/modules/bluetooth/backend-ofono.c
+++ b/src/modules/bluetooth/backend-ofono.c
@@ -281,9 +281,6 @@ static void hf_audio_agent_card_removed(pa_bluetooth_backend *backend, const cha
if (!card)
return;
- if (card->transport)
- pa_bluetooth_transport_unlink(card->transport);
-
hf_audio_card_free(card);
}
diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c
index 8bb57f4..1ee2f33 100644
--- a/src/modules/bluetooth/bluez5-util.c
+++ b/src/modules/bluetooth/bluez5-util.c
@@ -149,8 +149,6 @@ pa_bluetooth_transport *pa_bluetooth_transport_new(pa_bluetooth_device *d, const
memcpy(t->config, config, size);
}
- pa_assert_se(pa_hashmap_put(d->discovery->transports, t->path, t) >= 0);
-
return t;
}
@@ -181,10 +179,6 @@ void pa_bluetooth_transport_set_state(pa_bluetooth_transport *t, pa_bluetooth_tr
t->path, transport_state_to_string(t->state), transport_state_to_string(state));
t->state = state;
- if (state == PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED)
- t->device->transports[t->profile] = NULL;
- else
- t->device->transports[t->profile] = t;
pa_hook_fire(&t->device->discovery->hooks[PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED], t);
@@ -193,17 +187,26 @@ void pa_bluetooth_transport_set_state(pa_bluetooth_transport *t, pa_bluetooth_tr
}
void pa_bluetooth_transport_put(pa_bluetooth_transport *t) {
+ pa_assert(t);
+
+ t->device->transports[t->profile] = t;
+ pa_assert_se(pa_hashmap_put(t->device->discovery->transports, t->path, t) >= 0);
pa_bluetooth_transport_set_state(t, PA_BLUETOOTH_TRANSPORT_STATE_IDLE);
}
void pa_bluetooth_transport_unlink(pa_bluetooth_transport *t) {
+ pa_assert(t);
+
pa_bluetooth_transport_set_state(t, PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED);
+ pa_hashmap_remove(t->device->discovery->transports, t->path);
+ t->device->transports[t->profile] = NULL;
}
void pa_bluetooth_transport_free(pa_bluetooth_transport *t) {
pa_assert(t);
- pa_hashmap_remove(t->device->discovery->transports, t->path);
+ pa_bluetooth_transport_unlink(t);
+
pa_xfree(t->owner);
pa_xfree(t->path);
pa_xfree(t->config);
@@ -418,7 +421,6 @@ static void device_free(pa_bluetooth_device *d) {
if (!(t = d->transports[i]))
continue;
- pa_bluetooth_transport_set_state(t, PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED);
pa_bluetooth_transport_free(t);
}
@@ -1446,7 +1448,6 @@ static DBusMessage *endpoint_clear_configuration(DBusConnection *conn, DBusMessa
if ((t = pa_hashmap_get(y->transports, path))) {
pa_log_debug("Clearing transport %s profile %s", t->path, pa_bluetooth_profile_to_string(t->profile));
- pa_bluetooth_transport_set_state(t, PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED);
pa_bluetooth_transport_free(t);
}
More information about the pulseaudio-commits
mailing list