From: "Gix, Brian" <brian.gix@intel.com>
To: "linux-bluetooth@vger.kernel.org" <linux-bluetooth@vger.kernel.org>
Cc: "michal.lowas-rzechonek@silvair.com"
<michal.lowas-rzechonek@silvair.com>,
"Stotland, Inga" <inga.stotland@intel.com>
Subject: Re: [PATCH BlueZ v2] mesh: Add deferral of Attach() and Leave() if busy
Date: Thu, 18 Jun 2020 15:41:14 +0000 [thread overview]
Message-ID: <f4c0a48f8d7c30b7c12bdcce84cf8ee172709daa.camel@intel.com> (raw)
In-Reply-To: <20200616181436.50319-1-brian.gix@intel.com>
Applied
On Tue, 2020-06-16 at 11:14 -0700, Brian Gix wrote:
> We require the successful return of JoinComplete() method before
> handling subsequent Attach() or Leave() method calls. To simplify the
> construction of Applications, we will accept one of these calls up to 1
> second prior to receiving the final return status of JoinComplete,
> which tells us that the Application is ready to use the node.
>
> If the node is still not ready after the deferral, Attach and/or Leave
> will fail.
> ---
> mesh/mesh.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 52 insertions(+), 2 deletions(-)
>
> diff --git a/mesh/mesh.c b/mesh/mesh.c
> index ab2393deb..bc170371d 100644
> --- a/mesh/mesh.c
> +++ b/mesh/mesh.c
> @@ -104,6 +104,10 @@ static struct l_queue *pending_queue;
>
> static const char *storage_dir;
>
> +/* Forward static decalrations */
> +static void def_attach(struct l_timeout *timeout, void *user_data);
> +static void def_leave(struct l_timeout *timeout, void *user_data);
> +
> static bool simple_match(const void *a, const void *b)
> {
> return a == b;
> @@ -634,12 +638,26 @@ static struct l_dbus_message *attach_call(struct l_dbus *dbus,
> uint64_t token;
> const char *app_path, *sender;
> struct l_dbus_message *pending_msg;
> + struct mesh_node *node;
>
> l_debug("Attach");
>
> if (!l_dbus_message_get_arguments(msg, "ot", &app_path, &token))
> return dbus_error(msg, MESH_ERROR_INVALID_ARGS, NULL);
>
> + node = node_find_by_token(token);
> + if (!node)
> + return dbus_error(msg, MESH_ERROR_NOT_FOUND, "Attach failed");
> +
> + if (node_is_busy(node)) {
> + if (user_data)
> + return dbus_error(msg, MESH_ERROR_BUSY, NULL);
> +
> + /* Try once more in 1 second */
> + l_timeout_create(1, def_attach, l_dbus_message_ref(msg), NULL);
> + return NULL;
> + }
> +
> sender = l_dbus_message_get_sender(msg);
>
> pending_msg = l_dbus_message_ref(msg);
> @@ -650,6 +668,19 @@ static struct l_dbus_message *attach_call(struct l_dbus *dbus,
> return NULL;
> }
>
> +static void def_attach(struct l_timeout *timeout, void *user_data)
> +{
> + struct l_dbus *dbus = dbus_get_bus();
> + struct l_dbus_message *msg = user_data;
> + struct l_dbus_message *reply;
> +
> + l_timeout_remove(timeout);
> +
> + reply = attach_call(dbus, msg, (void *) true);
> + l_dbus_send(dbus, reply);
> + l_dbus_message_unref(msg);
> +}
> +
> static struct l_dbus_message *leave_call(struct l_dbus *dbus,
> struct l_dbus_message *msg,
> void *user_data)
> @@ -666,14 +697,33 @@ static struct l_dbus_message *leave_call(struct l_dbus *dbus,
> if (!node)
> return dbus_error(msg, MESH_ERROR_NOT_FOUND, NULL);
>
> - if (node_is_busy(node))
> - return dbus_error(msg, MESH_ERROR_BUSY, NULL);
> + if (node_is_busy(node)) {
> + if (user_data)
> + return dbus_error(msg, MESH_ERROR_BUSY, NULL);
> +
> + /* Try once more in 1 second */
> + l_timeout_create(1, def_leave, l_dbus_message_ref(msg), NULL);
> + return NULL;
> + }
>
> node_remove(node);
>
> return l_dbus_message_new_method_return(msg);
> }
>
> +static void def_leave(struct l_timeout *timeout, void *user_data)
> +{
> + struct l_dbus *dbus = dbus_get_bus();
> + struct l_dbus_message *msg = user_data;
> + struct l_dbus_message *reply;
> +
> + l_timeout_remove(timeout);
> +
> + reply = leave_call(dbus, msg, (void *) true);
> + l_dbus_send(dbus, reply);
> + l_dbus_message_unref(msg);
> +}
> +
> static void create_join_complete_reply_cb(struct l_dbus_message *msg,
> void *user_data)
> {
next prev parent reply other threads:[~2020-06-18 15:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-16 18:14 [PATCH BlueZ v2] mesh: Add deferral of Attach() and Leave() if busy Brian Gix
2020-06-17 7:50 ` Michał Lowas-Rzechonek
2020-06-18 15:41 ` Gix, Brian [this message]
2020-06-18 15:43 ` michal.lowas-rzechonek
2020-06-18 15:48 ` Gix, Brian
2020-06-18 15:54 ` michal.lowas-rzechonek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f4c0a48f8d7c30b7c12bdcce84cf8ee172709daa.camel@intel.com \
--to=brian.gix@intel.com \
--cc=inga.stotland@intel.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=michal.lowas-rzechonek@silvair.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox