ua_client.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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-2017 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
  6. * Copyright 2015-2016 (c) Sten Grüner
  7. * Copyright 2015-2016 (c) Chris Iatrou
  8. * Copyright 2015 (c) hfaham
  9. * Copyright 2015-2017 (c) Florian Palm
  10. * Copyright 2017-2018 (c) Thomas Stalder, Blue Time Concept SA
  11. * Copyright 2015 (c) Holger Jeromin
  12. * Copyright 2015 (c) Oleksiy Vasylyev
  13. * Copyright 2016 (c) TorbenD
  14. * Copyright 2017 (c) Stefan Profanter, fortiss GmbH
  15. * Copyright 2016 (c) Lykurg
  16. * Copyright 2017 (c) Mark Giraud, Fraunhofer IOSB
  17. * Copyright 2018 (c) Kalycito Infotech Private Limited
  18. */
  19. #include <open62541/types_generated_encoding_binary.h>
  20. #include "ua_client_internal.h"
  21. #include "ua_connection_internal.h"
  22. #include "ua_types_encoding_binary.h"
  23. #define STATUS_CODE_BAD_POINTER 0x01
  24. /********************/
  25. /* Client Lifecycle */
  26. /********************/
  27. static void
  28. UA_Client_init(UA_Client* client) {
  29. memset(client, 0, sizeof(UA_Client));
  30. UA_SecureChannel_init(&client->channel);
  31. if(client->config.stateCallback)
  32. client->config.stateCallback(client, client->state);
  33. /* Catch error during async connection */
  34. client->connectStatus = UA_STATUSCODE_GOOD;
  35. UA_Timer_init(&client->timer);
  36. UA_WorkQueue_init(&client->workQueue);
  37. }
  38. UA_Client *
  39. UA_Client_new() {
  40. UA_Client *client = (UA_Client*)UA_malloc(sizeof(UA_Client));
  41. if(!client)
  42. return NULL;
  43. UA_Client_init(client);
  44. return client;
  45. }
  46. static void
  47. UA_ClientConfig_deleteMembers(UA_ClientConfig *config) {
  48. UA_ApplicationDescription_deleteMembers(&config->clientDescription);
  49. UA_ExtensionObject_deleteMembers(&config->userIdentityToken);
  50. UA_String_deleteMembers(&config->securityPolicyUri);
  51. UA_EndpointDescription_deleteMembers(&config->endpoint);
  52. UA_UserTokenPolicy_deleteMembers(&config->userTokenPolicy);
  53. if(config->certificateVerification.deleteMembers)
  54. config->certificateVerification.deleteMembers(&config->certificateVerification);
  55. /* Delete the SecurityPolicies */
  56. if(config->securityPolicies == 0)
  57. return;
  58. for(size_t i = 0; i < config->securityPoliciesSize; i++)
  59. config->securityPolicies[i].deleteMembers(&config->securityPolicies[i]);
  60. UA_free(config->securityPolicies);
  61. config->securityPolicies = 0;
  62. }
  63. static void
  64. UA_Client_deleteMembers(UA_Client *client) {
  65. UA_Client_disconnect(client);
  66. /* Commented as UA_SecureChannel_deleteMembers already done
  67. * in UA_Client_disconnect function */
  68. //UA_SecureChannel_deleteMembersCleanup(&client->channel);
  69. if (client->connection.free)
  70. client->connection.free(&client->connection);
  71. UA_Connection_deleteMembers(&client->connection);
  72. UA_NodeId_deleteMembers(&client->authenticationToken);
  73. UA_String_deleteMembers(&client->endpointUrl);
  74. /* Delete the async service calls */
  75. UA_Client_AsyncService_removeAll(client, UA_STATUSCODE_BADSHUTDOWN);
  76. /* Delete the subscriptions */
  77. #ifdef UA_ENABLE_SUBSCRIPTIONS
  78. UA_Client_Subscriptions_clean(client);
  79. #endif
  80. /* Delete the timed work */
  81. UA_Timer_deleteMembers(&client->timer);
  82. /* Clean up the work queue */
  83. UA_WorkQueue_cleanup(&client->workQueue);
  84. UA_ClientConfig_deleteMembers(&client->config);
  85. }
  86. void
  87. UA_Client_reset(UA_Client* client) {
  88. UA_Client_deleteMembers(client);
  89. UA_Client_init(client);
  90. }
  91. void
  92. UA_Client_delete(UA_Client* client) {
  93. UA_Client_deleteMembers(client);
  94. UA_free(client);
  95. }
  96. UA_ClientState
  97. UA_Client_getState(UA_Client *client) {
  98. return client->state;
  99. }
  100. UA_ClientConfig *
  101. UA_Client_getConfig(UA_Client *client) {
  102. if(!client)
  103. return NULL;
  104. return &client->config;
  105. }
  106. /****************/
  107. /* Raw Services */
  108. /****************/
  109. /* For synchronous service calls. Execute async responses with a callback. When
  110. * the response with the correct requestId turns up, return it via the
  111. * SyncResponseDescription pointer. */
  112. typedef struct {
  113. UA_Client *client;
  114. UA_Boolean received;
  115. UA_UInt32 requestId;
  116. void *response;
  117. const UA_DataType *responseType;
  118. } SyncResponseDescription;
  119. /* For both synchronous and asynchronous service calls */
  120. static UA_StatusCode
  121. sendSymmetricServiceRequest(UA_Client *client, const void *request,
  122. const UA_DataType *requestType, UA_UInt32 *requestId) {
  123. /* Make sure we have a valid session */
  124. UA_StatusCode retval = UA_STATUSCODE_GOOD;
  125. /* FIXME: this is just a dirty workaround. We need to rework some of the sync and async processing
  126. * FIXME: in the client. Currently a lot of stuff is semi broken and in dire need of cleaning up.*/
  127. /*UA_StatusCode retval = openSecureChannel(client, true);
  128. if(retval != UA_STATUSCODE_GOOD)
  129. return retval;*/
  130. /* Adjusting the request header. The const attribute is violated, but we
  131. * only touch the following members: */
  132. UA_RequestHeader *rr = (UA_RequestHeader*)(uintptr_t)request;
  133. rr->authenticationToken = client->authenticationToken; /* cleaned up at the end */
  134. rr->timestamp = UA_DateTime_now();
  135. rr->requestHandle = ++client->requestHandle;
  136. /* Send the request */
  137. UA_UInt32 rqId = ++client->requestId;
  138. UA_LOG_DEBUG(&client->config.logger, UA_LOGCATEGORY_CLIENT,
  139. "Sending a request of type %i", requestType->typeId.identifier.numeric);
  140. if (client->channel.nextSecurityToken.tokenId != 0) // Change to the new security token if the secure channel has been renewed.
  141. UA_SecureChannel_revolveTokens(&client->channel);
  142. retval = UA_SecureChannel_sendSymmetricMessage(&client->channel, rqId, UA_MESSAGETYPE_MSG,
  143. rr, requestType);
  144. UA_NodeId_init(&rr->authenticationToken); /* Do not return the token to the user */
  145. if(retval != UA_STATUSCODE_GOOD)
  146. return retval;
  147. *requestId = rqId;
  148. return UA_STATUSCODE_GOOD;
  149. }
  150. static const UA_NodeId
  151. serviceFaultId = {0, UA_NODEIDTYPE_NUMERIC, {UA_NS0ID_SERVICEFAULT_ENCODING_DEFAULTBINARY}};
  152. /* Look for the async callback in the linked list, execute and delete it */
  153. static UA_StatusCode
  154. processAsyncResponse(UA_Client *client, UA_UInt32 requestId, const UA_NodeId *responseTypeId,
  155. const UA_ByteString *responseMessage, size_t *offset) {
  156. /* Find the callback */
  157. AsyncServiceCall *ac;
  158. LIST_FOREACH(ac, &client->asyncServiceCalls, pointers) {
  159. if(ac->requestId == requestId)
  160. break;
  161. }
  162. if(!ac)
  163. return UA_STATUSCODE_BADREQUESTHEADERINVALID;
  164. /* Allocate the response */
  165. UA_STACKARRAY(UA_Byte, responseBuf, ac->responseType->memSize);
  166. void *response = (void*)(uintptr_t)&responseBuf[0]; /* workaround aliasing rules */
  167. /* Verify the type of the response */
  168. const UA_DataType *responseType = ac->responseType;
  169. const UA_NodeId expectedNodeId = UA_NODEID_NUMERIC(0, ac->responseType->binaryEncodingId);
  170. UA_StatusCode retval = UA_STATUSCODE_GOOD;
  171. if(!UA_NodeId_equal(responseTypeId, &expectedNodeId)) {
  172. UA_init(response, ac->responseType);
  173. if(UA_NodeId_equal(responseTypeId, &serviceFaultId)) {
  174. /* Decode as a ServiceFault, i.e. only the response header */
  175. UA_LOG_INFO(&client->config.logger, UA_LOGCATEGORY_CLIENT,
  176. "Received a ServiceFault response");
  177. responseType = &UA_TYPES[UA_TYPES_SERVICEFAULT];
  178. } else {
  179. /* Close the connection */
  180. UA_LOG_ERROR(&client->config.logger, UA_LOGCATEGORY_CLIENT,
  181. "Reply contains the wrong service response");
  182. retval = UA_STATUSCODE_BADCOMMUNICATIONERROR;
  183. goto process;
  184. }
  185. }
  186. /* Decode the response */
  187. retval = UA_decodeBinary(responseMessage, offset, response, responseType, client->config.customDataTypes);
  188. process:
  189. if(retval != UA_STATUSCODE_GOOD) {
  190. UA_LOG_INFO(&client->config.logger, UA_LOGCATEGORY_CLIENT,
  191. "Could not decode the response with id %u due to %s",
  192. requestId, UA_StatusCode_name(retval));
  193. ((UA_ResponseHeader*)response)->serviceResult = retval;
  194. } else if(((UA_ResponseHeader*)response)->serviceResult != UA_STATUSCODE_GOOD) {
  195. /* Decode as a ServiceFault, i.e. only the response header */
  196. UA_LOG_INFO(&client->config.logger, UA_LOGCATEGORY_CLIENT,
  197. "The ServiceResult has the StatusCode %s",
  198. UA_StatusCode_name(((UA_ResponseHeader*)response)->serviceResult));
  199. }
  200. /* Call the callback */
  201. if(ac->callback)
  202. ac->callback(client, ac->userdata, requestId, response);
  203. UA_deleteMembers(response, ac->responseType);
  204. /* Remove the callback */
  205. LIST_REMOVE(ac, pointers);
  206. UA_free(ac);
  207. return retval;
  208. }
  209. /* Processes the received service response. Either with an async callback or by
  210. * decoding the message and returning it "upwards" in the
  211. * SyncResponseDescription. */
  212. static void
  213. processServiceResponse(void *application, UA_SecureChannel *channel,
  214. UA_MessageType messageType, UA_UInt32 requestId,
  215. const UA_ByteString *message) {
  216. SyncResponseDescription *rd = (SyncResponseDescription*)application;
  217. /* Must be OPN or MSG */
  218. if(messageType != UA_MESSAGETYPE_OPN &&
  219. messageType != UA_MESSAGETYPE_MSG) {
  220. UA_LOG_TRACE_CHANNEL(&rd->client->config.logger, channel,
  221. "Invalid message type");
  222. return;
  223. }
  224. /* Forward declaration for the goto */
  225. UA_NodeId expectedNodeId = UA_NODEID_NULL;
  226. /* Decode the data type identifier of the response */
  227. size_t offset = 0;
  228. UA_NodeId responseId;
  229. UA_StatusCode retval = UA_NodeId_decodeBinary(message, &offset, &responseId);
  230. if(retval != UA_STATUSCODE_GOOD)
  231. goto finish;
  232. /* Got an asynchronous response. Don't expected a synchronous response
  233. * (responseType NULL) or the id does not match. */
  234. if(!rd->responseType || requestId != rd->requestId) {
  235. retval = processAsyncResponse(rd->client, requestId, &responseId, message, &offset);
  236. goto finish;
  237. }
  238. /* Got the synchronous response */
  239. rd->received = true;
  240. /* Check that the response type matches */
  241. expectedNodeId = UA_NODEID_NUMERIC(0, rd->responseType->binaryEncodingId);
  242. if(!UA_NodeId_equal(&responseId, &expectedNodeId)) {
  243. if(UA_NodeId_equal(&responseId, &serviceFaultId)) {
  244. UA_init(rd->response, rd->responseType);
  245. retval = UA_decodeBinary(message, &offset, rd->response,
  246. &UA_TYPES[UA_TYPES_SERVICEFAULT],
  247. rd->client->config.customDataTypes);
  248. if(retval != UA_STATUSCODE_GOOD)
  249. ((UA_ResponseHeader*)rd->response)->serviceResult = retval;
  250. UA_LOG_INFO(&rd->client->config.logger, UA_LOGCATEGORY_CLIENT,
  251. "Received a ServiceFault response with StatusCode %s",
  252. UA_StatusCode_name(((UA_ResponseHeader*)rd->response)->serviceResult));
  253. } else {
  254. /* Close the connection */
  255. UA_LOG_ERROR(&rd->client->config.logger, UA_LOGCATEGORY_CLIENT,
  256. "Reply contains the wrong service response");
  257. retval = UA_STATUSCODE_BADCOMMUNICATIONERROR;
  258. }
  259. goto finish;
  260. }
  261. #ifdef UA_ENABLE_TYPENAMES
  262. UA_LOG_DEBUG(&rd->client->config.logger, UA_LOGCATEGORY_CLIENT,
  263. "Decode a message of type %s", rd->responseType->typeName);
  264. #else
  265. UA_LOG_DEBUG(&rd->client->config.logger, UA_LOGCATEGORY_CLIENT,
  266. "Decode a message of type %u", responseId.identifier.numeric);
  267. #endif
  268. /* Decode the response */
  269. retval = UA_decodeBinary(message, &offset, rd->response, rd->responseType,
  270. rd->client->config.customDataTypes);
  271. finish:
  272. UA_NodeId_deleteMembers(&responseId);
  273. if(retval != UA_STATUSCODE_GOOD) {
  274. if(retval == UA_STATUSCODE_BADENCODINGLIMITSEXCEEDED)
  275. retval = UA_STATUSCODE_BADRESPONSETOOLARGE;
  276. UA_LOG_INFO(&rd->client->config.logger, UA_LOGCATEGORY_CLIENT,
  277. "Error receiving the response with status code %s",
  278. UA_StatusCode_name(retval));
  279. if(rd->response) {
  280. UA_ResponseHeader *respHeader = (UA_ResponseHeader*)rd->response;
  281. respHeader->serviceResult = retval;
  282. }
  283. }
  284. }
  285. /* Forward complete chunks directly to the securechannel */
  286. static UA_StatusCode
  287. client_processChunk(void *application, UA_Connection *connection, UA_ByteString *chunk) {
  288. SyncResponseDescription *rd = (SyncResponseDescription*)application;
  289. UA_StatusCode retval = UA_SecureChannel_decryptAddChunk(&rd->client->channel, chunk, true);
  290. if(retval != UA_STATUSCODE_GOOD)
  291. return retval;
  292. return UA_SecureChannel_persistIncompleteMessages(&rd->client->channel);
  293. }
  294. /* Receive and process messages until a synchronous message arrives or the
  295. * timout finishes */
  296. UA_StatusCode
  297. receiveServiceResponse(UA_Client *client, void *response, const UA_DataType *responseType,
  298. UA_DateTime maxDate, const UA_UInt32 *synchronousRequestId) {
  299. /* Prepare the response and the structure we give into processServiceResponse */
  300. SyncResponseDescription rd = { client, false, 0, response, responseType };
  301. /* Return upon receiving the synchronized response. All other responses are
  302. * processed with a callback "in the background". */
  303. if(synchronousRequestId)
  304. rd.requestId = *synchronousRequestId;
  305. UA_StatusCode retval;
  306. do {
  307. UA_DateTime now = UA_DateTime_nowMonotonic();
  308. /* >= avoid timeout to be set to 0 */
  309. if(now >= maxDate)
  310. return UA_STATUSCODE_GOODNONCRITICALTIMEOUT;
  311. /* round always to upper value to avoid timeout to be set to 0
  312. * if(maxDate - now) < (UA_DATETIME_MSEC/2) */
  313. UA_UInt32 timeout = (UA_UInt32)(((maxDate - now) + (UA_DATETIME_MSEC - 1)) / UA_DATETIME_MSEC);
  314. retval = UA_Connection_receiveChunksBlocking(&client->connection, &rd, client_processChunk, timeout);
  315. UA_SecureChannel_processCompleteMessages(&client->channel, &rd, processServiceResponse);
  316. if(retval != UA_STATUSCODE_GOOD && retval != UA_STATUSCODE_GOODNONCRITICALTIMEOUT) {
  317. if(retval == UA_STATUSCODE_BADCONNECTIONCLOSED)
  318. setClientState(client, UA_CLIENTSTATE_DISCONNECTED);
  319. UA_Client_disconnect(client);
  320. break;
  321. }
  322. } while(!rd.received);
  323. return retval;
  324. }
  325. void
  326. __UA_Client_Service(UA_Client *client, const void *request,
  327. const UA_DataType *requestType, void *response,
  328. const UA_DataType *responseType) {
  329. UA_init(response, responseType);
  330. UA_ResponseHeader *respHeader = (UA_ResponseHeader*)response;
  331. /* Send the request */
  332. UA_UInt32 requestId;
  333. UA_StatusCode retval = sendSymmetricServiceRequest(client, request, requestType, &requestId);
  334. if(retval != UA_STATUSCODE_GOOD) {
  335. if(retval == UA_STATUSCODE_BADENCODINGLIMITSEXCEEDED)
  336. respHeader->serviceResult = UA_STATUSCODE_BADREQUESTTOOLARGE;
  337. else
  338. respHeader->serviceResult = retval;
  339. UA_Client_disconnect(client);
  340. return;
  341. }
  342. /* Retrieve the response */
  343. UA_DateTime maxDate = UA_DateTime_nowMonotonic() +
  344. (client->config.timeout * UA_DATETIME_MSEC);
  345. retval = receiveServiceResponse(client, response, responseType, maxDate, &requestId);
  346. if(retval == UA_STATUSCODE_GOODNONCRITICALTIMEOUT) {
  347. /* In synchronous service, if we have don't have a reply we need to close the connection */
  348. UA_Client_disconnect(client);
  349. retval = UA_STATUSCODE_BADCONNECTIONCLOSED;
  350. }
  351. if(retval != UA_STATUSCODE_GOOD)
  352. respHeader->serviceResult = retval;
  353. }
  354. UA_StatusCode
  355. receiveServiceResponseAsync(UA_Client *client, void *response,
  356. const UA_DataType *responseType) {
  357. SyncResponseDescription rd = { client, false, 0, response, responseType };
  358. UA_StatusCode retval = UA_Connection_receiveChunksNonBlocking(
  359. &client->connection, &rd, client_processChunk);
  360. UA_SecureChannel_processCompleteMessages(&client->channel, &rd, processServiceResponse);
  361. /*let client run when non critical timeout*/
  362. if(retval != UA_STATUSCODE_GOOD
  363. && retval != UA_STATUSCODE_GOODNONCRITICALTIMEOUT) {
  364. if(retval == UA_STATUSCODE_BADCONNECTIONCLOSED) {
  365. setClientState(client, UA_CLIENTSTATE_DISCONNECTED);
  366. }
  367. UA_Client_disconnect(client);
  368. }
  369. return retval;
  370. }
  371. UA_StatusCode
  372. receivePacketAsync(UA_Client *client) {
  373. UA_StatusCode retval = UA_STATUSCODE_GOOD;
  374. if (UA_Client_getState(client) == UA_CLIENTSTATE_DISCONNECTED ||
  375. UA_Client_getState(client) == UA_CLIENTSTATE_WAITING_FOR_ACK) {
  376. retval = UA_Connection_receiveChunksNonBlocking(&client->connection, client, processACKResponseAsync);
  377. }
  378. else if(UA_Client_getState(client) == UA_CLIENTSTATE_CONNECTED) {
  379. retval = UA_Connection_receiveChunksNonBlocking(&client->connection, client, processOPNResponseAsync);
  380. }
  381. if(retval != UA_STATUSCODE_GOOD && retval != UA_STATUSCODE_GOODNONCRITICALTIMEOUT) {
  382. if(retval == UA_STATUSCODE_BADCONNECTIONCLOSED)
  383. setClientState(client, UA_CLIENTSTATE_DISCONNECTED);
  384. UA_Client_disconnect(client);
  385. }
  386. return retval;
  387. }
  388. void
  389. UA_Client_AsyncService_cancel(UA_Client *client, AsyncServiceCall *ac,
  390. UA_StatusCode statusCode) {
  391. /* Create an empty response with the statuscode */
  392. UA_STACKARRAY(UA_Byte, responseBuf, ac->responseType->memSize);
  393. void *resp = (void*)(uintptr_t)&responseBuf[0]; /* workaround aliasing rules */
  394. UA_init(resp, ac->responseType);
  395. ((UA_ResponseHeader*)resp)->serviceResult = statusCode;
  396. if(ac->callback)
  397. ac->callback(client, ac->userdata, ac->requestId, resp);
  398. /* Clean up the response. Users might move data into it. For whatever reasons. */
  399. UA_deleteMembers(resp, ac->responseType);
  400. }
  401. void UA_Client_AsyncService_removeAll(UA_Client *client, UA_StatusCode statusCode) {
  402. AsyncServiceCall *ac, *ac_tmp;
  403. LIST_FOREACH_SAFE(ac, &client->asyncServiceCalls, pointers, ac_tmp) {
  404. LIST_REMOVE(ac, pointers);
  405. UA_Client_AsyncService_cancel(client, ac, statusCode);
  406. UA_free(ac);
  407. }
  408. }
  409. UA_StatusCode
  410. __UA_Client_AsyncServiceEx(UA_Client *client, const void *request,
  411. const UA_DataType *requestType,
  412. UA_ClientAsyncServiceCallback callback,
  413. const UA_DataType *responseType,
  414. void *userdata, UA_UInt32 *requestId,
  415. UA_UInt32 timeout) {
  416. /* Prepare the entry for the linked list */
  417. AsyncServiceCall *ac = (AsyncServiceCall*)UA_malloc(sizeof(AsyncServiceCall));
  418. if(!ac)
  419. return UA_STATUSCODE_BADOUTOFMEMORY;
  420. ac->callback = callback;
  421. ac->responseType = responseType;
  422. ac->userdata = userdata;
  423. ac->timeout = timeout;
  424. /* Call the service and set the requestId */
  425. UA_StatusCode retval = sendSymmetricServiceRequest(client, request, requestType, &ac->requestId);
  426. if(retval != UA_STATUSCODE_GOOD) {
  427. UA_free(ac);
  428. return retval;
  429. }
  430. ac->start = UA_DateTime_nowMonotonic();
  431. /* Store the entry for async processing */
  432. LIST_INSERT_HEAD(&client->asyncServiceCalls, ac, pointers);
  433. if(requestId)
  434. *requestId = ac->requestId;
  435. return UA_STATUSCODE_GOOD;
  436. }
  437. UA_StatusCode
  438. __UA_Client_AsyncService(UA_Client *client, const void *request,
  439. const UA_DataType *requestType,
  440. UA_ClientAsyncServiceCallback callback,
  441. const UA_DataType *responseType,
  442. void *userdata, UA_UInt32 *requestId) {
  443. return __UA_Client_AsyncServiceEx(client, request, requestType, callback,
  444. responseType, userdata, requestId,
  445. client->config.timeout);
  446. }
  447. UA_StatusCode
  448. UA_Client_sendAsyncRequest(UA_Client *client, const void *request,
  449. const UA_DataType *requestType,
  450. UA_ClientAsyncServiceCallback callback,
  451. const UA_DataType *responseType, void *userdata,
  452. UA_UInt32 *requestId) {
  453. if (UA_Client_getState(client) < UA_CLIENTSTATE_SECURECHANNEL) {
  454. UA_LOG_INFO(&client->config.logger, UA_LOGCATEGORY_CLIENT,
  455. "Cient must be connected to send high-level requests");
  456. return UA_STATUSCODE_GOOD;
  457. }
  458. return __UA_Client_AsyncService(client, request, requestType, callback,
  459. responseType, userdata, requestId);
  460. }
  461. UA_StatusCode UA_EXPORT
  462. UA_Client_addTimedCallback(UA_Client *client, UA_ClientCallback callback,
  463. void *data, UA_DateTime date, UA_UInt64 *callbackId) {
  464. return UA_Timer_addTimedCallback(&client->timer, (UA_ApplicationCallback) callback,
  465. client, data, date, callbackId);
  466. }
  467. UA_StatusCode
  468. UA_Client_addRepeatedCallback(UA_Client *client, UA_ClientCallback callback,
  469. void *data, UA_Double interval_ms, UA_UInt64 *callbackId) {
  470. return UA_Timer_addRepeatedCallback(&client->timer, (UA_ApplicationCallback) callback,
  471. client, data, interval_ms, callbackId);
  472. }
  473. UA_StatusCode
  474. UA_Client_changeRepeatedCallbackInterval(UA_Client *client, UA_UInt64 callbackId,
  475. UA_Double interval_ms) {
  476. return UA_Timer_changeRepeatedCallbackInterval(&client->timer, callbackId,
  477. interval_ms);
  478. }
  479. void
  480. UA_Client_removeCallback(UA_Client *client, UA_UInt64 callbackId) {
  481. UA_Timer_removeCallback(&client->timer, callbackId);
  482. }