Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1157038lqj; Mon, 3 Jun 2024 11:53:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUTNDrnGu6438AB9Ffu8PgLnJgoYlmHUEreG8TYqHKSD+M6DmJTzx8JBZyaCpej9lRPuWM92mabNMnBlH1eJnA1akEI2vfgmQ1QljqDhw== X-Google-Smtp-Source: AGHT+IGC0srGlAK98AQjpA96wzyTtH4hZsZlh1vvRmROByv4xwzo5UCtQI2/IkjmHCMjRQRdTlTP X-Received: by 2002:a17:903:11c5:b0:1f4:8bba:5102 with SMTP id d9443c01a7336-1f63708fa0emr105726985ad.42.1717440812955; Mon, 03 Jun 2024 11:53:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717440812; cv=pass; d=google.com; s=arc-20160816; b=WMYDLcXx2VasgTNvJGfMWJuyx5qpPMa96eGNMCAPZrGFC+6Wu3lTSFZDdwiBvhWsdz v3YWODSiJASIweXxckjRU6dvktuR8ahIgjGux9saHt7ScM222T5cir9MVN6Xi7HC1Krt 1zV2JKGGSjpjEZ1RS5bZXAsBxi9lXPue+v2/Ez3O0NehgTy3my/GN+kh9THluYMTfbH7 LNb1u4SMu1lLVjIuyD5h/h7MgsuIXqxb6xnkj3xI0i0O1Mrhg+oZnt/efiHUfnZoSfgN dlrrf3lDxGtPsi/Il62RNEXzWouDtqcT4b2d2dybMSm7avG59bIqvlDoRbJqMt6eQOid Ur0w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=Euucq6IfSWE4jNGcSdYkP4D/Lw58XowlpkSXFe+Qksw=; fh=4lGQI6056MBa4/oovMyIYaKLn+Wz/24RGvUivMmQP8E=; b=nwMTnsc5AX5MlpjGXqTzzPLepMa5AUrbJlRhGb5taddYIkYJ9fBEwgnmbGR9oQ9uZJ uf37R6sm7ZhU/dIG6x1HaopWc9hetFc4sua8dtdWM3J9vcuS6GD+p40OHf661j5KpjnC SsWph4eg+LIFmhgg/ZZbEY8PN1coEixOdXrUqTqZe4GMR5J0dchRqEFFMP0SUeY/NnMm P+Yz/UiJzPpu+xZJ67MEc2foNG5DGtiSeZrVLwqLjUb6teI/6j74QilyGe39/53Och2h 1ON1Vdl8JJWFWIYiaEC2Jv4zaaPFfm65UdkFQ12D3MnqWUf1YfUnYIkMoqrE7d6knCNl ctsQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Ql7Jcqrz; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-bluetooth+bounces-5087-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-5087-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f68f2cd44csi6015215ad.243.2024.06.03.11.53.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 11:53:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-5087-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Ql7Jcqrz; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-bluetooth+bounces-5087-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-5087-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E09D7282A06 for ; Mon, 3 Jun 2024 18:53:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 40C3613A253; Mon, 3 Jun 2024 18:53:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ql7Jcqrz" X-Original-To: linux-bluetooth@vger.kernel.org Received: from mail-vk1-f182.google.com (mail-vk1-f182.google.com [209.85.221.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43E22139D03 for ; Mon, 3 Jun 2024 18:53:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717440799; cv=none; b=N1zEAyakgIe9PV1b11QyNbIWlhEUGBw4/Ry9U/i5TZhvldGefheu+N4POWUDo7k29aYjYcReic8TOcxSfntQ7rMf5X9JS1k4K4Quaj6z5HkaFsOYNWvqdrwVf6DIuLrFJOKG6WbrgB5190r63ZQ9jeX/3+L6nQ6+paZFZ7vNmog= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717440799; c=relaxed/simple; bh=BlMQ+hgTxxVK9SiYt7DjZJcwexb5fb9X1HYYnXHRsa0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jsF2JSf78jKXh35oMug25sLxoX/CknZrA9oDRkBa3bdaLgx6HYNuE5zd9ElMMhERk74mLpHqIseN95ySXRHjU1d4aYXi3MDBApThSC6UYcPo6tIbFOswgRhbTW2HH1Blb3mZhHDTsuf4GM71aLgTxT/SYqXa9Jhd73j7CObXxAo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ql7Jcqrz; arc=none smtp.client-ip=209.85.221.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-vk1-f182.google.com with SMTP id 71dfb90a1353d-4eaf67ad82dso1354490e0c.1 for ; Mon, 03 Jun 2024 11:53:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717440796; x=1718045596; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Euucq6IfSWE4jNGcSdYkP4D/Lw58XowlpkSXFe+Qksw=; b=Ql7JcqrzaAtbc3PwjRqNKaxpK3ukw4fn7ZdWjeUWYg6lqwre95UAaSAfYsi5A7JeoF 5SbKLGnhZphJ4GZieUyaVNalNUVuIk43LDRN4y8MssYeIRTTBSFQTdCYh56SZ7W34w0/ 7CbqqOfDj0tU6nl0A0Xmi1Z3sUtSdupr+rdbNMeLe+EErHIopp3Vrjqu2Tl2mrl9SscR QDLCJ5QgEU+ICXqQEWU/viBne7oLUo8l2qULxW9/xgsW0unkXgfCdyQT7JqhPTtD69VF tV/V5e+nGYYINNX28FHD7M0bAhC0lu3OfuY4uR3ekckz1s/3Qla640qn0fHj14RCUIte 7xmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717440796; x=1718045596; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Euucq6IfSWE4jNGcSdYkP4D/Lw58XowlpkSXFe+Qksw=; b=DMaDVG8FlmLn16TeScm8Zqby/yrJLTqW7wQdX2D46s6NgFqWWU6hvGV4ElNlv+xiWv rHgrj8emysdTJ8cP6ki6fn1uDPNGozgNKZsNfPTvJhmKSry/117cNraFtyibjkN7sM4F QFXAFVRvZ/5mIx4mARhzNqbDxME50RtWtG3llhp+U5quX0Uxmkjmr062yye/HVwLAFTq BWvfT2QJSUnJfrdL5gAx6xuTBgpS38eSKMg+gh6gZfZpHC5GX1ZUGLSYMWH48jfnbO33 TG4/+dCOxw1IY4N38NfdacGJLP3lX9z76VS2OPKvQSIrK2UoZJv5ue6guXUw4bm3Qxzq SObw== X-Gm-Message-State: AOJu0YxNPo3lCgbGixAY9gL0o6z24GO6+JeTbSlHgScTUCAYCVK/NfGv g3sMLt8WZ3XEqvre78MMQ5mBHpuSrN6SZxL6fbRNRebOZ05CmzgAOia6wQ== X-Received: by 2002:ac5:c888:0:b0:4c9:2540:8520 with SMTP id 71dfb90a1353d-4eb02d7c90amr8709989e0c.1.1717440796231; Mon, 03 Jun 2024 11:53:16 -0700 (PDT) Received: from lvondent-mobl4.. (syn-107-146-107-067.res.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-4eafecbab81sm1231658e0c.0.2024.06.03.11.53.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 11:53:15 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 2/3] shared/gatt-db: Introduce gatt_db_clone Date: Mon, 3 Jun 2024 14:53:11 -0400 Message-ID: <20240603185312.162337-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240603185312.162337-1-luiz.dentz@gmail.com> References: <20240603185312.162337-1-luiz.dentz@gmail.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Luiz Augusto von Dentz This introduces gatt_db_clone which can be used to clonse/deep copy and existing database. --- src/shared/gatt-db.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ src/shared/gatt-db.h | 1 + 2 files changed, 55 insertions(+) diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c index 2c8e7d31eda1..d8d21392fee6 100644 --- a/src/shared/gatt-db.c +++ b/src/shared/gatt-db.c @@ -260,6 +260,60 @@ struct gatt_db *gatt_db_new(void) return gatt_db_ref(db); } +static void service_clone(void *data, void *user_data) +{ + struct gatt_db_service *service = data; + struct gatt_db *db = user_data; + struct gatt_db_service *clone; + int i; + + clone = new0(struct gatt_db_service, 1); + clone->db = db; + clone->active = service->active; + clone->num_handles = service->num_handles; + clone->attributes = new0(struct gatt_db_attribute *, + service->num_handles); + + /* Clone attributes */ + for (i = 0; i < service->num_handles; i++) { + struct gatt_db_attribute *attr = service->attributes[i]; + + /* Only clone values for characteristics since that is + * cacheable. + */ + if (bt_uuid_len(&attr->uuid) == 2 && + attr->uuid.value.u16 == GATT_CHARAC_UUID) + clone->attributes[i] = new_attribute(clone, + attr->handle, + &attr->uuid, + attr->value, + attr->value_len); + else + clone->attributes[i] = new_attribute(clone, + attr->handle, + &attr->uuid, + NULL, 0); + } + + queue_push_tail(db->services, clone); +} + +struct gatt_db *gatt_db_clone(struct gatt_db *db) +{ + struct gatt_db *clone; + + if (!db) + return NULL; + + clone = gatt_db_new(); + if (!clone) + return NULL; + + queue_foreach(db->services, service_clone, clone); + + return clone; +} + static void notify_destroy(void *data) { struct notify *notify = data; diff --git a/src/shared/gatt-db.h b/src/shared/gatt-db.h index f7596e33529a..dc2daf7fc1ba 100644 --- a/src/shared/gatt-db.h +++ b/src/shared/gatt-db.h @@ -12,6 +12,7 @@ struct gatt_db; struct gatt_db_attribute; struct gatt_db *gatt_db_new(void); +struct gatt_db *gatt_db_clone(struct gatt_db *db); struct gatt_db *gatt_db_ref(struct gatt_db *db); void gatt_db_unref(struct gatt_db *db); -- 2.45.1