ua_client_internal.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 "ua_securechannel.h"
  16. #include "ua_workqueue.h"
  17. #include "ua_client.h"
  18. #include "ua_client_highlevel.h"
  19. #include "ua_client_subscriptions.h"
  20. #include "ua_timer.h"
  21. #include "open62541_queue.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. checkClientSignature(const UA_SecureChannel *channel, const UA_CreateSessionResponse *response);
  76. UA_StatusCode
  77. signActivateSessionRequest(UA_SecureChannel *channel,
  78. UA_ActivateSessionRequest *request);
  79. /**********/
  80. /* Client */
  81. /**********/
  82. typedef struct AsyncServiceCall {
  83. LIST_ENTRY(AsyncServiceCall) pointers;
  84. UA_UInt32 requestId;
  85. UA_ClientAsyncServiceCallback callback;
  86. const UA_DataType *responseType;
  87. void *userdata;
  88. UA_DateTime start;
  89. UA_UInt32 timeout;
  90. void *responsedata;
  91. } AsyncServiceCall;
  92. void UA_Client_AsyncService_cancel(UA_Client *client, AsyncServiceCall *ac,
  93. UA_StatusCode statusCode);
  94. void UA_Client_AsyncService_removeAll(UA_Client *client, UA_StatusCode statusCode);
  95. typedef struct CustomCallback {
  96. LIST_ENTRY(CustomCallback)
  97. pointers;
  98. //to find the correct callback
  99. UA_UInt32 callbackId;
  100. UA_ClientAsyncServiceCallback callback;
  101. UA_AttributeId attributeId;
  102. const UA_DataType *outDataType;
  103. } CustomCallback;
  104. struct UA_Client {
  105. /* State */
  106. UA_ClientState state;
  107. UA_ClientConfig config;
  108. UA_Timer timer;
  109. UA_StatusCode connectStatus;
  110. /* Connection */
  111. UA_Connection connection;
  112. /* SecureChannel */
  113. UA_SecureChannel channel;
  114. UA_UInt32 requestId;
  115. UA_DateTime nextChannelRenewal;
  116. /* Session */
  117. UA_NodeId authenticationToken;
  118. UA_UInt32 requestHandle;
  119. UA_Boolean endpointsHandshake;
  120. UA_String endpointUrl; /* Only for the async connect */
  121. /* Async Service */
  122. AsyncServiceCall asyncConnectCall;
  123. LIST_HEAD(ListOfAsyncServiceCall, AsyncServiceCall) asyncServiceCalls;
  124. /*When using highlevel functions these are the callbacks that can be accessed by the user*/
  125. LIST_HEAD(ListOfCustomCallback, CustomCallback) customCallbacks;
  126. /* Work queue */
  127. UA_WorkQueue workQueue;
  128. /* Subscriptions */
  129. #ifdef UA_ENABLE_SUBSCRIPTIONS
  130. UA_UInt32 monitoredItemHandles;
  131. LIST_HEAD(, UA_Client_NotificationsAckNumber) pendingNotificationsAcks;
  132. LIST_HEAD(, UA_Client_Subscription) subscriptions;
  133. UA_UInt16 currentlyOutStandingPublishRequests;
  134. #endif
  135. /* Connectivity check */
  136. UA_DateTime lastConnectivityCheck;
  137. UA_Boolean pendingConnectivityCheck;
  138. };
  139. void
  140. setClientState(UA_Client *client, UA_ClientState state);
  141. /* The endpointUrl must be set in the configuration. If the complete
  142. * endpointdescription is not set, a GetEndpoints is performed. */
  143. UA_StatusCode
  144. UA_Client_connectInternal(UA_Client *client, const UA_String endpointUrl);
  145. UA_StatusCode
  146. UA_Client_connectTCPSecureChannel(UA_Client *client, const UA_String endpointUrl);
  147. UA_StatusCode
  148. UA_Client_connectSession(UA_Client *client);
  149. UA_StatusCode
  150. UA_Client_getEndpointsInternal(UA_Client *client, const UA_String endpointUrl,
  151. size_t *endpointDescriptionsSize,
  152. UA_EndpointDescription **endpointDescriptions);
  153. /* Receive and process messages until a synchronous message arrives or the
  154. * timout finishes */
  155. UA_StatusCode
  156. receivePacketAsync(UA_Client *client);
  157. UA_StatusCode
  158. processACKResponseAsync(void *application, UA_Connection *connection,
  159. UA_ByteString *chunk);
  160. UA_StatusCode
  161. processOPNResponseAsync(void *application, UA_Connection *connection,
  162. UA_ByteString *chunk);
  163. UA_StatusCode
  164. openSecureChannel(UA_Client *client, UA_Boolean renew);
  165. UA_StatusCode
  166. receiveServiceResponse(UA_Client *client, void *response,
  167. const UA_DataType *responseType, UA_DateTime maxDate,
  168. UA_UInt32 *synchronousRequestId);
  169. UA_StatusCode
  170. receiveServiceResponseAsync(UA_Client *client, void *response,
  171. const UA_DataType *responseType);
  172. UA_StatusCode
  173. UA_Client_connect_iterate (UA_Client *client);
  174. void
  175. setUserIdentityPolicyId(const UA_EndpointDescription *endpoint,
  176. const UA_DataType *tokenType,
  177. UA_String *policyId, UA_String *securityPolicyUri);
  178. UA_SecurityPolicy *
  179. getSecurityPolicy(UA_Client *client, UA_String policyUri);
  180. UA_StatusCode
  181. encryptUserIdentityToken(UA_Client *client, const UA_String *userTokenSecurityPolicy,
  182. UA_ExtensionObject *userIdentityToken);
  183. _UA_END_DECLS
  184. #endif /* UA_CLIENT_INTERNAL_H_ */