mesh: Clean up Attach() method call 20/235120/1
authorInga Stotland <inga.stotland@intel.com>
Fri, 22 May 2020 00:34:59 +0000 (17:34 -0700)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Thu, 28 May 2020 11:27:22 +0000 (16:57 +0530)
This consolidates error return form one place: off a callback
with unsuccessful status.

Change-Id: I3c39a8bb7e6198f730ce8c1a8f7da97e43f65823
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
mesh/mesh.c
mesh/node.c
mesh/node.h

index 707f18f..6575393 100644 (file)
@@ -616,24 +616,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,
@@ -643,7 +636,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");
 
@@ -655,14 +647,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,
index 74b7603..535a021 100644 (file)
@@ -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)
index ca5d60b..290681e 100644 (file)
@@ -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);