Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp131060pxu; Wed, 2 Dec 2020 17:13:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJzb2bCV3VaTSANQ4CF8MK+q5/jJ+veSw3o6oEhrP3t0T7zQ1MSAniU4yus+X5+glyzhaeP3 X-Received: by 2002:a17:906:b307:: with SMTP id n7mr483236ejz.102.1606958012627; Wed, 02 Dec 2020 17:13:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606958012; cv=none; d=google.com; s=arc-20160816; b=qpng3AEIrlSuRP9e5LA2S8SU3oHx4Elp5bT9V9bLbGa44Wk7dJT7e1FWRJgPNuJUkw wkIKTr7lUHok+5+R8djOH14EVqy/TCIwZhGfedV2TTaRdGWRUul960ONR9gFysYl7+sV uE8PrJAWBe/mIA3l0tnPWIK07aknxFhuDbA3smiyvkoiSN0omk7LK3UH5H1U5Hplx7ZH QJTSULCHRg4nk+IQR2oW6k+n7YKX+cI4Hr4R1kZmhF+tt/KV77TqWxVebsnZ5OrQjp9i nMZhHtYL/NO9ksctpFBNXnKAtGzhweeDAoKG7Y6MHgXtMuwHQ/1rJ7zkaFTj4k6HKIQY 6kaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=opqzi+AgOotz5svJ/AiQaa67EGKTUUHAhD1f2YtYbqk=; b=AgwIUmjPY8HfqOKWmuBVfOcq6AYp3O/7uZ5ovgaxnINngD9Setene0lhRk3h50zcki mNNqqhHrzNbvsfou/LtKyyZ/hoKrfwlegjTzNrF2vvIVLxAxXfLjOMjsNag0jC8+8lyz tolvtPMRZHt3FPaqQmxFdIM7QW2QD9z58cAldjNPa7DyBi03uOGY3/33Renr/TbBlkcX U9j7PkEZ72rhJGR3Heb4Wtnuru6CsvVkefbllFYs5ms1Dt+lzRg0PfvvrcFt1So9n4qW S2c/n6oFjj248PCGedri/K/0SiMtbB9iqbhhP5x1azbJkuKVqM8hBGuueBlqVrNNDP5p yTQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pklpZx5e; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hs9si29960ejc.187.2020.12.02.17.12.51; Wed, 02 Dec 2020 17:13:32 -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=@gmail.com header.s=20161025 header.b=pklpZx5e; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729228AbgLCBLj (ORCPT + 99 others); Wed, 2 Dec 2020 20:11:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729224AbgLCBLi (ORCPT ); Wed, 2 Dec 2020 20:11:38 -0500 Received: from mail-oi1-x241.google.com (mail-oi1-x241.google.com [IPv6:2607:f8b0:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B01CFC0613D6 for ; Wed, 2 Dec 2020 17:10:58 -0800 (PST) Received: by mail-oi1-x241.google.com with SMTP id f11so478795oij.6 for ; Wed, 02 Dec 2020 17:10:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=opqzi+AgOotz5svJ/AiQaa67EGKTUUHAhD1f2YtYbqk=; b=pklpZx5ehf3Fdm6GTfhA67xhuILcBibVF2DMCr2b/ZL+qVIPD8I7TP/zo8uMvv1cLl /duCXtsizIZCb0AYtBmv1I0S2j6Mkvlu6CDQ7GKGvLjqI4V3Hegcdg3QPuGNejK9B6QU iOOIPTQ7WQomQYm/A7Sotm/eeWVbhOF4z0licisSIsdglCBhYk+Fh7j1FI90nf/+yhT+ 48i4Avb0tLx8thvNRd6ds0eDYKRAN1A4S/WOq1d6hK3ZCCGX1gwewJ652V+9VGOlbcSh OaVoDP4YZ4iBc71mvgFHTW/Is7EQC8l8T8ixCZGG9i9GCOubUMe1qCTP2hoC39cRcRGj BPvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=opqzi+AgOotz5svJ/AiQaa67EGKTUUHAhD1f2YtYbqk=; b=f8ql5ZIWOMlbgvhHbpe4LwUCxS+1LTAx5KXfhxjV1GYva3BydR0NMbotJl5vJp6G+x bKuPRo3OHvJcRTGjaKEG87jb6PxjKiAGQRq2Nrov+f5II3RVUDHHZh1BwU5C526Oajhu rNVIlRvXmLtDTxcntMQf7As7vdMLaSLRR6OZ89+ctUDH8POaIQ/AffP0BSCc8bOH0OfP AzyTmmIIxuHtv/lwW1X7yveKBrnfF99in2SBl+SGVRBuUR4aorDds+SLpk/lfV8YA1DT f1jgngCY2mv3vfD71pWu2SeQAWEvE67P62boOtB+q1pLOsFRFTqFvitmRe54lYbhG6BU D7lg== X-Gm-Message-State: AOAM532ScdITkMbw1rB3yaDHt9qGE9cSg7EQzhoHAWsZI3h2jjVnuLh8 BIaOy5Jt+Ix1QNVXPbfKDBt28a7/TOCOheGUbe4= X-Received: by 2002:a05:6808:1d8:: with SMTP id x24mr406722oic.64.1606957857999; Wed, 02 Dec 2020 17:10:57 -0800 (PST) MIME-Version: 1.0 References: <20201202011930.2130671-1-mmandlik@google.com> <20201201171838.bluez.v1.2.Ia29ecb3a2ddfd9e2939c94feca9eca0f06655ad9@changeid> In-Reply-To: From: Luiz Augusto von Dentz Date: Wed, 2 Dec 2020 17:10:45 -0800 Message-ID: Subject: Re: [bluez PATCH v1 2/3] gdbus: Emit InterfacesAdded/Removed at app root path To: Sonny Sasaka Cc: Manish Mandlik , Marcel Holtmann , "linux-bluetooth@vger.kernel.org" , ChromeOS Bluetooth Upstreaming , Yun-hao Chung , Miao-chen Chou Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Sonny, On Wed, Dec 2, 2020 at 3:27 PM Sonny Sasaka wrote: > > Hi Luiz, > > If I understand correctly, your concern is only on the bluetoothctl > part? If so, it is okay for bluetoothd to listen to subtrees for > clients that want to use subtree, is that correct? Yep, in fact using the same tree may be even preferable in case of bluetoothctl since we can just reference the same client in case it is registering a monitor and GATT service for example. > On Wed, Dec 2, 2020 at 11:50 AM Luiz Augusto von Dentz > wrote: > > > > Hi Sonny, > > > > On Wed, Dec 2, 2020 at 10:58 AM Sonny Sasaka wrote: > > > > > > Hi Luiz, > > > > > > The purpose here is that each application can have its own namespace > > > (e.g. /my/app, its objects should be in the form of /my/app/...) so > > > that it doesn't get mixed up with objects of other applications. I see > > > that there is already a pattern of using D-Bus ObjectManager this way > > > in bluez (there exists g_dbus_client_new_full to listen to objects in > > > a subtree), and also it is documented in D-Bus specification > > > (https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager) > > > so I don't think this violates any D-Bus best practices. > > > > The subtree support is meant for clients that actually want to do this > > in a subtree, rather then using '/', but bluetoothctl is already using > > '/' which would be parent to any subtree you would like to do. So > > while we support client using substres, I don't feel like bluetoothctl > > should use that as we already support adding GATT applications using > > '/' except if you really want to have multiple apps/subtrees but it > > doesn't look like this is the case and anyway when that happen that > > normally involves using different D-Bus connection. > > > > > On Wed, Dec 2, 2020 at 9:46 AM Luiz Augusto von Dentz > > > wrote: > > > > > > > > Hi Manish, > > > > > > > > On Tue, Dec 1, 2020 at 5:20 PM Manish Mandlik wrote: > > > > > > > > > > Bluetoothctl shares the gdbus library implementation with bluetoothd. > > > > > When bluetoothctl starts, it registers itself with the dbus with root > > > > > path same as the bluez root path i.e. '/'. > > > > > > > > > > When advertisement monitor objects are created or removed, > > > > > InterfacesAdded/InterfacesRemoved signals are emitted. These signals > > > > > are emitted at the registered root path by default. > > > > > > > > > > However, these signals need to be emitted at the app root path > > > > > registered using the "RegisterMonitor" method while registering the > > > > > client app with bluetoothd. > > > > > > > > > > This patch adds support in the gdbus library to emit signals at the app > > > > > root path. > > > > > > > > There can only be one root path really to guarantee there is one > > > > ObjectManager and we don't end up with ObjectManager listing other > > > > object managers which would likely cause problems. > > > > > > > > > Signed-off-by: Manish Mandlik > > > > > Reviewed-by: sonnysasaka@chromium.org > > > > > Reviewed-by: howardchung@google.com > > > > > Reviewed-by: mcchou@chromium.org > > > > > > > > > > --- > > > > > > > > > > gdbus/gdbus.h | 15 +++++++++++++++ > > > > > gdbus/object.c | 39 ++++++++++++++++++++++++++++++--------- > > > > > 2 files changed, 45 insertions(+), 9 deletions(-) > > > > > > > > > > diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h > > > > > index 28b802296..3bddaf9e6 100644 > > > > > --- a/gdbus/gdbus.h > > > > > +++ b/gdbus/gdbus.h > > > > > @@ -210,6 +210,13 @@ struct GDBusSecurityTable { > > > > > void g_dbus_set_flags(int flags); > > > > > int g_dbus_get_flags(void); > > > > > > > > > > +/* Note that, when new interface is registered, InterfacesAdded signal is > > > > > + * emitted. This signal is by default emitted at root path "/" registered > > > > > + * while registering a client using g_dbus_client_new(). If this behavior > > > > > + * is undesired, use g_dbus_register_interface_full() with a desired root > > > > > + * path to ensure InterfacesAdded / InterfacesRemoved signals get emitted > > > > > + * at the correct path. > > > > > + */ > > > > > gboolean g_dbus_register_interface(DBusConnection *connection, > > > > > const char *path, const char *name, > > > > > const GDBusMethodTable *methods, > > > > > @@ -217,6 +224,14 @@ gboolean g_dbus_register_interface(DBusConnection *connection, > > > > > const GDBusPropertyTable *properties, > > > > > void *user_data, > > > > > GDBusDestroyFunction destroy); > > > > > +gboolean g_dbus_register_interface_full(DBusConnection *connection, > > > > > + const char *path, const char *name, > > > > > + const char *root_path, > > > > > + const GDBusMethodTable *methods, > > > > > + const GDBusSignalTable *signals, > > > > > + const GDBusPropertyTable *properties, > > > > > + void *user_data, > > > > > + GDBusDestroyFunction destroy); > > > > > gboolean g_dbus_unregister_interface(DBusConnection *connection, > > > > > const char *path, const char *name); > > > > > > > > > > diff --git a/gdbus/object.c b/gdbus/object.c > > > > > index 50a8b4ff1..0d8a0696e 100644 > > > > > --- a/gdbus/object.c > > > > > +++ b/gdbus/object.c > > > > > @@ -38,6 +38,7 @@ struct generic_data { > > > > > unsigned int refcount; > > > > > DBusConnection *conn; > > > > > char *path; > > > > > + char *root_path; > > > > > GSList *interfaces; > > > > > GSList *objects; > > > > > GSList *added; > > > > > @@ -551,9 +552,10 @@ static void emit_interfaces_added(struct generic_data *data) > > > > > if (root == NULL || data == root) > > > > > return; > > > > > > > > > > - signal = dbus_message_new_signal(root->path, > > > > > - DBUS_INTERFACE_OBJECT_MANAGER, > > > > > - "InterfacesAdded"); > > > > > + signal = dbus_message_new_signal( > > > > > + data->root_path ? data->root_path : root->path, > > > > > + DBUS_INTERFACE_OBJECT_MANAGER, > > > > > + "InterfacesAdded"); > > > > > if (signal == NULL) > > > > > return; > > > > > > > > > > @@ -953,9 +955,10 @@ static void emit_interfaces_removed(struct generic_data *data) > > > > > if (root == NULL || data == root) > > > > > return; > > > > > > > > > > - signal = dbus_message_new_signal(root->path, > > > > > - DBUS_INTERFACE_OBJECT_MANAGER, > > > > > - "InterfacesRemoved"); > > > > > + signal = dbus_message_new_signal( > > > > > + data->root_path ? data->root_path : root->path, > > > > > + DBUS_INTERFACE_OBJECT_MANAGER, > > > > > + "InterfacesRemoved"); > > > > > if (signal == NULL) > > > > > return; > > > > > > > > > > @@ -1026,6 +1029,7 @@ static void generic_unregister(DBusConnection *connection, void *user_data) > > > > > > > > > > dbus_connection_unref(data->conn); > > > > > g_free(data->introspect); > > > > > + g_free(data->root_path); > > > > > g_free(data->path); > > > > > g_free(data); > > > > > } > > > > > @@ -1222,7 +1226,8 @@ done: > > > > > } > > > > > > > > > > static struct generic_data *object_path_ref(DBusConnection *connection, > > > > > - const char *path) > > > > > + const char *path, > > > > > + const char *root_path) > > > > > { > > > > > struct generic_data *data; > > > > > > > > > > @@ -1237,6 +1242,8 @@ static struct generic_data *object_path_ref(DBusConnection *connection, > > > > > data = g_new0(struct generic_data, 1); > > > > > data->conn = dbus_connection_ref(connection); > > > > > data->path = g_strdup(path); > > > > > + if (root_path) > > > > > + data->root_path = g_strdup(root_path); > > > > > data->refcount = 1; > > > > > > > > > > data->introspect = g_strdup(DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE ""); > > > > > @@ -1245,6 +1252,7 @@ static struct generic_data *object_path_ref(DBusConnection *connection, > > > > > &generic_table, data)) { > > > > > dbus_connection_unref(data->conn); > > > > > g_free(data->path); > > > > > + g_free(data->root_path); > > > > > g_free(data->introspect); > > > > > g_free(data); > > > > > return NULL; > > > > > @@ -1330,6 +1338,19 @@ gboolean g_dbus_register_interface(DBusConnection *connection, > > > > > const GDBusPropertyTable *properties, > > > > > void *user_data, > > > > > GDBusDestroyFunction destroy) > > > > > +{ > > > > > + return g_dbus_register_interface_full(connection, path, name, NULL, > > > > > + methods, signals, properties, user_data, destroy); > > > > > +} > > > > > + > > > > > +gboolean g_dbus_register_interface_full(DBusConnection *connection, > > > > > + const char *path, const char *name, > > > > > + const char *root_path, > > > > > + const GDBusMethodTable *methods, > > > > > + const GDBusSignalTable *signals, > > > > > + const GDBusPropertyTable *properties, > > > > > + void *user_data, > > > > > + GDBusDestroyFunction destroy) > > > > > { > > > > > struct generic_data *data; > > > > > > > > > > @@ -1343,7 +1364,7 @@ gboolean g_dbus_register_interface(DBusConnection *connection, > > > > > return FALSE; > > > > > } > > > > > > > > > > - data = object_path_ref(connection, path); > > > > > + data = object_path_ref(connection, path, root_path); > > > > > if (data == NULL) > > > > > return FALSE; > > > > > > > > > > @@ -1811,7 +1832,7 @@ gboolean g_dbus_attach_object_manager(DBusConnection *connection) > > > > > { > > > > > struct generic_data *data; > > > > > > > > > > - data = object_path_ref(connection, "/"); > > > > > + data = object_path_ref(connection, "/", NULL); > > > > > if (data == NULL) > > > > > return FALSE; > > > > > > > > > > -- > > > > > 2.29.2.454.gaff20da3a2-goog > > > > > > > > > > > > > > > > > -- > > > > Luiz Augusto von Dentz > > > > > > > > -- > > Luiz Augusto von Dentz -- Luiz Augusto von Dentz