Mesh: Fix network proxy issue 70/240970/5
authorAbhay Agarwal <ay.agarwal@samsung.com>
Mon, 10 Aug 2020 13:07:25 +0000 (18:37 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Mon, 17 Aug 2020 11:33:10 +0000 (17:03 +0530)
This patch fix an issue of proxy added callback not being called
for network interface due to simultaeneous operations to register
proxy callback and to launch bluetooth-meshd.

Change-Id: Ibab370d9200ba3563e09f5396c4e0e3434a532ed
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
bt-service/services/bt-request-handler.c
bt-service/services/mesh/bt-service-mesh-main.c

index 8ac2903..8e17a47 100644 (file)
@@ -228,6 +228,7 @@ static gboolean __bt_is_sync_function(int service_function)
                        || service_function == BT_GATT_ACQUIRE_WRITE
                        || service_function == BT_AUDIO_SELECT_ROLE
                        /* Mesh API's */
+                       || service_function == BT_MESH_INIT
                        || service_function == BT_MESH_NETWORK_CREATE
                        || service_function == BT_MESH_NETWORK_DESTROY
                        || service_function == BT_MESH_NETWORK_LOAD
@@ -3356,6 +3357,14 @@ normal:
 
        case BT_MESH_INIT:
                result = _bt_mesh_init();
+               /* Save invocation */
+               if (result == BLUETOOTH_ERROR_NONE) {
+                       BT_INFO("Mesh: Save Invoation");
+                       sender = (char*)g_dbus_method_invocation_get_sender(context);
+                       _bt_save_invocation_context(context,
+                                       result, sender,
+                                       function_name, NULL);
+               }
                break;
 
        case BT_MESH_DEINIT:
index f3dc1e5..a5313c5 100644 (file)
@@ -47,6 +47,9 @@
 #include <oal-mesh.h>
 
 #define MESH_SYSTEMD_SERVICE_NAME "bluetooth-mesh.service"
+#define MESH_LAUNCH_DELAY 500
+
+static guint launch_timer = 0;
 
 /* Event handlers */
 static void __bt_mesh_handle_pending_request_info(int result,
@@ -65,6 +68,15 @@ static void __bt_mesh_handle_pending_request_info(int result,
                        continue;
 
                switch (service_function) {
+               case BT_MESH_INIT: {
+                       BT_INFO("Mesh: Request: BT_MESH_INIT Sender: [%s] result[%d]",
+                                       req_info->sender, result);
+                       out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
+                       _bt_service_method_return(req_info->context,
+                               out_param, result);
+                       _bt_free_info_from_invocation_list(req_info);
+                       break;
+               }
                case BT_MESH_NETWORK_CREATE: {
                        char uuid_str[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
                        bluetooth_mesh_node_t *node;
@@ -742,12 +754,10 @@ static void __handle_mesh_events(int event_type,
        }
 }
 
-int _bt_mesh_init(void)
+static int __bt_meshd_launch()
 {
        int ret = UNIT_CONTROL_OK;
-       oal_status_t status = OAL_STATUS_SUCCESS;
-
-       /* Launch bluetooth-meshd */
+       BT_INFO("Mesh: Launch Meshd");
        ret = actd_start_unit(UNIT_CONTROL_BUS_TYPE_SYSTEM,
                                MESH_SYSTEMD_SERVICE_NAME, 5000);
 
@@ -755,10 +765,18 @@ int _bt_mesh_init(void)
                BT_ERR("Failed to call systemact service: %d", ret);
                return BLUETOOTH_ERROR_INTERNAL;
        }
+       BT_INFO("Mesh: Launch Meshd successful");
 
+       return BLUETOOTH_ERROR_NONE;
+}
+
+static int __bt_mesh_enable()
+{
+       oal_status_t status = OAL_STATUS_SUCCESS;
+       BT_INFO("Mesh: Set dbus callbacks");
        status = mesh_enable();
        if (OAL_STATUS_SUCCESS != status) {
-               BT_ERR("Mesh: Failed to initialize Mesh profile, status: %d",
+               BT_ERR("Mesh: Failed to enable mesh interface, status: %d",
                                status);
                return BLUETOOTH_ERROR_INTERNAL;
        }
@@ -771,6 +789,46 @@ int _bt_mesh_init(void)
        return BLUETOOTH_ERROR_NONE;
 }
 
+static gboolean __bt_mesh_launch_timer_expired_cb(gpointer data)
+{
+       BT_INFO("Mesh: Enable Mesh dbus");
+       int ret = BLUETOOTH_ERROR_NONE;
+       ret = __bt_mesh_enable();
+       if (BLUETOOTH_ERROR_NONE != ret)
+               BT_ERR("Mesh: Mesh enable failed: %d", ret);
+
+       /* Handle DBUS Context return */
+       BT_INFO("Mesh: Handle DBUS Context return");
+       __bt_mesh_handle_pending_request_info(ret,
+                       BT_MESH_INIT,
+                       NULL, 0);
+       return FALSE;
+}
+
+int _bt_mesh_init(void)
+{
+       int ret = BLUETOOTH_ERROR_NONE;
+
+       if (launch_timer > 0) {
+               BT_INFO("Mesh: BT_MESH_INIT in progress");
+               return ret;
+       }
+
+       /* Launch bluetooth-meshd */
+       ret = __bt_meshd_launch();
+       if (BLUETOOTH_ERROR_NONE != ret) {
+               BT_ERR("Mesh: Meshd launch failed: %d", ret);
+               return ret;
+       }
+
+       /* wait for half a second*/
+       launch_timer = g_timeout_add(MESH_LAUNCH_DELAY,
+                               (GSourceFunc)__bt_mesh_launch_timer_expired_cb,
+                                                                       NULL);
+
+       return ret;
+}
+
 int _bt_mesh_deinit(void)
 {
        oal_status_t status = OAL_STATUS_SUCCESS;