From 24998ea93418daafa83e86275c664b2fdd1b0f4a Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 14 Dec 2012 15:22:46 +0200 Subject: [PATCH] core: Add btd_device_get_primary convenience function --- src/device.c | 20 ++++++++++++++++++++ src/device.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/src/device.c b/src/device.c index 01c40a72e..77466ff0b 100644 --- a/src/device.c +++ b/src/device.c @@ -4020,6 +4020,26 @@ gboolean device_is_authenticating(struct btd_device *device) return (device->authr != NULL); } +static int primary_uuid_cmp(gconstpointer a, gconstpointer b) +{ + const struct gatt_primary *prim = a; + const char *uuid = b; + + return strcasecmp(prim->uuid, uuid); +} + +struct gatt_primary *btd_device_get_primary(struct btd_device *device, + const char *uuid) +{ + GSList *match; + + match = g_slist_find_custom(device->primaries, uuid, primary_uuid_cmp); + if (match) + return match->data; + + return NULL; +} + GSList *btd_device_get_primaries(struct btd_device *device) { return device->primaries; diff --git a/src/device.h b/src/device.h index b9e20cc86..8534117ed 100644 --- a/src/device.h +++ b/src/device.h @@ -46,6 +46,8 @@ GSList *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, const char *uuid); +struct gatt_primary *btd_device_get_primary(struct btd_device *device, + const char *uuid); GSList *btd_device_get_primaries(struct btd_device *device); void btd_device_gatt_set_service_changed(struct btd_device *device, uint16_t start, uint16_t end); -- 2.47.3