@@ -872,6 +872,30 @@ struct btd_device *btd_adapter_find_device(struct btd_adapter *adapter,
return device;
}
+static int device_path_cmp(gconstpointer a, gconstpointer b)
+{
+ const struct btd_device *device = a;
+ const char *path = b;
+ const char *dev_path = device_get_path(device);
+
+ return strcasecmp(dev_path, path);
+}
+
+struct btd_device *btd_adapter_find_device_by_path(struct btd_adapter *adapter,
+ const char *path)
+{
+ GSList *list;
+
+ if (!adapter)
+ return NULL;
+
+ list = g_slist_find_custom(adapter->devices, path, device_path_cmp);
+ if (!list)
+ return NULL;
+
+ return list->data;
+}
+
static void uuid_to_uuid128(uuid_t *uuid128, const uuid_t *uuid)
{
if (uuid->type == SDP_UUID16)
@@ -3184,15 +3208,6 @@ static gboolean property_get_roles(const GDBusPropertyTable *property,
return TRUE;
}
-static int device_path_cmp(gconstpointer a, gconstpointer b)
-{
- const struct btd_device *device = a;
- const char *path = b;
- const char *dev_path = device_get_path(device);
-
- return strcasecmp(dev_path, path);
-}
-
static DBusMessage *remove_device(DBusConnection *conn,
DBusMessage *msg, void *user_data)
{
@@ -83,6 +83,8 @@ sdp_list_t *btd_adapter_get_services(struct btd_adapter *adapter);
struct btd_device *btd_adapter_find_device(struct btd_adapter *adapter,
const bdaddr_t *dst,
uint8_t dst_type);
+struct btd_device *btd_adapter_find_device_by_path(struct btd_adapter *adapter,
+ const char *path);
const char *adapter_get_path(struct btd_adapter *adapter);
const bdaddr_t *btd_adapter_get_address(struct btd_adapter *adapter);
The public function is motivated by the Battery Provider API code which needs to probe whether a device exists. Reviewed-by: Miao-chen Chou <mcchou@chromium.org> --- src/adapter.c | 33 ++++++++++++++++++++++++--------- src/adapter.h | 2 ++ 2 files changed, 26 insertions(+), 9 deletions(-)