Explorar el Código

Add check for correct namespace index. See #824

Add check for statuscode good
Stefan Profanter hace 8 años
padre
commit
731ff5954c
Se han modificado 2 ficheros con 10 adiciones y 4 borrados
  1. 6 1
      examples/server_nodeset.c
  2. 4 3
      tools/pyUANamespace/ua_namespace.py

+ 6 - 1
examples/server_nodeset.c

@@ -36,7 +36,12 @@ int main(int argc, char** argv) {
     UA_Server *server = UA_Server_new(config);
 
     /* create nodes from nodeset */
-    nodeset(server);
+    if (nodeset(server) != UA_STATUSCODE_GOOD) {
+		UA_LOG_ERROR(logger, UA_LOGCATEGORY_SERVER, "Namespace index for generated nodeset does not match. The call to the generated method has to be before any other namespace add calls.");
+		UA_Server_delete(server);
+		nl.deleteMembers(&nl);
+		return (int)UA_STATUSCODE_BADUNEXPECTEDERROR;
+	}
 
     /* start server */
     UA_StatusCode retval = UA_Server_run(server, &running); //UA_blocks until running=false

+ 4 - 3
tools/pyUANamespace/ua_namespace.py

@@ -674,7 +674,7 @@ class opcua_namespace():
     header.append('#endif')
     
     code.append('#include "'+outfilename+'.h"')
-    code.append("UA_INLINE void "+outfilename+"(UA_Server *server) {")
+    code.append("UA_INLINE UA_StatusCode "+outfilename+"(UA_Server *server) {")
     code.append('UA_StatusCode retval = UA_STATUSCODE_GOOD; ')
 
     # Before printing nodes, we need to request additional namespace arrays from the server
@@ -684,7 +684,7 @@ class opcua_namespace():
       else:
         name =  self.namespaceIdentifiers[nsid]
         name = name.replace("\"","\\\"")
-        code.append("UA_Server_addNamespace(server, \"" + name + "\");")
+        code.append("if (UA_Server_addNamespace(server, \"{0}\") != {1})\n    return UA_STATUSCODE_BADUNEXPECTEDERROR;".format(name, nsid))
 
     # Find all references necessary to create the namespace and
     # "Bootstrap" them so all other nodes can safely use these referencetypes whenever
@@ -707,7 +707,7 @@ class opcua_namespace():
     for r in refsUsed:
       code = code + r.printOpen62541CCode(unPrintedNodes, unPrintedRefs);
 
-    header.append("extern void "+outfilename+"(UA_Server *server);\n")
+    header.append("extern UA_StatusCode "+outfilename+"(UA_Server *server);\n")
     header.append("#endif /* "+outfilename.upper()+"_H_ */")
 
     # Note to self: do NOT - NOT! - try to iterate over unPrintedNodes!
@@ -744,6 +744,7 @@ class opcua_namespace():
     else:
       logger.debug("Printing succeeded for all references")
 
+    code.append("return UA_STATUSCODE_GOOD;")
     code.append("}")
     return (header,code)