Changed the return type of functions in uarraylist
authorhyuna0213.jo <hyuna0213.jo@samsung.com>
Mon, 17 Aug 2015 11:53:43 +0000 (20:53 +0900)
committerJon A. Cruz <jonc@osg.samsung.com>
Tue, 18 Aug 2015 18:52:37 +0000 (18:52 +0000)
uarraylist.h includes the common functions for array list.
but now it depend on cacommon.h file.
so I modified the return value to reduce the dependence
on the other files.

Change-Id: Ia8584f000f78fec80b21006594af6574dbb6840b
Signed-off-by: hyuna0213.jo <hyuna0213.jo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2218
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jaehong Jo <jaehong.jo@samsung.com>
Reviewed-by: jihwan seo <jihwan.seo@samsung.com>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
resource/csdk/connectivity/common/inc/uarraylist.h
resource/csdk/connectivity/common/src/cathreadpool_pthreads.c
resource/csdk/connectivity/common/src/uarraylist.c
resource/csdk/connectivity/src/adapter_util/caadapternetdtls.c
resource/csdk/connectivity/src/cablockwisetransfer.c
resource/csdk/connectivity/src/canetworkconfigurator.c
resource/csdk/connectivity/src/ip_adapter/android/caipnwmonitor.c
resource/csdk/connectivity/src/ip_adapter/arduino/caipnwmonitor_eth.cpp
resource/csdk/connectivity/src/ip_adapter/arduino/caipnwmonitor_wifi.cpp
resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c
resource/csdk/connectivity/src/ip_adapter/tizen/caipnwmonitor.c

index 5a64937..7e8403a 100644 (file)
@@ -22,7 +22,7 @@
 #define U_ARRAYLIST_H_
 
 #include <stdint.h>
-#include "cacommon.h"
+#include <stdbool.h>
 
 #ifdef __cplusplus
 extern "C"
@@ -54,10 +54,8 @@ u_arraylist_t *u_arraylist_create();
  * Arraylist elements are deleted. Calling function must take care of free
  * dynamic memory allocated before freeing the arraylist.
  * @param[in] list       u_arraylist pointer
- * @return ::CAResult_t.
- * ::CA_STATUS_OK if Success, ::CA_STATUS_INVALID_PARAM if pointer to list is NULL.
  */
-CAResult_t u_arraylist_free(u_arraylist_t **list);
+void u_arraylist_free(u_arraylist_t **list);
 
 /**
  * Returns the data of the index from the array list.
@@ -71,10 +69,9 @@ void *u_arraylist_get(const u_arraylist_t *list, uint32_t index);
  * Add data in the array list.
  * @param[in] list        pointer of array list.
  * @param[in] data        pointer of data.
- * @return CAResult_t.
- * ::CA_STATUS_OK if Success, ::CA_MEMORY_ALLOC_FAILED if memory allocation fails.
+ * @return true if success, false otherwise.
  */
