Fix in LE adapter to return CA_STATUS_OK when BT is not enabled 19/8119/2
authorvimala.v <vimala.v@samsung.com>
Thu, 12 May 2016 11:48:01 +0000 (17:18 +0530)
committerJon A. Cruz <jon@joncruz.org>
Tue, 17 May 2016 06:51:51 +0000 (06:51 +0000)
LE Adapter returns error when BT is not enabled.  This patch returns
CA_STATUS_OK and when BT is enabled, with the notification of device state
change callback, LE server/client is started.

Change-Id: Ic6c717535547f76d37b55f49e23b0efe25f77dff
Signed-off-by: vimala.v <vimala.v@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8119
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jon@joncruz.org>
resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c
resource/csdk/connectivity/src/bt_le_adapter/tizen/calenwmonitor.c
resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver.c

index ca42cb4..05cf9af 100644 (file)
@@ -1913,6 +1913,7 @@ static CAResult_t CAStartLEListeningServer()
             OIC_LOG(DEBUG,
                     CALEADAPTER_TAG,
                     "Listen Server will be started once BT Adapter is enabled");
+            result = CA_STATUS_OK;
         }
     }
     else
@@ -1969,6 +1970,7 @@ static CAResult_t CAStartLEDiscoveryServer()
             OIC_LOG(DEBUG,
                     CALEADAPTER_TAG,
                     "Discovery Server will be started once BT Adapter is enabled");
+            result = CA_STATUS_OK;
         }
     }
     else
index dd4e3f3..669ed11 100644 (file)
@@ -123,11 +123,19 @@ void CALEMainLoopThread(void *param)
         OIC_LOG(ERROR, TAG, "bt_initialize failed");
         return;
     }
-    ret = bt_adapter_set_visibility(BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE, 0);
-    if (BT_ERROR_NONE != ret)
+
+    bt_adapter_state_e adapterState = BT_ADAPTER_DISABLED;
+    //Get Bluetooth adapter state
+    ret = bt_adapter_get_state(&adapterState);
+
+    if (BT_ERROR_NONE != ret && BT_ADAPTER_ENABLED == adapterState)
     {
-        OIC_LOG(ERROR, TAG, "bt_adapter_set_visibility failed");
-        return;
+        ret = bt_adapter_set_visibility(BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE, 0);
+        if (BT_ERROR_NONE != ret)
+        {
+            OIC_LOG(ERROR, TAG, "bt_adapter_set_visibility failed");
+            return;
+        }
     }
 
     ret = bt_adapter_set_state_changed_cb(CALEAdapterStateChangedCb, NULL);
@@ -403,6 +411,14 @@ void CALEAdapterStateChangedCb(int result, bt_adapter_state_e adapter_state,
     }
 
     OIC_LOG(DEBUG, TAG, "Adapter is Enabled");
+
+    int ret = bt_adapter_set_visibility(BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE, 0);
+    if (BT_ERROR_NONE != ret)
+    {
+        OIC_LOG(ERROR, TAG, "bt_adapter_set_visibility failed");
+        return;
+    }
+
     g_bleDeviceStateChangedCallback(CA_ADAPTER_ENABLED);
     ca_mutex_unlock(g_bleDeviceStateChangedCbMutex);
 
index 0b234d7..8ce25bc 100644 (file)
@@ -472,6 +472,17 @@ CAResult_t CAInitGattServerMutexVariables()
             return CA_STATUS_FAILED;
         }
     }
+
+    if (NULL == g_leServerThreadPoolMutex)
+    {
+        g_leServerThreadPoolMutex = ca_mutex_new();
+        if (NULL == g_leServerThreadPoolMutex)
+        {
+            OIC_LOG(ERROR, TAG, "ca_mutex_new failed");
+            return CA_STATUS_FAILED;
+        }
+    }
+
     OIC_LOG(DEBUG, TAG, "OUT");
     return CA_STATUS_OK;
 }