ua_client.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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. * start a connection to the selected server
  71. *
  72. * @param client to use
  73. * @param connection function. You can use ClientNetworkLayerTCP_connect from examples/networklayer_tcp.h
  74. * @param endpointURL to connect (for example "opc.tcp://localhost:16664")
  75. * @param username
  76. * @param password
  77. * @return Indicates whether the operation succeeded or returns an error code
  78. */
  79. UA_StatusCode UA_EXPORT
  80. UA_Client_connect_username(UA_Client *client, UA_ConnectClientConnection connFunc, const char *endpointUrl, const char *username, const char *password);
  81. /**
  82. * close a connection to the selected server
  83. *
  84. * @param client to use
  85. * @return Indicates whether the operation succeeded or returns an error code
  86. */
  87. UA_StatusCode UA_EXPORT UA_Client_disconnect(UA_Client *client);
  88. /**
  89. * renew a secure channel if needed
  90. *
  91. * @param client to use
  92. * @return Indicates whether the operation succeeded or returns an error code
  93. */
  94. UA_StatusCode UA_EXPORT UA_Client_manuallyRenewSecureChannel(UA_Client *client);
  95. /****************/
  96. /* Raw Services */
  97. /****************/
  98. /* Don't use this function. There are typed versions. */
  99. void UA_EXPORT
  100. __UA_Client_Service(UA_Client *client, const void *request, const UA_DataType *requestType,
  101. void *response, const UA_DataType *responseType);
  102. /* NodeManagement Service Set */
  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_AddNodesResponse
  111. UA_Client_Service_addNodes(UA_Client *client, const UA_AddNodesRequest request) {
  112. UA_AddNodesResponse 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_AddReferencesResponse
  124. UA_Client_Service_addReferences(UA_Client *client, const UA_AddReferencesRequest request) {
  125. UA_AddReferencesResponse response;
  126. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_ADDNODESREQUEST],
  127. &response, &UA_TYPES[UA_TYPES_ADDNODESRESPONSE]);
  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_DeleteNodesResponse
  137. UA_Client_Service_deleteNodes(UA_Client *client, const UA_DeleteNodesRequest request) {
  138. UA_DeleteNodesResponse response;
  139. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_DELETENODESREQUEST],
  140. &response, &UA_TYPES[UA_TYPES_DELETENODESRESPONSE]);
  141. return response; }
  142. /**
  143. * performs a service
  144. *
  145. * @param client to use
  146. * @param request to use
  147. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  148. */
  149. static UA_INLINE UA_DeleteReferencesResponse
  150. UA_Client_Service_deleteReferences(UA_Client *client, const UA_DeleteReferencesRequest request) {
  151. UA_DeleteReferencesResponse response;
  152. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_DELETENODESREQUEST],
  153. &response, &UA_TYPES[UA_TYPES_DELETENODESRESPONSE]);
  154. return response; }
  155. /* View Service Set */
  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_BrowseResponse
  164. UA_Client_Service_browse(UA_Client *client, const UA_BrowseRequest request) {
  165. UA_BrowseResponse response;
  166. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_BROWSEREQUEST],
  167. &response, &UA_TYPES[UA_TYPES_BROWSERESPONSE]);
  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_BrowseNextResponse
  177. UA_Client_Service_browseNext(UA_Client *client, const UA_BrowseNextRequest request) {
  178. UA_BrowseNextResponse response;
  179. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_BROWSENEXTREQUEST],
  180. &response, &UA_TYPES[UA_TYPES_BROWSENEXTRESPONSE]);
  181. return response; }
  182. /**
  183. * performs a service
  184. *
  185. * @param client to use
  186. * @param request to use
  187. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  188. */
  189. static UA_INLINE UA_TranslateBrowsePathsToNodeIdsResponse
  190. UA_Client_Service_translateBrowsePathsToNodeIds(UA_Client *client,
  191. const UA_TranslateBrowsePathsToNodeIdsRequest request) {
  192. UA_TranslateBrowsePathsToNodeIdsResponse response;
  193. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_TRANSLATEBROWSEPATHSTONODEIDSREQUEST],
  194. &response, &UA_TYPES[UA_TYPES_TRANSLATEBROWSEPATHSTONODEIDSRESPONSE]);
  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_RegisterNodesResponse
  204. UA_Client_Service_registerNodes(UA_Client *client, const UA_RegisterNodesRequest request) {
  205. UA_RegisterNodesResponse response;
  206. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_REGISTERNODESREQUEST],
  207. &response, &UA_TYPES[UA_TYPES_REGISTERNODESRESPONSE]);
  208. return response; }
  209. /**
  210. * performs a service
  211. *
  212. * @param client to use
  213. * @param request to use
  214. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  215. */
  216. static UA_INLINE UA_UnregisterNodesResponse
  217. UA_Client_Service_unregisterNodes(UA_Client *client, const UA_UnregisterNodesRequest request) {
  218. UA_UnregisterNodesResponse response;
  219. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_UNREGISTERNODESREQUEST],
  220. &response, &UA_TYPES[UA_TYPES_UNREGISTERNODESRESPONSE]);
  221. return response; }
  222. /* Query Service Set */
  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_QueryFirstResponse
  231. UA_Client_Service_queryFirst(UA_Client *client, const UA_QueryFirstRequest request) {
  232. UA_QueryFirstResponse response;
  233. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_QUERYFIRSTREQUEST],
  234. &response, &UA_TYPES[UA_TYPES_QUERYFIRSTRESPONSE]);
  235. return response; }
  236. /**
  237. * performs a service
  238. *
  239. * @param client to use
  240. * @param request to use
  241. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  242. */
  243. static UA_INLINE UA_QueryNextResponse
  244. UA_Client_Service_queryNext(UA_Client *client, const UA_QueryNextRequest request) {
  245. UA_QueryNextResponse response;
  246. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_QUERYFIRSTREQUEST],
  247. &response, &UA_TYPES[UA_TYPES_QUERYFIRSTRESPONSE]);
  248. return response; }
  249. /* Attribute Service Set */
  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_ReadResponse
  258. UA_Client_Service_read(UA_Client *client, const UA_ReadRequest request) {
  259. UA_ReadResponse response;
  260. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_READREQUEST],
  261. &response, &UA_TYPES[UA_TYPES_READRESPONSE]);
  262. return response; }
  263. /**
  264. * performs a service
  265. *
  266. * @param client to use
  267. * @param request to use
  268. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  269. */
  270. static UA_INLINE UA_WriteResponse
  271. UA_Client_Service_write(UA_Client *client, const UA_WriteRequest request) {
  272. UA_WriteResponse response;
  273. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_WRITEREQUEST],
  274. &response, &UA_TYPES[UA_TYPES_WRITERESPONSE]);
  275. return response; }
  276. /* Method Service Set */
  277. /**
  278. * performs a service
  279. *
  280. * @param client to use
  281. * @param request to use
  282. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  283. */
  284. static UA_INLINE UA_CallResponse
  285. UA_Client_Service_call(UA_Client *client, const UA_CallRequest request) {
  286. UA_CallResponse response;
  287. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_CALLREQUEST],
  288. &response, &UA_TYPES[UA_TYPES_CALLRESPONSE]);
  289. return response; }
  290. #ifdef UA_ENABLE_SUBSCRIPTIONS
  291. /* MonitoredItem Service Set */
  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_CreateMonitoredItemsResponse
  300. UA_Client_Service_createMonitoredItems(UA_Client *client, const UA_CreateMonitoredItemsRequest request) {
  301. UA_CreateMonitoredItemsResponse response;
  302. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_CREATEMONITOREDITEMSREQUEST],
  303. &response, &UA_TYPES[UA_TYPES_CREATEMONITOREDITEMSRESPONSE]);
  304. return response; }
  305. /**
  306. * performs a service
  307. *
  308. * @param client to use
  309. * @param request to use
  310. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  311. */
  312. static UA_INLINE UA_DeleteMonitoredItemsResponse
  313. UA_Client_Service_deleteMonitoredItems(UA_Client *client, const UA_DeleteMonitoredItemsRequest request) {
  314. UA_DeleteMonitoredItemsResponse response;
  315. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_DELETEMONITOREDITEMSREQUEST],
  316. &response, &UA_TYPES[UA_TYPES_DELETEMONITOREDITEMSRESPONSE]);
  317. return response; }
  318. /* Subscription Service Set */
  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_CreateSubscriptionResponse
  327. UA_Client_Service_createSubscription(UA_Client *client, const UA_CreateSubscriptionRequest request) {
  328. UA_CreateSubscriptionResponse response;
  329. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_CREATESUBSCRIPTIONREQUEST],
  330. &response, &UA_TYPES[UA_TYPES_CREATESUBSCRIPTIONRESPONSE]);
  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_ModifySubscriptionResponse
  340. UA_Client_Service_modifySubscription(UA_Client *client, const UA_ModifySubscriptionRequest request) {
  341. UA_ModifySubscriptionResponse response;
  342. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_MODIFYSUBSCRIPTIONREQUEST],
  343. &response, &UA_TYPES[UA_TYPES_MODIFYSUBSCRIPTIONRESPONSE]);
  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_DeleteSubscriptionsResponse
  353. UA_Client_Service_deleteSubscriptions(UA_Client *client, const UA_DeleteSubscriptionsRequest request) {
  354. UA_DeleteSubscriptionsResponse response;
  355. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_DELETESUBSCRIPTIONSREQUEST],
  356. &response, &UA_TYPES[UA_TYPES_DELETESUBSCRIPTIONSRESPONSE]);
  357. return response; }
  358. /**
  359. * performs a service
  360. *
  361. * @param client to use
  362. * @param request to use
  363. * @return returns the response which has the UA_StatusCode in a UA_ResponseHeader
  364. */
  365. static UA_INLINE UA_PublishResponse
  366. UA_Client_Service_publish(UA_Client *client, const UA_PublishRequest request) {
  367. UA_PublishResponse response;
  368. __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_PUBLISHREQUEST],
  369. &response, &UA_TYPES[UA_TYPES_PUBLISHRESPONSE]);
  370. return response; }
  371. #endif
  372. #ifdef __cplusplus
  373. } // extern "C"
  374. #endif
  375. #endif /* UA_CLIENT_H_ */