From 4c527e87cafc2d66c7b4c12643102e978a63ba2d Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 25 Sep 2012 13:22:42 +0300 Subject: [PATCH] core: Use btd_profile_foreach for device probing --- src/device.c | 62 +++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/src/device.c b/src/device.c index a7e363b32..1258109e2 100644 --- a/src/device.c +++ b/src/device.c @@ -1342,44 +1342,52 @@ static GSList *device_match_profile(struct btd_device *device, return match_uuids; } -void device_probe_profiles(struct btd_device *device, GSList *uuids) -{ +struct probe_data { + struct btd_device *dev; + GSList *uuids; char addr[18]; - GSList *l; +}; - ba2str(&device->bdaddr, addr); +static void dev_probe(struct btd_profile *p, void *user_data) +{ + struct probe_data *d = user_data; + GSList *probe_uuids; + int err; - if (device->blocked) { - DBG("Skipping profiles for blocked device %s", addr); - goto add_uuids; - } + if (p->device_probe == NULL) + return; - DBG("Probing profiles for device %s", addr); + probe_uuids = device_match_profile(d->dev, p, d->uuids); + if (!probe_uuids) + return; - for (l = btd_get_profiles(); l != NULL; l = g_slist_next(l)) { - struct btd_profile *profile = l->data; - GSList *probe_uuids; - int err; + err = p->device_probe(d->dev, probe_uuids); + if (err < 0) { + error("%s profile probe failed for %s", p->name, d->addr); + g_slist_free(probe_uuids); + return; + } - if (profile->device_probe == NULL) - continue; + d->dev->profiles = g_slist_append(d->dev->profiles, p); + g_slist_free(probe_uuids); +} - probe_uuids = device_match_profile(device, profile, uuids); - if (!probe_uuids) - continue; +void device_probe_profiles(struct btd_device *device, GSList *uuids) +{ + struct probe_data d = { device, uuids }; + GSList *l; - err = profile->device_probe(device, probe_uuids); - if (err < 0) { - error("%s profile probe failed for device %s", - profile->name, addr); - g_slist_free(probe_uuids); - continue; - } + ba2str(&device->bdaddr, d.addr); - device->profiles = g_slist_append(device->profiles, profile); - g_slist_free(probe_uuids); + if (device->blocked) { + DBG("Skipping profiles for blocked device %s", d.addr); + goto add_uuids; } + DBG("Probing profiles for device %s", d.addr); + + btd_profile_foreach(dev_probe, &d); + add_uuids: for (l = uuids; l != NULL; l = g_slist_next(l)) { GSList *match = g_slist_find_custom(device->uuids, l->data, -- 2.47.3