ua_client.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. #ifndef UA_CLIENT_H_
  2. #define UA_CLIENT_H_
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include "ua_config.h"
  7. #include "ua_types.h"
  8. #include "ua_connection.h"
  9. #include "ua_log.h"
  10. #include "ua_types_generated.h"
  11. struct UA_Client;
  12. typedef struct UA_Client UA_Client;
  13. typedef struct UA_ClientConfig {
  14. UA_Int32 timeout; //sync response timeout
  15. UA_Int32 secureChannelLifeTime; // lifetime in ms (then the channel needs to be renewed)
  16. UA_Int32 timeToRenewSecureChannel; //time in ms before expiration to renew the secure channel
  17. UA_ConnectionConfig localConnectionConfig;
  18. } UA_ClientConfig;
  19. extern UA_EXPORT const UA_ClientConfig UA_ClientConfig_standard;
  20. /**
  21. * Creates and initialize a Client object
  22. *
  23. * @param config for the new client. You can use UA_ClientConfig_standard which has sane defaults
  24. * @param logger function pointer to a logger function. See examples/logger_stdout.c for a simple implementation
  25. * @return return the new Client object
  26. */
  27. UA_Client UA_EXPORT * UA_Client_new(UA_ClientConfig config, UA_Logger logger);
  28. /**
  29. * resets a Client object
  30. *
  31. * @param client to reset
  32. * @return Void
  33. */
  34. void UA_EXPORT UA_Client_reset(UA_Client* client);
  35. /**
  36. * delete a Client object
  37. *
  38. * @param client to delete
  39. * @return Void
  40. */
  41. void UA_EXPORT UA_Client_delete(UA_Client* client);
  42. /*************************/
  43. /* Manage the Connection */
  44. /*************************/
  45. typedef UA_Connection (*UA_ConnectClientConnection)(UA_ConnectionConfig localConf, const char *endpointUrl,
  46. UA_Logger logger);
  47. /**
  48. * start a connection to the selected server
  49. *
  50. * @param client to use
  51. * @param connection function. You can use ClientNetworkLayerTCP_connect from examples/networklayer_tcp.h
  52. * @param endpointURL to connect (for example "opc.tcp://localhost:16664")
  53. * @return Indicates whether the operation succeeded or returns an error code
  54. */
  55. UA_StatusCode UA_EXPORT
  56. UA_Client_connect(UA_Client *client, UA_ConnectClientConnection connFunc, const char *endpointUrl);
  57. /**
  58. * close a connection to the selected server
  59. *
  60. * @param client to use
  61. * @return Indicates whether the operation succeeded or returns an error code
  62. */
  63. UA_StatusCode UA_EXPORT UA_Client_disconnect(UA_Client *client);
  64. /**
  65. * renew a secure channel if needed
  66. *
  67. * @param client to use
  68. * @return Indicates whether the operation succeeded or returns an error code
  69. */
  70. UA_StatusCode UA_EXPORT UA_Client_manuallyRenewSecureChannel(UA_Client *client);
  71. /****************/
  72. /* Raw Services */
  73. /****************/
  74. /* Don't use this function. There are typed versions. */
  75. void UA_EXPORT
  76. __UA_Client_Service(UA_Client *client, const void *request, const UA_DataType *requestType,
  77. void *response, const UA_DataType *responseType);
  78. /* NodeManagement Service Set */
  79. /**
  80. * performs a service
  81. *
  82. * @param client to use
  83. * @param request to use
  84. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  85. */
  86. static UA_INLINE UA_AddNodesResponse
  87. UA_Client_Service_addNodes(UA_Client *client, const UA_AddNodesRequest request) {
  88. UA_AddNodesResponse response;
  89. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_ADDNODESREQUEST],
  90. &response, &UA_TYPES[UA_TYPES_ADDNODESRESPONSE]);
  91. return response; }
  92. /**
  93. * performs a service
  94. *
  95. * @param client to use
  96. * @param request to use
  97. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  98. */
  99. static UA_INLINE UA_AddReferencesResponse
  100. UA_Client_Service_addReferences(UA_Client *client, const UA_AddReferencesRequest request) {
  101. UA_AddReferencesResponse response;
  102. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_ADDNODESREQUEST],
  103. &response, &UA_TYPES[UA_TYPES_ADDNODESRESPONSE]);
  104. return response; }
  105. /**
  106. * performs a service
  107. *
  108. * @param client to use
  109. * @param request to use
  110. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  111. */
  112. static UA_INLINE UA_DeleteNodesResponse
  113. UA_Client_Service_deleteNodes(UA_Client *client, const UA_DeleteNodesRequest request) {
  114. UA_DeleteNodesResponse response;
  115. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_DELETENODESREQUEST],
  116. &response, &UA_TYPES[UA_TYPES_DELETENODESRESPONSE]);
  117. return response; }
  118. /**
  119. * performs a service
  120. *
  121. * @param client to use
  122. * @param request to use
  123. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  124. */
  125. static UA_INLINE UA_DeleteReferencesResponse
  126. UA_Client_Service_deleteReferences(UA_Client *client, const UA_DeleteReferencesRequest request) {
  127. UA_DeleteReferencesResponse response;
  128. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_DELETENODESREQUEST],
  129. &response, &UA_TYPES[UA_TYPES_DELETENODESRESPONSE]);
  130. return response; }
  131. /* View Service Set */
  132. /**
  133. * performs a service
  134. *
  135. * @param client to use
  136. * @param request to use
  137. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  138. */
  139. static UA_INLINE UA_BrowseResponse
  140. UA_Client_Service_browse(UA_Client *client, const UA_BrowseRequest request) {
  141. UA_BrowseResponse response;
  142. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_BROWSEREQUEST],
  143. &response, &UA_TYPES[UA_TYPES_BROWSERESPONSE]);
  144. return response; }
  145. /**
  146. * performs a service
  147. *
  148. * @param client to use
  149. * @param request to use
  150. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  151. */
  152. static UA_INLINE UA_BrowseNextResponse
  153. UA_Client_Service_browseNext(UA_Client *client, const UA_BrowseNextRequest request) {
  154. UA_BrowseNextResponse response;
  155. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_BROWSENEXTREQUEST],
  156. &response, &UA_TYPES[UA_TYPES_BROWSENEXTRESPONSE]);
  157. return response; }
  158. /**
  159. * performs a service
  160. *
  161. * @param client to use
  162. * @param request to use
  163. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  164. */
  165. static UA_INLINE UA_TranslateBrowsePathsToNodeIdsResponse
  166. UA_Client_Service_translateBrowsePathsToNodeIds(UA_Client *client,
  167. const UA_TranslateBrowsePathsToNodeIdsRequest request) {
  168. UA_TranslateBrowsePathsToNodeIdsResponse response;
  169. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_TRANSLATEBROWSEPATHSTONODEIDSREQUEST],
  170. &response, &UA_TYPES[UA_TYPES_TRANSLATEBROWSEPATHSTONODEIDSRESPONSE]);
  171. return response; }
  172. /**
  173. * performs a service
  174. *
  175. * @param client to use
  176. * @param request to use
  177. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  178. */
  179. static UA_INLINE UA_RegisterNodesResponse
  180. UA_Client_Service_registerNodes(UA_Client *client, const UA_RegisterNodesRequest request) {
  181. UA_RegisterNodesResponse response;
  182. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_REGISTERNODESREQUEST],
  183. &response, &UA_TYPES[UA_TYPES_REGISTERNODESRESPONSE]);
  184. return response; }
  185. /**
  186. * performs a service
  187. *
  188. * @param client to use
  189. * @param request to use
  190. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  191. */
  192. static UA_INLINE UA_UnregisterNodesResponse
  193. UA_Client_Service_unregisterNodes(UA_Client *client, const UA_UnregisterNodesRequest request) {
  194. UA_UnregisterNodesResponse response;
  195. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_UNREGISTERNODESREQUEST],
  196. &response, &UA_TYPES[UA_TYPES_UNREGISTERNODESRESPONSE]);
  197. return response; }
  198. /* Query Service Set */
  199. /**
  200. * performs a service
  201. *
  202. * @param client to use
  203. * @param request to use
  204. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  205. */
  206. static UA_INLINE UA_QueryFirstResponse
  207. UA_Client_Service_queryFirst(UA_Client *client, const UA_QueryFirstRequest request) {
  208. UA_QueryFirstResponse response;
  209. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_QUERYFIRSTREQUEST],
  210. &response, &UA_TYPES[UA_TYPES_QUERYFIRSTRESPONSE]);
  211. return response; }
  212. /**
  213. * performs a service
  214. *
  215. * @param client to use
  216. * @param request to use
  217. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  218. */
  219. static UA_INLINE UA_QueryNextResponse
  220. UA_Client_Service_queryNext(UA_Client *client, const UA_QueryNextRequest request) {
  221. UA_QueryNextResponse response;
  222. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_QUERYFIRSTREQUEST],
  223. &response, &UA_TYPES[UA_TYPES_QUERYFIRSTRESPONSE]);
  224. return response; }
  225. /* Attribute Service Set */
  226. /**
  227. * performs a service
  228. *
  229. * @param client to use
  230. * @param request to use
  231. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  232. */
  233. static UA_INLINE UA_ReadResponse
  234. UA_Client_Service_read(UA_Client *client, const UA_ReadRequest request) {
  235. UA_ReadResponse response;
  236. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_READREQUEST],
  237. &response, &UA_TYPES[UA_TYPES_READRESPONSE]);
  238. return response; }
  239. /**
  240. * performs a service
  241. *
  242. * @param client to use
  243. * @param request to use
  244. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  245. */
  246. static UA_INLINE UA_WriteResponse
  247. UA_Client_Service_write(UA_Client *client, const UA_WriteRequest request) {
  248. UA_WriteResponse response;
  249. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_WRITEREQUEST],
  250. &response, &UA_TYPES[UA_TYPES_WRITERESPONSE]);
  251. return response; }
  252. /* Method Service Set */
  253. /**
  254. * performs a service
  255. *
  256. * @param client to use
  257. * @param request to use
  258. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  259. */
  260. static UA_INLINE UA_CallResponse
  261. UA_Client_Service_call(UA_Client *client, const UA_CallRequest request) {
  262. UA_CallResponse response;
  263. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_CALLREQUEST],
  264. &response, &UA_TYPES[UA_TYPES_CALLRESPONSE]);
  265. return response; }
  266. #ifdef ENABLE_SUBSCRIPTIONS
  267. /* MonitoredItem Service Set */
  268. /**
  269. * performs a service
  270. *
  271. * @param client to use
  272. * @param request to use
  273. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  274. */
  275. static UA_INLINE UA_CreateMonitoredItemsResponse
  276. UA_Client_Service_createMonitoredItems(UA_Client *client, const UA_CreateMonitoredItemsRequest request) {
  277. UA_CreateMonitoredItemsResponse response;
  278. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_CREATEMONITOREDITEMSREQUEST],
  279. &response, &UA_TYPES[UA_TYPES_CREATEMONITOREDITEMSRESPONSE]);
  280. return response; }
  281. /**
  282. * performs a service
  283. *
  284. * @param client to use
  285. * @param request to use
  286. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  287. */
  288. static UA_INLINE UA_DeleteMonitoredItemsResponse
  289. UA_Client_Service_deleteMonitoredItems(UA_Client *client, const UA_DeleteMonitoredItemsRequest request) {
  290. UA_DeleteMonitoredItemsResponse response;
  291. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_DELETEMONITOREDITEMSREQUEST],
  292. &response, &UA_TYPES[UA_TYPES_DELETEMONITOREDITEMSRESPONSE]);
  293. return response; }
  294. /* Subscription Service Set */
  295. /**
  296. * performs a service
  297. *
  298. * @param client to use
  299. * @param request to use
  300. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  301. */
  302. static UA_INLINE UA_CreateSubscriptionResponse
  303. UA_Client_Service_createSubscription(UA_Client *client, const UA_CreateSubscriptionRequest request) {
  304. UA_CreateSubscriptionResponse response;
  305. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_CREATESUBSCRIPTIONREQUEST],
  306. &response, &UA_TYPES[UA_TYPES_CREATESUBSCRIPTIONRESPONSE]);
  307. return response; }
  308. /**
  309. * performs a service
  310. *
  311. * @param client to use
  312. * @param request to use
  313. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  314. */
  315. static UA_INLINE UA_ModifySubscriptionResponse
  316. UA_Client_Service_modifySubscription(UA_Client *client, const UA_ModifySubscriptionRequest request) {
  317. UA_ModifySubscriptionResponse response;
  318. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_MODIFYSUBSCRIPTIONREQUEST],
  319. &response, &UA_TYPES[UA_TYPES_MODIFYSUBSCRIPTIONRESPONSE]);
  320. return response; }
  321. /**
  322. * performs a service
  323. *
  324. * @param client to use
  325. * @param request to use
  326. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  327. */
  328. static UA_INLINE UA_DeleteSubscriptionsResponse
  329. UA_Client_Service_deleteSubscriptions(UA_Client *client, const UA_DeleteSubscriptionsRequest request) {
  330. UA_DeleteSubscriptionsResponse response;
  331. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_DELETESUBSCRIPTIONSREQUEST],
  332. &response, &UA_TYPES[UA_TYPES_DELETESUBSCRIPTIONSRESPONSE]);
  333. return response; }
  334. /**
  335. * performs a service
  336. *
  337. * @param client to use
  338. * @param request to use
  339. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  340. */
  341. static UA_INLINE UA_PublishResponse
  342. UA_Client_Service_publish(UA_Client *client, const UA_PublishRequest request) {
  343. UA_PublishResponse response;
  344. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_PUBLISHREQUEST],
  345. &response, &UA_TYPES[UA_TYPES_PUBLISHRESPONSE]);
  346. return response; }
  347. #endif
  348. #ifdef __cplusplus
  349. } // extern "C"
  350. #endif
  351. #endif /* UA_CLIENT_H_ */