ua_client.h 14 KB

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