open62541 1.3.12
Open source implementation of OPC UA
Loading...
Searching...
No Matches
ua_server_async.h
Go to the documentation of this file.
1/** This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 *
5 * Copyright 2019 (c) Fraunhofer IOSB (Author: Klaus Schick)
6 * based on
7 * Copyright 2014-2017 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
8 * Copyright 2014, 2017 (c) Florian Palm
9 * Copyright 2015 (c) Sten GrĂ¼ner
10 * Copyright 2015 (c) Oleksiy Vasylyev
11 * Copyright 2017 (c) Stefan Profanter, fortiss GmbH
12 */
13
14#ifndef UA_SERVER_ASYNC_H_
15#define UA_SERVER_ASYNC_H_
16
17#include <open62541/server.h>
18
19#include "open62541_queue.h"
20#include "ua_util_internal.h"
21
23
24#if UA_MULTITHREADING >= 100
25
26struct UA_AsyncResponse;
27typedef struct UA_AsyncResponse UA_AsyncResponse;
28
29/** A single operation (of a larger request) */
30typedef struct UA_AsyncOperation {
31 TAILQ_ENTRY(UA_AsyncOperation) pointers;
33 UA_CallMethodResult response;
34 size_t index; /* Index of the operation in the array of ops in
35 * request/response */
36 UA_AsyncResponse *parent; /* Always non-NULL. The parent is only removed
37 * when its operations are removed */
38} UA_AsyncOperation;
39
40struct UA_AsyncResponse {
41 TAILQ_ENTRY(UA_AsyncResponse) pointers; /* Insert new at the end */
42 UA_UInt32 requestId;
43 UA_NodeId sessionId;
44 UA_UInt32 requestHandle;
45 UA_DateTime timeout;
46 UA_AsyncOperationType operationType;
47 union {
48 UA_CallResponse callResponse;
49 UA_ReadResponse readResponse;
50 UA_WriteResponse writeResponse;
51 } response;
52 UA_UInt32 opCountdown; /* Counter for outstanding operations. The AR can
53 * only be deleted when all have returned. */
54};
55
56typedef TAILQ_HEAD(UA_AsyncOperationQueue, UA_AsyncOperation) UA_AsyncOperationQueue;
57
58typedef struct {
59 /* Requests / Responses */
60 TAILQ_HEAD(, UA_AsyncResponse) asyncResponses;
61 size_t asyncResponsesCount;
62
63 /* Operations for the workers. The queues are all FIFO: Put in at the tail,
64 * take out at the head.*/
65 UA_Lock queueLock;
66 UA_AsyncOperationQueue newQueue; /* New operations for the workers */
67 UA_AsyncOperationQueue dispatchedQueue; /* Operations taken by a worker. When a result is
68 * returned, we search for the op here to see if it
69 * is still "alive" (not timed out). */
70 UA_AsyncOperationQueue resultQueue; /* Results to be integrated */
71 size_t opsCount; /* How many operations are transient (in one of the three queues)? */
72
73 UA_UInt64 checkTimeoutCallbackId; /* Registered repeated callbacks */
74} UA_AsyncManager;
75
76void UA_AsyncManager_init(UA_AsyncManager *am, UA_Server *server);
77void UA_AsyncManager_clear(UA_AsyncManager *am, UA_Server *server);
78
80UA_AsyncManager_createAsyncResponse(UA_AsyncManager *am, UA_Server *server,
81 const UA_NodeId *sessionId,
82 const UA_UInt32 requestId,
83 const UA_UInt32 requestHandle,
84 const UA_AsyncOperationType operationType,
85 UA_AsyncResponse **outAr);
86
87/** Only remove the AsyncResponse when the operation count is zero */
88void
89UA_AsyncManager_removeAsyncResponse(UA_AsyncManager *am, UA_AsyncResponse *ar);
90
92UA_AsyncManager_createAsyncOp(UA_AsyncManager *am, UA_Server *server,
93 UA_AsyncResponse *ar, size_t opIndex,
94 const UA_CallMethodRequest *opRequest);
95
96typedef void (*UA_AsyncServiceOperation)(UA_Server *server, UA_Session *session,
97 UA_UInt32 requestId, UA_UInt32 requestHandle,
98 size_t opIndex, const void *requestOperation,
99 void *responseOperation, UA_AsyncResponse **ar);
100
101/** Creates an AsyncResponse in-situ when an async operation is encountered. If
102 * that is the case, the sync responses are moved to the AsyncResponse. */
104UA_Server_processServiceOperationsAsync(UA_Server *server, UA_Session *session,
105 UA_UInt32 requestId, UA_UInt32 requestHandle,
106 UA_AsyncServiceOperation operationCallback,
107 const size_t *requestOperations,
108 const UA_DataType *requestOperationsType,
109 size_t *responseOperations,
110 const UA_DataType *responseOperationsType,
111 UA_AsyncResponse **ar)
112UA_FUNC_ATTR_WARN_UNUSED_RESULT;
113
114#endif /* UA_MULTITHREADING >= 100 */
115
117
118#endif /* UA_SERVER_ASYNC_H_ */
#define _UA_BEGIN_DECLS
#undef UA_DEBUG_DUMP_PKGS
Definition config.h:89
#define _UA_END_DECLS
Definition config.h:96
#define TAILQ_HEAD(name, type)
#define TAILQ_ENTRY(type)
uint32_t UA_UInt32
Definition types.h:56
int64_t UA_DateTime
Definition types.h:144
uint32_t UA_StatusCode
Definition types.h:77
uint64_t UA_UInt64
Definition types.h:66