server.h 59 KB

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