ua_client_internal.h 7.2 KB

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