-CAResult_t u_arraylist_add(u_arraylist_t *list, void *data);
+bool u_arraylist_add(u_arraylist_t *list, void *data);
 
 /**
  * Remove the data of the index from the array list.
index 744b1a5..751bafc 100644 (file)
@@ -165,13 +165,13 @@ CAResult_t ca_thread_pool_add_task(ca_thread_pool_t thread_pool, ca_thread_func
     }
 
     ca_mutex_lock(thread_pool->details->list_lock);
-    CAResult_t addResult = u_arraylist_add(thread_pool->details->threads_list, (void*)threadHandle);
+    bool addResult = u_arraylist_add(thread_pool->details->threads_list, (void*)threadHandle);
     ca_mutex_unlock(thread_pool->details->list_lock);
 
-    if(addResult != CA_STATUS_OK)
+    if(!addResult)
     {
         OIC_LOG_V(ERROR, TAG, "Arraylist Add failed, may not be properly joined: %d", addResult);
-        return addResult;
+        return CA_STATUS_FAILED;
     }
 
     OIC_LOG(DEBUG, TAG, "OUT");
@@ -200,11 +200,7 @@ void ca_thread_pool_free(ca_thread_pool_t thread_pool)
         }
     }
 
-    CAResult_t freeres = u_arraylist_free(&(thread_pool->details->threads_list));
-    if(CA_STATUS_OK != freeres)
-    {
-        OIC_LOG_V(ERROR, TAG, "Failed to free array list, error was: %d", freeres);
-    }
+    u_arraylist_free(&(thread_pool->details->threads_list));
 
     ca_mutex_unlock(thread_pool->details->list_lock);
     ca_mutex_free(thread_pool->details->list_lock);
index be897be..8cc88f4 100644 (file)
@@ -54,19 +54,17 @@ u_arraylist_t *u_arraylist_create()
     return list;
 }
 
-CAResult_t u_arraylist_free(u_arraylist_t **list)
+void u_arraylist_free(u_arraylist_t **list)
 {
     if (!list || !(*list))
     {
-        return CA_STATUS_INVALID_PARAM;
+        return;
     }
 
     OICFree((*list)->data);
     OICFree(*list);
 
     *list = NULL;
-
-    return CA_STATUS_OK;
 }
 
 void *u_arraylist_get(const u_arraylist_t *list, uint32_t index)
@@ -84,20 +82,20 @@ void *u_arraylist_get(const u_arraylist_t *list, uint32_t index)
     return NULL;
 }
 
-CAResult_t u_arraylist_add(u_arraylist_t *list, void *data)
+bool u_arraylist_add(u_arraylist_t *list, void *data)
 {
     if (!list)
     {
-        return CA_STATUS_INVALID_PARAM;
+        return false;
     }
 
     if (list->size <= list->length)
     {
-
-       uint32_t new_size = list->size + 1;
+        uint32_t new_size = list->size + 1;
         if (!(list->data = (void **) realloc(list->data, new_size * sizeof(void *))))
         {
-            return CA_MEMORY_ALLOC_FAILED;
+            OIC_LOG(ERROR, TAG, "Failed to re-allocation memory");
+            return false;
         }
 
         memset(list->data + list->size, 0, (new_size - list->size) * sizeof(void *));
@@ -107,7 +105,7 @@ CAResult_t u_arraylist_add(u_arraylist_t *list, void *data)
     list->data[list->length] = data;
     list->length++;
 
-    return CA_STATUS_OK;
+    return true;
 }
 
 void *u_arraylist_remove(u_arraylist_t *list, uint32_t index)
index b4ae019..af9ed9a 100644 (file)
@@ -113,8 +113,8 @@ static CAResult_t CAAddIdToPeerInfoList(const char *peerAddr, uint32_t port,
         return CA_STATUS_FAILED;
     }
 
-    CAResult_t result = u_arraylist_add(g_caDtlsContext->peerInfoList, (void *)peer);
-    if (CA_STATUS_OK != result)
+    bool result = u_arraylist_add(g_caDtlsContext->peerInfoList, (void *)peer);
+    if (!result)
     {
         OIC_LOG(ERROR, NET_DTLS_TAG, "u_arraylist_add failed!");
         OICFree(peer);
@@ -298,8 +298,8 @@ static CAResult_t CADtlsCacheMsg(stCACacheMessage_t *msg)
         return CA_STATUS_FAILED;
     }
 
-    CAResult_t result = u_arraylist_add(g_caDtlsContext->cacheList, (void *)msg);
-    if (CA_STATUS_OK != result)
+    bool result = u_arraylist_add(g_caDtlsContext->cacheList, (void *)msg);
+    if (!result)
     {
         OIC_LOG(ERROR, NET_DTLS_TAG, "u_arraylist_add failed!");
     }
index 5aa9f28..80cd517 100644 (file)
@@ -2459,8 +2459,8 @@ CABlockData_t *CACreateNewBlockData(const CAData_t *sendData)
 
     ca_mutex_lock(g_context.blockDataListMutex);
 
-    CAResult_t res = u_arraylist_add(g_context.dataList, (void *) data);
-    if (CA_STATUS_OK != res)
+    bool res = u_arraylist_add(g_context.dataList, (void *) data);
+    if (!res)
     {
         OIC_LOG(ERROR, TAG, "add has failed");
         CADestroyBlockID(data->blockDataId);
index 01e9d4d..d36d378 100644 (file)
@@ -50,7 +50,7 @@ CAResult_t CAAddNetworkType(CATransportAdapter_t transportType)
             return CA_MEMORY_ALLOC_FAILED;
         }
     }
-    CAResult_t res = CA_STATUS_OK;
+    bool res = true;
     switch (transportType)
     {
         case CA_ADAPTER_IP:
@@ -111,15 +111,15 @@ CAResult_t CAAddNetworkType(CATransportAdapter_t transportType)
             break;
     }
 
-    if (CA_STATUS_OK != res)
+    if (!res)
     {
         OIC_LOG_V(ERROR, TAG, "Add arraylist failed[Err code: %d]", res);
-        return res;
+        return CA_STATUS_FAILED;
     }
     // start selected interface adapter
-    res = CAStartAdapter(transportType);
+    CAResult_t result = CAStartAdapter(transportType);
     OIC_LOG(DEBUG, TAG, "OUT");
-    return res;
+    return result;
 
 exit:
     OIC_LOG(DEBUG, TAG, "This adapter is already enabled");
index 8353ecd..7896334 100755 (executable)
@@ -261,8 +261,8 @@ static CAResult_t CAAddInterfaceItem(u_arraylist_t *iflist, int index,
     {
         return CA_STATUS_FAILED;
     }
-    CAResult_t result = u_arraylist_add(iflist, ifitem);
-    if (CA_STATUS_OK != result)
+    bool result = u_arraylist_add(iflist, ifitem);
+    if (!result)
     {
         OIC_LOG(ERROR, TAG, "u_arraylist_add failed.");
         OICFree(ifitem);
index 7cbc691..06fca45 100644 (file)
@@ -74,7 +74,7 @@ void CAArduinoGetInterfaceAddress(uint32_t *address)
 
 u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex)
 {
-    CAResult_t result;
+    bool result = true;
 
     u_arraylist_t *iflist = u_arraylist_create();
     if (!iflist)
@@ -98,7 +98,7 @@ u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex)
     CAArduinoGetInterfaceAddress(&ifitem->ipv4addr);
 
     result = u_arraylist_add(iflist, ifitem);
-    if (CA_STATUS_OK != result)
+    if (!result)
     {
         OIC_LOG(ERROR, TAG, "u_arraylist_add failed.");
         goto exit;
index b2b3228..f35de3c 100644 (file)
@@ -78,7 +78,7 @@ void CAArduinoGetInterfaceAddress(uint32_t *address)
 
 u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex)
 {
-    CAResult_t result = CA_STATUS_OK;
+    bool result = true;
 
     u_arraylist_t *iflist = u_arraylist_create();
     if (!iflist)
@@ -102,7 +102,7 @@ u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex)
     CAArduinoGetInterfaceAddress(&ifitem->ipv4addr);
 
     result = u_arraylist_add(iflist, ifitem);
-    if (CA_STATUS_OK != result)
+    if (!result)
     {
         OIC_LOG(ERROR, TAG, "u_arraylist_add failed.");
         goto exit;
index 2b946da..fd889ee 100644 (file)
@@ -131,8 +131,8 @@ u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex)
         ifitem->ipv4addr = ((struct sockaddr_in *)(ifa->ifa_addr))->sin_addr.s_addr;
         ifitem->flags = ifa->ifa_flags;
 
-        CAResult_t result = u_arraylist_add(iflist, ifitem);
-        if (CA_STATUS_OK != result)
+        bool result = u_arraylist_add(iflist, ifitem);
+        if (!result)
         {
             OIC_LOG(ERROR, TAG, "u_arraylist_add failed.");
             goto exit;
index 1c4d279..b81b357 100644 (file)
@@ -112,8 +112,8 @@ u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex)
         ifitem->ipv4addr = ((struct sockaddr_in *)(ifa->ifa_addr))->sin_addr.s_addr;
         ifitem->flags = ifa->ifa_flags;
 
-        CAResult_t result = u_arraylist_add(iflist, ifitem);
-        if (CA_STATUS_OK != result)
+        bool result = u_arraylist_add(iflist, ifitem);
+        if (!result)
         {
             OIC_LOG(ERROR, TAG, "u_arraylist_add failed.");
             goto exit;