ua_client_internal.h 7.1 KB

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