forked from gatsby/datalink_repo
rewrite node list (base on util list).
This commit is contained in:
@@ -16,23 +16,34 @@
|
|||||||
|
|
||||||
/***************************** Include Files *********************************/
|
/***************************** Include Files *********************************/
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include "linklayer814_types.h"
|
#include "linklayer814_types.h"
|
||||||
#include "node_list.h"
|
#include "node_list.h"
|
||||||
|
#include "../util/list.h"
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
#include "../error.h"
|
#include "../error.h"
|
||||||
|
|
||||||
/***************** Macros (Inline Functions) Definitions *********************/
|
/***************** Macros (Inline Functions) Definitions *********************/
|
||||||
inline int32_t GetNodeNum(NODE_LIST *list) {
|
inline uint32_t L2_GetNodeListLen(NODE_LIST *list) {
|
||||||
ASSERT(list != NULL);
|
ASSERT(list != NULL);
|
||||||
return list->nodeNum;
|
return list->len;
|
||||||
}
|
}
|
||||||
/**************************** Type Definitions *******************************/
|
/**************************** Type Definitions *******************************/
|
||||||
|
|
||||||
/************************** Variable Definitions *****************************/
|
/************************** Variable Definitions *****************************/
|
||||||
|
static NODE_ENTRY util_entry;
|
||||||
/************************** Function Prototypes ******************************/
|
/************************** Function Prototypes ******************************/
|
||||||
|
static void entry_free(void* val){
|
||||||
|
free(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool entry_match(void* a, void* b){
|
||||||
|
ASSERT(a == NULL);
|
||||||
|
ASSERT(b != NULL);
|
||||||
|
return (((NODE_ENTRY*)a)->nodeInfo.nodeId
|
||||||
|
== ((NODE_ENTRY*)b)->nodeInfo.nodeId);
|
||||||
|
}
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/**
|
/**
|
||||||
* @brief Initialize node list
|
* @brief Initialize node list
|
||||||
@@ -43,47 +54,23 @@ inline int32_t GetNodeNum(NODE_LIST *list) {
|
|||||||
* ENOMEM - not enough memory.
|
* ENOMEM - not enough memory.
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
int32_t NodeList_Init(NODE_LIST **list) {
|
int32_t L2_NodeList_Init(NODE_LIST **list) {
|
||||||
NODE_ENTRY *entry;
|
(*list) = list_new();
|
||||||
(*list) = malloc(sizeof(NODE_LIST));
|
|
||||||
if (*list == NULL) {
|
if (*list == NULL) {
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
entry = malloc(sizeof(NODE_ENTRY));
|
(*list)->free = entry_free;
|
||||||
if(entry == NULL) {
|
(*list)->match = entry_match;
|
||||||
free(*list);
|
|
||||||
return ENOMEM;
|
|
||||||
}
|
|
||||||
entry->nodeInfo.nodeId = 0;
|
|
||||||
entry->nextNode = entry;
|
|
||||||
entry->preNode = entry;
|
|
||||||
(*list)->head = entry;
|
|
||||||
(*list)->nodeNum = 0;
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeList_Clear(NODE_LIST *list){
|
void L2_NodeList_Clear(NODE_LIST *list){
|
||||||
ASSERT(list != NULL);
|
ASSERT(list != NULL);
|
||||||
NODE_ENTRY *nodeEntry, *deletEntry;
|
list_clear(list);
|
||||||
nodeEntry = list->head->nextNode;
|
|
||||||
while (nodeEntry != list->head) {
|
|
||||||
deletEntry = nodeEntry;
|
|
||||||
nodeEntry = nodeEntry->nextNode;
|
|
||||||
deletEntry->preNode->nextNode = deletEntry->nextNode;
|
|
||||||
deletEntry->nextNode->preNode = deletEntry->preNode;
|
|
||||||
DBG_INFO("Deleting node [%d].\n", deletEntry->nodeInfo.nodeId);
|
|
||||||
free(deletEntry);
|
|
||||||
list->nodeNum--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeList_Destroy(NODE_LIST *list){
|
void L2_NodeList_Destroy(NODE_LIST *list){
|
||||||
if(list == NULL){
|
list_destroy(list);
|
||||||
return;
|
|
||||||
}
|
|
||||||
NodeList_Clear(list);
|
|
||||||
free(list->head);
|
|
||||||
free(list);
|
|
||||||
}
|
}
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/**
|
/**
|
||||||
@@ -96,40 +83,19 @@ void NodeList_Destroy(NODE_LIST *list){
|
|||||||
* NULL if node dose not exist.
|
* NULL if node dose not exist.
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
NODE_ENTRY* GetNode(NODE_LIST *list, uint32_t nodeId) {
|
NODE_ENTRY* L2_GetNodeById(NODE_LIST *list, uint8_t nodeId) {
|
||||||
ASSERT(list != NULL);
|
ASSERT(list != NULL);
|
||||||
NODE_ENTRY* nodeEntry = list->head->nextNode;
|
util_entry.nodeInfo.nodeId = nodeId;
|
||||||
while (nodeEntry != list->head) {
|
list_node_t* node = list_find(list, &util_entry);
|
||||||
if (nodeEntry->nodeInfo.nodeId == nodeId) {
|
if(node == NULL) {
|
||||||
break;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
nodeEntry = nodeEntry->nextNode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (nodeEntry == list->head) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return nodeEntry;
|
return ((NODE_ENTRY*) node->val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/**
|
|
||||||
* @brief Check whether the node is already in the node list.
|
|
||||||
*
|
|
||||||
* @param list
|
|
||||||
* @param nodeId
|
|
||||||
*
|
|
||||||
* @return true node in the list
|
|
||||||
* false node not in the list
|
|
||||||
*
|
|
||||||
******************************************************************************/
|
|
||||||
inline bool IsNodeInList(NODE_LIST *list, uint8_t nodeId) {
|
|
||||||
ASSERT(list != NULL);
|
|
||||||
return (GetNode(list, nodeId) != NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/**
|
/**
|
||||||
@@ -143,20 +109,27 @@ inline bool IsNodeInList(NODE_LIST *list, uint8_t nodeId) {
|
|||||||
* Other Error occurred.(Node already exist, memory alloc error ect.)
|
* Other Error occurred.(Node already exist, memory alloc error ect.)
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
int32_t AppendNode(NODE_LIST *list, uint8_t nodeId, L2_NODE_TYPE nodeType)
|
NODE_ENTRY* L2_AppendNode(NODE_LIST *list, uint8_t nodeId, L2_NODE_TYPE nodeType)
|
||||||
{
|
{
|
||||||
ASSERT(list != NULL);
|
ASSERT(list != NULL);
|
||||||
if(IsNodeInList(list, nodeId)){
|
if(L2_isNodeInList(list, nodeId)){
|
||||||
DBG_WARNING("Node [%d] already exist.\n", nodeId);
|
DBG_WARNING("Node [%d] already exist.\n", nodeId);
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
DBG_INFO("Link layer appending node [%d] to node list.\n", nodeId);
|
DBG_INFO("Link layer appending node [%d] to node list.\n", nodeId);
|
||||||
NODE_ENTRY* nodeEntry = (NODE_ENTRY*) malloc(sizeof(NODE_ENTRY));
|
NODE_ENTRY* nodeEntry = (NODE_ENTRY*) malloc(sizeof(NODE_ENTRY));
|
||||||
if (nodeEntry == NULL) {
|
if (nodeEntry == NULL) {
|
||||||
|
DBG_ERROR("Failed to allocated memory for nodeEntry.\n");
|
||||||
|
return ENOMEM;
|
||||||
|
}
|
||||||
|
list_node_t* node = list_node_new(nodeEntry);
|
||||||
|
if(node == NULL) {
|
||||||
|
DBG_ERROR("Failed to allocated memory for list node.\n");
|
||||||
|
free(nodeEntry);
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
nodeEntry->nodeInfo.nodeId = nodeId;
|
nodeEntry->nodeInfo.nodeId = nodeId;
|
||||||
nodeEntry->nodeInfo.nodeType = (uint8_t) nodeType;
|
nodeEntry->nodeInfo.nodeType = (uint8_t)nodeType;
|
||||||
nodeEntry->nodeInfo.pos.x = 0;
|
nodeEntry->nodeInfo.pos.x = 0;
|
||||||
nodeEntry->nodeInfo.pos.y = 0;
|
nodeEntry->nodeInfo.pos.y = 0;
|
||||||
nodeEntry->nodeInfo.pos.z = 0;
|
nodeEntry->nodeInfo.pos.z = 0;
|
||||||
@@ -165,12 +138,6 @@ int32_t AppendNode(NODE_LIST *list, uint8_t nodeId, L2_NODE_TYPE nodeType)
|
|||||||
nodeEntry->nodeInfo.speed.z = 0;
|
nodeEntry->nodeInfo.speed.z = 0;
|
||||||
nodeEntry->nodeInfo.beamNo = 0;
|
nodeEntry->nodeInfo.beamNo = 0;
|
||||||
nodeEntry->ttlCnt = 0;
|
nodeEntry->ttlCnt = 0;
|
||||||
|
|
||||||
nodeEntry->nextNode = list->head;
|
|
||||||
nodeEntry->preNode = list->head->nextNode;
|
|
||||||
list->head->nextNode = nodeEntry;
|
|
||||||
|
|
||||||
list->nodeNum++;
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,21 +152,34 @@ int32_t AppendNode(NODE_LIST *list, uint8_t nodeId, L2_NODE_TYPE nodeType)
|
|||||||
* Other Node not exist.
|
* Other Node not exist.
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
int32_t DeletNode(NODE_LIST *list, uint8_t nodeId) {
|
int32_t L2_DeleteNode(NODE_LIST *list, uint8_t nodeId) {
|
||||||
ASSERT(list != NULL);
|
ASSERT(list != NULL);
|
||||||
NODE_ENTRY* nodeEntry = GetNode(list, nodeId);
|
util_entry.nodeInfo.nodeId = nodeId;
|
||||||
if(nodeEntry == NULL){
|
list_node_t* node = list_find(list, &util_entry);
|
||||||
|
if(node == NULL) {
|
||||||
DBG_WARNING("Node [%d] in not in node list, skip deleting process.\n", nodeId);
|
DBG_WARNING("Node [%d] in not in node list, skip deleting process.\n", nodeId);
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
nodeEntry->preNode->nextNode = nodeEntry->nextNode;
|
|
||||||
nodeEntry->nextNode->preNode = nodeEntry->preNode;
|
|
||||||
DBG_INFO("Deleting node [%d].\n", nodeId);
|
DBG_INFO("Deleting node [%d].\n", nodeId);
|
||||||
free(nodeEntry);
|
list_remove(list, node);
|
||||||
list->nodeNum--;
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/**
|
||||||
|
* @brief Check whether the node is already in the node list.
|
||||||
|
*
|
||||||
|
* @param list
|
||||||
|
* @param nodeId
|
||||||
|
*
|
||||||
|
* @return true node in the list
|
||||||
|
* false node not in the list
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
bool L2_IsNodeInList(NODE_LIST *list, uint8_t nodeId) {
|
||||||
|
ASSERT(list != NULL);
|
||||||
|
return (L2_GetNodeById(list, nodeId) != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/**
|
/**
|
||||||
@@ -214,9 +194,9 @@ int32_t DeletNode(NODE_LIST *list, uint8_t nodeId) {
|
|||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
int32_t GetDistance(NODE_LIST *list, COORD myCoord, uint8_t nodeId, double* dst) {
|
int32_t L2_GetDistance(NODE_LIST *list, COORD myCoord, uint8_t nodeId, double* dst) {
|
||||||
ASSERT(list != NULL);
|
ASSERT(list != NULL);
|
||||||
NODE_ENTRY* nodeEntry = GetNode(list, nodeId);
|
NODE_ENTRY* nodeEntry = L2_GetNodeById(list, nodeId);
|
||||||
if (nodeEntry == NULL) {
|
if (nodeEntry == NULL) {
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
@@ -238,9 +218,9 @@ int32_t GetDistance(NODE_LIST *list, COORD myCoord, uint8_t nodeId, double* dst)
|
|||||||
* FAILURE node not exist.
|
* FAILURE node not exist.
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
int32_t UpdateNodePos(NODE_LIST *list, uint8_t nodeId, const COORD *newPos) {
|
int32_t L2_UpdateNodePos(NODE_LIST *list, uint8_t nodeId, const COORD *newPos) {
|
||||||
ASSERT(list != NULL);
|
ASSERT(list != NULL);
|
||||||
NODE_ENTRY* nodeEntry = GetNode(list, nodeId);
|
NODE_ENTRY* nodeEntry = L2_GetNodeById(list, nodeId);
|
||||||
if (nodeEntry == NULL) {
|
if (nodeEntry == NULL) {
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
@@ -263,9 +243,9 @@ int32_t UpdateNodePos(NODE_LIST *list, uint8_t nodeId, const COORD *newPos) {
|
|||||||
* FAILURE node not exist.
|
* FAILURE node not exist.
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
int32_t GetNodePos(NODE_LIST *list, uint8_t nodeId, COORD *pos) {
|
int32_t L2_GetNodePos(NODE_LIST *list, uint8_t nodeId, COORD *pos) {
|
||||||
ASSERT(list != NULL);
|
ASSERT(list != NULL);
|
||||||
NODE_ENTRY* nodeEntry = GetNode(list, nodeId);
|
NODE_ENTRY* nodeEntry = L2_GetNodeById(list, nodeId);
|
||||||
if (nodeEntry == NULL) {
|
if (nodeEntry == NULL) {
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
@@ -287,9 +267,9 @@ int32_t GetNodePos(NODE_LIST *list, uint8_t nodeId, COORD *pos) {
|
|||||||
* FAILURE node not exist.
|
* FAILURE node not exist.
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
int32_t UpdateNodeSpeed(NODE_LIST *list, uint8_t nodeId, const COORD *newSpeed) {
|
int32_t L2_UpdateNodeSpeed(NODE_LIST *list, uint8_t nodeId, const COORD *newSpeed) {
|
||||||
ASSERT(list != NULL);
|
ASSERT(list != NULL);
|
||||||
NODE_ENTRY* nodeEntry = GetNode(list, nodeId);
|
NODE_ENTRY* nodeEntry = L2_GetNodeById(list, nodeId);
|
||||||
if (nodeEntry == NULL) {
|
if (nodeEntry == NULL) {
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
@@ -312,9 +292,9 @@ int32_t UpdateNodeSpeed(NODE_LIST *list, uint8_t nodeId, const COORD *newSpeed)
|
|||||||
* FAILURE node not exist.
|
* FAILURE node not exist.
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
int32_t GetNodeSpeed(NODE_LIST *list, uint8_t nodeId, COORD *speed) {
|
int32_t L2_GetNodeSpeed(NODE_LIST *list, uint8_t nodeId, COORD *speed) {
|
||||||
ASSERT(list != NULL);
|
ASSERT(list != NULL);
|
||||||
NODE_ENTRY* nodeEntry = GetNode(list, nodeId);
|
NODE_ENTRY* nodeEntry = L2_GetNodeById(list, nodeId);
|
||||||
if (nodeEntry == NULL) {
|
if (nodeEntry == NULL) {
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
@@ -335,9 +315,9 @@ int32_t GetNodeSpeed(NODE_LIST *list, uint8_t nodeId, COORD *speed) {
|
|||||||
* FAILURE Node not exist.
|
* FAILURE Node not exist.
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
int32_t UpdateNodeTimeDeviation(NODE_LIST *list, uint8_t nodeId, int32_t devi) {
|
int32_t L2_UpdateNodeTimeDeviation(NODE_LIST *list, uint8_t nodeId, int32_t devi) {
|
||||||
ASSERT(list != NULL);
|
ASSERT(list != NULL);
|
||||||
NODE_ENTRY* nodeEntry = GetNode(list, nodeId);
|
NODE_ENTRY* nodeEntry = L2_GetNodeById(list, nodeId);
|
||||||
if (nodeEntry == NULL) {
|
if (nodeEntry == NULL) {
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
@@ -358,9 +338,9 @@ int32_t UpdateNodeTimeDeviation(NODE_LIST *list, uint8_t nodeId, int32_t devi) {
|
|||||||
* @return NONE
|
* @return NONE
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
int32_t IncNodeTTL(NODE_LIST *list, uint8_t nodeId, uint32_t inc) {
|
int32_t L2_IncNodeTTL(NODE_LIST *list, uint8_t nodeId, uint32_t inc) {
|
||||||
ASSERT(list != NULL);
|
ASSERT(list != NULL);
|
||||||
NODE_ENTRY* nodeEntry = GetNode(list, nodeId);
|
NODE_ENTRY* nodeEntry = L2_GetNodeById(list, nodeId);
|
||||||
if (nodeEntry == NULL) {
|
if (nodeEntry == NULL) {
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
@@ -381,9 +361,9 @@ int32_t IncNodeTTL(NODE_LIST *list, uint8_t nodeId, uint32_t inc) {
|
|||||||
* FAILURE Node not exist.
|
* FAILURE Node not exist.
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
int32_t RstNodeTTL(NODE_LIST *list, uint8_t nodeId) {
|
int32_t L2_RstNodeTTL(NODE_LIST *list, uint8_t nodeId) {
|
||||||
ASSERT(list != NULL);
|
ASSERT(list != NULL);
|
||||||
NODE_ENTRY* nodeEntry = GetNode(list, nodeId);
|
NODE_ENTRY* nodeEntry = L2_GetNodeById(list, nodeId);
|
||||||
if (nodeEntry == NULL) {
|
if (nodeEntry == NULL) {
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
@@ -404,9 +384,9 @@ int32_t RstNodeTTL(NODE_LIST *list, uint8_t nodeId) {
|
|||||||
* @return NONE
|
* @return NONE
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
int32_t GetNodeTTL(NODE_LIST *list, uint8_t nodeId, uint32_t *ttl) {
|
int32_t L2_GetNodeTTL(NODE_LIST *list, uint8_t nodeId, uint32_t *ttl) {
|
||||||
ASSERT(list != NULL);
|
ASSERT(list != NULL);
|
||||||
NODE_ENTRY* nodeEntry = GetNode(list, nodeId);
|
NODE_ENTRY* nodeEntry = L2_GetNodeById(list, nodeId);
|
||||||
if (nodeEntry == NULL) {
|
if (nodeEntry == NULL) {
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
@@ -429,17 +409,24 @@ int32_t GetNodeTTL(NODE_LIST *list, uint8_t nodeId, uint32_t *ttl) {
|
|||||||
* Other Error occurred.
|
* Other Error occurred.
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
int32_t IterEditNode(NODE_LIST *list, const void *param, int32_t (*operation)(NODE_ENTRY *, const void *)) {
|
int32_t L2_IterEditNode(NODE_LIST *list, const void *param, int32_t (*operation)(NODE_ENTRY *, const void *)) {
|
||||||
ASSERT(list != NULL);
|
ASSERT(list != NULL);
|
||||||
int32_t Status = SUCCESS;
|
int32_t Status;
|
||||||
NODE_ENTRY *nodeEntry = list->head->nextNode;
|
list_node_t* node;
|
||||||
while (nodeEntry != list->head) {
|
list_iterator_t* iter = list_iterator_new(list, LIST_HEAD);
|
||||||
Status = operation(nodeEntry, param);
|
if(iter == NULL) {
|
||||||
|
DBG_ERROR("Failed to initialize list iteration process.\n");
|
||||||
|
return EALLOC;
|
||||||
|
}
|
||||||
|
while (iter->next != NULL)
|
||||||
|
{
|
||||||
|
node = list_iterator_next(iter);
|
||||||
|
Status = operation((NODE_ENTRY*)node->val, param);
|
||||||
if(Status != SUCCESS){
|
if(Status != SUCCESS){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
nodeEntry = nodeEntry->nextNode;
|
|
||||||
}
|
}
|
||||||
|
list_iterator_destroy(iter);
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -454,24 +441,23 @@ int32_t IterEditNode(NODE_LIST *list, const void *param, int32_t (*operation)(NO
|
|||||||
* @return SUCCESS
|
* @return SUCCESS
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
int32_t IterDeleteNode(NODE_LIST *list, bool (*condition)(NODE_ENTRY *)) {
|
int32_t L2_IterDeleteNode(NODE_LIST *list, bool (*condition)(NODE_ENTRY *)) {
|
||||||
ASSERT(list != NULL);
|
ASSERT(list != NULL);
|
||||||
NODE_ENTRY *nodeEntry, *deletEntry;
|
list_node_t* node;
|
||||||
nodeEntry = list->head->nextNode;
|
list_iterator_t* iter = list_iterator_new(list, LIST_HEAD);
|
||||||
while (nodeEntry != list->head) {
|
if(iter == NULL) {
|
||||||
if (condition(nodeEntry) == false) {
|
DBG_ERROR("Failed to initialize list iteration process.\n");
|
||||||
deletEntry = nodeEntry;
|
return EALLOC;
|
||||||
nodeEntry = nodeEntry->nextNode;
|
|
||||||
deletEntry->preNode->nextNode = deletEntry->nextNode;
|
|
||||||
deletEntry->nextNode->preNode = deletEntry->preNode;
|
|
||||||
DBG_INFO("Deleting node [%d].\n", deletEntry->nodeInfo.nodeId);
|
|
||||||
free(deletEntry);
|
|
||||||
list->nodeNum--;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
nodeEntry = nodeEntry->nextNode;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
while (iter->next != NULL)
|
||||||
|
{
|
||||||
|
node = list_iterator_next(iter);
|
||||||
|
if (condition((NODE_ENTRY*) node->val) == false) {
|
||||||
|
list_remove(list, node);
|
||||||
|
}
|
||||||
|
node = list_iterator_next(iter);
|
||||||
|
}
|
||||||
|
list_iterator_destroy(iter);
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,16 +48,15 @@ NODE_ENTRY* L2_GetNodeById(NODE_LIST *list, uint8_t nodeId);
|
|||||||
NODE_ENTRY* L2_AppendNode(NODE_LIST *list, uint8_t nodeId, L2_NODE_TYPE nodeType);
|
NODE_ENTRY* L2_AppendNode(NODE_LIST *list, uint8_t nodeId, L2_NODE_TYPE nodeType);
|
||||||
int32_t L2_DeleteNode(NODE_LIST *list, uint8_t nodeId);
|
int32_t L2_DeleteNode(NODE_LIST *list, uint8_t nodeId);
|
||||||
int32_t L2_UpdateNodePos(NODE_LIST *list, uint8_t nodeId, const COORD *newPos);
|
int32_t L2_UpdateNodePos(NODE_LIST *list, uint8_t nodeId, const COORD *newPos);
|
||||||
|
bool L2_isNodeInList(NODE_LIST *list, uint8_t nodeId);
|
||||||
int32_t L2_GetNodePos(NODE_LIST *list, uint8_t nodeId, COORD *newPos);
|
int32_t L2_GetNodePos(NODE_LIST *list, uint8_t nodeId, COORD *newPos);
|
||||||
int32_t L2_UpdateNodeSpeed(NODE_LIST *list, uint8_t nodeId, const COORD *newSpeed);
|
int32_t L2_UpdateNodeSpeed(NODE_LIST *list, uint8_t nodeId, const COORD *newSpeed);
|
||||||
int32_t L2_GetNodeSpeed(NODE_LIST *list, uint8_t nodeId, COORD *speed);
|
int32_t L2_GetNodeSpeed(NODE_LIST *list, uint8_t nodeId, COORD *speed);
|
||||||
int32_t L2_UpdateNodeTimeDeviation(NODE_LIST *list, uint8_t nodeId, int32_t devi);
|
int32_t L2_UpdateNodeTimeDeviation(NODE_LIST *list, uint8_t nodeId, int32_t devi);
|
||||||
int32_t L2_GetDistance(NODE_LIST *list, COORD myCoord, uint8_t nodeId, double* dst);
|
int32_t L2_GetDistance(NODE_LIST *list, COORD myCoord, uint8_t nodeId, double* dst);
|
||||||
int32_t L2_GetNodeNum(NODE_LIST *list);
|
|
||||||
int32_t L2_RstNodeTTL(NODE_LIST *list, uint8_t nodeId);
|
int32_t L2_RstNodeTTL(NODE_LIST *list, uint8_t nodeId);
|
||||||
int32_t L2_IncNodeTTL(NODE_LIST *list, uint8_t nodeId, uint32_t inc);
|
int32_t L2_IncNodeTTL(NODE_LIST *list, uint8_t nodeId, uint32_t inc);
|
||||||
int32_t L2_GetNodeTTL(NODE_LIST *list, uint8_t nodeId, uint32_t *ttl);
|
int32_t L2_GetNodeTTL(NODE_LIST *list, uint8_t nodeId, uint32_t *ttl);
|
||||||
bool L2_IsNodeInList(NODE_LIST *list, uint8_t nodeId);
|
|
||||||
int32_t L2_IterEditNode(NODE_LIST *list, const void *param, int32_t (*operation)(NODE_ENTRY*, const void*));
|
int32_t L2_IterEditNode(NODE_LIST *list, const void *param, int32_t (*operation)(NODE_ENTRY*, const void*));
|
||||||
int32_t L2_IterDeleteNode(NODE_LIST *list, bool (*condition)(NODE_ENTRY *));
|
int32_t L2_IterDeleteNode(NODE_LIST *list, bool (*condition)(NODE_ENTRY *));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user