OSDN Git Service

core: Add function to look up devices also by their type
authorJohan Hedberg <johan.hedberg@intel.com>
Sat, 22 Mar 2014 17:28:45 +0000 (19:28 +0200)
committerJohan Hedberg <johan.hedberg@intel.com>
Sat, 22 Mar 2014 17:34:32 +0000 (19:34 +0200)
src/device.c
src/device.h

index a69cfa6..1a60b96 100644 (file)
@@ -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)
 {
index 66b257d..30e2d5d 100644 (file)
@@ -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,