--- src/modules/bluetooth/bluetooth-util.c | 64 ++++++++++++++++++++++++++++++++ src/modules/bluetooth/bluetooth-util.h | 3 + 2 files changed, 67 insertions(+), 0 deletions(-) diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c index 7680065..0dbf143 100644 --- a/src/modules/bluetooth/bluetooth-util.c +++ b/src/modules/bluetooth/bluetooth-util.c @@ -75,6 +75,11 @@ struct pa_bluetooth_discovery { pa_bool_t filter_added; }; +struct pending_config_info { + bt_transport_config_cb_t cb; + void *data; +}; + static void get_properties_reply(DBusPendingCall *pending, void *userdata); static pa_dbus_pending* send_and_add_to_pending(pa_bluetooth_discovery *y, DBusMessage *m, DBusPendingCallNotifyFunction func, void *call_data); @@ -1036,6 +1041,65 @@ const pa_bluetooth_transport* pa_bluetooth_device_get_transport(const pa_bluetoo return NULL; } +static void request_configuration_reply(DBusPendingCall *pending, void *userdata) { + DBusMessage *r; + pa_dbus_pending *p; + pa_bluetooth_discovery *y; + struct pending_config_info *cbinfo; + int err; + + pa_assert(pending); + + pa_assert_se(p = userdata); + pa_assert_se(y = p->context_data); + pa_assert_se(cbinfo = p->call_data); + pa_assert_se(r = dbus_pending_call_steal_reply(pending)); + + if (dbus_message_is_error(r, DBUS_ERROR_SERVICE_UNKNOWN)) { + pa_log("Bluetooth daemon is apparently not available."); + err = -1; + goto finish; + } + + if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) { + pa_log("org.bluez.MediaTransport.RequestConfiguration() failed: %s: %s", dbus_message_get_error_name(r), pa_dbus_get_error_message(r)); + err = -2; + goto finish; + } + + err = 0; + +finish: + dbus_message_unref(r); + + PA_LLIST_REMOVE(pa_dbus_pending, y->pending, p); + pa_dbus_pending_free(p); + + if (cbinfo->cb) + cbinfo->cb(err, cbinfo->data); + + pa_xfree(cbinfo); +} + +void pa_bluetooth_transport_reconfigure(const pa_bluetooth_transport *t, const char *endpoint, bt_transport_config_cb_t cb, void *data) { + DBusMessage *m; + DBusError err; + struct pending_config_info *cbinfo; + + pa_assert(t); + pa_assert(t->y); + + dbus_error_init(&err); + + pa_assert_se(m = dbus_message_new_method_call("org.bluez", t->path, "org.bluez.MediaTransport", "Reconfigure")); + pa_assert_se(dbus_message_append_args(m, DBUS_TYPE_STRING, &endpoint, DBUS_TYPE_INVALID)); + + cbinfo = pa_xmalloc(sizeof(struct pending_config_info)); + cbinfo->cb = cb; + cbinfo->data = data; + send_and_add_to_pending(t->y, m, request_configuration_reply, cbinfo); +} + int pa_bluetooth_transport_acquire(const pa_bluetooth_transport *t, const char *accesstype, size_t *imtu, size_t *omtu) { DBusMessage *m, *r; DBusError err; diff --git a/src/modules/bluetooth/bluetooth-util.h b/src/modules/bluetooth/bluetooth-util.h index 2752a69..b446cbe 100644 --- a/src/modules/bluetooth/bluetooth-util.h +++ b/src/modules/bluetooth/bluetooth-util.h @@ -115,6 +115,8 @@ struct pa_bluetooth_device { pa_bt_audio_state_t hfgw_state; }; +typedef int (*bt_transport_config_cb_t)(int err, void *data); + pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *core); pa_bluetooth_discovery* pa_bluetooth_discovery_ref(pa_bluetooth_discovery *y); void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *d); @@ -127,6 +129,7 @@ const pa_bluetooth_device* pa_bluetooth_discovery_get_by_address(pa_bluetooth_di const pa_bluetooth_transport* pa_bluetooth_discovery_get_transport(pa_bluetooth_discovery *y, const char *path); const pa_bluetooth_transport* pa_bluetooth_device_get_transport(const pa_bluetooth_device *d, enum profile profile); +void pa_bluetooth_transport_reconfigure(const pa_bluetooth_transport *t, const char *endpoint, bt_transport_config_cb_t cb, void *data); int pa_bluetooth_transport_acquire(const pa_bluetooth_transport *t, const char *accesstype, size_t *imtu, size_t *omtu); void pa_bluetooth_transport_release(const pa_bluetooth_transport *t, const char *accesstype); int pa_bluetooth_transport_parse_property(pa_bluetooth_transport *t, DBusMessageIter *i); -- 1.7.5.4