forked from gatsby/datalink_repo
miscellaneous update (enhance code coherence)
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
/***************************** Include Files *********************************/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "linklayer814_types.h"
|
||||
@@ -34,10 +35,16 @@ inline uint32_t L2_GetNodeListLen(NODE_LIST *list) {
|
||||
/************************** Variable Definitions *****************************/
|
||||
static NODE_ENTRY util_entry;
|
||||
/************************** Function Prototypes ******************************/
|
||||
/**
|
||||
* @brief helper function to free node entry.
|
||||
*/
|
||||
static void entry_free(void* val){
|
||||
free(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief helper function to match node entries by nodeIds
|
||||
*/
|
||||
static bool entry_match(void* a, void* b){
|
||||
ASSERT(a != NULL);
|
||||
ASSERT(b != NULL);
|
||||
@@ -64,11 +71,28 @@ int32_t L2_NodeList_Init(NODE_LIST **list) {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Clear all nodes in the node list, free allocated memory.
|
||||
*
|
||||
* @param list
|
||||
*NONE
|
||||
*
|
||||
******************************************************************************/
|
||||
void L2_NodeList_Clear(NODE_LIST *list){
|
||||
ASSERT(list != NULL);
|
||||
list_clear(list);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Completely destroy node list.
|
||||
*
|
||||
* @param list
|
||||
*
|
||||
* @return NONE
|
||||
*
|
||||
******************************************************************************/
|
||||
void L2_NodeList_Destroy(NODE_LIST *list){
|
||||
list_destroy(list);
|
||||
}
|
||||
@@ -153,7 +177,7 @@ NODE_ENTRY* L2_AppendNode(NODE_LIST *list, uint8_t nodeId, L2_NODE_TYPE nodeType
|
||||
* Other Node not exist.
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t L2_DeleteNode(NODE_LIST *list, uint8_t nodeId) {
|
||||
int32_t L2_DeleteNodeById(NODE_LIST *list, uint8_t nodeId) {
|
||||
ASSERT(list != NULL);
|
||||
util_entry.nodeInfo.nodeId = nodeId;
|
||||
list_node_t* node = list_find(list, &util_entry);
|
||||
@@ -177,7 +201,7 @@ int32_t L2_DeleteNode(NODE_LIST *list, uint8_t nodeId) {
|
||||
* false node not in the list
|
||||
*
|
||||
******************************************************************************/
|
||||
bool L2_IsNodeInList(NODE_LIST *list, uint8_t nodeId) {
|
||||
bool L2_isNodeInList(NODE_LIST *list, uint8_t nodeId) {
|
||||
ASSERT(list != NULL);
|
||||
return (L2_GetNodeById(list, nodeId) != NULL);
|
||||
}
|
||||
@@ -419,11 +443,11 @@ int32_t L2_IterEditNode(NODE_LIST *list, const void *param, int32_t (*operation)
|
||||
DBG_ERROR("Failed to initialize list iteration process.\n");
|
||||
return EALLOC;
|
||||
}
|
||||
while (iter->next != NULL)
|
||||
while ((node = list_iterator_next(iter)))
|
||||
{
|
||||
node = list_iterator_next(iter);
|
||||
Status = operation((NODE_ENTRY*)node->val, param);
|
||||
if(Status != SUCCESS){
|
||||
DBG_ERROR("Error occurred when iteratively edit node entry.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -450,13 +474,11 @@ int32_t L2_IterDeleteNode(NODE_LIST *list, bool (*condition)(NODE_ENTRY *)) {
|
||||
DBG_ERROR("Failed to initialize list iteration process.\n");
|
||||
return EALLOC;
|
||||
}
|
||||
while (iter->next != NULL)
|
||||
while ((node = list_iterator_next(iter)))
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -46,7 +46,7 @@ void L2_NodeList_Destroy(NODE_LIST *list);
|
||||
uint32_t L2_GetNodeListLen(NODE_LIST *list);
|
||||
NODE_ENTRY* L2_GetNodeById(NODE_LIST *list, uint8_t nodeId);
|
||||
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_DeleteNodeById(NODE_LIST *list, uint8_t nodeId);
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user