ua_server.h 49 KB

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