Browse Source

Fixed multiple reference problem caused by UA_Server_addReference in addNode function implicitly adding reverse references.

Chris Iatrou 9 years ago
parent
commit
01f7eb9811
2 changed files with 11 additions and 1 deletions
  1. 1 0
      tools/pyUANamespace/open62541_MacroHelper.py
  2. 10 1
      tools/pyUANamespace/ua_node_types.py

+ 1 - 0
tools/pyUANamespace/open62541_MacroHelper.py

@@ -94,6 +94,7 @@ class open62541_MacroHelper():
     elif node.nodeClass() == NODE_CLASS_VARIABLE:
       code.append("UA_Server_addVariableNode(server,")
     elif node.nodeClass() == NODE_CLASS_METHOD:
+      code.append("#ifdef ENABLE_METHODCALL")
       code.append("UA_Server_addMethodNode(server,")
     elif node.nodeClass() == NODE_CLASS_OBJECTTYPE:
       code.append("UA_Server_addObjectTypeNode(server,")

+ 10 - 1
tools/pyUANamespace/ua_node_types.py

@@ -143,7 +143,8 @@ class opcua_referencePointer_t():
       return -1
     if other.target() == self.target():
       if other.referenceType() == self.referenceType():
-        return 0
+        if other.isForward() == self.isForward():
+	  return 0
     return 1
 
 
@@ -667,9 +668,17 @@ class opcua_node_t:
       code = code + codegen.getCreateNodeNoBootstrap(self, parentNode, parentRef)
       code = code + self.printOpen62541CCode_Subtype(bootstrapping = False)
       code.append("       UA_NULL);") # createdNodeId, wraps up the UA_Server_add<XYType>Node() call
+      if self.nodeClass() == NODE_CLASS_METHOD:
+	code.append("#endif //ENABLE_METHODCALL") # ifdef added by codegen when methods are detected
       # Parent to child reference is added by the server, do not reprint that reference
       if parentRef in unPrintedReferences:
         unPrintedReferences.remove(parentRef)
+      # the UA_Server_addNode function will use addReference which creates a biderectional reference; remove any inverse
+      # references to our parent to avoid duplicate refs
+      for ref in self.getReferences():
+	if ref.target() == parentNode and ref.referenceType() == parentRef.referenceType() and ref.isForward() == False:
+	  while ref in unPrintedReferences:
+	    unPrintedReferences.remove(ref)
     # Otherwise use the "Bootstrapping" method and we will get registered with other nodes later.
     else:
       code = code + self.printOpen62541CCode_SubtypeEarly(bootstrapping = True)