ua_client.h 14 KB

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