From cd959f4cbc103b2f80a0a0733e433ad0dc81753e Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Wed, 12 Dec 2012 11:28:07 +0100 Subject: [PATCH] audio: Simplify manager_find_device Now that audio_device and other audio structures holds references to btd_device and not addresses or paths there is no need for complex find function. --- profiles/audio/manager.c | 70 +++++------------------------------------------- 1 file changed, 6 insertions(+), 64 deletions(-) diff --git a/profiles/audio/manager.c b/profiles/audio/manager.c index 178b6f9b1..b6b23852a 100644 --- a/profiles/audio/manager.c +++ b/profiles/audio/manager.c @@ -102,80 +102,25 @@ static struct audio_device *get_audio_dev(struct btd_device *device) return manager_get_audio_device(device, TRUE); } -static GSList *manager_find_devices(const char *path, - const bdaddr_t *src, - const bdaddr_t *dst, - const char *interface, - gboolean connected) +static struct audio_device *manager_find_device(struct btd_device *device) { - GSList *result = NULL; GSList *l; for (l = devices; l != NULL; l = l->next) { struct audio_device *dev = l->data; - const bdaddr_t *dev_src; - const bdaddr_t *dev_dst; - dev_src = adapter_get_address(device_get_adapter(dev->btd_dev)); - dev_dst = device_get_address(dev->btd_dev); - - if ((path && (strcmp(path, "")) && - strcmp(device_get_path(dev->btd_dev), path))) - continue; - - if ((src && bacmp(src, BDADDR_ANY)) && bacmp(dev_src, src)) - continue; - - if ((dst && bacmp(dst, BDADDR_ANY)) && bacmp(dev_dst, dst)) - continue; - - if (interface && !strcmp(AUDIO_SINK_INTERFACE, interface) - && !dev->sink) - continue; - - if (interface && !strcmp(AUDIO_SOURCE_INTERFACE, interface) - && !dev->source) - continue; - - if (interface && !strcmp(AUDIO_CONTROL_INTERFACE, interface) - && !dev->control) - continue; - - if (connected && !audio_device_is_active(dev, interface)) - continue; - - result = g_slist_append(result, dev); + if (dev->btd_dev == device) + return dev; } - return result; -} - -static struct audio_device *manager_find_device(const char *path, - const bdaddr_t *src, - const bdaddr_t *dst, - const char *interface, - gboolean connected) -{ - struct audio_device *result; - GSList *l; - - l = manager_find_devices(path, src, dst, interface, connected); - if (l == NULL) - return NULL; - - result = l->data; - g_slist_free(l); - return result; + return NULL; } static void audio_remove(struct btd_profile *p, struct btd_device *device) { struct audio_device *dev; - const char *path; - - path = device_get_path(device); - dev = manager_find_device(path, NULL, NULL, NULL, FALSE); + dev = manager_find_device(device); if (dev == NULL) return; @@ -641,11 +586,8 @@ struct audio_device *manager_get_audio_device(struct btd_device *device, gboolean create) { struct audio_device *dev; - struct btd_adapter *adapter = device_get_adapter(device); - dev = manager_find_device(NULL, adapter_get_address(adapter), - device_get_address(device), NULL, - FALSE); + dev = manager_find_device(device); if (dev) return dev; -- 2.11.0