Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1574174pxb; Fri, 20 Nov 2020 13:01:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJyJm5fMKh0JKoIzaMBAeNMvJkrd5b/k9WUB7cRe+xbUnAmDPTobRVTh6cTT6I4JWD1j7hR2 X-Received: by 2002:a17:906:5955:: with SMTP id g21mr8448572ejr.271.1605906066050; Fri, 20 Nov 2020 13:01:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605906066; cv=none; d=google.com; s=arc-20160816; b=n3IlFu4y3QKyyDuJnEX1Lz4emRPhW9uUcVnGiesu+7OBE2ZAPC71p6IfLDTsd8DYe1 /BYnkP+/7EB8zkvtvClbFejR6k8LpUPXcJqsrhVeAKzbbiljBPTrJTwPsWYe3Jb2TH/g u/RY/RChk7Z70T3fVhRytMygGP6kvz5JcFvMPTnAnMpasVLgcb8vOugaLQryALbWnq3K 0gJmY1DFkCtjIwRNnRKMz9BaoVHNLoRhJZSbmGQXI8yoBEUsQ3b75fOzYQ2jKHgRcfFW YaQTya5AECdkaUkug27vX8JNvrqrEWKnnuYTuTKcOMZSRPmp8Vmo4v73hyofXmH5l6Yc ywtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Osr2t5lC/rtahR1ayaZEYydm7foHMd951I0Pg1nz0qM=; b=joCXgg2Vm1dOyEobU3jyKXzq7iBSRYzEJV1wqWs+JL7dvQE4JoiJv5IF9Yg1dyIRn9 6Onj3BJM82Khk65LCCuyqC6p1Cvpv7XG6X+jNxOKI/uXPxjP4Lt+HtYmN1EX7tzjqcij LJQku8XPniBkq2pXm6pOjgCaoQ/md6Zyz0WNtU5y5gI1PiZ1Pp95zZVBDVxCrfvYkYix 2kVlEoWSiKPZnNc2f+JFSeQhfGe28AYMhS36sBU02A+GKv5EwU67MCiPOV7x/A27vIoE iycp7uvDWwndtiJvJ4hUYMEjfRbpFA+9AbLKXMdnqssRTB62t1sWuY9Mhd8XOA1i0vzF 1SLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=S01E+jmf; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b1si2474435edf.583.2020.11.20.13.00.42; Fri, 20 Nov 2020 13:01:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=S01E+jmf; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730391AbgKTU55 (ORCPT + 99 others); Fri, 20 Nov 2020 15:57:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730387AbgKTU55 (ORCPT ); Fri, 20 Nov 2020 15:57:57 -0500 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 807ACC0613CF for ; Fri, 20 Nov 2020 12:57:57 -0800 (PST) Received: by mail-pf1-x443.google.com with SMTP id c66so9047494pfa.4 for ; Fri, 20 Nov 2020 12:57:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Osr2t5lC/rtahR1ayaZEYydm7foHMd951I0Pg1nz0qM=; b=S01E+jmfS95tkeThCaHIzMh+Ap6cSUAnbaFq9QviXZ+JTwZGwOB4kIiOkGwK+JE3Pk vIIhj4NA17xyHJuw1q9vGtIAO65N5Yvx5axvzmgUTXBSixDvP69InmZB9R9PdLEHjEa1 RsK83MduUqsHfsT0rw/jBRRtrhs/J3J7KjZCM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Osr2t5lC/rtahR1ayaZEYydm7foHMd951I0Pg1nz0qM=; b=ieWa1hOu+bZnLuABx3SD2L+8hBWsryNQ4OJ010Bzyvt9EXeaD+uu3pONBnFx0Sk8qC Jx3q/TDoBpPd8llLlJj58hPyaEsf0qZfmp25/WFLUzZ8aqITkAFrVwNuD16JS0c2VE3e 6Xn1ku7MG4wy2at5w6007NYVaOzLJt2xJBsBBssW5Wkvv38XZf7Po7PJM76oSy9oI5Wi isRLhlSzIBvOn2Dy8JQpLfKyvimOk/2hSBU6cEn1ZPEhOQFq77DnVrVBMGwA1jc9KIb9 LHyJtHNwWBbLnVnk5jnpfC1cimJ/aJa7yTdgrzd9PoZmdgsz5N0FC/huGpG+kBwWN62E ffnQ== X-Gm-Message-State: AOAM533dkwyz5sDZUb6j/6Xyxqq9eIrmDugQ7NeiNNUtOhxUZucit6Cn 354PSAB/R+hf99jb8sRuqCXA+OF4eBYWBw== X-Received: by 2002:a17:90a:5310:: with SMTP id x16mr12274140pjh.62.1605905876837; Fri, 20 Nov 2020 12:57:56 -0800 (PST) Received: from sonnysasaka-chrome.mtv.corp.google.com ([2620:15c:202:201:4a0f:cfff:fe66:e60c]) by smtp.gmail.com with ESMTPSA id a67sm3232080pfa.77.2020.11.20.12.57.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Nov 2020 12:57:56 -0800 (PST) From: Sonny Sasaka To: linux-bluetooth@vger.kernel.org Cc: Sonny Sasaka , Miao-chen Chou Subject: [PATCH BlueZ v3 6/7] adapter: Add a public function to find a device by path Date: Fri, 20 Nov 2020 12:57:27 -0800 Message-Id: <20201120205728.339325-6-sonnysasaka@chromium.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201120205728.339325-1-sonnysasaka@chromium.org> References: <20201120205728.339325-1-sonnysasaka@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org The public function is motivated by the Battery Provider API code which needs to probe whether a device exists. Reviewed-by: Miao-chen Chou --- src/adapter.c | 33 ++++++++++++++++++++++++--------- src/adapter.h | 2 ++ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index 56d0c6eaa..03d9d29e9 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -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) @@ -3192,15 +3216,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) { diff --git a/src/adapter.h b/src/adapter.h index e5750a37b..60b5e3bcc 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -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); -- 2.26.2