From f6a403f084e683fb8ab1601f7cb7cbc1a4f6cd76 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Sat, 22 Mar 2014 19:28:45 +0200 Subject: [PATCH] core: Add function to look up devices also by their type --- src/device.c | 21 +++++++++++++++++++++ src/device.h | 8 ++++++++ 2 files changed, 29 insertions(+) diff --git a/src/device.c b/src/device.c index a69cfa6f0..1a60b96f1 100644 --- a/src/device.c +++ b/src/device.c @@ -2662,6 +2662,27 @@ int device_bdaddr_cmp(gconstpointer a, gconstpointer b) return bacmp(&device->bdaddr, bdaddr); } +int device_addr_type_cmp(gconstpointer a, gconstpointer b) +{ + const struct btd_device *dev = a; + const struct device_addr_type *addr = b; + + if (addr->bdaddr_type == BDADDR_BREDR) { + if (!dev->bredr) + return -1; + + return bacmp(&dev->bdaddr, &addr->bdaddr); + } + + if (!dev->le) + return -1; + + if (addr->bdaddr_type != dev->bdaddr_type) + return -1; + + return bacmp(&dev->bdaddr, &addr->bdaddr); +} + static gboolean record_has_uuid(const sdp_record_t *rec, const char *profile_uuid) { diff --git a/src/device.h b/src/device.h index 66b257de9..30e2d5dd4 100644 --- a/src/device.h +++ b/src/device.h @@ -51,6 +51,14 @@ uint16_t btd_device_get_version(struct btd_device *device); void device_remove(struct btd_device *device, gboolean remove_stored); int device_address_cmp(gconstpointer a, gconstpointer b); int device_bdaddr_cmp(gconstpointer a, gconstpointer b); + +/* Struct used by device_addr_type_cmp() */ +struct device_addr_type { + bdaddr_t bdaddr; + uint8_t bdaddr_type; +}; + +int device_addr_type_cmp(gconstpointer a, gconstpointer b); GSList *btd_device_get_uuids(struct btd_device *device); void device_probe_profiles(struct btd_device *device, GSList *profiles); const sdp_record_t *btd_device_get_record(struct btd_device *device, -- 2.47.3