Linux-Bluetooth Archive on lore.kernel.org
 help / color / Atom feed
From: Inga Stotland <inga.stotland@intel.com>
To: linux-bluetooth@vger.kernel.org
Cc: brian.gix@intel.com, Inga Stotland <inga.stotland@intel.com>
Subject: [PATCH BlueZ 08/10] mesh: Clean up Attach() method call
Date: Thu, 21 May 2020 17:34:59 -0700
Message-ID: <20200522003501.106165-9-inga.stotland@intel.com> (raw)
In-Reply-To: <20200522003501.106165-1-inga.stotland@intel.com>

This consolidates error return form one place: off a callback
with unsuccessful status.
---
 mesh/mesh.c | 29 ++++++++---------------------
 mesh/node.c | 14 +++++++-------
 mesh/node.h |  2 +-
 3 files changed, 16 insertions(+), 29 deletions(-)

diff --git a/mesh/mesh.c b/mesh/mesh.c
index e5b36cd94..c68436caa 100644
--- a/mesh/mesh.c
+++ b/mesh/mesh.c
@@ -617,24 +617,17 @@ static void attach_ready_cb(void *user_data, int status, struct mesh_node *node)
 	struct l_dbus_message *reply;
 	struct l_dbus_message *pending_msg;
 
-	pending_msg = l_queue_find(pending_queue, simple_match, user_data);
+	pending_msg = l_queue_remove_if(pending_queue, simple_match, user_data);
 	if (!pending_msg)
 		return;
 
-	if (status != MESH_ERROR_NONE) {
-		const char *desc = (status == MESH_ERROR_NOT_FOUND) ?
-				"Node match not found" : "Attach failed";
-		reply = dbus_error(pending_msg, status, desc);
-		goto done;
-	}
-
-	reply = l_dbus_message_new_method_return(pending_msg);
+	if (status == MESH_ERROR_NONE) {
+		reply = l_dbus_message_new_method_return(pending_msg);
+		node_build_attach_reply(node, reply);
+	} else
+		reply = dbus_error(pending_msg, status, "Attach failed");
 
-	node_build_attach_reply(node, reply);
-
-done:
 	l_dbus_send(dbus_get_bus(), reply);
-	l_queue_remove(pending_queue, pending_msg);
 }
 
 static struct l_dbus_message *attach_call(struct l_dbus *dbus,
@@ -644,7 +637,6 @@ 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;
-	int status;
 
 	l_debug("Attach");
 
@@ -656,14 +648,9 @@ static struct l_dbus_message *attach_call(struct l_dbus *dbus,
 	pending_msg = l_dbus_message_ref(msg);
 	l_queue_push_tail(pending_queue, pending_msg);
 
-	status = node_attach(app_path, sender, token, attach_ready_cb,
-								pending_msg);
-	if (status == MESH_ERROR_NONE)
-		return NULL;
+	node_attach(app_path, sender, token, attach_ready_cb, pending_msg);
 
-	l_queue_remove(pending_queue, pending_msg);
-
-	return dbus_error(msg, status, NULL);
+	return NULL;
 }
 
 static struct l_dbus_message *leave_call(struct l_dbus *dbus,
diff --git a/mesh/node.c b/mesh/node.c
index 9ba5ad877..dd28dfd77 100644
--- a/mesh/node.c
+++ b/mesh/node.c
@@ -1634,20 +1634,23 @@ fail:
 }
 
 /* Establish relationship between application and mesh node */
-int node_attach(const char *app_root, const char *sender, uint64_t token,
+void node_attach(const char *app_root, const char *sender, uint64_t token,
 					node_ready_func_t cb, void *user_data)
 {
 	struct managed_obj_request *req;
 	struct mesh_node *node;
 
 	node = l_queue_find(nodes, match_token, (void *) &token);
-	if (!node)
-		return MESH_ERROR_NOT_FOUND;
+	if (!node) {
+		cb(user_data, MESH_ERROR_NOT_FOUND, NULL);
+		return;
+	}
 
 	/* Check if the node is already in use */
 	if (node->owner) {
 		l_warn("The node is already in use");
-		return MESH_ERROR_ALREADY_EXISTS;
+		cb(user_data, MESH_ERROR_ALREADY_EXISTS, NULL);
+		return;
 	}
 
 	req = l_new(struct managed_obj_request, 1);
@@ -1668,11 +1671,8 @@ int node_attach(const char *app_root, const char *sender, uint64_t token,
 					"GetManagedObjects", NULL,
 					get_managed_objects_cb,
 					req, l_free);
-	return MESH_ERROR_NONE;
-
 }
 
-
 /* Create a temporary pre-provisioned node */
 void node_join(const char *app_root, const char *sender, const uint8_t *uuid,
 						node_join_ready_func_t cb)
diff --git a/mesh/node.h b/mesh/node.h
index ca5d60b6b..290681e28 100644
--- a/mesh/node.h
+++ b/mesh/node.h
@@ -81,7 +81,7 @@ const char *node_get_app_path(struct mesh_node *node);
 bool node_add_pending_local(struct mesh_node *node, void *info);
 void node_attach_io_all(struct mesh_io *io);
 void node_attach_io(struct mesh_node *node, struct mesh_io *io);
-int node_attach(const char *app_root, const char *sender, uint64_t token,
+void node_attach(const char *app_root, const char *sender, uint64_t token,
 					node_ready_func_t cb, void *user_data);
 void node_build_attach_reply(struct mesh_node *node,
 						struct l_dbus_message *reply);
-- 
2.26.2


  parent reply index

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-22  0:34 [PATCH BlueZ 00/10] Mesh code clean up Inga Stotland
2020-05-22  0:34 ` [PATCH BlueZ 01/10] mesh: Remove unused structure member Inga Stotland
2020-05-22  0:34 ` [PATCH BlueZ 02/10] mesh: Free allocated agent in mesh_remove_agent() Inga Stotland
2020-05-22  0:34 ` [PATCH BlueZ 03/10] mesh: Remove agent when freeing node's dynamic resources Inga Stotland
2020-05-22  0:34 ` [PATCH BlueZ 04/10] mesh: Add finalization of a newly created node Inga Stotland
2020-05-22  0:34 ` [PATCH BlueZ 05/10] mesh: Remove unused function prototypes from node.h Inga Stotland
2020-05-22  1:12   ` [BlueZ,05/10] " bluez.test.bot
2020-05-22  0:34 ` [PATCH BlueZ 06/10] mesh: Create a queue of pending requests in mesh_init() Inga Stotland
2020-05-22  0:34 ` [PATCH BlueZ 07/10] mesh: Clean up Import() method call Inga Stotland
2020-05-22  0:34 ` Inga Stotland [this message]
2020-05-22  0:35 ` [PATCH BlueZ 09/10] mesh: Fix memory leak in Create, Import & Attach methods Inga Stotland
2020-05-22  0:35 ` [PATCH BlueZ 10/10] mesh: Clean up Join() method Inga Stotland
2020-05-22 20:54 ` [PATCH BlueZ 00/10] Mesh code clean up Gix, Brian

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=20200522003501.106165-9-inga.stotland@intel.com \
    --to=inga.stotland@intel.com \
    --cc=brian.gix@intel.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /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

Linux-Bluetooth Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-bluetooth/0 linux-bluetooth/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-bluetooth linux-bluetooth/ https://lore.kernel.org/linux-bluetooth \
		linux-bluetooth@vger.kernel.org
	public-inbox-index linux-bluetooth

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-bluetooth


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git