[IOT-898] Propagate result of CA discovery/listen start call.
authorOssama Othman <ossama.othman@intel.com>
Mon, 7 Dec 2015 21:52:24 +0000 (13:52 -0800)
committerJon A. Cruz <jonc@osg.samsung.com>
Thu, 10 Dec 2015 22:58:55 +0000 (22:58 +0000)
Capture and return the result of CA discovery and listen start
function calls to allow for better differentiation of transport
adapter initialization and communication errors.

Change-Id: Ib5717600708e36792c020cb1c3b9f9caeaad9839
Signed-off-by: Ossama Othman <ossama.othman@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4443
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c
resource/csdk/connectivity/src/cainterfacecontroller.c
resource/csdk/connectivity/src/ip_adapter/caipadapter.c

index 571a89064647c34b6cc47c27f760b8cc84761eff..26e0852e05e76461ac78fa48c1a364e26e199879 100644 (file)
@@ -1774,14 +1774,14 @@ static CAResult_t CAStartLEListeningServer()
         return CA_STATUS_FAILED;
     }
 
-    CAStartLEGattServer();
+    result = CAStartLEGattServer();
 
     ca_mutex_lock(g_bleIsServerMutex);
     g_isServer = true;
     ca_mutex_unlock(g_bleIsServerMutex);
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return CA_STATUS_OK;
+    return result;
 #else
     // Routing Gateway only supports BLE client mode.
     OIC_LOG(ERROR, CALEADAPTER_TAG, "LE server not supported in Routing Gateway");
@@ -1821,14 +1821,14 @@ static CAResult_t CAStartLEDiscoveryServer()
         return CA_STATUS_FAILED;
     }
 
-    CAStartLEGattClient();
+    result = CAStartLEGattClient();
 
     ca_mutex_lock(g_bleIsServerMutex);
     g_isServer = false;
     ca_mutex_unlock(g_bleIsServerMutex);
 
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
-    return CA_STATUS_OK;
+    return result;
 }
 
 static CAResult_t CAReadLEData()
index 71124d3f9d1903d28a0b3e82e983da1c20168a17..33244131aba301c95da63f865230b9eef526a7f2 100644 (file)
@@ -469,11 +469,13 @@ CAResult_t CAStartListeningServerAdapters()
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
+    CAResult_t result = CA_STATUS_FAILED;
+
     u_arraylist_t *list = CAGetSelectedNetworkList();
     if (!list)
     {
         OIC_LOG(ERROR, TAG, "No selected network");
-        return CA_STATUS_FAILED;
+        return result;
     }
 
     for (uint32_t i = 0; i < u_arraylist_length(list); i++)
@@ -496,12 +498,19 @@ CAResult_t CAStartListeningServerAdapters()
 
         if (g_adapterHandler[index].startListenServer != NULL)
         {
-            g_adapterHandler[index].startListenServer();
+            const CAResult_t tmp =
+                g_adapterHandler[index].startListenServer();
+
+            // Successful listen if at least one adapter started.
+            if (CA_STATUS_OK == tmp)
+            {
+                result = tmp;
+            }
         }
     }
 
     OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
+    return result;
 }
 
 CAResult_t CAStopListeningServerAdapters()
@@ -546,12 +555,14 @@ CAResult_t CAStartDiscoveryServerAdapters()
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
+    CAResult_t result = CA_STATUS_FAILED;
+
     u_arraylist_t *list = CAGetSelectedNetworkList();
 
     if (!list)
     {
         OIC_LOG(ERROR, TAG, "No selected network");
-        return CA_STATUS_FAILED;
+        return result;
     }
 
     for (uint32_t i = 0; i < u_arraylist_length(list); i++)
@@ -575,12 +586,19 @@ CAResult_t CAStartDiscoveryServerAdapters()
 
         if (g_adapterHandler[index].startDiscoveryServer != NULL)
         {
-            g_adapterHandler[index].startDiscoveryServer();
+            const CAResult_t tmp =
+                g_adapterHandler[index].startDiscoveryServer();
+
+            // Successful discovery if at least one adapter started.
+            if (CA_STATUS_OK == tmp)
+            {
+                result = tmp;
+            }
         }
     }
 
     OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
+    return result;
 }
 
 void CATerminateAdapters()
index 998e26c4248b144e3551e125ecbbdfc53f102e4a..4bb258fcc2d748a8a206dd38f57b4b6839ef9dd0 100644 (file)
@@ -349,10 +349,9 @@ CAResult_t CAStopIPListeningServer()
     if (CA_STATUS_OK != ret)
     {
         OIC_LOG_V(ERROR, TAG, "Failed to stop listening server![%d]", ret);
-        return ret;
     }
     OIC_LOG(DEBUG, TAG, "OUT");
-    return CA_STATUS_OK;
+    return ret;
 }
 
 CAResult_t CAStartIPDiscoveryServer()