ua_client_internal.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 2015-2016 (c) Sten Grüner
  6. * Copyright 2015-2017 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
  7. * Copyright 2015 (c) Oleksiy Vasylyev
  8. * Copyright 2016-2017 (c) Florian Palm
  9. * Copyright 2017 (c) Stefan Profanter, fortiss GmbH
  10. * Copyright 2017 (c) Mark Giraud, Fraunhofer IOSB
  11. */
  12. #ifndef UA_CLIENT_INTERNAL_H_
  13. #define UA_CLIENT_INTERNAL_H_
  14. #define UA_INTERNAL
  15. #include <open62541/client.h>
  16. #include <open62541/client_highlevel.h>
  17. #include <open62541/client_subscriptions.h>
  18. #include "open62541_queue.h"
  19. #include "ua_securechannel.h"
  20. #include "ua_timer.h"
  21. #include "ua_workqueue.h"
  22. _UA_BEGIN_DECLS
  23. /**************************/
  24. /* Subscriptions Handling */
  25. /**************************/
  26. #ifdef UA_ENABLE_SUBSCRIPTIONS
  27. typedef struct UA_Client_NotificationsAckNumber {
  28. LIST_ENTRY(UA_Client_NotificationsAckNumber) listEntry;
  29. UA_SubscriptionAcknowledgement subAck;
  30. } UA_Client_NotificationsAckNumber;
  31. typedef struct UA_Client_MonitoredItem {
  32. LIST_ENTRY(UA_Client_MonitoredItem) listEntry;
  33. UA_UInt32 monitoredItemId;
  34. UA_UInt32 clientHandle;
  35. void *context;
  36. UA_Client_DeleteMonitoredItemCallback deleteCallback;
  37. union {
  38. UA_Client_DataChangeNotificationCallback dataChangeCallback;
  39. UA_Client_EventNotificationCallback eventCallback;
  40. } handler;
  41. UA_Boolean isEventMonitoredItem; /* Otherwise a DataChange MoniitoredItem */
  42. } UA_Client_MonitoredItem;
  43. typedef struct UA_Client_Subscription {
  44. LIST_ENTRY(UA_Client_Subscription) listEntry;
  45. UA_UInt32 subscriptionId;
  46. void *context;
  47. UA_Double publishingInterval;
  48. UA_UInt32 maxKeepAliveCount;
  49. UA_Client_StatusChangeNotificationCallback statusChangeCallback;
  50. UA_Client_DeleteSubscriptionCallback deleteCallback;
  51. UA_UInt32 sequenceNumber;
  52. UA_DateTime lastActivity;
  53. LIST_HEAD(UA_ListOfClientMonitoredItems, UA_Client_MonitoredItem) monitoredItems;
  54. } UA_Client_Subscription;
  55. void
  56. UA_Client_Subscriptions_clean(UA_Client *client);
  57. void
  58. UA_Client_MonitoredItem_remove(UA_Client *client, UA_Client_Subscription *sub,
  59. UA_Client_MonitoredItem *mon);
  60. void
  61. UA_Client_Subscriptions_processPublishResponse(UA_Client *client,
  62. UA_PublishRequest *request,
  63. UA_PublishResponse *response);
  64. UA_StatusCode
  65. UA_Client_preparePublishRequest(UA_Client *client, UA_PublishRequest *request);
  66. UA_StatusCode
  67. UA_Client_Subscriptions_backgroundPublish(UA_Client *client);
  68. void
  69. UA_Client_Subscriptions_backgroundPublishInactivityCheck(UA_Client *client);
  70. #endif /* UA_ENABLE_SUBSCRIPTIONS */
  71. /**************/
  72. /* Encryption */
  73. /**************/
  74. UA_StatusCode
  75. signActivateSessionRequest(UA_SecureChannel *channel,
  76. UA_ActivateSessionRequest *request);
  77. /**********/
  78. /* Client */
  79. /**********/
  80. typedef struct AsyncServiceCall {
  81. LIST_ENTRY(AsyncServiceCall) pointers;
  82. UA_UInt32 requestId;
  83. UA_ClientAsyncServiceCallback callback;
  84. const UA_DataType *responseType;
  85. void *userdata;
  86. UA_DateTime start;
  87. UA_UInt32 timeout;
  88. void *responsedata;
  89. } AsyncServiceCall;
  90. void UA_Client_AsyncService_cancel(UA_Client *client, AsyncServiceCall *ac,
  91. UA_StatusCode statusCode);
  92. void UA_Client_AsyncService_removeAll(UA_Client *client, UA_StatusCode statusCode);
  93. typedef struct CustomCallback {
  94. LIST_ENTRY(CustomCallback)
  95. pointers;
  96. //to find the correct callback
  97. UA_UInt32 callbackId;
  98. UA_ClientAsyncServiceCallback callback;
  99. UA_AttributeId attributeId;
  100. const UA_DataType *outDataType;
  101. } CustomCallback;
  102. struct UA_Client {
  103. /* State */
  104. UA_ClientState state;
  105. UA_ClientConfig config;
  106. UA_Timer timer;
  107. UA_StatusCode connectStatus;
  108. /* Connection */
  109. UA_Connection connection;
  110. /* SecureChannel */
  111. UA_SecureChannel channel;
  112. UA_UInt32 requestId;
  113. UA_DateTime nextChannelRenewal;
  114. /* Session */
  115. UA_NodeId authenticationToken;
  116. UA_UInt32 requestHandle;
  117. UA_Boolean endpointsHandshake;
  118. UA_String endpointUrl; /* Only for the async connect */
  119. /* Async Service */
  120. AsyncServiceCall asyncConnectCall;
  121. LIST_HEAD(ListOfAsyncServiceCall, AsyncServiceCall) asyncServiceCalls;
  122. /*When using highlevel functions these are the callbacks that can be accessed by the user*/
  123. LIST_HEAD(ListOfCustomCallback, CustomCallback) customCallbacks;
  124. /* Work queue */
  125. UA_WorkQueue workQueue;
  126. /* Subscriptions */
  127. #ifdef UA_ENABLE_SUBSCRIPTIONS
  128. UA_UInt32 monitoredItemHandles;
  129. LIST_HEAD(, UA_Client_NotificationsAckNumber) pendingNotificationsAcks;
  130. LIST_HEAD(, UA_Client_Subscription) subscriptions;
  131. UA_UInt16 currentlyOutStandingPublishRequests;
  132. #endif
  133. /* Connectivity check */
  134. UA_DateTime lastConnectivityCheck;
  135. UA_Boolean pendingConnectivityCheck;
  136. };
  137. void
  138. setClientState(UA_Client *client, UA_ClientState state);
  139. /* The endpointUrl must be set in the configuration. If the complete
  140. * endpointdescription is not set, a GetEndpoints is performed. */
  141. UA_StatusCode
  142. UA_Client_connectInternal(UA_Client *client, const UA_String endpointUrl);
  143. UA_StatusCode
  144. UA_Client_connectTCPSecureChannel(UA_Client *client, const UA_String endpointUrl);
  145. UA_StatusCode
  146. UA_Client_connectSession(UA_Client *client);
  147. UA_StatusCode
  148. UA_Client_getEndpointsInternal(UA_Client *client, const UA_String endpointUrl,
  149. size_t *endpointDescriptionsSize,
  150. UA_EndpointDescription **endpointDescriptions);
  151. /* Receive and process messages until a synchronous message arrives or the
  152. * timout finishes */
  153. UA_StatusCode
  154. receivePacketAsync(UA_Client *client);
  155. UA_StatusCode
  156. processACKResponseAsync(void *application, UA_Connection *connection,
  157. UA_ByteString *chunk);
  158. UA_StatusCode
  159. processOPNResponseAsync(void *application, UA_Connection *connection,
  160. UA_ByteString *chunk);
  161. UA_StatusCode
  162. openSecureChannel(UA_Client *client, UA_Boolean renew);
  163. UA_StatusCode
  164. receiveServiceResponse(UA_Client *client, void *response,
  165. const UA_DataType *responseType, UA_DateTime maxDate,
  166. const UA_UInt32 *synchronousRequestId);
  167. UA_StatusCode
  168. receiveServiceResponseAsync(UA_Client *client, void *response,
  169. const UA_DataType *responseType);
  170. UA_StatusCode
  171. UA_Client_connect_iterate (UA_Client *client);
  172. void
  173. setUserIdentityPolicyId(const UA_EndpointDescription *endpoint,
  174. const UA_DataType *tokenType,
  175. UA_String *policyId, UA_String *securityPolicyUri);
  176. UA_SecurityPolicy *
  177. getSecurityPolicy(UA_Client *client, UA_String policyUri);
  178. UA_StatusCode
  179. encryptUserIdentityToken(UA_Client *client, const UA_String *userTokenSecurityPolicy,
  180. UA_ExtensionObject *userIdentityToken);
  181. _UA_END_DECLS
  182. #endif /* UA_CLIENT_INTERNAL_H_ */