mesh: Clean up Import() method call 19/235119/1
authorInga Stotland <inga.stotland@intel.com>
Fri, 22 May 2020 00:34:58 +0000 (17:34 -0700)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Thu, 28 May 2020 11:27:22 +0000 (16:57 +0530)
This removes unnecessary failing conditions in Import() call and
simplifies iterations through "flags" dictionary.

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

index b603d8b..707f18f 100644 (file)
@@ -705,22 +705,19 @@ static void create_node_ready_cb(void *user_data, int status,
        const char *path;
        const uint8_t *token;
 
-       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) {
                reply = dbus_error(pending_msg, status, NULL);
-
                l_dbus_send(dbus_get_bus(), reply);
-               l_queue_remove(pending_queue, pending_msg);
                return;
        }
 
        reply = l_dbus_message_new_method_return(pending_msg);
 
        l_dbus_send(dbus, reply);
-       l_queue_remove(pending_queue, pending_msg);
 
        owner = l_dbus_message_get_sender(pending_msg);
        path = node_get_app_path(node);
@@ -824,19 +821,13 @@ static struct l_dbus_message *import_call(struct l_dbus *dbus,
                                                        "Bad net index");
 
        while (l_dbus_message_iter_next_entry(&iter_flags, &key, &var)) {
-               if (!strcmp(key, "IVUpdate")) {
-                       if (!l_dbus_message_iter_get_variant(&var, "b",
-                                                               &ivu))
-                               goto fail;
+               if (!strcmp(key, "IVUpdate") &&
+                       l_dbus_message_iter_get_variant(&var, "b", &ivu))
                        continue;
-               }
 
-               if (!strcmp(key, "KeyRefresh")) {
-                       if (!l_dbus_message_iter_get_variant(&var, "b",
-                                                               &kr))
-                               goto fail;
+               if (!strcmp(key, "KeyRefresh") &&
+                       l_dbus_message_iter_get_variant(&var, "b", &kr))
                        continue;
-               }
 
                return dbus_error(msg, MESH_ERROR_INVALID_ARGS,
                                                        "Bad flags");
@@ -851,20 +842,10 @@ static struct l_dbus_message *import_call(struct l_dbus *dbus,
        pending_msg = l_dbus_message_ref(msg);
        l_queue_push_tail(pending_queue, pending_msg);
 
-       if (!node_import(app_path, sender, uuid, dev_key, net_key, net_idx,
-                                       kr, ivu, iv_index, unicast,
-                                       create_node_ready_cb, pending_msg))
-               goto fail;
+       node_import(app_path, sender, uuid, dev_key, net_key, net_idx, kr, ivu,
+                       iv_index, unicast, create_node_ready_cb, pending_msg);
 
        return NULL;
-
-fail:
-       if (pending_msg) {
-               l_dbus_message_unref(msg);
-               l_queue_remove(pending_queue, pending_msg);
-       }
-
-       return dbus_error(msg, MESH_ERROR_INVALID_ARGS, "Node import failed");
 }
 
 static void setup_network_interface(struct l_dbus_interface *iface)
index 809485a..74b7603 100644 (file)
@@ -1693,7 +1693,7 @@ void node_join(const char *app_root, const char *sender, const uint8_t *uuid,
                                        req, l_free);
 }
 
-bool node_import(const char *app_root, const char *sender, const uint8_t *uuid,
+void node_import(const char *app_root, const char *sender, const uint8_t *uuid,
                        const uint8_t dev_key[16], const uint8_t net_key[16],
                        uint16_t net_idx, bool kr, bool ivu,
                        uint32_t iv_index, uint16_t unicast,
@@ -1725,7 +1725,6 @@ bool node_import(const char *app_root, const char *sender, const uint8_t *uuid,
                                                "GetManagedObjects", NULL,
                                                get_managed_objects_cb,
                                                req, l_free);
-       return true;
 }
 
 void node_create(const char *app_root, const char *sender, const uint8_t *uuid,
index 076714e..ca5d60b 100644 (file)
@@ -87,7 +87,7 @@ void node_build_attach_reply(struct mesh_node *node,
                                                struct l_dbus_message *reply);
 void node_create(const char *app_root, const char *sender, const uint8_t *uuid,
                                        node_ready_func_t cb, void *user_data);
-bool node_import(const char *app_root, const char *sender, const uint8_t *uuid,
+void node_import(const char *app_root, const char *sender, const uint8_t *uuid,
                        const uint8_t dev_key[16], const uint8_t net_key[16],
                        uint16_t net_idx, bool kr, bool ivu,
                        uint32_t iv_index, uint16_t unicast,