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>
#define U_ARRAYLIST_H_
#include <stdint.h>
-#include "cacommon.h"
+#include <stdbool.h>
#ifdef __cplusplus
extern "C"
* 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.
* 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.
}
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");
}
}
- 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);
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)
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 *));
list->data[list->length] = data;
list->length++;
- return CA_STATUS_OK;
+ return true;
}
void *u_arraylist_remove(u_arraylist_t *list, uint32_t index)
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);
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!");
}
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);
return CA_MEMORY_ALLOC_FAILED;
}
}
- CAResult_t res = CA_STATUS_OK;
+ bool res = true;
switch (transportType)
{
case CA_ADAPTER_IP:
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");
{
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);
u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex)
{
- CAResult_t result;
+ bool result = true;
u_arraylist_t *iflist = u_arraylist_create();
if (!iflist)
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;
u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex)
{
- CAResult_t result = CA_STATUS_OK;
+ bool result = true;
u_arraylist_t *iflist = u_arraylist_create();
if (!iflist)
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;
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;
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;