bazza2jw / open62541Cpp

C++ Wrappers for Open62541 Version 0.3
35 stars 21 forks source link

addObjectType.... does not return new Node ID when "mandatory" is set to true (default) #17

Open manfredholl opened 2 years ago

manfredholl commented 2 years ago

I'm currently evaluating your solution for a personal project, thanks for all your hard work. I noticed that the methods ServerObjectType:: addObjectTypeVariable addObjectTypeArrayVariable addObjectTypeFolder addHistoricalObjectTypeVariable

will not return the new node ID, when the "mandatory" parameter is true.

The code pattern is identical in all methods:

        if (_server.addVariableNode(...) {
            if (mandatory) {
                return _server.addReference(....);
            }
            if (!nodeId.isNull())
                nodeId = newNode;
            return true;
        }

So if mandatory is set it will return without doing the assignment "nodeId = newNode;". Generally suggest using "return early" pattern only for unsuccessful return, i.e. there is only one successful return point at the end of the function, all other early returns are "false".

bazza2jw commented 2 years ago

I think it is correct. If an entry is not mandatory then an empty, but non-null node is returned.