guint attachid; /* Attrib server attach */
gboolean connected;
- GSList *connected_profiles;
sdp_list_t *tmp_records;
return NULL;
}
+static GSList *find_service_with_state(GSList *list,
+ btd_service_state_t state)
+{
+ GSList *l;
+
+ for (l = list; l != NULL; l = g_slist_next(l)) {
+ struct btd_service *service = l->data;
+
+ if (btd_service_get_state(service) == state)
+ return l;
+ }
+
+ return NULL;
+}
+
static gboolean store_device_info_cb(gpointer user_data)
{
struct btd_device *device = user_data;
adapter_cancel_bonding(adapter, &device->bdaddr, device->bdaddr_type);
}
-static void dev_disconn_profile(gpointer a, gpointer b)
+static void dev_disconn_service(gpointer a, gpointer b)
{
- struct btd_profile *profile = a;
- struct btd_device *dev = b;
- struct btd_service *service;
- GSList *l;
-
- l = find_service_with_profile(dev->services, profile);
- service = l->data;
- btd_service_disconnect(service);
+ btd_service_disconnect(a);
}
void device_request_disconnect(struct btd_device *device, DBusMessage *msg)
if (device->disconn_timer)
return;
- g_slist_foreach(device->connected_profiles, dev_disconn_profile,
- device);
- g_slist_free(device->connected_profiles);
- device->connected_profiles = NULL;
+ g_slist_foreach(device->services, dev_disconn_service, NULL);
g_slist_free(device->pending);
device->pending = NULL;
struct btd_profile *profile, int err)
{
struct btd_profile *pending;
+ GSList *l;
DBG("%s %s (%d)", profile->name, strerror(-err), -err);
pending = dev->pending->data;
dev->pending = g_slist_remove(dev->pending, profile);
- if (!err)
- dev->connected_profiles =
- g_slist_append(dev->connected_profiles,
- profile);
+ l = find_service_with_profile(dev->services, profile);
+ if (l != NULL)
+ btd_service_connecting_complete(l->data, err);
/* Only continue connecting the next profile if it matches the first
* pending, otherwise it will trigger another connect to the same
DBG("returning response to %s", dbus_message_get_sender(dev->connect));
- if (err && dev->connected_profiles == NULL)
+ l = find_service_with_state(dev->services, BTD_SERVICE_STATE_CONNECTED);
+
+ if (err && l == NULL)
g_dbus_send_message(dbus_conn,
btd_error_failed(dev->connect, strerror(-err)));
else
if (g_slist_find(dev->pending, p))
continue;
- if (g_slist_find(dev->connected_profiles, p))
+ if (btd_service_get_state(service) !=
+ BTD_SERVICE_STATE_DISCONNECTED)
continue;
dev->pending = g_slist_insert_sorted(dev->pending, p,
void device_profile_disconnected(struct btd_device *dev,
struct btd_profile *profile, int err)
{
- dev->connected_profiles = g_slist_remove(dev->connected_profiles,
- profile);
+ GSList *l;
+
+ l = find_service_with_profile(dev->services, profile);
+ if (l != NULL)
+ btd_service_disconnecting_complete(l->data, err);
if (!dev->disconnect)
return;
if (device->browse)
browse_request_cancel(device->browse);
- g_slist_foreach(device->connected_profiles, dev_disconn_profile,
- device);
- g_slist_free(device->connected_profiles);
- device->connected_profiles = NULL;
+ g_slist_foreach(device->services, dev_disconn_service, NULL);
g_slist_free(device->pending);
device->pending = NULL;
if (l == NULL)
return;
- device->connected_profiles = g_slist_remove(device->connected_profiles,
- profile);
-
service = l->data;
device->services = g_slist_delete_link(device->services, l);
remove_service(service);