[pulseaudio-discuss] [RFC next v0 11/11] bluetooth: Use bluez_backend_private for endpoint userdata
Mikel Astiz
mikel.astiz.oss at gmail.com
Wed May 15 01:46:56 PDT 2013
From: Mikel Astiz <mikel.astiz at bmw-carit.de>
The endpoint is backend-specific and therefore it's logically more
appropriate to use the bluez_backend_private struct as the userdata
pointer in all endpoint callbacks.
---
src/modules/bluetooth/bluetooth-util.c | 39 ++++++++++++++++++----------------
1 file changed, 21 insertions(+), 18 deletions(-)
diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index 92094bf..f26ec92 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -97,6 +97,7 @@ struct profile_data {
};
typedef struct bluez_backend_private {
+ pa_bluetooth_discovery *discovery;
pa_hashmap *transports;
} bluez_backend_private;
@@ -1692,11 +1693,10 @@ static pa_bluetooth_transport *transport_new(pa_bluetooth_device *d, const char
return t;
}
-static DBusMessage *endpoint_set_configuration(DBusConnection *conn, DBusMessage *m, void *userdata) {
- pa_bluetooth_discovery *y = userdata;
+static DBusMessage *endpoint_set_configuration(DBusConnection *conn, DBusMessage *m, bluez_backend_private *bbp) {
+ pa_bluetooth_discovery *y;
pa_bluetooth_device *d;
pa_bluetooth_transport *t;
- bluez_backend_private *bbp;
const char *sender, *path, *dev_path = NULL, *uuid = NULL;
uint8_t *config = NULL;
int size = 0;
@@ -1706,7 +1706,8 @@ static DBusMessage *endpoint_set_configuration(DBusConnection *conn, DBusMessage
DBusMessage *r;
bool old_any_connected;
- bbp = &y->backend_private;
+ pa_assert(bbp);
+ pa_assert_se(y = bbp->discovery);
if (!dbus_message_iter_init(m, &args) || !pa_streq(dbus_message_get_signature(m), "oa{sv}")) {
pa_log("Invalid signature for method SetConfiguration");
@@ -1817,17 +1818,13 @@ fail2:
return r;
}
-static DBusMessage *endpoint_clear_configuration(DBusConnection *c, DBusMessage *m, void *userdata) {
- pa_bluetooth_discovery *y = userdata;
+static DBusMessage *endpoint_clear_configuration(DBusConnection *c, DBusMessage *m, bluez_backend_private *bbp) {
pa_bluetooth_transport *t;
- bluez_backend_private *bbp;
DBusMessage *r;
DBusError e;
const char *path;
- pa_assert(y);
-
- bbp = &y->backend_private;
+ pa_assert(bbp);
dbus_error_init(&e);
@@ -1894,8 +1891,8 @@ static uint8_t a2dp_default_bitpool(uint8_t freq, uint8_t mode) {
}
}
-static DBusMessage *endpoint_select_configuration(DBusConnection *c, DBusMessage *m, void *userdata) {
- pa_bluetooth_discovery *y = userdata;
+static DBusMessage *endpoint_select_configuration(DBusConnection *c, DBusMessage *m, bluez_backend_private *bbp) {
+ pa_bluetooth_discovery *y;
a2dp_sbc_t *cap, config;
uint8_t *pconf = (uint8_t *) &config;
int i, size;
@@ -1912,6 +1909,9 @@ static DBusMessage *endpoint_select_configuration(DBusConnection *c, DBusMessage
{ 48000U, SBC_SAMPLING_FREQ_48000 }
};
+ pa_assert(bbp);
+ pa_assert_se(y = bbp->discovery);
+
dbus_error_init(&e);
if (!dbus_message_get_args(m, &e, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &cap, &size, DBUS_TYPE_INVALID)) {
@@ -2017,12 +2017,14 @@ fail:
}
static DBusHandlerResult endpoint_handler(DBusConnection *c, DBusMessage *m, void *userdata) {
- struct pa_bluetooth_discovery *y = userdata;
+ bluez_backend_private *bbp = userdata;
+ pa_bluetooth_discovery *y;
DBusMessage *r = NULL;
DBusError e;
const char *path, *interface, *member;
- pa_assert(y);
+ pa_assert(bbp);
+ pa_assert_se(y = bbp->discovery);
path = dbus_message_get_path(m);
interface = dbus_message_get_interface(m);
@@ -2094,6 +2096,7 @@ pa_bluetooth_backend bluez_backend = {
static void bluez_backend_init(pa_bluetooth_discovery *y) {
bluez_backend_private *bbp = &y->backend_private;
+ bbp->discovery = y;
bbp->transports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
pa_bt_backend_register(y, &bluez_backend, PROFILE_A2DP, bbp);
@@ -2191,10 +2194,10 @@ pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c) {
goto fail;
}
- pa_assert_se(dbus_connection_register_object_path(conn, HFP_AG_ENDPOINT, &vtable_endpoint, y));
- pa_assert_se(dbus_connection_register_object_path(conn, HFP_HS_ENDPOINT, &vtable_endpoint, y));
- pa_assert_se(dbus_connection_register_object_path(conn, A2DP_SOURCE_ENDPOINT, &vtable_endpoint, y));
- pa_assert_se(dbus_connection_register_object_path(conn, A2DP_SINK_ENDPOINT, &vtable_endpoint, y));
+ pa_assert_se(dbus_connection_register_object_path(conn, HFP_AG_ENDPOINT, &vtable_endpoint, &y->backend_private));
+ pa_assert_se(dbus_connection_register_object_path(conn, HFP_HS_ENDPOINT, &vtable_endpoint, &y->backend_private));
+ pa_assert_se(dbus_connection_register_object_path(conn, A2DP_SOURCE_ENDPOINT, &vtable_endpoint, &y->backend_private));
+ pa_assert_se(dbus_connection_register_object_path(conn, A2DP_SINK_ENDPOINT, &vtable_endpoint, &y->backend_private));
init_bluez(y);
--
1.8.1.4
More information about the pulseaudio-discuss
mailing list