backend_open62541_nodes.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ###
  4. ### Author: Chris Iatrou (ichrispa@core-vector.net)
  5. ### Version: rev 13
  6. ###
  7. ### This program was created for educational purposes and has been
  8. ### contributed to the open62541 project by the author. All licensing
  9. ### terms for this source is inherited by the terms and conditions
  10. ### specified for by the open62541 project (see the projects readme
  11. ### file for more information on the LGPL terms and restrictions).
  12. ###
  13. ### This program is not meant to be used in a production environment. The
  14. ### author is not liable for any complications arising due to the use of
  15. ### this program.
  16. ###
  17. from nodes import *
  18. from backend_open62541_datatypes import *
  19. import re
  20. import logging
  21. import sys
  22. if sys.version_info[0] >= 3:
  23. # strings are already parsed to unicode
  24. def unicode(s):
  25. return s
  26. logger = logging.getLogger(__name__)
  27. #################
  28. # Generate Code #
  29. #################
  30. def generateNodeIdPrintable(node):
  31. if isinstance(node.id, NodeId):
  32. CodePrintable = node.__class__.__name__ + "_" + str(node.id)
  33. else:
  34. CodePrintable = node.__class__.__name__ + "_unknown_nid"
  35. return re.sub('[^0-9a-z_]+', '_', CodePrintable.lower())
  36. def generateNodeValueInstanceName(node, parent, arrayIndex):
  37. return generateNodeIdPrintable(parent) + "_" + str(node.alias) + "_" + str(arrayIndex)
  38. def generateReferenceCode(reference):
  39. if reference.isForward:
  40. return "retVal |= UA_Server_addReference(server, %s, %s, %s, true);" % \
  41. (generateNodeIdCode(reference.source),
  42. generateNodeIdCode(reference.referenceType),
  43. generateExpandedNodeIdCode(reference.target))
  44. else:
  45. return "retVal |= UA_Server_addReference(server, %s, %s, %s, false);" % \
  46. (generateNodeIdCode(reference.source),
  47. generateNodeIdCode(reference.referenceType),
  48. generateExpandedNodeIdCode(reference.target))
  49. def generateReferenceTypeNodeCode(node):
  50. code = []
  51. code.append("UA_ReferenceTypeAttributes attr = UA_ReferenceTypeAttributes_default;")
  52. if node.isAbstract:
  53. code.append("attr.isAbstract = true;")
  54. if node.symmetric:
  55. code.append("attr.symmetric = true;")
  56. if node.inverseName != "":
  57. code.append("attr.inverseName = UA_LOCALIZEDTEXT(\"\", \"%s\");" % \
  58. node.inverseName)
  59. return code
  60. def generateObjectNodeCode(node):
  61. code = []
  62. code.append("UA_ObjectAttributes attr = UA_ObjectAttributes_default;")
  63. if node.eventNotifier:
  64. code.append("attr.eventNotifier = true;")
  65. return code
  66. def generateCommonVariableCode(node, nodeset):
  67. code = []
  68. codeCleanup = []
  69. codeGlobal = []
  70. if node.valueRank is not None:
  71. code.append("attr.valueRank = %d;" % node.valueRank)
  72. if node.valueRank > 0:
  73. code.append("attr.arrayDimensionsSize = %d;" % node.valueRank)
  74. code.append("UA_UInt32 arrayDimensions[{}];".format(node.valueRank))
  75. if len(node.arrayDimensions) == node.valueRank:
  76. for idx, v in enumerate(node.arrayDimensions):
  77. code.append("arrayDimensions[{}] = {};".format(idx, int(str(v))))
  78. else:
  79. for dim in range(0, node.valueRank):
  80. code.append("arrayDimensions[{}] = 0;".format(dim))
  81. code.append("attr.arrayDimensions = &arrayDimensions[0];")
  82. if node.dataType is not None:
  83. dataTypeNode = nodeset.getBaseDataType(nodeset.getDataTypeNode(node.dataType))
  84. if dataTypeNode is None:
  85. raise RuntimeError("Cannot get BaseDataType for dataType : " + str(node.dataType) + " of node " + node.browseName.name + " " + str(node.id))
  86. code.append("attr.dataType = %s;" % generateNodeIdCode(node.dataType))
  87. if dataTypeNode.isEncodable():
  88. if node.value is not None:
  89. [code1, codeCleanup1, codeGlobal1] = generateValueCode(node.value, nodeset.nodes[node.id], nodeset)
  90. code += code1
  91. codeCleanup += codeCleanup1
  92. codeGlobal += codeGlobal1
  93. if node.valueRank is not None and node.valueRank > 0 and len(node.arrayDimensions) == node.valueRank and len(node.value.value) > 0:
  94. numElements = 1
  95. hasZero = False
  96. for v in node.arrayDimensions:
  97. dim = int(unicode(v))
  98. if dim > 0:
  99. numElements = numElements * dim
  100. else:
  101. hasZero = True
  102. if hasZero == False and len(node.value.value) == numElements:
  103. code.append("attr.value.arrayDimensionsSize = attr.arrayDimensionsSize;")
  104. code.append("attr.value.arrayDimensions = attr.arrayDimensions;")
  105. logger.warning("printing arrayDimensions")
  106. else:
  107. logger.error("Dimension with size 0 or value count mismatch detected, ArrayDimensions won't be copied to the Value attribute.")
  108. elif not isinstance(node, VariableTypeNode): # Don't generate a dummy value for VariableType nodes
  109. code += generateValueCodeDummy(dataTypeNode, nodeset.nodes[node.id], nodeset)
  110. elif node.value is not None:
  111. raise RuntimeError("Cannot encode dataTypeNode: " + dataTypeNode.browseName.name + " for value of node " + node.browseName.name + " " + str(node.id))
  112. return [code, codeCleanup, codeGlobal]
  113. def generateVariableNodeCode(node, nodeset):
  114. code = []
  115. codeCleanup = []
  116. codeGlobal = []
  117. code.append("UA_VariableAttributes attr = UA_VariableAttributes_default;")
  118. if node.historizing:
  119. code.append("attr.historizing = true;")
  120. code.append("attr.minimumSamplingInterval = %f;" % node.minimumSamplingInterval)
  121. code.append("attr.userAccessLevel = %d;" % node.userAccessLevel)
  122. code.append("attr.accessLevel = %d;" % node.accessLevel)
  123. # in order to be compatible with mostly OPC UA client
  124. # force valueRank = -1 for scalar VariableNode
  125. if node.valueRank == -2 and node.value is not None and len(node.value.value) == 1:
  126. node.valueRank = -1
  127. [code1, codeCleanup1, codeGlobal1] = generateCommonVariableCode(node, nodeset)
  128. code += code1
  129. codeCleanup += codeCleanup1
  130. codeGlobal += codeGlobal1
  131. return [code, codeCleanup, codeGlobal]
  132. def generateVariableTypeNodeCode(node, nodeset):
  133. code = []
  134. codeCleanup = []
  135. codeGlobal = []
  136. code.append("UA_VariableTypeAttributes attr = UA_VariableTypeAttributes_default;")
  137. if node.isAbstract:
  138. code.append("attr.isAbstract = true;")
  139. [code1, codeCleanup1, codeGlobal1] = generateCommonVariableCode(node, nodeset)
  140. code += code1
  141. codeCleanup += codeCleanup1
  142. codeGlobal += codeGlobal1
  143. return [code, codeCleanup, codeGlobal]
  144. def lowerFirstChar(inputString):
  145. return inputString[0].lower() + inputString[1:]
  146. def generateExtensionObjectSubtypeCode(node, parent, nodeset, global_var_code, instanceName=None, isArrayElement=False):
  147. code = [""]
  148. codeCleanup = [""]
  149. logger.debug("Building extensionObject for " + str(parent.id))
  150. logger.debug("Value " + str(node.value))
  151. logger.debug("Encoding " + str(node.encodingRule))
  152. typeBrowseNode = makeCIdentifier(nodeset.getDataTypeNode(parent.dataType).browseName.name)
  153. #TODO: review this
  154. if typeBrowseNode == "NumericRange":
  155. # in the stack we define a separate structure for the numeric range, but
  156. # the value itself is just a string
  157. typeBrowseNode = "String"
  158. typeString = "UA_" + typeBrowseNode
  159. if instanceName is None:
  160. instanceName = generateNodeValueInstanceName(node, parent, 0)
  161. code.append("UA_STACKARRAY(" + typeString + ", " + instanceName + ", 1);")
  162. typeArr = nodeset.getDataTypeNode(parent.dataType).typesArray
  163. typeString = nodeset.getDataTypeNode(parent.dataType).browseName.name.upper()
  164. typeArrayString = typeArr + "[" + typeArr + "_" + typeString + "]"
  165. code.append("UA_init({ref}{instanceName}, &{typeArrayString});".format(ref="&" if isArrayElement else "",
  166. instanceName=instanceName,
  167. typeArrayString=typeArrayString))
  168. # Assign data to the struct contents
  169. # Track the encoding rule definition to detect arrays and/or ExtensionObjects
  170. encFieldIdx = 0
  171. for subv in node.value:
  172. encField = node.encodingRule[encFieldIdx]
  173. encFieldIdx = encFieldIdx + 1
  174. memberName = lowerFirstChar(encField[0])
  175. if isinstance(subv, list):
  176. if len(subv) == 0:
  177. continue
  178. logger.info("ExtensionObject contains array")
  179. memberName = lowerFirstChar(encField[0])
  180. encTypeString = "UA_" + subv[0].__class__.__name__
  181. code.append("UA_STACKARRAY(" + encTypeString + ", " + instanceName + "_" + memberName+", {0});".format(len(subv)))
  182. encTypeArr = nodeset.getDataTypeNode(subv[0].__class__.__name__).typesArray
  183. encTypeArrayString = encTypeArr + "[" + encTypeArr + "_" + subv[0].__class__.__name__.upper() + "]"
  184. code.append("UA_init({ref}{instanceName}, &{typeArrayString});".format(ref="&" if isArrayElement else "",
  185. instanceName=instanceName + "_" + memberName,
  186. typeArrayString=encTypeArrayString))
  187. subArrayIdx = 0
  188. for val in subv:
  189. code.append(generateNodeValueCode(instanceName + "_" + memberName + "[" + str(subArrayIdx) + "]" +" = ", val, instanceName,instanceName + "_gehtNed_member", global_var_code, asIndirect=False))
  190. subArrayIdx = subArrayIdx + 1
  191. code.append(instanceName + "->" + memberName + " = " + instanceName+"_"+ memberName+";")
  192. continue
  193. else:
  194. logger.debug(
  195. "Encoding of field " + memberName + " is " + str(subv.encodingRule) + "defined by " + str(encField))
  196. # Check if this is an array
  197. accessor = "." if isArrayElement else "->"
  198. if subv.valueRank is None or subv.valueRank == 0:
  199. valueName = instanceName + accessor + memberName
  200. code.append(generateNodeValueCode(valueName + " = " ,
  201. subv, instanceName,valueName, global_var_code, asIndirect=False))
  202. else:
  203. memberName = lowerFirstChar(encField[0])
  204. code.append(generateNodeValueCode(instanceName + accessor + memberName + "Size = ", subv, instanceName,valueName, global_var_code, asIndirect=False))
  205. if not isArrayElement:
  206. code.append("UA_Variant_setScalar(&attr.value, " + instanceName + ", &" + typeArrayString + ");")
  207. return [code, codeCleanup]
  208. def getTypeBrowseName(dataTypeNode):
  209. typeBrowseName = makeCIdentifier(dataTypeNode.browseName.name)
  210. #TODO: review this
  211. if typeBrowseName == "NumericRange":
  212. # in the stack we define a separate structure for the numeric range, but
  213. # the value itself is just a string
  214. typeBrowseName = "String"
  215. return typeBrowseName
  216. def generateValueCodeDummy(dataTypeNode, parentNode, nodeset):
  217. code = []
  218. valueName = generateNodeIdPrintable(parentNode) + "_variant_DataContents"
  219. typeBrowseName = getTypeBrowseName(dataTypeNode)
  220. typeArr = dataTypeNode.typesArray + "[" + dataTypeNode.typesArray + "_" + typeBrowseName.upper() + "]"
  221. typeStr = "UA_" + typeBrowseName
  222. if parentNode.valueRank is not None and parentNode.valueRank > 0:
  223. for i in range(0, parentNode.valueRank):
  224. code.append("UA_Variant_setArray(&attr.value, NULL, (UA_Int32) " + "0, &" + typeArr + ");")
  225. elif not dataTypeNode.isAbstract:
  226. code.append("UA_STACKARRAY(" + typeStr + ", " + valueName + ", 1);")
  227. code.append("UA_init(" + valueName + ", &" + typeArr + ");")
  228. code.append("UA_Variant_setScalar(&attr.value, " + valueName + ", &" + typeArr + ");")
  229. return code
  230. def getTypesArrayForValue(nodeset, value):
  231. typeNode = nodeset.getNodeByBrowseName(value.__class__.__name__)
  232. if typeNode is None or value.isInternal:
  233. typesArray = "UA_TYPES"
  234. else:
  235. typesArray = typeNode.typesArray
  236. typeName = makeCIdentifier(value.__class__.__name__.upper())
  237. return "&" + typesArray + "[" + typesArray + "_" + typeName + "]"
  238. def isArrayVariableNode(node, parentNode):
  239. return parentNode.valueRank is not None and (parentNode.valueRank != -1 and (parentNode.valueRank >= 0
  240. or (len(node.value) > 1
  241. and (parentNode.valueRank != -2 or parentNode.valueRank != -3))))
  242. def generateValueCode(node, parentNode, nodeset, bootstrapping=True):
  243. code = []
  244. codeCleanup = []
  245. codeGlobal = []
  246. valueName = generateNodeIdPrintable(parentNode) + "_variant_DataContents"
  247. # node.value either contains a list of multiple identical BUILTINTYPES, or it
  248. # contains a single builtintype (which may be a container); choose if we need
  249. # to create an array or a single variable.
  250. # Note that some genious defined that there are arrays of size 1, which are
  251. # distinctly different then a single value, so we need to check that as well
  252. # Semantics:
  253. # -3: Scalar or 1-dim
  254. # -2: Scalar or x-dim | x>0
  255. # -1: Scalar
  256. # 0: x-dim | x>0
  257. # n: n-dim | n>0
  258. if (len(node.value) == 0):
  259. return ["", "", ""]
  260. if not isinstance(node.value[0], Value):
  261. return ["", "", ""]
  262. dataTypeNode = nodeset.getDataTypeNode(parentNode.dataType)
  263. if isArrayVariableNode(node, parentNode):
  264. # User the following strategy for all directly mappable values a la 'UA_Type MyInt = (UA_Type) 23;'
  265. if isinstance(node.value[0], Guid):
  266. logger.warn("Don't know how to print array of GUID in node " + str(parentNode.id))
  267. elif isinstance(node.value[0], DiagnosticInfo):
  268. logger.warn("Don't know how to print array of DiagnosticInfo in node " + str(parentNode.id))
  269. elif isinstance(node.value[0], StatusCode):
  270. logger.warn("Don't know how to print array of StatusCode in node " + str(parentNode.id))
  271. else:
  272. if isinstance(node.value[0], ExtensionObject):
  273. code.append("UA_" + getTypeBrowseName(dataTypeNode) + " " + valueName + "[" + str(len(node.value)) + "];")
  274. for idx, v in enumerate(node.value):
  275. logger.debug("Building extObj array index " + str(idx))
  276. instanceName = valueName + "[" + str(idx) + "]"
  277. [code1, codeCleanup1] = generateExtensionObjectSubtypeCode(v, parent=parentNode, nodeset=nodeset,
  278. global_var_code=codeGlobal, instanceName=instanceName,
  279. isArrayElement=True)
  280. code = code + code1
  281. codeCleanup = codeCleanup + codeCleanup1
  282. else:
  283. code.append("UA_" + node.value[0].__class__.__name__ + " " + valueName + "[" + str(len(node.value)) + "];")
  284. for idx, v in enumerate(node.value):
  285. instanceName = generateNodeValueInstanceName(v, parentNode, idx)
  286. code.append(generateNodeValueCode(
  287. valueName + "[" + str(idx) + "] = " , v, instanceName, valueName, codeGlobal))
  288. code.append("UA_Variant_setArray(&attr.value, &" + valueName +
  289. ", (UA_Int32) " + str(len(node.value)) + ", " + "&" +
  290. dataTypeNode.typesArray + "["+dataTypeNode.typesArray + "_" + getTypeBrowseName(dataTypeNode).upper() +"]);")
  291. #scalar value
  292. else:
  293. # User the following strategy for all directly mappable values a la 'UA_Type MyInt = (UA_Type) 23;'
  294. if isinstance(node.value[0], Guid):
  295. logger.warn("Don't know how to print scalar GUID in node " + str(parentNode.id))
  296. elif isinstance(node.value[0], DiagnosticInfo):
  297. logger.warn("Don't know how to print scalar DiagnosticInfo in node " + str(parentNode.id))
  298. elif isinstance(node.value[0], StatusCode):
  299. logger.warn("Don't know how to print scalar StatusCode in node " + str(parentNode.id))
  300. else:
  301. # The following strategy applies to all other types, in particular strings and numerics.
  302. if isinstance(node.value[0], ExtensionObject):
  303. [code1, codeCleanup1] = generateExtensionObjectSubtypeCode(node.value[0], parent=parentNode, nodeset=nodeset, global_var_code=codeGlobal, isArrayElement=False)
  304. code = code + code1
  305. codeCleanup = codeCleanup + codeCleanup1
  306. instanceName = generateNodeValueInstanceName(node.value[0], parentNode, 0)
  307. if not(isinstance(node.value[0], ExtensionObject)):
  308. code.append("UA_" + node.value[0].__class__.__name__ + " *" + valueName + " = UA_" + node.value[
  309. 0].__class__.__name__ + "_new();")
  310. code.append("if (!" + valueName + ") return UA_STATUSCODE_BADOUTOFMEMORY;")
  311. code.append(generateNodeValueCode("*" + valueName + " = " , node.value[0], instanceName, valueName, codeGlobal, asIndirect=True))
  312. code.append(
  313. "UA_Variant_setScalar(&attr.value, " + valueName + ", " +
  314. getTypesArrayForValue(nodeset, node.value[0]) + ");")
  315. if node.value[0].__class__.__name__ == "ByteString":
  316. # The data is on the stack, not heap, so we can not delete the ByteString
  317. codeCleanup.append("{}->data = NULL;".format(valueName))
  318. codeCleanup.append("{}->length = 0;".format(valueName))
  319. codeCleanup.append("UA_{0}_delete({1});".format(
  320. node.value[0].__class__.__name__, valueName))
  321. return [code, codeCleanup, codeGlobal]
  322. def generateMethodNodeCode(node):
  323. code = []
  324. code.append("UA_MethodAttributes attr = UA_MethodAttributes_default;")
  325. if node.executable:
  326. code.append("attr.executable = true;")
  327. if node.userExecutable:
  328. code.append("attr.userExecutable = true;")
  329. return code
  330. def generateObjectTypeNodeCode(node):
  331. code = []
  332. code.append("UA_ObjectTypeAttributes attr = UA_ObjectTypeAttributes_default;")
  333. if node.isAbstract:
  334. code.append("attr.isAbstract = true;")
  335. return code
  336. def generateDataTypeNodeCode(node):
  337. code = []
  338. code.append("UA_DataTypeAttributes attr = UA_DataTypeAttributes_default;")
  339. if node.isAbstract:
  340. code.append("attr.isAbstract = true;")
  341. return code
  342. def generateViewNodeCode(node):
  343. code = []
  344. code.append("UA_ViewAttributes attr = UA_ViewAttributes_default;")
  345. if node.containsNoLoops:
  346. code.append("attr.containsNoLoops = true;")
  347. code.append("attr.eventNotifier = (UA_Byte)%s;" % str(node.eventNotifier))
  348. return code
  349. def getNodeTypeDefinition(node):
  350. for ref in node.references:
  351. # 40 = HasTypeDefinition
  352. if ref.referenceType.i == 40:
  353. return ref.target
  354. return None
  355. def generateSubtypeOfDefinitionCode(node):
  356. for ref in node.inverseReferences:
  357. # 45 = HasSubtype
  358. if ref.referenceType.i == 45:
  359. return generateNodeIdCode(ref.target)
  360. return "UA_NODEID_NULL"
  361. def generateNodeCode_begin(node, nodeset, generate_ns0, parentref, code_global):
  362. code = []
  363. codeCleanup = []
  364. code.append("UA_StatusCode retVal = UA_STATUSCODE_GOOD;")
  365. # Attributes
  366. if isinstance(node, ReferenceTypeNode):
  367. code.extend(generateReferenceTypeNodeCode(node))
  368. elif isinstance(node, ObjectNode):
  369. code.extend(generateObjectNodeCode(node))
  370. elif isinstance(node, VariableNode) and not isinstance(node, VariableTypeNode):
  371. [code1, codeCleanup1, codeGlobal1] = generateVariableNodeCode(node, nodeset)
  372. code.extend(code1)
  373. codeCleanup.extend(codeCleanup1)
  374. code_global.extend(codeGlobal1)
  375. elif isinstance(node, VariableTypeNode):
  376. [code1, codeCleanup1, codeGlobal1] = generateVariableTypeNodeCode(node, nodeset)
  377. code.extend(code1)
  378. codeCleanup.extend(codeCleanup1)
  379. code_global.extend(codeGlobal1)
  380. elif isinstance(node, MethodNode):
  381. code.extend(generateMethodNodeCode(node))
  382. elif isinstance(node, ObjectTypeNode):
  383. code.extend(generateObjectTypeNodeCode(node))
  384. elif isinstance(node, DataTypeNode):
  385. code.extend(generateDataTypeNodeCode(node))
  386. elif isinstance(node, ViewNode):
  387. code.extend(generateViewNodeCode(node))
  388. if node.displayName is not None:
  389. code.append("attr.displayName = " + generateLocalizedTextCode(node.displayName, alloc=False) + ";")
  390. if node.description is not None:
  391. code.append("#ifdef UA_ENABLE_NODESET_COMPILER_DESCRIPTIONS")
  392. code.append("attr.description = " + generateLocalizedTextCode(node.description, alloc=False) + ";")
  393. code.append("#endif")
  394. if node.writeMask is not None:
  395. code.append("attr.writeMask = %d;" % node.writeMask)
  396. if node.userWriteMask is not None:
  397. code.append("attr.userWriteMask = %d;" % node.userWriteMask)
  398. # AddNodes call
  399. code.append("retVal |= UA_Server_addNode_begin(server, UA_NODECLASS_{},".
  400. format(makeCIdentifier(node.__class__.__name__.upper().replace("NODE" ,""))))
  401. code.append(generateNodeIdCode(node.id) + ",")
  402. code.append(generateNodeIdCode(parentref.target) + ",")
  403. code.append(generateNodeIdCode(parentref.referenceType) + ",")
  404. code.append(generateQualifiedNameCode(node.browseName) + ",")
  405. if isinstance(node, VariableNode) or isinstance(node, ObjectNode):
  406. typeDefRef = node.popTypeDef()
  407. code.append(generateNodeIdCode(typeDefRef.target) + ",")
  408. else:
  409. code.append(" UA_NODEID_NULL,")
  410. code.append("(const UA_NodeAttributes*)&attr, &UA_TYPES[UA_TYPES_{}ATTRIBUTES],NULL, NULL);".
  411. format(makeCIdentifier(node.__class__.__name__.upper().replace("NODE" ,""))))
  412. code.extend(codeCleanup)
  413. return "\n".join(code)
  414. def generateNodeCode_finish(node):
  415. code = []
  416. if isinstance(node, MethodNode):
  417. code.append("UA_Server_addMethodNode_finish(server, ")
  418. else:
  419. code.append("UA_Server_addNode_finish(server, ")
  420. code.append(generateNodeIdCode(node.id))
  421. if isinstance(node, MethodNode):
  422. code.append(", NULL, 0, NULL, 0, NULL);")
  423. else:
  424. code.append(");")
  425. return "\n".join(code)