Ver código fonte

Added userspace function to (re-)attach functions to existing methodnodes.

ichrispa 9 anos atrás
pai
commit
50ebfd437f
2 arquivos alterados com 29 adições e 0 exclusões
  1. 3 0
      include/ua_server.h
  2. 26 0
      src/server/ua_server_addressspace.c

+ 3 - 0
include/ua_server.h

@@ -154,6 +154,9 @@ UA_Server_addMethodNode(UA_Server *server, const UA_QualifiedName browseName, UA
                         UA_MethodCallback method, UA_Int32 inputArgumentsSize,
                         const UA_Argument *inputArguments, UA_Int32 outputArgumentsSize,
                         const UA_Argument *outputArguments);
+
+UA_StatusCode UA_EXPORT
+UA_Server_attachMethod_toNode(UA_Server *server, UA_NodeId methodNodeId, UA_MethodCallback method);
 #endif
 
 /** Jobs describe work that is executed once or repeatedly. */

+ 26 - 0
src/server/ua_server_addressspace.c

@@ -445,4 +445,30 @@ UA_Server_addMethodNode(UA_Server *server, const UA_QualifiedName browseName, UA
     
     return retval;
 }
+
+UA_StatusCode
+UA_Server_attachMethod_toNode(UA_Server *server, UA_NodeId methodNodeId, UA_MethodCallback method) {
+    UA_StatusCode retval = UA_STATUSCODE_GOOD;
+    const UA_Node *attachToMethod;
+    UA_MethodNode *replacementMethod = UA_MethodNode_new();
+    
+    if (!method)
+        return UA_STATUSCODE_BADMETHODINVALID;
+    if (!server)
+        return UA_STATUSCODE_BADSERVERINDEXINVALID;
+    
+    attachToMethod =  UA_NodeStore_get(server->nodestore, &methodNodeId);
+    if (!attachToMethod)
+        return UA_STATUSCODE_BADNODEIDINVALID;
+    
+    if (attachToMethod->nodeClass != UA_NODECLASS_METHOD)
+        return UA_STATUSCODE_BADNODEIDINVALID;
+    
+    UA_MethodNode_copy((const UA_MethodNode *) attachToMethod, replacementMethod);
+    UA_NodeStore_release(attachToMethod);
+    
+    replacementMethod->attachedMethod = method;
+    UA_NodeStore_replace(server->nodestore, attachToMethod, (UA_Node *) replacementMethod, UA_NULL);
+    return retval;
+}
 #endif