open62541 / open62541-nodeset-loader

Library for loading opc ua nodesets from xml and sorting the nodes
Mozilla Public License 2.0
27 stars 23 forks source link

Finding ParentId from a reference. #238

Open xydan83 opened 1 year ago

xydan83 commented 1 year ago

Hi again)) There is some code in import.c

Code num 1.

static NL_Reference *getHierachicalInverseReference(const NL_Node *node)
{

    NL_Reference *hierachicalRef = node->hierachicalRefs;
    while (hierachicalRef)
    {
        if (!hierachicalRef->isForward)
        {
            return hierachicalRef;
        }
        hierachicalRef = hierachicalRef->next;
    }
    return NULL;
}

And this code (num 2):

static UA_NodeId getParentId(const NL_Node *node, UA_NodeId *parentRefId)
{
    UA_NodeId parentId = UA_NODEID_NULL;

    if(NodesetLoader_isInstanceNode(node))
    {
        parentId = ((const NL_InstanceNode*)node)->parentNodeId;
    }
    NL_Reference *ref = getHierachicalInverseReference((const NL_Node *)node);
    *parentRefId = getReferenceTypeId(ref);
    if (UA_NodeId_equal(&parentId, &UA_NODEID_NULL))
    {
        parentId = getReferenceTarget(ref);
    }
    return parentId;
}

I have a question. If we can't find the ParentNodeId from ((const NL_InstanceNode*)node)->parentNodeId; and we need to find it by reference, we try to find it by the first inverse reference (code number 1). But the references are sorted before it or not?

matkonnerth commented 1 year ago

the first inverse hierachical reference is taken, they are not sorted