char *address;
char *path;
- const pa_bluetooth_device* device;
+ pa_bluetooth_discovery *discovery;
pa_dbus_connection *connection;
struct userdata *u;
enum profile *d;
pa_queue *inputs = NULL, *outputs = NULL;
+ const pa_bluetooth_device *device;
pa_assert(c);
pa_assert(new_profile);
d = PA_CARD_PROFILE_DATA(new_profile);
- if (u->device->headset_state < PA_BT_AUDIO_STATE_CONNECTED && *d == PROFILE_HSP) {
+ if (!(device = pa_bluetooth_discovery_get_by_path(u->discovery, u->path))) {
+ pa_log_error("Failed to get device object.");
+ return -1;
+ }
+
+ if (device->headset_state != PA_BT_AUDIO_STATE_CONNECTED && *d == PROFILE_HSP) {
pa_log_warn("HSP is not connected, refused to switch profile");
return -1;
}
- else if (u->device->audio_sink_state < PA_BT_AUDIO_STATE_CONNECTED && *d == PROFILE_A2DP) {
+ else if (device->audio_sink_state != PA_BT_AUDIO_STATE_CONNECTED && *d == PROFILE_A2DP) {
pa_log_warn("A2DP is not connected, refused to switch profile");
return -1;
}
return 0;
}
-static const pa_bluetooth_device* find_device(struct userdata *u, pa_bluetooth_discovery *y, const char *address, const char *path) {
+static const pa_bluetooth_device* find_device(struct userdata *u, const char *address, const char *path) {
const pa_bluetooth_device *d = NULL;
pa_assert(u);
- pa_assert(y);
if (!address && !path) {
pa_log_error("Failed to get device address/path from module arguments.");
}
if (path) {
- if (!(d = pa_bluetooth_discovery_get_by_path(y, path))) {
+ if (!(d = pa_bluetooth_discovery_get_by_path(u->discovery, path))) {
pa_log_error("%s is not a valid BlueZ audio device.", path);
return NULL;
}
}
} else {
- if (!(d = pa_bluetooth_discovery_get_by_address(y, address))) {
+ if (!(d = pa_bluetooth_discovery_get_by_address(u->discovery, address))) {
pa_log_error("%s is not known.", address);
return NULL;
}
uint32_t channels;
struct userdata *u;
const char *address, *path;
- pa_bluetooth_discovery *y = NULL;
DBusError err;
char *mike, *speaker;
+ const pa_bluetooth_device *device;
pa_assert(m);
if (setup_dbus(u) < 0)
goto fail;
- if (!(y = pa_bluetooth_discovery_get(m->core)))
+ if (!(u->discovery = pa_bluetooth_discovery_get(m->core)))
goto fail;
- if (!(u->device = find_device(u, y, address, path))) /* should discovery ref be kept? */
+ if (!(device = find_device(u, address, path)))
goto fail;
/* Add the card structure. This will also initialize the default profile */
- if (add_card(u, pa_modargs_get_value(ma, "profile", NULL), u->device) < 0)
+ if (add_card(u, pa_modargs_get_value(ma, "profile", NULL), device) < 0)
goto fail;
- pa_bluetooth_discovery_unref(y);
- y = NULL;
-
/* Connect to the BT service and query capabilities */
if (init_bt(u) < 0)
goto fail;
fail:
- if (y)
- pa_bluetooth_discovery_unref(y);
-
pa__done(m);
dbus_error_free(&err);
pa_xfree(u->address);
pa_xfree(u->path);
+ if (u->discovery)
+ pa_bluetooth_discovery_unref(u->discovery);
+
pa_xfree(u);
}