Browse Source

Enabled -DENABLE_METHODSCALLS to enable call service; struct UA_MethodCallManager is being initialized in server internal related function. Service now handles parameters (does not call anything yet).

ichrispa 9 years ago
parent
commit
4717f4f305

+ 3 - 1
CMakeLists.txt

@@ -182,8 +182,10 @@ set(UA_LOGLEVEL 300 CACHE STRING "Level at which logs shall be reported")
 # Enable Methodcall service
 option(ENABLE_METHODCALLS "Enable CallMethod/MethodCall service set" OFF)
 if(ENABLE_METHODCALLS)
-    list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_services_call.c)
     add_definitions(-DENABLE_METHODCALLS)
+    list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_services_call.c)
+    list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_methodcall_manager.c)
+    list(APPEND internal_headers ${PROJECT_SOURCE_DIR}/src/server/ua_methodcall_manager.h)
 endif()
 
 ## multithreading

+ 5 - 0
src/server/ua_methodcall_manager.c

@@ -0,0 +1,5 @@
+#include "ua_methodcall_manager.h"
+
+UA_MethodCall_Manager *UA_MethodCallManager_new(void) {
+    return UA_NULL;
+}

+ 14 - 0
src/server/ua_methodcall_manager.h

@@ -0,0 +1,14 @@
+#ifndef UA_METHODCALL_H
+#define UA_METHODCALL_H
+
+#include "ua_util.h"
+#include "ua_types.h"
+#include "ua_types_generated.h"
+#include "ua_nodes.h"
+
+typedef struct UA_MethodCall_Manager_s {
+    UA_Int32 placeHolder;
+} UA_MethodCall_Manager;
+
+UA_MethodCall_Manager *UA_MethodCallManager_new(void);
+#endif

+ 7 - 0
src/server/ua_server.c

@@ -473,6 +473,13 @@ UA_Server * UA_Server_new(UA_ServerConfig config) {
 #define HUNDRED_NANOSEC_PER_SEC (HUNDRED_NANOSEC_PER_USEC * 1000000LL)
     server->buildDate = (mktime(&ct) + UNIX_EPOCH_BIAS_SEC) * HUNDRED_NANOSEC_PER_SEC;
 
+#ifdef ENABLE_METHODCALLS
+    /**************************/
+    /* Method Hook Management */
+    /**************************/
+    server->methodCallManager = UA_MethodCallManager_new();
+#endif
+
     /**************/
     /* References */
     /**************/

+ 4 - 0
src/server/ua_server_binary.c

@@ -8,6 +8,10 @@
 #include "ua_session_manager.h"
 #include "ua_nodeids.h"
 
+#ifdef ENABLE_METHODCALLS
+#include "ua_methodcall_manager.h"
+#endif
+
 /** Max size of messages that are allocated on the stack */
 #define MAX_STACK_MESSAGE 65536
 

+ 10 - 1
src/server/ua_server_internal.h

@@ -11,6 +11,10 @@
 #include "ua_subscription_manager.h"
 #endif
 
+#ifdef ENABLE_METHODCALLS
+#include "ua_methodcall_manager.h"
+#endif
+
 #define PRODUCT_URI "http://open62541.org"
 #define ANONYMOUS_POLICY "open62541-anonymous-policy"
 #define USERNAME_POLICY "open62541-username-policy"
@@ -51,10 +55,15 @@ struct UA_Server {
     UA_String *namespaces;
     size_t externalNamespacesSize;
     UA_ExternalNamespace *externalNamespaces;
-
+     
     /* Jobs with a repetition interval */
     LIST_HEAD(RepeatedJobsList, RepeatedJobs) repeatedJobs;
 
+    /* Method hooks  */
+#ifdef ENABLE_METHODCALLS
+    UA_MethodCall_Manager *methodCallManager;
+#endif
+
 #ifdef UA_MULTITHREADING
     /* Dispatch queue head for the worker threads (the tail should not be in the same cache line) */
 	struct cds_wfcq_head dispatchQueue_head;

+ 3 - 3
src/server/ua_services.h

@@ -286,8 +286,8 @@ void Service_Publish(UA_Server *server, UA_Session *session,
 #endif
 
 #ifdef ENABLE_METHODCALLS
-void Service_MethodCall(UA_Server *server, UA_Session *session,
-                        const UA_CallMethodRequest *request,
-                        UA_CallMethodResult *response);
+void Service_Call(UA_Server *server, UA_Session *session,
+                  const UA_CallRequest *request,
+                  UA_CallResponse *response);
 #endif
 #endif /* UA_SERVICES_H_ */

+ 57 - 0
src/server/ua_services_call.c

@@ -0,0 +1,57 @@
+#include "ua_services.h"
+#include "ua_server_internal.h"
+#include "ua_subscription_manager.h"
+#include "ua_subscription.h"
+#include "ua_statuscodes.h"
+#include "ua_util.h"
+#include "ua_nodestore.h"
+
+#ifdef ENABLE_METHODCALLS
+
+void Service_Call(UA_Server *server, UA_Session *session,
+                  const UA_CallRequest *request,
+                  UA_CallResponse *response) {
+    
+    if (request->methodsToCall == UA_NULL) return;
+    
+    response->responseHeader.serviceResult = UA_STATUSCODE_GOOD;
+    response->resultsSize=request->methodsToCallSize;
+    response->results = (UA_CallMethodResult *) UA_malloc(sizeof(UA_CallMethodResult)*response->resultsSize);
+    
+    for(int i=0; i<request->methodsToCallSize;i++){
+        UA_CallMethodRequest *rq = &request->methodsToCall[i];
+        UA_CallMethodResult  *rs = &response->results[i];
+        UA_CallMethodResult_init(rs);
+        
+        rs->inputArgumentDiagnosticInfosSize = 0;
+        rs->inputArgumentResultsSize = 0;
+        rs->outputArgumentsSize = 0;
+        
+        const UA_Node *methodCalled = UA_NodeStore_get(server->nodestore, &rq->methodId);
+        if (methodCalled == UA_NULL) {
+            rs->statusCode = UA_STATUSCODE_BADMETHODINVALID;
+            continue;
+        }
+        const UA_Node *withObject   = UA_NodeStore_get(server->nodestore, &rq->objectId);
+        if (withObject == UA_NULL) {
+            rs->statusCode = UA_STATUSCODE_BADNODEIDINVALID;
+            printf("Obj not found\n");
+            continue;
+        }
+        
+        if (methodCalled->nodeClass != UA_NODECLASS_METHOD) {
+            rs->statusCode = UA_STATUSCODE_BADMETHODINVALID;
+            continue;
+        }
+        if (withObject->nodeClass != UA_NODECLASS_OBJECT && withObject->nodeClass != UA_NODECLASS_OBJECTTYPE) {
+            rs->statusCode = UA_STATUSCODE_BADNODEIDINVALID;
+            printf("Obj not found 1\n");
+            continue;
+        }
+        
+    }
+    
+    
+    return;
+}
+#endif