mesh: Add timeout to GetManagedObjects call
authorInga Stotland <inga.stotland@intel.com>
Wed, 10 Jun 2020 17:11:20 +0000 (10:11 -0700)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Mon, 28 Dec 2020 06:10:01 +0000 (11:40 +0530)
Switch to using dbus_send_with_timeout when making a request
to get managed objects from an application.

Change-Id: I5c95b22e0cafa36133ffb5bff1e76764fb4cf398
Signed-off-by: anuj.bhumiya <anuj.bhumiya@samsung.com>
mesh/node.c

index 18c728506295900e72b58795e8a1c44b42d684c8..3a9b341277feb2f6f04f903f1534fa425a3edc18 100644 (file)
@@ -1475,7 +1475,7 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data)
        struct keyring_net_key net_key;
        uint8_t dev_key[16];
 
-       if (l_dbus_message_is_error(msg)) {
+       if (!msg || l_dbus_message_is_error(msg)) {
                l_error("Failed to get app's dbus objects");
                goto fail;
        }
@@ -1632,8 +1632,7 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data)
 
 fail:
        /* Handle failed requests */
-       if (node)
-               node_remove(node);
+       node_remove(node);
 
        if (req->type == REQUEST_TYPE_JOIN)
                req->join_ready_cb(NULL, NULL);
@@ -1644,6 +1643,20 @@ fail:
                l_free(req->import);
 }
 
+static void send_managed_objects_request(const char *destination,
+                                               const char *path,
+                                               struct managed_obj_request *req)
+{
+       struct l_dbus_message *msg;
+
+       msg = l_dbus_message_new_method_call(dbus_get_bus(), destination, path,
+                                               L_DBUS_INTERFACE_OBJECT_MANAGER,
+                                               "GetManagedObjects");
+       l_dbus_message_set_arguments(msg, "");
+       dbus_send_with_timeout(dbus_get_bus(), msg, get_managed_objects_cb,
+                                       req, l_free, DEFAULT_DBUS_TIMEOUT);
+}
+
 /* Establish relationship between application and mesh node */
 void node_attach(const char *app_root, const char *sender, uint64_t token,
                                        node_ready_func_t cb, void *user_data)
@@ -1697,11 +1710,7 @@ void node_join(const char *app_root, const char *sender, const uint8_t *uuid,
        req->join_ready_cb = cb;
        req->type = REQUEST_TYPE_JOIN;
 
-       l_dbus_method_call(dbus_get_bus(), sender, app_root,
-                                       L_DBUS_INTERFACE_OBJECT_MANAGER,
-                                       "GetManagedObjects", NULL,
-                                       get_managed_objects_cb,
-                                       req, l_free);
+       send_managed_objects_request(sender, app_root, req);
 }
 
 void node_import(const char *app_root, const char *sender, const uint8_t *uuid,
@@ -1731,11 +1740,7 @@ void node_import(const char *app_root, const char *sender, const uint8_t *uuid,
 
        req->type = REQUEST_TYPE_IMPORT;
 
-       l_dbus_method_call(dbus_get_bus(), sender, app_root,
-                                               L_DBUS_INTERFACE_OBJECT_MANAGER,
-                                               "GetManagedObjects", NULL,
-                                               get_managed_objects_cb,
-                                               req, l_free);
+       send_managed_objects_request(sender, app_root, req);
 }
 
 void node_create(const char *app_root, const char *sender, const uint8_t *uuid,
@@ -1751,11 +1756,7 @@ void node_create(const char *app_root, const char *sender, const uint8_t *uuid,
        req->pending_msg = user_data;
        req->type = REQUEST_TYPE_CREATE;
 
-       l_dbus_method_call(dbus_get_bus(), sender, app_root,
-                                       L_DBUS_INTERFACE_OBJECT_MANAGER,
-                                       "GetManagedObjects", NULL,
-                                       get_managed_objects_cb,
-                                       req, l_free);
+       send_managed_objects_request(sender, app_root, req);
 }
 
 static void build_element_config(void *a, void *b)