Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6055505pxv; Thu, 29 Jul 2021 05:29:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyF0YKKlZYq7DG+x6CT6U5mBuBcKdcB/ArFdBpSvZvIiYLnR/SGaghBmeFGzgcqXcEwPvzX X-Received: by 2002:a17:906:7393:: with SMTP id f19mr4574164ejl.79.1627561786471; Thu, 29 Jul 2021 05:29:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627561786; cv=none; d=google.com; s=arc-20160816; b=KHBqFFg5QfxipAPLQpODs+ZRgasphz1Y5ZHw2FDKRcwiSmDJi6nbMdDwu01Uofgx44 tbe3uYGV+E2xcynPfgNBjxNI8OuN7jcW+N0wW5bnxHDb7a8nb0VGeL5f7gbZTpvlXTHB 3MS+Px0mnPZkjC73XHYc7x3zsVxkzezpL1pgBTF6GNJ1Cmn+75sM3kAVJWNXfr++a027 0+Fn/U/dU+Te1+zQBnsB5XJ8eEDwNIyjjbsJKKlVPvieIcIo20NfLHAdkkDTY8eOU034 02mUVxoZWgXSglq7RI5+kz+Bmds69L+npmB5rHLbYBSBQDzmA/MmL+Rs/F5T8GtrJAgL MJPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=Q/e+0IQlyiwFsKtb7qCWpUP84WxAop8SbAryiByocQw=; b=jotAkuflFhxJeKDJQnBrdkKaSFDRrPUTmV0ZkDjxep4N8VjCiF5KdmMxmHz3BQ+FRV 12fXrsw6elHudPdK8VjKzvB45ATvMvAG9lyihoi2SUinguNi/WGif4fR5TA2Hd/4N7IB zTHiS+CdfXy7TnEOdGn1yN04NdX1JblYByl9lc58EIzcpwd1EUbZhlAnL2jwe1ldtad+ zbuEUbyfgvTXEV0i/ks/ZgfbRRXH1bpv99wye4XdISDuaFOBXpK8EPnTEcgrhRZfqRRY B2OQUrq+VmYpE2EXDrjaHE5nGsZpAGQHxZrDMDuJ6zC5ax+14ApgZDxWqvccuuHQXZkD 5aXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Upam9157; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w20si2570991edu.376.2021.07.29.05.29.21; Thu, 29 Jul 2021 05:29:46 -0700 (PDT) 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=@google.com header.s=20161025 header.b=Upam9157; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237096AbhG2M2a (ORCPT + 99 others); Thu, 29 Jul 2021 08:28:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236927AbhG2M2a (ORCPT ); Thu, 29 Jul 2021 08:28:30 -0400 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1719EC061765 for ; Thu, 29 Jul 2021 05:28:26 -0700 (PDT) Received: by mail-qk1-x749.google.com with SMTP id q9-20020a05620a0c89b02903ba3e0f08d7so3751538qki.3 for ; Thu, 29 Jul 2021 05:28:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Q/e+0IQlyiwFsKtb7qCWpUP84WxAop8SbAryiByocQw=; b=Upam9157F1DAgkqV8tGfg9Xrmuz195NlzDyf4OBWTRyHQG6o6Pz3VkRjfRc9gnOeBG 4xKSAZ+Zn0V+kbvu2aq2AfUuuSzEl8jATmi1lo6irK1AoUix9vTaaDkp5UY3jUFN5lnn H17xR5uvqoqkH+K/N6iqRvgGvoxnrGLvy1TsJI9vhM3t3GWgiFm1+Y+bu9lu9ofHp4m0 vZ2nTpOwG8qeDdqIeiKfjQ6gxbzeki0A82hjYt1MsMdkzYipX/c1uPj8gwYM7Bmkz8kg GVNRsF2+FTJPA95AvJ9v4VA9mgAtwV8o0vcp9l5eY/kT+RG1dCO9yfJJsjFGNW5cYr79 bW9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Q/e+0IQlyiwFsKtb7qCWpUP84WxAop8SbAryiByocQw=; b=uWs2Dp8cb8kRoKYkZwJNgYp/5+ac1PmjF8DP8ZfESBCsmphRlhRFylMSCL49nasAeV gxfgI+5vTZLcRv1nPoaRZYCB9+X/SEhnm7rnwriNQaeMRw7KtmF095rEy/FVr7w57wLy jd6QAtowOLvK+2W821L7F33mft7b4L6ZcTq60HH6qChjn5Ne/4EvHgOFbyL0qpfgGBs/ 7Y8RLI3VhmKTNtz9xvR38IeGGmNFR7YSLiao5++59h2dQZWpKT0tNC8sePh2KE9p9V8V Iz6v8dnKrDLVED3YDDbTxz1+IKv8+lEhfyC32VSC8Mj2ejEf2Q0Iawcrtf9g+5e8q90H 5/rw== X-Gm-Message-State: AOAM533Fo7WceHYL6VXHBcWAxoM2txZrZXwDwyqZIgQt8WxoeNxnelpH B+xt6mM4cswZ3fho5NWYBMcNHqlOzyHdmSQCeHdl12gjLon0hor1qidlpGpaT5aDm+yGxhg6XXh bWUFdTRw8a34JNEl4Q6e2onFRWFwKZyvbcfMeiv+fJ+1lrJF7li7BPxNmZuZKiOQQHDjtkVNKjw ltZ1hddzenmoI= X-Received: from howardchung-p920.tpe.corp.google.com ([2401:fa00:1:10:ff72:1420:4502:fdaf]) (user=howardchung job=sendgmr) by 2002:a05:6214:2482:: with SMTP id gi2mr5116344qvb.51.1627561705100; Thu, 29 Jul 2021 05:28:25 -0700 (PDT) Date: Thu, 29 Jul 2021 20:27:43 +0800 In-Reply-To: <20210729122751.3728885-1-howardchung@google.com> Message-Id: <20210729202648.Bluez.v6.5.Iee308dd18bfdfd3dae9e343e78b3942ee462314f@changeid> Mime-Version: 1.0 References: <20210729122751.3728885-1-howardchung@google.com> X-Mailer: git-send-email 2.32.0.554.ge1b32706d8-goog Subject: [Bluez PATCH v6 05/13] core: add device_added and device_removed to adapter driver From: Howard Chung To: linux-bluetooth@vger.kernel.org, luiz.dentz@gmail.com Cc: Yun-Hao Chung Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Yun-Hao Chung This adds device_added and device_removed to btd_adapter_driver so that a driver can get notification when device is added or removed. --- (no changes since v1) src/adapter.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++----- src/adapter.h | 4 ++++ 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index 6c8096147bdd..5c556b569ca7 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -1218,6 +1218,9 @@ void adapter_service_remove(struct btd_adapter *adapter, uint32_t handle) remove_record_from_server(rec->handle); } +static void adapter_add_device(struct btd_adapter *adapter, + struct btd_device *device); + static struct btd_device *adapter_create_device(struct btd_adapter *adapter, const bdaddr_t *bdaddr, uint8_t bdaddr_type) @@ -1228,8 +1231,7 @@ static struct btd_device *adapter_create_device(struct btd_adapter *adapter, if (!device) return NULL; - adapter->devices = g_slist_append(adapter->devices, device); - + adapter_add_device(adapter, device); return device; } @@ -1256,6 +1258,9 @@ static void service_auth_cancel(struct service_auth *auth) g_free(auth); } +static void adapter_remove_device(struct btd_adapter *adapter, + struct btd_device *device); + void btd_adapter_remove_device(struct btd_adapter *adapter, struct btd_device *dev) { @@ -1263,7 +1268,7 @@ void btd_adapter_remove_device(struct btd_adapter *adapter, adapter->connect_list = g_slist_remove(adapter->connect_list, dev); - adapter->devices = g_slist_remove(adapter->devices, dev); + adapter_remove_device(adapter, dev); btd_adv_monitor_device_remove(adapter->adv_monitor_manager, dev); adapter->discovery_found = g_slist_remove(adapter->discovery_found, @@ -4665,7 +4670,7 @@ static void load_devices(struct btd_adapter *adapter) goto free; btd_device_set_temporary(device, false); - adapter->devices = g_slist_append(adapter->devices, device); + adapter_add_device(adapter, device); /* TODO: register services from pre-loaded list of primaries */ @@ -4827,6 +4832,48 @@ void adapter_remove_profile(struct btd_adapter *adapter, gpointer p) profile->adapter_remove(profile, adapter); } +static void device_added_drivers(struct btd_adapter *adapter, + struct btd_device *device) +{ + struct btd_adapter_driver *driver; + GSList *l; + + for (l = adapter_drivers; l; l = l->next) { + driver = l->data; + + if (driver->device_added) + driver->device_added(adapter, device); + } +} + +static void device_removed_drivers(struct btd_adapter *adapter, + struct btd_device *device) +{ + struct btd_adapter_driver *driver; + GSList *l; + + for (l = adapter_drivers; l; l = l->next) { + driver = l->data; + + if (driver->device_removed) + driver->device_removed(adapter, device); + } +} + +static void adapter_add_device(struct btd_adapter *adapter, + struct btd_device *device) +{ + adapter->devices = g_slist_append(adapter->devices, device); + device_added_drivers(adapter, device); +} + +static void adapter_remove_device(struct btd_adapter *adapter, + struct btd_device *device) +{ + adapter->devices = g_slist_remove(adapter->devices, device); + device_removed_drivers(adapter, device); +} + static void adapter_add_connection(struct btd_adapter *adapter, struct btd_device *device, uint8_t bdaddr_type) @@ -6445,8 +6492,10 @@ static void adapter_remove(struct btd_adapter *adapter) g_slist_free(adapter->connect_list); adapter->connect_list = NULL; - for (l = adapter->devices; l; l = l->next) + for (l = adapter->devices; l; l = l->next) { + device_removed_drivers(adapter, l->data); device_remove(l->data, FALSE); + } g_slist_free(adapter->devices); adapter->devices = NULL; diff --git a/src/adapter.h b/src/adapter.h index 7cac51451249..a2567330ddc9 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -111,6 +111,10 @@ struct btd_adapter_driver { int (*probe) (struct btd_adapter *adapter); void (*remove) (struct btd_adapter *adapter); void (*resume) (struct btd_adapter *adapter); + void (*device_added) (struct btd_adapter *adapter, + struct btd_device *device); + void (*device_removed) (struct btd_adapter *adapter, + struct btd_device *device); }; typedef void (*service_auth_cb) (DBusError *derr, void *user_data); -- 2.32.0.554.ge1b32706d8-goog