diff options
author | Johan Hedberg <johan.hedberg@nokia.com> | 2007-08-12 21:34:50 +0000 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2007-08-12 21:34:50 +0000 |
commit | f817fefff69cc44d5a2e1ba7d8ed9976fe3b4235 (patch) | |
tree | ea7d54290d6a8cd20708cd094473947086f4111a /audio/manager.c | |
parent | fb58bd1b24d257ea884aa5d67f8e5a6362aafa94 (diff) |
Implement proper acceptor side functionality
Diffstat (limited to 'audio/manager.c')
-rw-r--r-- | audio/manager.c | 77 |
1 files changed, 56 insertions, 21 deletions
diff --git a/audio/manager.c b/audio/manager.c index 995cdde5..e3c5a564 100644 --- a/audio/manager.c +++ b/audio/manager.c @@ -85,6 +85,7 @@ struct audio_sdp_data { static DBusConnection *connection = NULL; +static struct device *default_hs = NULL; static struct device *default_dev = NULL; static GSList *devices = NULL; @@ -132,6 +133,11 @@ static void remove_device(struct device *device) default_dev = NULL; } + if (device == default_hs) { + debug("Removing default headset"); + default_hs = NULL; + } + devices = g_slist_remove(devices, device); dbus_connection_destroy_object_path(connection, device->path); @@ -144,6 +150,9 @@ static gboolean add_device(struct device *device) default_dev = device; } + if (!default_hs && device->headset && !devices) + default_hs = device; + devices = g_slist_append(devices, device); return TRUE; @@ -580,16 +589,13 @@ static DBusHandlerResult resolve_services(DBusMessage *msg, return get_handles(GENERIC_AUDIO_UUID, sdp_data); } -struct device *manager_device_connected(bdaddr_t *bda) +struct device *manager_device_connected(bdaddr_t *bda, const char *uuid) { struct device *device; const char *path; - gboolean created = FALSE; + gboolean headset = FALSE, created = FALSE; device = find_device(bda); - if (device && device->headset) - return device; - if (!device) { device = create_device(bda); if (!add_device(device)) { @@ -599,10 +605,26 @@ struct device *manager_device_connected(bdaddr_t *bda) created = TRUE; } - if (!device->headset) + if (!strcmp(uuid, HSP_AG_UUID) || !strcmp(uuid, HSP_AG_UUID)) { + if (device->headset) + return device; + device->headset = headset_init(device, NULL, 0); - if (!device->headset) + if (!device->headset) + return NULL; + + headset = TRUE; + } + else if (!strcmp(uuid, A2DP_SOURCE_UUID)) { + if (device->sink) + return device; + + device->sink = sink_init(device); + + if (!device->sink) + return NULL; + } else return NULL; path = device->path; @@ -616,17 +638,27 @@ struct device *manager_device_connected(bdaddr_t *bda) resolve_services(NULL, device); } - dbus_connection_emit_signal(connection, AUDIO_MANAGER_PATH, - AUDIO_MANAGER_INTERFACE, - "HeadsetCreated", - DBUS_TYPE_STRING, &path, - DBUS_TYPE_INVALID); + if (headset) + dbus_connection_emit_signal(connection, AUDIO_MANAGER_PATH, + AUDIO_MANAGER_INTERFACE, + "HeadsetCreated", + DBUS_TYPE_STRING, &path, + DBUS_TYPE_INVALID); + + if (headset && !default_hs) { + default_hs = device; + dbus_connection_emit_signal(connection, AUDIO_MANAGER_PATH, + AUDIO_MANAGER_INTERFACE, + "DefaultHeadsetChanged", + DBUS_TYPE_STRING, &path, + DBUS_TYPE_INVALID); + } if (!default_dev) { default_dev = device; dbus_connection_emit_signal(connection, AUDIO_MANAGER_PATH, AUDIO_MANAGER_INTERFACE, - "DefaultHeadsetChanged", + "DefaultDeviceChanged", DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID); } @@ -1405,6 +1437,7 @@ static gboolean ag_io_cb(GIOChannel *chan, GIOCondition cond, void *data) struct device *device; DBusMessage *auth; DBusPendingCall *pending; + headset_type_t type; if (cond & G_IO_NVAL) return FALSE; @@ -1425,7 +1458,15 @@ static gboolean ag_io_cb(GIOChannel *chan, GIOCondition cond, void *data) return TRUE; } - device = manager_device_connected(&addr.rc_bdaddr); + if (chan == hs_server) { + type = SVC_HEADSET; + uuid = HSP_AG_UUID; + } else { + type = SVC_HANDSFREE; + uuid = HFP_AG_UUID; + } + + device = manager_device_connected(&addr.rc_bdaddr, uuid); if (!device) { close(cli_sk); return TRUE; @@ -1443,13 +1484,7 @@ static gboolean ag_io_cb(GIOChannel *chan, GIOCondition cond, void *data) return TRUE; } - if (chan == hs_server) { - headset_set_type(device, SVC_HEADSET); - uuid = HSP_AG_UUID; - } else { - headset_set_type(device, SVC_HANDSFREE); - uuid = HFP_AG_UUID; - } + headset_set_type(device, type); auth = dbus_message_new_method_call("org.bluez", "/org/bluez", "org.bluez.Database", |