/**
* array list structure.
+ *
+ * @note
+ * Members should be treated as private and not accessed directly. Instead
+ * all access should be through the defined u_arraylist_*() functions.
*/
typedef struct u_arraylist_t
{
void CAEDRReorderingDeviceList(uint32_t index)
{
- if (index >= g_deviceStateList->length)
- {
- return;
- }
-
- if (index < g_deviceStateList->length - 1)
- {
- memmove(&g_deviceStateList->data[index], &g_deviceStateList->data[index + 1],
- (g_deviceStateList->length - index - 1) * sizeof(void *));
- }
-
- g_deviceStateList->size--;
- g_deviceStateList->length--;
+ u_arraylist_remove(g_deviceStateList, index);
}
/**
void CAEDRReorderingDeviceSocketList(uint32_t index)
{
- if (index >= g_deviceObjectList->length)
- {
- return;
- }
-
- if (index < g_deviceObjectList->length - 1)
- {
- memmove(&g_deviceObjectList->data[index], &g_deviceObjectList->data[index + 1],
- (g_deviceObjectList->length - index - 1) * sizeof(void *));
- }
-
- g_deviceObjectList->size--;
- g_deviceObjectList->length--;
+ u_arraylist_remove(g_deviceObjectList, index);
}
CAResult_t CALEClientReorderingList(uint32_t index, u_arraylist_t *list)
{
- if (!list)
+ if (u_arraylist_remove(list, index) == NULL)
{
- OIC_LOG(ERROR, TAG, "list is null");
+ OIC_LOG(ERROR, TAG, "List removal failed.");
return CA_STATUS_FAILED;
}
-
- if (index >= list->length)
- {
- OIC_LOG(ERROR, TAG, "index is not available");
- return CA_STATUS_FAILED;
- }
-
- if (index < list->length - 1)
+ else
{
- memmove(&list->data[index], &list->data[index + 1],
- (list->length - index - 1) * sizeof(void *));
+ return CA_STATUS_OK;
}
-
- list->size--;
- list->length--;
-
- return CA_STATUS_OK;
}
/**
CAResult_t CALEServerReorderinglist(uint32_t index)
{
- if (!g_connectedDeviceList)
- {
- OIC_LOG(ERROR, TAG, "g_connectedDeviceList is null");
- return CA_STATUS_FAILED;
- }
-
- if (index >= g_connectedDeviceList->length)
+ if (u_arraylist_remove(g_connectedDeviceList, index) == NULL)
{
- OIC_LOG(ERROR, TAG, "index is not available");
+ OIC_LOG(ERROR, TAG, "List removal failed.");
return CA_STATUS_FAILED;
}
-
- if (index < g_connectedDeviceList->length - 1)
+ else
{
- memmove(&g_connectedDeviceList->data[index], &g_connectedDeviceList->data[index + 1],
- (g_connectedDeviceList->length - index - 1) * sizeof(void *));
+ return CA_STATUS_OK;
}
-
- g_connectedDeviceList->size--;
- g_connectedDeviceList->length--;
-
- return CA_STATUS_OK;
}
JNIEXPORT void JNICALL
static bool CAIsSelectedNetworkAvailable()
{
u_arraylist_t *list = CAGetSelectedNetworkList();
- if (!list || list->length == 0)
+ if (!list || u_arraylist_length(list) == 0)
{
OIC_LOG(ERROR, TAG, "No selected network");
return false;