Browse Source

refactor(server): Remove server pointer from AsyncMethodManager

Julius Pfrommer 4 years ago
parent
commit
b322f4d128

+ 13 - 15
src/server/ua_asyncmethod_manager.c

@@ -18,10 +18,9 @@
 #if UA_MULTITHREADING >= 100
 
 UA_StatusCode
-UA_AsyncMethodManager_init(UA_AsyncMethodManager *amm, UA_Server *server) {
+UA_AsyncMethodManager_init(UA_AsyncMethodManager *amm) {
     LIST_INIT(&amm->asyncmethods);
     amm->currentCount = 0;
-    amm->server = server;
     return UA_STATUSCODE_GOOD;
 }
 
@@ -46,20 +45,21 @@ UA_AsyncMethodManager_getById(UA_AsyncMethodManager *amm, const UA_UInt32 reques
 }
 
 UA_StatusCode
-UA_AsyncMethodManager_createEntry(UA_AsyncMethodManager *amm, const UA_NodeId *sessionId,
-    const UA_UInt32 channelId, const UA_UInt32 requestId, const UA_UInt32 requestHandle,
-    const UA_DataType *responseType, const UA_UInt32 nCountdown) {
+UA_AsyncMethodManager_createEntry(UA_AsyncMethodManager *amm, UA_Server *server,
+                                  const UA_NodeId *sessionId, const UA_UInt32 channelId,
+                                  const UA_UInt32 requestId, const UA_UInt32 requestHandle,
+                                  const UA_DataType *responseType, const UA_UInt32 nCountdown) {
     asyncmethod_list_entry *newentry = (asyncmethod_list_entry*)
         UA_calloc(1, sizeof(asyncmethod_list_entry));
     if(!newentry) {
-        UA_LOG_ERROR(&amm->server->config.logger, UA_LOGCATEGORY_SERVER,
+        UA_LOG_ERROR(&server->config.logger, UA_LOGCATEGORY_SERVER,
                      "UA_AsyncMethodManager_createEntry: Mem alloc failed.");
         return UA_STATUSCODE_BADOUTOFMEMORY;
     }
 
     UA_StatusCode res = UA_NodeId_copy(sessionId, &newentry->sessionId);
     if(res != UA_STATUSCODE_GOOD) {
-        UA_LOG_ERROR(&amm->server->config.logger, UA_LOGCATEGORY_SERVER,
+        UA_LOG_ERROR(&server->config.logger, UA_LOGCATEGORY_SERVER,
                      "UA_AsyncMethodManager_createEntry: Mem alloc failed.");
         UA_free(newentry);
         return res;
@@ -76,8 +76,8 @@ UA_AsyncMethodManager_createEntry(UA_AsyncMethodManager *amm, const UA_NodeId *s
         UA_calloc(nCountdown, sizeof(UA_CallMethodResult));
     newentry->response.resultsSize = nCountdown;
     if(newentry->response.results == NULL) {
-        UA_LOG_ERROR(&amm->server->config.logger, UA_LOGCATEGORY_SERVER,
-            "UA_AsyncMethodManager_createEntry: Mem alloc failed.");
+        UA_LOG_ERROR(&server->config.logger, UA_LOGCATEGORY_SERVER,
+                     "UA_AsyncMethodManager_createEntry: Mem alloc failed.");
         UA_free(newentry);
         return UA_STATUSCODE_BADOUTOFMEMORY;
     }
@@ -89,8 +89,8 @@ UA_AsyncMethodManager_createEntry(UA_AsyncMethodManager *amm, const UA_NodeId *s
 
     LIST_INSERT_HEAD(&amm->asyncmethods, newentry, pointers);
 
-    UA_LOG_DEBUG(&amm->server->config.logger, UA_LOGCATEGORY_SERVER,
-        "UA_AsyncMethodManager_createEntry: Chan: %u. Req# %u", channelId, requestId);
+    UA_LOG_DEBUG(&server->config.logger, UA_LOGCATEGORY_SERVER,
+                 "UA_AsyncMethodManager_createEntry: Chan: %u. Req# %u", channelId, requestId);
 
     return UA_STATUSCODE_GOOD;
 }
@@ -105,8 +105,6 @@ UA_AsyncMethodManager_removeEntry(UA_AsyncMethodManager *amm,
     UA_CallResponse_deleteMembers(&current->response);
     UA_NodeId_clear(&current->sessionId);
     UA_free(current);
-    UA_LOG_DEBUG(&amm->server->config.logger, UA_LOGCATEGORY_SERVER,
-                 "UA_AsyncMethodManager_removeEntry: # of open CallRequests: %u", amm->currentCount);
     return UA_STATUSCODE_GOOD;
 }
 
@@ -133,11 +131,11 @@ UA_AsyncMethodManager_checkTimeouts(UA_Server *server, UA_AsyncMethodManager *am
 
         /* Get the session */
         UA_LOCK(server->serviceMutex);
-        UA_Session* session = UA_SessionManager_getSessionById(&amm->server->sessionManager,
+        UA_Session* session = UA_SessionManager_getSessionById(&server->sessionManager,
                                                                &current->sessionId);
         UA_UNLOCK(server->serviceMutex);
         if(!session) {
-            UA_LOG_WARNING(&amm->server->config.logger, UA_LOGCATEGORY_SERVER,
+            UA_LOG_WARNING(&server->config.logger, UA_LOGCATEGORY_SERVER,
                            "UA_AsyncMethodManager_checkTimeouts: Session is gone");
             goto remove;
         }

+ 6 - 5
src/server/ua_asyncmethod_manager.h

@@ -39,18 +39,19 @@ typedef struct asyncmethod_list_entry {
 typedef struct UA_AsyncMethodManager {
     LIST_HEAD(asyncmethod_list, asyncmethod_list_entry) asyncmethods; // doubly-linked list of CallRequests/Responses
     UA_UInt32 currentCount;
-    UA_Server *server;
 } UA_AsyncMethodManager;
 
 UA_StatusCode
-UA_AsyncMethodManager_init(UA_AsyncMethodManager *amm, UA_Server *server);
+UA_AsyncMethodManager_init(UA_AsyncMethodManager *amm);
 
 /* Deletes all entries */
-void UA_AsyncMethodManager_deleteMembers(UA_AsyncMethodManager *ammm);
+void UA_AsyncMethodManager_deleteMembers(UA_AsyncMethodManager *amm);
 
 UA_StatusCode
-UA_AsyncMethodManager_createEntry(UA_AsyncMethodManager *amm, const UA_NodeId *sessionId, const UA_UInt32 channelId,
-    const UA_UInt32 requestId, const UA_UInt32 requestHandle, const UA_DataType *responseType, const UA_UInt32 nCountdown);
+UA_AsyncMethodManager_createEntry(UA_AsyncMethodManager *amm, UA_Server *server,
+                                  const UA_NodeId *sessionId, const UA_UInt32 channelId,
+                                  const UA_UInt32 requestId, const UA_UInt32 requestHandle,
+                                  const UA_DataType *responseType, const UA_UInt32 nCountdown);
 
 /* The pointers amm and current must not be NULL */
 UA_StatusCode

+ 1 - 1
src/server/ua_server.c

@@ -294,7 +294,7 @@ UA_Server_init(UA_Server *server) {
     UA_SessionManager_init(&server->sessionManager, server);
 
 #if UA_MULTITHREADING >= 100
-    UA_AsyncMethodManager_init(&server->asyncMethodManager, server);
+    UA_AsyncMethodManager_init(&server->asyncMethodManager);
     UA_Server_MethodQueues_init(server);
     /* Add a regular callback for for checking responmses using a 50ms interval. */
     UA_Server_addRepeatedCallback(server, (UA_ServerCallback)UA_Server_CallMethodResponse, NULL,

+ 3 - 2
src/server/ua_server_binary.c

@@ -554,8 +554,9 @@ processMSGDecoded(UA_Server *server, UA_SecureChannel *channel, UA_UInt32 reques
      * there is an error */
     if(requestType == &UA_TYPES[UA_TYPES_CALLREQUEST]) {
         responseHeader->serviceResult =
-            UA_AsyncMethodManager_createEntry(&server->asyncMethodManager, &session->sessionId,
-                                              channel->securityToken.channelId, requestId, requestHeader->requestHandle, responseType,
+            UA_AsyncMethodManager_createEntry(&server->asyncMethodManager, server,
+                                              &session->sessionId, channel->securityToken.channelId,
+                                              requestId, requestHeader->requestHandle, responseType,
                                               (UA_UInt32)((const UA_CallRequest*)requestHeader)->methodsToCallSize);
         if(responseHeader->serviceResult == UA_STATUSCODE_GOOD)
             Service_CallAsync(server, session, channel, requestId,

+ 4 - 2
tests/server/check_server_asyncop.c

@@ -99,8 +99,10 @@ START_TEST(InternalTestingManager) {
     UA_LOG_INFO(&globalServer->config.logger, UA_LOGCATEGORY_SERVER, "* Checking UA_AsyncMethodManager_createEntry: create CallRequests");
     UA_DataType dataType = UA_TYPES[UA_TYPES_CALLMETHODREQUEST];
     for (UA_Int32 i = 1; i < 7; i++) {
-        UA_StatusCode result = UA_AsyncMethodManager_createEntry(&globalServer->asyncMethodManager, &session.sessionId,
-            channel.securityToken.channelId, i, i, &dataType, 1);
+        UA_StatusCode result =
+            UA_AsyncMethodManager_createEntry(&globalServer->asyncMethodManager, globalServer,
+                                              &session.sessionId, channel.securityToken.channelId,
+                                              i, i, &dataType, 1);
         ck_assert_int_eq(result, UA_STATUSCODE_GOOD);
     }
     UA_fakeSleep(121000);