ua_server.h 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056
  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. #ifndef UA_SERVER_H_
  5. #define UA_SERVER_H_
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. #include "ua_types.h"
  10. #include "ua_types_generated.h"
  11. #include "ua_types_generated_handling.h"
  12. struct UA_ServerConfig;
  13. typedef struct UA_ServerConfig UA_ServerConfig;
  14. struct UA_Server;
  15. typedef struct UA_Server UA_Server;
  16. /**
  17. * .. _server:
  18. *
  19. * Server
  20. * ======
  21. *
  22. * .. _server-lifecycle:
  23. *
  24. * Server Lifecycle
  25. * ---------------- */
  26. UA_Server UA_EXPORT * UA_Server_new(const UA_ServerConfig *config);
  27. void UA_EXPORT UA_Server_delete(UA_Server *server);
  28. /* Runs the main loop of the server. In each iteration, this calls into the
  29. * networklayers to see if messages have arrived.
  30. *
  31. * @param server The server object.
  32. * @param running The loop is run as long as *running is true.
  33. * Otherwise, the server shuts down.
  34. * @return Returns the statuscode of the UA_Server_run_shutdown method */
  35. UA_StatusCode UA_EXPORT
  36. UA_Server_run(UA_Server *server, volatile UA_Boolean *running);
  37. /* The prologue part of UA_Server_run (no need to use if you call
  38. * UA_Server_run) */
  39. UA_StatusCode UA_EXPORT
  40. UA_Server_run_startup(UA_Server *server);
  41. /* Executes a single iteration of the server's main loop.
  42. *
  43. * @param server The server object.
  44. * @param waitInternal Should we wait for messages in the networklayer?
  45. * Otherwise, the timouts for the networklayers are set to zero.
  46. * The default max wait time is 50millisec.
  47. * @return Returns how long we can wait until the next scheduled
  48. * callback (in ms) */
  49. UA_UInt16 UA_EXPORT
  50. UA_Server_run_iterate(UA_Server *server, UA_Boolean waitInternal);
  51. /* The epilogue part of UA_Server_run (no need to use if you call
  52. * UA_Server_run) */
  53. UA_StatusCode UA_EXPORT
  54. UA_Server_run_shutdown(UA_Server *server);
  55. /**
  56. * Repeated Callbacks
  57. * ------------------ */
  58. typedef void (*UA_ServerCallback)(UA_Server *server, void *data);
  59. /* Add a callback for cyclic repetition to the server.
  60. *
  61. * @param server The server object.
  62. * @param callback The callback that shall be added.
  63. * @param interval The callback shall be repeatedly executed with the given interval
  64. * (in ms). The interval must be larger than 5ms. The first execution
  65. * occurs at now() + interval at the latest.
  66. * @param callbackId Set to the identifier of the repeated callback . This can be used to cancel
  67. * the callback later on. If the pointer is null, the identifier is not set.
  68. * @return Upon success, UA_STATUSCODE_GOOD is returned.
  69. * An error code otherwise. */
  70. UA_StatusCode UA_EXPORT
  71. UA_Server_addRepeatedCallback(UA_Server *server, UA_ServerCallback callback,
  72. void *data, UA_UInt32 interval, UA_UInt64 *callbackId);
  73. UA_StatusCode UA_EXPORT
  74. UA_Server_changeRepeatedCallbackInterval(UA_Server *server, UA_UInt64 callbackId,
  75. UA_UInt32 interval);
  76. /* Remove a repeated callback.
  77. *
  78. * @param server The server object.
  79. * @param callbackId The id of the callback that shall be removed.
  80. * @return Upon success, UA_STATUSCODE_GOOD is returned.
  81. * An error code otherwise. */
  82. UA_StatusCode UA_EXPORT
  83. UA_Server_removeRepeatedCallback(UA_Server *server, UA_UInt64 callbackId);
  84. /**
  85. * Reading and Writing Node Attributes
  86. * -----------------------------------
  87. * The functions for reading and writing node attributes call the regular read
  88. * and write service in the background that are also used over the network.
  89. *
  90. * The following attributes cannot be read, since the local "admin" user always
  91. * has full rights.
  92. *
  93. * - UserWriteMask
  94. * - UserAccessLevel
  95. * - UserExecutable */
  96. /* Read an attribute of a node. The specialized functions below provide a more
  97. * concise syntax.
  98. *
  99. * @param server The server object.
  100. * @param item ReadValueIds contain the NodeId of the target node, the id of the
  101. * attribute to read and (optionally) an index range to read parts
  102. * of an array only. See the section on NumericRange for the format
  103. * used for array ranges.
  104. * @param timestamps Which timestamps to return for the attribute.
  105. * @return Returns a DataValue that contains either an error code, or a variant
  106. * with the attribute value and the timestamps. */
  107. UA_DataValue UA_EXPORT
  108. UA_Server_read(UA_Server *server, const UA_ReadValueId *item,
  109. UA_TimestampsToReturn timestamps);
  110. /* Don't use this function. There are typed versions for every supported
  111. * attribute. */
  112. UA_StatusCode UA_EXPORT
  113. __UA_Server_read(UA_Server *server, const UA_NodeId *nodeId,
  114. UA_AttributeId attributeId, void *v);
  115. static UA_INLINE UA_StatusCode
  116. UA_Server_readNodeId(UA_Server *server, const UA_NodeId nodeId,
  117. UA_NodeId *outNodeId) {
  118. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_NODEID, outNodeId);
  119. }
  120. static UA_INLINE UA_StatusCode
  121. UA_Server_readNodeClass(UA_Server *server, const UA_NodeId nodeId,
  122. UA_NodeClass *outNodeClass) {
  123. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_NODECLASS,
  124. outNodeClass);
  125. }
  126. static UA_INLINE UA_StatusCode
  127. UA_Server_readBrowseName(UA_Server *server, const UA_NodeId nodeId,
  128. UA_QualifiedName *outBrowseName) {
  129. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_BROWSENAME,
  130. outBrowseName);
  131. }
  132. static UA_INLINE UA_StatusCode
  133. UA_Server_readDisplayName(UA_Server *server, const UA_NodeId nodeId,
  134. UA_LocalizedText *outDisplayName) {
  135. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_DISPLAYNAME,
  136. outDisplayName);
  137. }
  138. static UA_INLINE UA_StatusCode
  139. UA_Server_readDescription(UA_Server *server, const UA_NodeId nodeId,
  140. UA_LocalizedText *outDescription) {
  141. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_DESCRIPTION,
  142. outDescription);
  143. }
  144. static UA_INLINE UA_StatusCode
  145. UA_Server_readWriteMask(UA_Server *server, const UA_NodeId nodeId,
  146. UA_UInt32 *outWriteMask) {
  147. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_WRITEMASK,
  148. outWriteMask);
  149. }
  150. static UA_INLINE UA_StatusCode
  151. UA_Server_readIsAbstract(UA_Server *server, const UA_NodeId nodeId,
  152. UA_Boolean *outIsAbstract) {
  153. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_ISABSTRACT,
  154. outIsAbstract);
  155. }
  156. static UA_INLINE UA_StatusCode
  157. UA_Server_readSymmetric(UA_Server *server, const UA_NodeId nodeId,
  158. UA_Boolean *outSymmetric) {
  159. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_SYMMETRIC,
  160. outSymmetric);
  161. }
  162. static UA_INLINE UA_StatusCode
  163. UA_Server_readInverseName(UA_Server *server, const UA_NodeId nodeId,
  164. UA_LocalizedText *outInverseName) {
  165. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_INVERSENAME,
  166. outInverseName);
  167. }
  168. static UA_INLINE UA_StatusCode
  169. UA_Server_readContainsNoLoop(UA_Server *server, const UA_NodeId nodeId,
  170. UA_Boolean *outContainsNoLoops) {
  171. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_CONTAINSNOLOOPS,
  172. outContainsNoLoops);
  173. }
  174. static UA_INLINE UA_StatusCode
  175. UA_Server_readEventNotifier(UA_Server *server, const UA_NodeId nodeId,
  176. UA_Byte *outEventNotifier) {
  177. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_EVENTNOTIFIER,
  178. outEventNotifier);
  179. }
  180. static UA_INLINE UA_StatusCode
  181. UA_Server_readValue(UA_Server *server, const UA_NodeId nodeId,
  182. UA_Variant *outValue) {
  183. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_VALUE, outValue);
  184. }
  185. static UA_INLINE UA_StatusCode
  186. UA_Server_readDataType(UA_Server *server, const UA_NodeId nodeId,
  187. UA_NodeId *outDataType) {
  188. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_DATATYPE,
  189. outDataType);
  190. }
  191. static UA_INLINE UA_StatusCode
  192. UA_Server_readValueRank(UA_Server *server, const UA_NodeId nodeId,
  193. UA_Int32 *outValueRank) {
  194. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_VALUERANK,
  195. outValueRank);
  196. }
  197. /* Returns a variant with an int32 array */
  198. static UA_INLINE UA_StatusCode
  199. UA_Server_readArrayDimensions(UA_Server *server, const UA_NodeId nodeId,
  200. UA_Variant *outArrayDimensions) {
  201. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_ARRAYDIMENSIONS,
  202. outArrayDimensions);
  203. }
  204. static UA_INLINE UA_StatusCode
  205. UA_Server_readAccessLevel(UA_Server *server, const UA_NodeId nodeId,
  206. UA_Byte *outAccessLevel) {
  207. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_ACCESSLEVEL,
  208. outAccessLevel);
  209. }
  210. static UA_INLINE UA_StatusCode
  211. UA_Server_readMinimumSamplingInterval(UA_Server *server, const UA_NodeId nodeId,
  212. UA_Double *outMinimumSamplingInterval) {
  213. return __UA_Server_read(server, &nodeId,
  214. UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL,
  215. outMinimumSamplingInterval);
  216. }
  217. static UA_INLINE UA_StatusCode
  218. UA_Server_readHistorizing(UA_Server *server, const UA_NodeId nodeId,
  219. UA_Boolean *outHistorizing) {
  220. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_HISTORIZING,
  221. outHistorizing);
  222. }
  223. static UA_INLINE UA_StatusCode
  224. UA_Server_readExecutable(UA_Server *server, const UA_NodeId nodeId,
  225. UA_Boolean *outExecutable) {
  226. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_EXECUTABLE,
  227. outExecutable);
  228. }
  229. /**
  230. * The following node attributes cannot be changed once a node has been created:
  231. *
  232. * - NodeClass
  233. * - NodeId
  234. * - Symmetric
  235. * - ContainsNoLoop
  236. *
  237. * The following attributes cannot be written from the server, as they are
  238. * specific to the different users and set by the access control callback:
  239. *
  240. * - UserWriteMask
  241. * - UserAccessLevel
  242. * - UserExecutable
  243. *
  244. * Historizing is currently unsupported */
  245. /* Overwrite an attribute of a node. The specialized functions below provide a
  246. * more concise syntax.
  247. *
  248. * @param server The server object.
  249. * @param value WriteValues contain the NodeId of the target node, the id of the
  250. * attribute to overwritten, the actual value and (optionally) an
  251. * index range to replace parts of an array only. of an array only.
  252. * See the section on NumericRange for the format used for array
  253. * ranges.
  254. * @return Returns a status code. */
  255. UA_StatusCode UA_EXPORT
  256. UA_Server_write(UA_Server *server, const UA_WriteValue *value);
  257. /* Don't use this function. There are typed versions with no additional
  258. * overhead. */
  259. UA_StatusCode UA_EXPORT
  260. __UA_Server_write(UA_Server *server, const UA_NodeId *nodeId,
  261. const UA_AttributeId attributeId,
  262. const UA_DataType *attr_type, const void *attr);
  263. static UA_INLINE UA_StatusCode
  264. UA_Server_writeBrowseName(UA_Server *server, const UA_NodeId nodeId,
  265. const UA_QualifiedName browseName) {
  266. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_BROWSENAME,
  267. &UA_TYPES[UA_TYPES_QUALIFIEDNAME], &browseName);
  268. }
  269. static UA_INLINE UA_StatusCode
  270. UA_Server_writeDisplayName(UA_Server *server, const UA_NodeId nodeId,
  271. const UA_LocalizedText displayName) {
  272. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_DISPLAYNAME,
  273. &UA_TYPES[UA_TYPES_LOCALIZEDTEXT], &displayName);
  274. }
  275. static UA_INLINE UA_StatusCode
  276. UA_Server_writeDescription(UA_Server *server, const UA_NodeId nodeId,
  277. const UA_LocalizedText description) {
  278. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_DESCRIPTION,
  279. &UA_TYPES[UA_TYPES_LOCALIZEDTEXT], &description);
  280. }
  281. static UA_INLINE UA_StatusCode
  282. UA_Server_writeWriteMask(UA_Server *server, const UA_NodeId nodeId,
  283. const UA_UInt32 writeMask) {
  284. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_WRITEMASK,
  285. &UA_TYPES[UA_TYPES_UINT32], &writeMask);
  286. }
  287. static UA_INLINE UA_StatusCode
  288. UA_Server_writeIsAbstract(UA_Server *server, const UA_NodeId nodeId,
  289. const UA_Boolean isAbstract) {
  290. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_ISABSTRACT,
  291. &UA_TYPES[UA_TYPES_BOOLEAN], &isAbstract);
  292. }
  293. static UA_INLINE UA_StatusCode
  294. UA_Server_writeInverseName(UA_Server *server, const UA_NodeId nodeId,
  295. const UA_LocalizedText inverseName) {
  296. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_INVERSENAME,
  297. &UA_TYPES[UA_TYPES_LOCALIZEDTEXT], &inverseName);
  298. }
  299. static UA_INLINE UA_StatusCode
  300. UA_Server_writeEventNotifier(UA_Server *server, const UA_NodeId nodeId,
  301. const UA_Byte eventNotifier) {
  302. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_EVENTNOTIFIER,
  303. &UA_TYPES[UA_TYPES_BYTE], &eventNotifier);
  304. }
  305. static UA_INLINE UA_StatusCode
  306. UA_Server_writeValue(UA_Server *server, const UA_NodeId nodeId,
  307. const UA_Variant value) {
  308. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_VALUE,
  309. &UA_TYPES[UA_TYPES_VARIANT], &value);
  310. }
  311. static UA_INLINE UA_StatusCode
  312. UA_Server_writeDataType(UA_Server *server, const UA_NodeId nodeId,
  313. const UA_NodeId dataType) {
  314. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_DATATYPE,
  315. &UA_TYPES[UA_TYPES_NODEID], &dataType);
  316. }
  317. static UA_INLINE UA_StatusCode
  318. UA_Server_writeValueRank(UA_Server *server, const UA_NodeId nodeId,
  319. const UA_Int32 valueRank) {
  320. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_VALUERANK,
  321. &UA_TYPES[UA_TYPES_INT32], &valueRank);
  322. }
  323. static UA_INLINE UA_StatusCode
  324. UA_Server_writeArrayDimensions(UA_Server *server, const UA_NodeId nodeId,
  325. const UA_Variant arrayDimensions) {
  326. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_VALUE,
  327. &UA_TYPES[UA_TYPES_VARIANT], &arrayDimensions);
  328. }
  329. static UA_INLINE UA_StatusCode
  330. UA_Server_writeAccessLevel(UA_Server *server, const UA_NodeId nodeId,
  331. const UA_Byte accessLevel) {
  332. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_ACCESSLEVEL,
  333. &UA_TYPES[UA_TYPES_BYTE], &accessLevel);
  334. }
  335. static UA_INLINE UA_StatusCode
  336. UA_Server_writeMinimumSamplingInterval(UA_Server *server, const UA_NodeId nodeId,
  337. const UA_Double miniumSamplingInterval) {
  338. return __UA_Server_write(server, &nodeId,
  339. UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL,
  340. &UA_TYPES[UA_TYPES_DOUBLE],
  341. &miniumSamplingInterval);
  342. }
  343. static UA_INLINE UA_StatusCode
  344. UA_Server_writeExecutable(UA_Server *server, const UA_NodeId nodeId,
  345. const UA_Boolean executable) {
  346. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_EXECUTABLE,
  347. &UA_TYPES[UA_TYPES_BOOLEAN], &executable); }
  348. /**
  349. * Browsing
  350. * -------- */
  351. UA_BrowseResult UA_EXPORT
  352. UA_Server_browse(UA_Server *server, UA_UInt32 maxrefs,
  353. const UA_BrowseDescription *descr);
  354. UA_BrowseResult UA_EXPORT
  355. UA_Server_browseNext(UA_Server *server, UA_Boolean releaseContinuationPoint,
  356. const UA_ByteString *continuationPoint);
  357. UA_BrowsePathResult UA_EXPORT
  358. UA_Server_translateBrowsePathToNodeIds(UA_Server *server,
  359. const UA_BrowsePath *browsePath);
  360. #ifndef HAVE_NODEITER_CALLBACK
  361. #define HAVE_NODEITER_CALLBACK
  362. /* Iterate over all nodes referenced by parentNodeId by calling the callback
  363. * function for each child node (in ifdef because GCC/CLANG handle include order
  364. * differently) */
  365. typedef UA_StatusCode
  366. (*UA_NodeIteratorCallback)(UA_NodeId childId, UA_Boolean isInverse,
  367. UA_NodeId referenceTypeId, void *handle);
  368. #endif
  369. UA_StatusCode UA_EXPORT
  370. UA_Server_forEachChildNodeCall(UA_Server *server, UA_NodeId parentNodeId,
  371. UA_NodeIteratorCallback callback, void *handle);
  372. #ifdef UA_ENABLE_DISCOVERY
  373. /**
  374. * Discovery
  375. * --------- */
  376. /* Register the given server instance at the discovery server.
  377. * This should be called periodically.
  378. * The semaphoreFilePath is optional. If the given file is deleted,
  379. * the server will automatically be unregistered. This could be
  380. * for example a pid file which is deleted if the server crashes.
  381. *
  382. * When the server shuts down you need to call unregister.
  383. *
  384. * @param server
  385. * @param discoveryServerUrl if set to NULL, the default value
  386. * 'opc.tcp://localhost:4840' will be used
  387. * @param semaphoreFilePath optional parameter pointing to semaphore file. */
  388. UA_StatusCode UA_EXPORT
  389. UA_Server_register_discovery(UA_Server *server, const char* discoveryServerUrl,
  390. const char* semaphoreFilePath);
  391. /* Unregister the given server instance from the discovery server.
  392. * This should only be called when the server is shutting down.
  393. * @param server
  394. * @param discoveryServerUrl if set to NULL, the default value
  395. * 'opc.tcp://localhost:4840' will be used */
  396. UA_StatusCode UA_EXPORT
  397. UA_Server_unregister_discovery(UA_Server *server, const char* discoveryServerUrl);
  398. /* Adds a periodic callback to register the server with the LDS (local discovery server)
  399. * periodically. The interval between each register call is given as second parameter.
  400. * It should be 10 minutes by default (= 10*60*1000).
  401. *
  402. * The delayFirstRegisterMs parameter indicates the delay for the first register call.
  403. * If it is 0, the first register call will be after intervalMs milliseconds,
  404. * otherwise the server's first register will be after delayFirstRegisterMs.
  405. *
  406. * When you manually unregister the server, you also need to cancel the
  407. * periodic callback, otherwise it will be automatically be registered again.
  408. *
  409. * If you call this method multiple times for the same discoveryServerUrl, the older
  410. * periodic callback will be removed.
  411. *
  412. * @param server
  413. * @param discoveryServerUrl if set to NULL, the default value
  414. * 'opc.tcp://localhost:4840' will be used
  415. * @param intervalMs
  416. * @param delayFirstRegisterMs
  417. * @param periodicCallbackId */
  418. UA_StatusCode UA_EXPORT
  419. UA_Server_addPeriodicServerRegisterCallback(UA_Server *server, const char* discoveryServerUrl,
  420. UA_UInt32 intervalMs,
  421. UA_UInt32 delayFirstRegisterMs,
  422. UA_UInt64 *periodicCallbackId);
  423. /* Callback for RegisterServer. Data is passed from the register call */
  424. typedef void (*UA_Server_registerServerCallback)(const UA_RegisteredServer *registeredServer,
  425. void* data);
  426. /* Set the callback which is called if another server registeres or unregisters
  427. * with this instance. If called multiple times, previous data will be
  428. * overwritten.
  429. *
  430. * @param server
  431. * @param cb the callback
  432. * @param data data passed to the callback
  433. * @return UA_STATUSCODE_SUCCESS on success */
  434. void UA_EXPORT
  435. UA_Server_setRegisterServerCallback(UA_Server *server, UA_Server_registerServerCallback cb,
  436. void* data);
  437. #ifdef UA_ENABLE_DISCOVERY_MULTICAST
  438. /* Callback for server detected through mDNS. Data is passed from the register
  439. * call
  440. *
  441. * @param isServerAnnounce indicates if the server has just been detected. If
  442. * set to false, this means the server is shutting down.
  443. * @param isTxtReceived indicates if we already received the corresponding TXT
  444. * record with the path and caps data */
  445. typedef void (*UA_Server_serverOnNetworkCallback)(const UA_ServerOnNetwork *serverOnNetwork,
  446. UA_Boolean isServerAnnounce,
  447. UA_Boolean isTxtReceived, void* data);
  448. /* Set the callback which is called if another server is found through mDNS or
  449. * deleted. It will be called for any mDNS message from the remote server, thus
  450. * it may be called multiple times for the same instance. Also the SRV and TXT
  451. * records may arrive later, therefore for the first call the server
  452. * capabilities may not be set yet. If called multiple times, previous data will
  453. * be overwritten.
  454. *
  455. * @param server
  456. * @param cb the callback
  457. * @param data data passed to the callback
  458. * @return UA_STATUSCODE_SUCCESS on success */
  459. void UA_EXPORT
  460. UA_Server_setServerOnNetworkCallback(UA_Server *server,
  461. UA_Server_serverOnNetworkCallback cb,
  462. void* data);
  463. #endif /* UA_ENABLE_DISCOVERY_MULTICAST */
  464. #endif /* UA_ENABLE_DISCOVERY */
  465. /**
  466. * Information Model Callbacks
  467. * ---------------------------
  468. *
  469. * There are three places where a callback from an information model to
  470. * user-defined code can happen.
  471. *
  472. * - Custom node constructors and destructors
  473. * - Linking VariableNodes with an external data source
  474. * - MethodNode callbacks
  475. *
  476. * .. _node-lifecycle:
  477. *
  478. * Node Lifecycle: Constructors, Destructors and Node Contexts
  479. * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  480. *
  481. * To finalize the instantiation of a node, a (user-defined) constructor
  482. * callback is executed. There can be both a global constructor for all nodes
  483. * and node-type constructor specific to the TypeDefinition of the new node
  484. * (attached to an ObjectTypeNode or VariableTypeNode).
  485. *
  486. * In the hierarchy of ObjectTypes and VariableTypes, only the constructor of
  487. * the (lowest) type defined for the new node is executed. Note that every
  488. * Object and Variable can have only one ``isTypeOf`` reference. But type-nodes
  489. * can technically have several ``hasSubType`` references to implement multiple
  490. * inheritance. Issues of (multiple) inheritance in the constructor need to be
  491. * solved by the user.
  492. *
  493. * When a node is destroyed, the node-type destructor is called before the
  494. * global destructor. So the overall node lifecycle is as follows:
  495. *
  496. * 1. Global Constructor (set in the server config)
  497. * 2. Node-Type Constructor (for VariableType or ObjectTypes)
  498. * 3. (Usage-period of the Node)
  499. * 4. Node-Type Destructor
  500. * 5. Global Destructor
  501. *
  502. * The constructor and destructor callbacks can be set to ``NULL`` and are not
  503. * used in that case. If the node-type constructor fails, the global destructor
  504. * will be called before removing the node. The destructors are assumed to never
  505. * fail.
  506. *
  507. * Every node carries a user-context and a constructor-context pointer. The
  508. * user-context is used to attach custom data to a node. But the (user-defined)
  509. * constructors and destructors may replace the user-context pointer if they
  510. * wish to do so. The initial value for the constructor-context is ``NULL``.
  511. * When the ``AddNodes`` service is used over the network, the user-context
  512. * pointer of the new node is also initially set to ``NULL``. */
  513. /* To be set in the server config. */
  514. typedef struct {
  515. /* Can be NULL. May replace the nodeContext */
  516. UA_StatusCode (*constructor)(UA_Server *server,
  517. const UA_NodeId *sessionId, void *sessionContext,
  518. const UA_NodeId *nodeId, void **nodeContext);
  519. /* Can be NULL. The context cannot be replaced since the node is destroyed
  520. * immediately afterwards anyway. */
  521. void (*destructor)(UA_Server *server,
  522. const UA_NodeId *sessionId, void *sessionContext,
  523. const UA_NodeId *nodeId, void *nodeContext);
  524. } UA_GlobalNodeLifecycle;
  525. typedef struct {
  526. /* Can be NULL. May replace the nodeContext */
  527. UA_StatusCode (*constructor)(UA_Server *server,
  528. const UA_NodeId *sessionId, void *sessionContext,
  529. const UA_NodeId *typeNodeId, void *typeNodeContext,
  530. const UA_NodeId *nodeId, void **nodeContext);
  531. /* Can be NULL. May replace the nodeContext. */
  532. void (*destructor)(UA_Server *server,
  533. const UA_NodeId *sessionId, void *sessionContext,
  534. const UA_NodeId *typeNodeId, void *typeNodeContext,
  535. const UA_NodeId *nodeId, void **nodeContext);
  536. } UA_NodeTypeLifecycle;
  537. UA_StatusCode UA_EXPORT
  538. UA_Server_setNodeTypeLifecycle(UA_Server *server, UA_NodeId nodeId,
  539. UA_NodeTypeLifecycle lifecycle);
  540. UA_StatusCode UA_EXPORT
  541. UA_Server_getNodeContext(UA_Server *server, UA_NodeId nodeId,
  542. void **nodeContext);
  543. /* Careful! The user has to ensure that the destructor callbacks still work. */
  544. UA_StatusCode UA_EXPORT
  545. UA_Server_setNodeContext(UA_Server *server, UA_NodeId nodeId,
  546. void *nodeContext);
  547. /**
  548. * .. _datasource:
  549. *
  550. * Data Source Callback
  551. * ^^^^^^^^^^^^^^^^^^^^
  552. *
  553. * The server has a unique way of dealing with the content of variables. Instead
  554. * of storing a variant attached to the variable node, the node can point to a
  555. * function with a local data provider. Whenever the value attribute is read,
  556. * the function will be called and asked to provide a UA_DataValue return value
  557. * that contains the value content and additional timestamps.
  558. *
  559. * It is expected that the read callback is implemented. The write callback can
  560. * be set to a null-pointer. */
  561. typedef struct {
  562. /* Copies the data from the source into the provided value.
  563. *
  564. * !! ZERO-COPY OPERATIONS POSSIBLE !!
  565. * It is not required to return a copy of the actual content data. You can
  566. * return a pointer to memory owned by the user. Memory can be reused
  567. * between read callbacks of a DataSource, as the result is already encoded
  568. * on the network buffer between each read operation.
  569. *
  570. * To use zero-copy reads, set the value of the `value->value` Variant
  571. * without copying, e.g. with `UA_Variant_setScalar`. Then, also set
  572. * `value->value.storageType` to `UA_VARIANT_DATA_NODELETE` to prevent the
  573. * memory being cleaned up. Don't forget to also set `value->hasValue` to
  574. * true to indicate the presence of a value.
  575. *
  576. * @param handle An optional pointer to user-defined data for the
  577. * specific data source
  578. * @param nodeid Id of the read node
  579. * @param includeSourceTimeStamp If true, then the datasource is expected to
  580. * set the source timestamp in the returned value
  581. * @param range If not null, then the datasource shall return only a
  582. * selection of the (nonscalar) data. Set
  583. * UA_STATUSCODE_BADINDEXRANGEINVALID in the value if this does not
  584. * apply.
  585. * @param value The (non-null) DataValue that is returned to the client. The
  586. * data source sets the read data, the result status and optionally a
  587. * sourcetimestamp.
  588. * @return Returns a status code for logging. Error codes intended for the
  589. * original caller are set in the value. If an error is returned,
  590. * then no releasing of the value is done. */
  591. UA_StatusCode (*read)(UA_Server *server, const UA_NodeId *sessionId,
  592. void *sessionContext, const UA_NodeId *nodeId,
  593. void *nodeContext, UA_Boolean includeSourceTimeStamp,
  594. const UA_NumericRange *range, UA_DataValue *value);
  595. /* Write into a data source. This method pointer can be NULL if the
  596. * operation is unsupported.
  597. *
  598. * @param handle An optional pointer to user-defined data for the
  599. * specific data source
  600. * @param nodeid Id of the node being written to
  601. * @param data The data to be written into the data source
  602. * @param range An optional data range. If the data source is scalar or does
  603. * not support writing of ranges, then an error code is returned.
  604. * @return Returns a status code that is returned to the user */
  605. UA_StatusCode (*write)(UA_Server *server, const UA_NodeId *sessionId,
  606. void *sessionContext, const UA_NodeId *nodeId,
  607. void *nodeContext, const UA_NumericRange *range,
  608. const UA_DataValue *value);
  609. } UA_DataSource;
  610. UA_StatusCode UA_EXPORT
  611. UA_Server_setVariableNode_dataSource(UA_Server *server, const UA_NodeId nodeId,
  612. const UA_DataSource dataSource);
  613. /**
  614. * .. _value-callback:
  615. *
  616. * Value Callback
  617. * ^^^^^^^^^^^^^^
  618. * Value Callbacks can be attached to variable and variable type nodes. If
  619. * not ``NULL``, they are called before reading and after writing respectively. */
  620. typedef struct {
  621. /* Called before the value attribute is read. It is possible to write into the
  622. * value attribute during onRead (using the write service). The node is
  623. * re-opened afterwards so that changes are considered in the following read
  624. * operation.
  625. *
  626. * @param handle Points to user-provided data for the callback.
  627. * @param nodeid The identifier of the node.
  628. * @param data Points to the current node value.
  629. * @param range Points to the numeric range the client wants to read from
  630. * (or NULL). */
  631. void (*onRead)(UA_Server *server, const UA_NodeId *sessionId,
  632. void *sessionContext, const UA_NodeId *nodeid,
  633. void *nodeContext, const UA_NumericRange *range,
  634. const UA_DataValue *value);
  635. /* Called after writing the value attribute. The node is re-opened after
  636. * writing so that the new value is visible in the callback.
  637. *
  638. * @param server The server executing the callback
  639. * @sessionId The identifier of the session
  640. * @sessionContext Additional data attached to the session
  641. * in the access control layer
  642. * @param nodeid The identifier of the node.
  643. * @param nodeUserContext Additional data attached to the node by
  644. * the user.
  645. * @param nodeConstructorContext Additional data attached to the node
  646. * by the type constructor(s).
  647. * @param range Points to the numeric range the client wants to write to (or
  648. * NULL). */
  649. void (*onWrite)(UA_Server *server, const UA_NodeId *sessionId,
  650. void *sessionContext, const UA_NodeId *nodeId,
  651. void *nodeContext, const UA_NumericRange *range,
  652. const UA_DataValue *data);
  653. } UA_ValueCallback;
  654. UA_StatusCode UA_EXPORT
  655. UA_Server_setVariableNode_valueCallback(UA_Server *server,
  656. const UA_NodeId nodeId,
  657. const UA_ValueCallback callback);
  658. /**
  659. * Method Callbacks
  660. * ^^^^^^^^^^^^^^^^
  661. * Method callbacks are set to `NULL` (not executable) when a method node is added
  662. * over the network. In theory, it is possible to add a callback via
  663. * ``UA_Server_setMethodNode_callback`` within the global constructor when adding
  664. * methods over the network is really wanted. */
  665. typedef UA_StatusCode
  666. (*UA_MethodCallback)(UA_Server *server, const UA_NodeId *sessionId,
  667. void *sessionContext, const UA_NodeId *methodId,
  668. void *methodContext, const UA_NodeId *objectId,
  669. void *objectContext, size_t inputSize,
  670. const UA_Variant *input, size_t outputSize,
  671. UA_Variant *output);
  672. #ifdef UA_ENABLE_METHODCALLS
  673. UA_StatusCode UA_EXPORT
  674. UA_Server_setMethodNode_callback(UA_Server *server,
  675. const UA_NodeId methodNodeId,
  676. UA_MethodCallback methodCallback);
  677. UA_CallMethodResult UA_EXPORT
  678. UA_Server_call(UA_Server *server, const UA_CallMethodRequest *request);
  679. #endif
  680. /**
  681. * .. _addnodes:
  682. *
  683. * Node Addition and Deletion
  684. * --------------------------
  685. * When creating dynamic node instances at runtime, chances are that you will
  686. * not care about the specific NodeId of the new node, as long as you can
  687. * reference it later. When passing numeric NodeIds with a numeric identifier 0,
  688. * the stack evaluates this as "select a random unassigned numeric NodeId in
  689. * that namespace". To find out which NodeId was actually assigned to the new
  690. * node, you may pass a pointer `outNewNodeId`, which will (after a successful
  691. * node insertion) contain the nodeId of the new node. You may also pass a
  692. * ``NULL`` pointer if this result is not needed.
  693. *
  694. * See the Section :ref:`node-lifecycle` on constructors and on attaching
  695. * user-defined data to nodes.
  696. *
  697. * The methods for node addition and deletion take mostly const arguments that
  698. * are not modified. When creating a node, a deep copy of the node identifier,
  699. * node attributes, etc. is created. Therefore, it is possible to call for
  700. * example ``UA_Server_addVariablenode`` with a value attribute (a
  701. * :ref:`variant`) pointing to a memory location on the stack. If you need
  702. * changes to a variable value to manifest at a specific memory location, please
  703. * use a :ref:`datasource` or a :ref:`value-callback`. */
  704. /* Protect against redundant definitions for server/client */
  705. #ifndef UA_DEFAULT_ATTRIBUTES_DEFINED
  706. #define UA_DEFAULT_ATTRIBUTES_DEFINED
  707. /* The default for variables is "BaseDataType" for the datatype, -2 for the
  708. * valuerank and a read-accesslevel. */
  709. UA_EXPORT extern const UA_VariableAttributes UA_VariableAttributes_default;
  710. UA_EXPORT extern const UA_VariableTypeAttributes UA_VariableTypeAttributes_default;
  711. /* Methods are executable by default */
  712. UA_EXPORT extern const UA_MethodAttributes UA_MethodAttributes_default;
  713. /* The remaining attribute definitions are currently all zeroed out */
  714. UA_EXPORT extern const UA_ObjectAttributes UA_ObjectAttributes_default;
  715. UA_EXPORT extern const UA_ObjectTypeAttributes UA_ObjectTypeAttributes_default;
  716. UA_EXPORT extern const UA_ReferenceTypeAttributes UA_ReferenceTypeAttributes_default;
  717. UA_EXPORT extern const UA_DataTypeAttributes UA_DataTypeAttributes_default;
  718. UA_EXPORT extern const UA_ViewAttributes UA_ViewAttributes_default;
  719. #endif
  720. /* Don't use this function. There are typed versions as inline functions. */
  721. UA_StatusCode UA_EXPORT
  722. __UA_Server_addNode(UA_Server *server, const UA_NodeClass nodeClass,
  723. const UA_NodeId *requestedNewNodeId,
  724. const UA_NodeId *parentNodeId,
  725. const UA_NodeId *referenceTypeId,
  726. const UA_QualifiedName browseName,
  727. const UA_NodeId *typeDefinition,
  728. const UA_NodeAttributes *attr,
  729. const UA_DataType *attributeType,
  730. void *nodeContext, UA_NodeId *outNewNodeId);
  731. static UA_INLINE UA_StatusCode
  732. UA_Server_addVariableNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  733. const UA_NodeId parentNodeId,
  734. const UA_NodeId referenceTypeId,
  735. const UA_QualifiedName browseName,
  736. const UA_NodeId typeDefinition,
  737. const UA_VariableAttributes attr,
  738. void *nodeContext, UA_NodeId *outNewNodeId) {
  739. return __UA_Server_addNode(server, UA_NODECLASS_VARIABLE, &requestedNewNodeId,
  740. &parentNodeId, &referenceTypeId, browseName,
  741. &typeDefinition, (const UA_NodeAttributes*)&attr,
  742. &UA_TYPES[UA_TYPES_VARIABLEATTRIBUTES],
  743. nodeContext, outNewNodeId);
  744. }
  745. static UA_INLINE UA_StatusCode
  746. UA_Server_addVariableTypeNode(UA_Server *server,
  747. const UA_NodeId requestedNewNodeId,
  748. const UA_NodeId parentNodeId,
  749. const UA_NodeId referenceTypeId,
  750. const UA_QualifiedName browseName,
  751. const UA_NodeId typeDefinition,
  752. const UA_VariableTypeAttributes attr,
  753. void *nodeContext, UA_NodeId *outNewNodeId) {
  754. return __UA_Server_addNode(server, UA_NODECLASS_VARIABLETYPE,
  755. &requestedNewNodeId, &parentNodeId, &referenceTypeId,
  756. browseName, &typeDefinition,
  757. (const UA_NodeAttributes*)&attr,
  758. &UA_TYPES[UA_TYPES_VARIABLETYPEATTRIBUTES],
  759. nodeContext, outNewNodeId);
  760. }
  761. static UA_INLINE UA_StatusCode
  762. UA_Server_addObjectNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  763. const UA_NodeId parentNodeId,
  764. const UA_NodeId referenceTypeId,
  765. const UA_QualifiedName browseName,
  766. const UA_NodeId typeDefinition,
  767. const UA_ObjectAttributes attr,
  768. void *nodeContext, UA_NodeId *outNewNodeId) {
  769. return __UA_Server_addNode(server, UA_NODECLASS_OBJECT, &requestedNewNodeId,
  770. &parentNodeId, &referenceTypeId, browseName,
  771. &typeDefinition, (const UA_NodeAttributes*)&attr,
  772. &UA_TYPES[UA_TYPES_OBJECTATTRIBUTES],
  773. nodeContext, outNewNodeId);
  774. }
  775. static UA_INLINE UA_StatusCode
  776. UA_Server_addObjectTypeNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  777. const UA_NodeId parentNodeId,
  778. const UA_NodeId referenceTypeId,
  779. const UA_QualifiedName browseName,
  780. const UA_ObjectTypeAttributes attr,
  781. void *nodeContext, UA_NodeId *outNewNodeId) {
  782. return __UA_Server_addNode(server, UA_NODECLASS_OBJECTTYPE, &requestedNewNodeId,
  783. &parentNodeId, &referenceTypeId, browseName,
  784. &UA_NODEID_NULL, (const UA_NodeAttributes*)&attr,
  785. &UA_TYPES[UA_TYPES_OBJECTTYPEATTRIBUTES],
  786. nodeContext, outNewNodeId);
  787. }
  788. static UA_INLINE UA_StatusCode
  789. UA_Server_addViewNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  790. const UA_NodeId parentNodeId,
  791. const UA_NodeId referenceTypeId,
  792. const UA_QualifiedName browseName,
  793. const UA_ViewAttributes attr,
  794. void *nodeContext, UA_NodeId *outNewNodeId) {
  795. return __UA_Server_addNode(server, UA_NODECLASS_VIEW, &requestedNewNodeId,
  796. &parentNodeId, &referenceTypeId, browseName,
  797. &UA_NODEID_NULL, (const UA_NodeAttributes*)&attr,
  798. &UA_TYPES[UA_TYPES_VIEWATTRIBUTES],
  799. nodeContext, outNewNodeId);
  800. }
  801. static UA_INLINE UA_StatusCode
  802. UA_Server_addReferenceTypeNode(UA_Server *server,
  803. const UA_NodeId requestedNewNodeId,
  804. const UA_NodeId parentNodeId,
  805. const UA_NodeId referenceTypeId,
  806. const UA_QualifiedName browseName,
  807. const UA_ReferenceTypeAttributes attr,
  808. void *nodeContext, UA_NodeId *outNewNodeId) {
  809. return __UA_Server_addNode(server, UA_NODECLASS_REFERENCETYPE,
  810. &requestedNewNodeId, &parentNodeId, &referenceTypeId,
  811. browseName, &UA_NODEID_NULL,
  812. (const UA_NodeAttributes*)&attr,
  813. &UA_TYPES[UA_TYPES_REFERENCETYPEATTRIBUTES],
  814. nodeContext, outNewNodeId);
  815. }
  816. static UA_INLINE UA_StatusCode
  817. UA_Server_addDataTypeNode(UA_Server *server,
  818. const UA_NodeId requestedNewNodeId,
  819. const UA_NodeId parentNodeId,
  820. const UA_NodeId referenceTypeId,
  821. const UA_QualifiedName browseName,
  822. const UA_DataTypeAttributes attr,
  823. void *nodeContext, UA_NodeId *outNewNodeId) {
  824. return __UA_Server_addNode(server, UA_NODECLASS_DATATYPE, &requestedNewNodeId,
  825. &parentNodeId, &referenceTypeId, browseName,
  826. &UA_NODEID_NULL, (const UA_NodeAttributes*)&attr,
  827. &UA_TYPES[UA_TYPES_DATATYPEATTRIBUTES],
  828. nodeContext, outNewNodeId);
  829. }
  830. UA_StatusCode UA_EXPORT
  831. UA_Server_addDataSourceVariableNode(UA_Server *server,
  832. const UA_NodeId requestedNewNodeId,
  833. const UA_NodeId parentNodeId,
  834. const UA_NodeId referenceTypeId,
  835. const UA_QualifiedName browseName,
  836. const UA_NodeId typeDefinition,
  837. const UA_VariableAttributes attr,
  838. const UA_DataSource dataSource,
  839. void *nodeContext, UA_NodeId *outNewNodeId);
  840. UA_StatusCode UA_EXPORT
  841. UA_Server_addMethodNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  842. const UA_NodeId parentNodeId,
  843. const UA_NodeId referenceTypeId,
  844. const UA_QualifiedName browseName,
  845. const UA_MethodAttributes attr, UA_MethodCallback method,
  846. size_t inputArgumentsSize, const UA_Argument* inputArguments,
  847. size_t outputArgumentsSize, const UA_Argument* outputArguments,
  848. void *nodeContext, UA_NodeId *outNewNodeId);
  849. /**
  850. * The method pair UA_Server_addNode_begin and _finish splits the AddNodes
  851. * service in two parts. This is useful if the node shall be modified before
  852. * finish the instantiation. For example to add children with specific NodeIds.
  853. * Otherwise, mandatory children (e.g. of an ObjectType) are added with
  854. * pseudo-random unique NodeIds. Existing children are detected during the
  855. * _finish part via their matching BrowseName.
  856. *
  857. * The _begin method prepares the node and adds it to the nodestore. It may copy
  858. * some unassigned attributes from the TypeDefinition node internally. The
  859. * _finish method adds the references to the parent (and the TypeDefinition if
  860. * applicable), copies mandatory children, performs type-checking of variables
  861. * and calls the node constructor(s) at the end. The _finish method may remove
  862. * the node if it encounters an error. */
  863. /* The ``attr`` argument must have a type according to the NodeClass.
  864. * ``VariableAttributes`` for variables, ``ObjectAttributes`` for objects, and
  865. * so on. Missing attributes are taken from the TypeDefinition node if
  866. * applicable. */
  867. UA_StatusCode UA_EXPORT
  868. UA_Server_addNode_begin(UA_Server *server, const UA_NodeClass nodeClass,
  869. const UA_NodeId requestedNewNodeId,
  870. const UA_QualifiedName browseName,
  871. const UA_NodeId typeDefinition,
  872. const void *attr, const UA_DataType *attributeType,
  873. void *nodeContext, UA_NodeId *outNewNodeId);
  874. UA_StatusCode UA_EXPORT
  875. UA_Server_addNode_finish(UA_Server *server, const UA_NodeId nodeId,
  876. const UA_NodeId parentNodeId,
  877. const UA_NodeId referenceTypeId,
  878. const UA_NodeId typeDefinitionId);
  879. /* Deletes a node and optionally all references leading to the node. */
  880. UA_StatusCode UA_EXPORT
  881. UA_Server_deleteNode(UA_Server *server, const UA_NodeId nodeId,
  882. UA_Boolean deleteReferences);
  883. /**
  884. * Reference Management
  885. * -------------------- */
  886. UA_StatusCode UA_EXPORT
  887. UA_Server_addReference(UA_Server *server, const UA_NodeId sourceId,
  888. const UA_NodeId refTypeId,
  889. const UA_ExpandedNodeId targetId, UA_Boolean isForward);
  890. UA_StatusCode UA_EXPORT
  891. UA_Server_deleteReference(UA_Server *server, const UA_NodeId sourceNodeId,
  892. const UA_NodeId referenceTypeId, UA_Boolean isForward,
  893. const UA_ExpandedNodeId targetNodeId,
  894. UA_Boolean deleteBidirectional);
  895. /**
  896. * Utility Functions
  897. * ----------------- */
  898. /* Add a new namespace to the server. Returns the index of the new namespace */
  899. UA_UInt16 UA_EXPORT UA_Server_addNamespace(UA_Server *server, const char* name);
  900. /**
  901. * Deprecated Server API
  902. * ---------------------
  903. * This file contains outdated API definitions that are kept for backwards
  904. * compatibility. Please switch to the new API, as the following definitions
  905. * will be removed eventually.
  906. *
  907. * UA_Job API
  908. * ^^^^^^^^^^
  909. * UA_Job was replaced since it unnecessarily exposed server internals to the
  910. * end-user. Please use plain UA_ServerCallbacks instead. The following UA_Job
  911. * definition contains just the fraction of the original struct that was useful
  912. * to end-users. */
  913. typedef enum {
  914. UA_JOBTYPE_METHODCALL
  915. } UA_JobType;
  916. typedef struct {
  917. UA_JobType type;
  918. union {
  919. struct {
  920. void *data;
  921. UA_ServerCallback method;
  922. } methodCall;
  923. } job;
  924. } UA_Job;
  925. UA_DEPRECATED static UA_INLINE UA_StatusCode
  926. UA_Server_addRepeatedJob(UA_Server *server, UA_Job job,
  927. UA_UInt32 interval, UA_Guid *jobId) {
  928. return UA_Server_addRepeatedCallback(server, job.job.methodCall.method,
  929. job.job.methodCall.data, interval,
  930. (UA_UInt64*)(uintptr_t)jobId);
  931. }
  932. UA_DEPRECATED static UA_INLINE UA_StatusCode
  933. UA_Server_removeRepeatedJob(UA_Server *server, UA_Guid jobId) {
  934. return UA_Server_removeRepeatedCallback(server,
  935. *(UA_UInt64*)(uintptr_t)&jobId);
  936. }
  937. #ifdef __cplusplus
  938. }
  939. #endif
  940. #endif /* UA_SERVER_H_ */