diff --git a/src/Nodeset.c b/src/Nodeset.c index ac86e3c..a3b3c88 100644 --- a/src/Nodeset.c +++ b/src/Nodeset.c @@ -496,11 +496,22 @@ void Nodeset_newNodeFinish(Nodeset *nodeset, NL_Node *node) { if (!node->unknownRefs) { - Sort_addNode(nodeset->sortCtx, node); - if (node->nodeClass == NODECLASS_REFERENCETYPE) + if(!Sort_addNode(nodeset->sortCtx, node)) + { + if (nodeset->logger) + { + nodeset->logger->log(nodeset->logger->context, NODESETLOADER_LOGLEVEL_ERROR, + "node was not added to sorting algorithm, already exists"); + } + Node_delete(node); + } + else { - nodeset->refService->addNewReferenceType( - nodeset->refService->context, (NL_ReferenceTypeNode *)node); + if (node->nodeClass == NODECLASS_REFERENCETYPE) + { + nodeset->refService->addNewReferenceType( + nodeset->refService->context, (NL_ReferenceTypeNode *)node); + } } } else diff --git a/src/Sort.c b/src/Sort.c index f5abc12..9ee81c3 100644 --- a/src/Sort.c +++ b/src/Sort.c @@ -279,10 +279,15 @@ void Sort_cleanup(SortContext *ctx) free(ctx); } -void Sort_addNode(SortContext *ctx, NL_Node *data) { +bool Sort_addNode(SortContext *ctx, NL_Node *data) { S_Node *j = NULL; // add node, no matter if there are references on it j = search_node(ctx->root1, &data->id); + // entry already exists + if(j->data!=NULL) + { + return false; + } j->data = data; NL_Reference *hierachicalRef = data->hierachicalRefs; bool hierachicalRefRecorded = false; @@ -303,7 +308,7 @@ void Sort_addNode(SortContext *ctx, NL_Node *data) { NL_InstanceNode *instanceNode = (NL_InstanceNode *)data; if(UA_NodeId_equal(&instanceNode->parentNodeId, &UA_NODEID_NULL)) { - return; + return true; } S_Node *k = search_node(ctx->root1, &instanceNode->parentNodeId); @@ -339,6 +344,7 @@ void Sort_addNode(SortContext *ctx, NL_Node *data) { data->hierachicalRefs = newRef; } } + return true; } bool Sort_start(SortContext *ctx, struct Nodeset *nodeset, diff --git a/src/Sort.h b/src/Sort.h index 10e38f2..047172f 100644 --- a/src/Sort.h +++ b/src/Sort.h @@ -22,7 +22,7 @@ struct NodesetLoader_Logger; typedef struct SortContext SortContext; SortContext* Sort_init(void); void Sort_cleanup(SortContext * ctx); -void Sort_addNode(SortContext* ctx, struct NL_Node *node); +bool Sort_addNode(SortContext* ctx, struct NL_Node *node); typedef void (*Sort_SortedNodeCallback)(struct Nodeset *nodeset, struct NL_Node *node); bool Sort_start(SortContext* ctx, struct Nodeset *nodeset, Sort_SortedNodeCallback callback, struct NodesetLoader_Logger* logger);