Browse Source

feature(server): Add UA_Server_getAsyncOperationNonBlocking

This replaces UA_Server_getAsyncOperation and returns the timeout
timestamp to the worker thread.
Julius Pfrommer 5 years ago
parent
commit
9b2c7812ea

+ 1 - 1
examples/tutorial_server_method_async.c

@@ -181,7 +181,7 @@ THREAD_CALLBACK(ThreadWorker) {
         const UA_AsyncOperationRequest* request = NULL;
         const UA_AsyncOperationRequest* request = NULL;
         void *context = NULL;
         void *context = NULL;
         UA_AsyncOperationType type;
         UA_AsyncOperationType type;
-        if(UA_Server_getAsyncOperation(globalServer, &type, &request, &context) == true) {
+        if(UA_Server_getAsyncOperationNonBlocking(globalServer, &type, &request, &context, NULL) == true) {
             UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "AsyncMethod_Testing: Got entry: OKAY");
             UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "AsyncMethod_Testing: Got entry: OKAY");
             UA_CallMethodResult response = UA_Server_call(globalServer, &request->callMethodRequest);
             UA_CallMethodResult response = UA_Server_call(globalServer, &request->callMethodRequest);
             UA_Server_setAsyncOperationResult(globalServer, (UA_AsyncOperationResponse*)&response,
             UA_Server_setAsyncOperationResult(globalServer, (UA_AsyncOperationResponse*)&response,

+ 20 - 5
include/open62541/server.h

@@ -1417,19 +1417,27 @@ typedef union {
     /* UA_StatusCode writeResult; */
     /* UA_StatusCode writeResult; */
 } UA_AsyncOperationResponse;
 } UA_AsyncOperationResponse;
 
 
-/* Get the next async operation
+/* Get the next async operation without blocking
  *
  *
  * @param server The server object
  * @param server The server object
  * @param type The type of the async operation
  * @param type The type of the async operation
  * @param request Receives pointer to the operation
  * @param request Receives pointer to the operation
  * @param context Receives the pointer to the operation context
  * @param context Receives the pointer to the operation context
+ * @param timeout The timestamp when the operation times out and can
+ *        no longer be returned to the client. The response has to
+ *        be set in UA_Server_setAsyncOperationResult in any case.
  * @return false if queue is empty, true else */
  * @return false if queue is empty, true else */
 UA_Boolean UA_EXPORT
 UA_Boolean UA_EXPORT
-UA_Server_getAsyncOperation(UA_Server *server, UA_AsyncOperationType *type,
-                            const UA_AsyncOperationRequest **request,
-                            void **context);
+UA_Server_getAsyncOperationNonBlocking(UA_Server *server, UA_AsyncOperationType *type,
+                                       const UA_AsyncOperationRequest **request,
+                                       void **context, UA_DateTime *timeout);
+
+/* UA_Boolean UA_EXPORT */
+/* UA_Server_getAsyncOperationBlocking(UA_Server *server, UA_AsyncOperationType *type, */
+/*                                     const UA_AsyncOperationRequest **request, */
+/*                                     void **context, UA_DateTime *timeout); */
 
 
-/* Submit the next async operation
+/* Submit an async operation result
  *
  *
  * @param server The server object
  * @param server The server object
  * @param response Pointer to the operation result
  * @param response Pointer to the operation result
@@ -1439,6 +1447,13 @@ UA_Server_setAsyncOperationResult(UA_Server *server,
                                   const UA_AsyncOperationResponse *response,
                                   const UA_AsyncOperationResponse *response,
                                   void *context);
                                   void *context);
 
 
+/* Get the next async operation. Attention! This method is deprecated and has
+ * been replaced by UA_Server_getAsyncOperationNonBlocking! */
+UA_DEPRECATED UA_Boolean UA_EXPORT
+UA_Server_getAsyncOperation(UA_Server *server, UA_AsyncOperationType *type,
+                            const UA_AsyncOperationRequest **request,
+                            void **context);
+
 #endif /* !UA_MULTITHREADING >= 100 */
 #endif /* !UA_MULTITHREADING >= 100 */
 
 
 _UA_END_DECLS
 _UA_END_DECLS

+ 12 - 3
src/server/ua_server_async.c

@@ -278,9 +278,9 @@ UA_AsyncManager_createAsyncOp(UA_AsyncManager *am, UA_Server *server,
 
 
 /* Get and remove next Method Call Request */
 /* Get and remove next Method Call Request */
 UA_Boolean
 UA_Boolean
-UA_Server_getAsyncOperation(UA_Server *server, UA_AsyncOperationType *type,
-                            const UA_AsyncOperationRequest **request,
-                            void **context) {
+UA_Server_getAsyncOperationNonBlocking(UA_Server *server, UA_AsyncOperationType *type,
+                                       const UA_AsyncOperationRequest **request,
+                                       void **context, UA_DateTime *timeout) {
     UA_AsyncManager *am = &server->asyncManager;
     UA_AsyncManager *am = &server->asyncManager;
 
 
     UA_Boolean bRV = false;
     UA_Boolean bRV = false;
@@ -293,6 +293,8 @@ UA_Server_getAsyncOperation(UA_Server *server, UA_AsyncOperationType *type,
         *type = UA_ASYNCOPERATIONTYPE_CALL;
         *type = UA_ASYNCOPERATIONTYPE_CALL;
         *request = (UA_AsyncOperationRequest*)&ao->request;
         *request = (UA_AsyncOperationRequest*)&ao->request;
         *context = (void*)ao;
         *context = (void*)ao;
+        if(timeout)
+            *timeout = ao->parent->timeout;
         bRV = true;
         bRV = true;
     }
     }
     UA_UNLOCK(am->queueLock);
     UA_UNLOCK(am->queueLock);
@@ -300,6 +302,13 @@ UA_Server_getAsyncOperation(UA_Server *server, UA_AsyncOperationType *type,
     return bRV;
     return bRV;
 }
 }
 
 
+UA_Boolean
+UA_Server_getAsyncOperation(UA_Server *server, UA_AsyncOperationType *type,
+                            const UA_AsyncOperationRequest **request,
+                            void **context) {
+    return UA_Server_getAsyncOperationNonBlocking(server, type, request, context, NULL);
+}
+
 /* Worker submits Method Call Response */
 /* Worker submits Method Call Response */
 void
 void
 UA_Server_setAsyncOperationResult(UA_Server *server,
 UA_Server_setAsyncOperationResult(UA_Server *server,