Skip to content

Commit

Permalink
check if sort algorithm if nodeId already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
matkonnerth committed Nov 19, 2024
1 parent a0fa8cb commit 78ca915
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
19 changes: 15 additions & 4 deletions src/Nodeset.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions src/Sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/Sort.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 78ca915

Please sign in to comment.