ua_client_internal.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. #include "ua_securechannel.h"
  15. #include "ua_client_highlevel.h"
  16. #include "ua_client_subscriptions.h"
  17. #include "ua_timer.h"
  18. #include "../../deps/queue.h"
  19. _UA_BEGIN_DECLS
  20. /**************************/
  21. /* Subscriptions Handling */
  22. /**************************/
  23. #ifdef UA_ENABLE_SUBSCRIPTIONS
  24. typedef struct UA_Client_NotificationsAckNumber {
  25. LIST_ENTRY(UA_Client_NotificationsAckNumber) listEntry;
  26. UA_SubscriptionAcknowledgement subAck;
  27. } UA_Client_NotificationsAckNumber;
  28. typedef struct UA_Client_MonitoredItem {
  29. LIST_ENTRY(UA_Client_MonitoredItem) listEntry;
  30. UA_UInt32 monitoredItemId;
  31. UA_UInt32 clientHandle;
  32. void *context;
  33. UA_Client_DeleteMonitoredItemCallback deleteCallback;
  34. union {
  35. UA_Client_DataChangeNotificationCallback dataChangeCallback;
  36. UA_Client_EventNotificationCallback eventCallback;
  37. } handler;
  38. UA_Boolean isEventMonitoredItem; /* Otherwise a DataChange MoniitoredItem */
  39. } UA_Client_MonitoredItem;
  40. typedef struct UA_Client_Subscription {
  41. LIST_ENTRY(UA_Client_Subscription) listEntry;
  42. UA_UInt32 subscriptionId;
  43. void *context;
  44. UA_Double publishingInterval;
  45. UA_UInt32 maxKeepAliveCount;
  46. UA_Client_StatusChangeNotificationCallback statusChangeCallback;
  47. UA_Client_DeleteSubscriptionCallback deleteCallback;
  48. UA_UInt32 sequenceNumber;
  49. UA_DateTime lastActivity;
  50. LIST_HEAD(UA_ListOfClientMonitoredItems, UA_Client_MonitoredItem) monitoredItems;
  51. } UA_Client_Subscription;
  52. void
  53. UA_Client_Subscriptions_clean(UA_Client *client);
  54. void
  55. UA_Client_MonitoredItem_remove(UA_Client *client, UA_Client_Subscription *sub,
  56. UA_Client_MonitoredItem *mon);
  57. void
  58. UA_Client_Subscriptions_processPublishResponse(UA_Client *client,
  59. UA_PublishRequest *request,
  60. UA_PublishResponse *response);
  61. UA_StatusCode
  62. UA_Client_preparePublishRequest(UA_Client *client, UA_PublishRequest *request);
  63. UA_StatusCode
  64. UA_Client_Subscriptions_backgroundPublish(UA_Client *client);
  65. void
  66. UA_Client_Subscriptions_backgroundPublishInactivityCheck(UA_Client *client);
  67. #endif /* UA_ENABLE_SUBSCRIPTIONS */
  68. /**************/
  69. /* Encryption */
  70. /**************/
  71. UA_StatusCode
  72. checkClientSignature(const UA_SecureChannel *channel, const UA_CreateSessionResponse *response);
  73. UA_StatusCode
  74. signActivateSessionRequest(UA_SecureChannel *channel,
  75. UA_ActivateSessionRequest *request);
  76. /**********/
  77. /* Client */
  78. /**********/
  79. typedef struct AsyncServiceCall {
  80. LIST_ENTRY(AsyncServiceCall) pointers;
  81. UA_UInt32 requestId;
  82. UA_ClientAsyncServiceCallback callback;
  83. const UA_DataType *responseType;
  84. void *userdata;
  85. UA_DateTime start;
  86. UA_UInt32 timeout;
  87. void *responsedata;
  88. } AsyncServiceCall;
  89. void UA_Client_AsyncService_cancel(UA_Client *client, AsyncServiceCall *ac,
  90. UA_StatusCode statusCode);
  91. void UA_Client_AsyncService_removeAll(UA_Client *client, UA_StatusCode statusCode);
  92. typedef struct CustomCallback {
  93. LIST_ENTRY(CustomCallback)
  94. pointers;
  95. //to find the correct callback
  96. UA_UInt32 callbackId;
  97. UA_ClientAsyncServiceCallback callback;
  98. UA_AttributeId attributeId;
  99. const UA_DataType *outDataType;
  100. } CustomCallback;
  101. typedef enum {
  102. UA_CHUNK_COMPLETED,
  103. UA_CHUNK_NOT_COMPLETED
  104. } UA_ChunkState;
  105. typedef enum {
  106. UA_CLIENTAUTHENTICATION_NONE,
  107. UA_CLIENTAUTHENTICATION_USERNAME
  108. } UA_Client_Authentication;
  109. struct UA_Client {
  110. /* State */
  111. UA_ClientState state;
  112. UA_ClientConfig config;
  113. UA_Timer timer;
  114. UA_StatusCode connectStatus;
  115. /* Connection */
  116. UA_Connection connection;
  117. UA_String endpointUrl;
  118. /* SecureChannel */
  119. UA_SecurityPolicy securityPolicy; /* TODO: Move supported policies to the config */
  120. UA_SecureChannel channel;
  121. UA_UInt32 requestId;
  122. UA_DateTime nextChannelRenewal;
  123. /* Authentication */
  124. UA_Client_Authentication authenticationMethod;
  125. UA_String username;
  126. UA_String password;
  127. /* Session */
  128. UA_UserTokenPolicy token;
  129. UA_NodeId authenticationToken;
  130. UA_UInt32 requestHandle;
  131. /* Connection Establishment (async) */
  132. UA_Connection_processChunk ackResponseCallback;
  133. UA_Connection_processChunk openSecureChannelResponseCallback;
  134. UA_Boolean endpointsHandshake;
  135. /* Async Service */
  136. AsyncServiceCall asyncConnectCall;
  137. LIST_HEAD(ListOfAsyncServiceCall, AsyncServiceCall) asyncServiceCalls;
  138. /*When using highlevel functions these are the callbacks that can be accessed by the user*/
  139. LIST_HEAD(ListOfCustomCallback, CustomCallback) customCallbacks;
  140. /* Delayed callbacks */
  141. SLIST_HEAD(DelayedClientCallbacksList, UA_DelayedClientCallback) delayedClientCallbacks;
  142. /* Subscriptions */
  143. #ifdef UA_ENABLE_SUBSCRIPTIONS
  144. UA_UInt32 monitoredItemHandles;
  145. LIST_HEAD(ListOfUnacknowledgedNotifications, UA_Client_NotificationsAckNumber) pendingNotificationsAcks;
  146. LIST_HEAD(ListOfClientSubscriptionItems, UA_Client_Subscription) subscriptions;
  147. UA_UInt16 currentlyOutStandingPublishRequests;
  148. #endif
  149. /* Connectivity check */
  150. UA_DateTime lastConnectivityCheck;
  151. UA_Boolean pendingConnectivityCheck;
  152. };
  153. void
  154. setClientState(UA_Client *client, UA_ClientState state);
  155. UA_StatusCode
  156. UA_Client_connectInternal(UA_Client *client, const char *endpointUrl,
  157. UA_Boolean endpointsHandshake, UA_Boolean createNewSession);
  158. UA_StatusCode
  159. UA_Client_connectInternalAsync(UA_Client *client, const char *endpointUrl,
  160. UA_ClientAsyncServiceCallback callback,
  161. void *connected, UA_Boolean endpointsHandshake,
  162. UA_Boolean createNewSession);
  163. UA_StatusCode
  164. UA_Client_getEndpointsInternal(UA_Client *client,
  165. size_t* endpointDescriptionsSize,
  166. UA_EndpointDescription** endpointDescriptions);
  167. /* Receive and process messages until a synchronous message arrives or the
  168. * timout finishes */
  169. UA_StatusCode
  170. receivePacketAsync(UA_Client *client);
  171. UA_StatusCode
  172. openSecureChannel(UA_Client *client, UA_Boolean renew);
  173. UA_StatusCode
  174. receiveServiceResponse(UA_Client *client, void *response,
  175. const UA_DataType *responseType, UA_DateTime maxDate,
  176. UA_UInt32 *synchronousRequestId);
  177. UA_StatusCode
  178. receiveServiceResponseAsync(UA_Client *client, void *response,
  179. const UA_DataType *responseType);
  180. void
  181. UA_Client_workerCallback(UA_Client *client, UA_ClientCallback callback,
  182. void *data);
  183. UA_StatusCode
  184. UA_Client_delayedCallback(UA_Client *client, UA_ClientCallback callback,
  185. void *data);
  186. UA_StatusCode
  187. UA_Client_connect_iterate (UA_Client *client);
  188. _UA_END_DECLS
  189. #endif /* UA_CLIENT_INTERNAL_H_ */