#ifndef UA_SERVER_ASYNC_H_
#define UA_SERVER_ASYNC_H_
#include <open62541/server.h>
#include "open62541_queue.h"
#include "../util/ua_util_internal.h"
#include "ua_session.h"
_UA_BEGIN_DECLS
struct UA_AsyncResponse;
typedef struct UA_AsyncResponse UA_AsyncResponse;
typedef enum {
UA_ASYNCOPERATIONTYPE_CALL_REQUEST = 0,
UA_ASYNCOPERATIONTYPE_READ_REQUEST = 1,
UA_ASYNCOPERATIONTYPE_WRITE_REQUEST = 2,
UA_ASYNCOPERATIONTYPE_CALL_DIRECT = (0 + 4),
UA_ASYNCOPERATIONTYPE_READ_DIRECT = (1 + 4),
UA_ASYNCOPERATIONTYPE_WRITE_DIRECT = (2 + 4)
} UA_AsyncOperationType;
typedef struct UA_AsyncOperation {
TAILQ_ENTRY(UA_AsyncOperation) pointers;
UA_AsyncOperationType asyncOperationType;
union {
UA_AsyncResponse *response;
struct {
UA_DateTime timeout;
void *context;
union {
UA_ServerAsyncReadResultCallback read;
UA_ServerAsyncWriteResultCallback write;
UA_ServerAsyncMethodResultCallback call;
} method;
} callback;
} handling;
union {
UA_CallMethodResult *call;
UA_StatusCode *write;
UA_DataValue *read;
UA_CallMethodResult directCall;
UA_StatusCode directWrite;
UA_DataValue directRead;
} output;
union {
UA_WriteValue writeValue;
} context;
} UA_AsyncOperation;
struct UA_AsyncResponse {
TAILQ_ENTRY(UA_AsyncResponse) pointers;
UA_UInt32 requestId;
UA_UInt32 requestHandle;
UA_DateTime timeout;
UA_NodeId sessionId;
UA_UInt32 opCountdown;
const UA_DataType *responseType;
union {
UA_CallResponse callResponse;
UA_ReadResponse readResponse;
UA_WriteResponse writeResponse;
} response;
};
typedef struct {
UA_UInt32 currentRequestId;
UA_UInt32 currentRequestHandle;
TAILQ_HEAD(, UA_AsyncResponse) waitingResponses;
TAILQ_HEAD(, UA_AsyncResponse) readyResponses;
TAILQ_HEAD(, UA_AsyncOperation) waitingOps;
TAILQ_HEAD(, UA_AsyncOperation) readyOps;
size_t opsCount;
UA_UInt64 checkTimeoutCallbackId;
UA_DelayedCallback dc;
} UA_AsyncManager;
void UA_AsyncManager_init(UA_AsyncManager *am, UA_Server *server);
void UA_AsyncManager_start(UA_AsyncManager *am, UA_Server *server);
void UA_AsyncManager_stop(UA_AsyncManager *am, UA_Server *server);
void UA_AsyncManager_clear(UA_AsyncManager *am, UA_Server *server);
UA_UInt32
UA_AsyncManager_cancel(UA_Server *server, UA_Session *session, UA_UInt32 requestHandle);
UA_StatusCode
read_async(UA_Server *server, UA_Session *session, const UA_ReadValueId *operation,
UA_TimestampsToReturn ttr, UA_ServerAsyncReadResultCallback callback,
void *context, UA_UInt32 timeout);
UA_StatusCode
write_async(UA_Server *server, UA_Session *session, const UA_WriteValue *operation,
UA_ServerAsyncWriteResultCallback callback, void *context,
UA_UInt32 timeout);
UA_StatusCode
call_async(UA_Server *server, UA_Session *session, const UA_CallMethodRequest *operation,
UA_ServerAsyncMethodResultCallback callback, void *context, UA_UInt32 timeout);
void
async_cancel(UA_Server *server, void *context, UA_StatusCode status,
UA_Boolean cancelSynchronous);
_UA_END_DECLS
#endif