server.h 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  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. /* Browse the references of a particular node. See the definition of
  390. * BrowseDescription structure for details. */
  391. UA_BrowseResult UA_EXPORT
  392. UA_Server_browse(UA_Server *server, UA_UInt32 maxReferences,
  393. const UA_BrowseDescription *bd);
  394. UA_BrowseResult UA_EXPORT
  395. UA_Server_browseNext(UA_Server *server, UA_Boolean releaseContinuationPoint,
  396. const UA_ByteString *continuationPoint);
  397. UA_BrowsePathResult UA_EXPORT
  398. UA_Server_translateBrowsePathToNodeIds(UA_Server *server,
  399. const UA_BrowsePath *browsePath);
  400. /* A simplified TranslateBrowsePathsToNodeIds based on the
  401. * SimpleAttributeOperand type (Part 4, 7.4.4.5).
  402. *
  403. * This specifies a relative path using a list of BrowseNames instead of the
  404. * RelativePath structure. The list of BrowseNames is equivalent to a
  405. * RelativePath that specifies forward references which are subtypes of the
  406. * HierarchicalReferences ReferenceType. All Nodes followed by the browsePath
  407. * shall be of the NodeClass Object or Variable. */
  408. UA_BrowsePathResult UA_EXPORT
  409. UA_Server_browseSimplifiedBrowsePath(UA_Server *server, const UA_NodeId origin,
  410. size_t browsePathSize,
  411. const UA_QualifiedName *browsePath);
  412. #ifndef HAVE_NODEITER_CALLBACK
  413. #define HAVE_NODEITER_CALLBACK
  414. /* Iterate over all nodes referenced by parentNodeId by calling the callback
  415. * function for each child node (in ifdef because GCC/CLANG handle include order
  416. * differently) */
  417. typedef UA_StatusCode
  418. (*UA_NodeIteratorCallback)(UA_NodeId childId, UA_Boolean isInverse,
  419. UA_NodeId referenceTypeId, void *handle);
  420. #endif
  421. UA_StatusCode UA_EXPORT
  422. UA_Server_forEachChildNodeCall(UA_Server *server, UA_NodeId parentNodeId,
  423. UA_NodeIteratorCallback callback, void *handle);
  424. #ifdef UA_ENABLE_DISCOVERY
  425. /**
  426. * Discovery
  427. * --------- */
  428. /* Register the given server instance at the discovery server.
  429. * This should be called periodically.
  430. * The semaphoreFilePath is optional. If the given file is deleted,
  431. * the server will automatically be unregistered. This could be
  432. * for example a pid file which is deleted if the server crashes.
  433. *
  434. * When the server shuts down you need to call unregister.
  435. *
  436. * @param server
  437. * @param client the client which is used to call the RegisterServer. It must
  438. * already be connected to the correct endpoint
  439. * @param semaphoreFilePath optional parameter pointing to semaphore file. */
  440. UA_StatusCode UA_EXPORT
  441. UA_Server_register_discovery(UA_Server *server, struct UA_Client *client,
  442. const char* semaphoreFilePath);
  443. /* Unregister the given server instance from the discovery server.
  444. * This should only be called when the server is shutting down.
  445. * @param server
  446. * @param client the client which is used to call the RegisterServer. It must
  447. * already be connected to the correct endpoint */
  448. UA_StatusCode UA_EXPORT
  449. UA_Server_unregister_discovery(UA_Server *server, struct UA_Client *client);
  450. /* Adds a periodic callback to register the server with the LDS (local discovery server)
  451. * periodically. The interval between each register call is given as second parameter.
  452. * It should be 10 minutes by default (= 10*60*1000).
  453. *
  454. * The delayFirstRegisterMs parameter indicates the delay for the first register call.
  455. * If it is 0, the first register call will be after intervalMs milliseconds,
  456. * otherwise the server's first register will be after delayFirstRegisterMs.
  457. *
  458. * When you manually unregister the server, you also need to cancel the
  459. * periodic callback, otherwise it will be automatically be registered again.
  460. *
  461. * If you call this method multiple times for the same discoveryServerUrl, the older
  462. * periodic callback will be removed.
  463. *
  464. * @param server
  465. * @param client the client which is used to call the RegisterServer.
  466. * It must not yet be connected and will be connected for every register call
  467. * to the given discoveryServerUrl.
  468. * @param discoveryServerUrl if set to NULL, the default value
  469. * 'opc.tcp://localhost:4840' will be used
  470. * @param intervalMs
  471. * @param delayFirstRegisterMs
  472. * @param periodicCallbackId */
  473. UA_StatusCode UA_EXPORT
  474. UA_Server_addPeriodicServerRegisterCallback(UA_Server *server, struct UA_Client *client,
  475. const char* discoveryServerUrl,
  476. UA_Double intervalMs,
  477. UA_Double delayFirstRegisterMs,
  478. UA_UInt64 *periodicCallbackId);
  479. /* Callback for RegisterServer. Data is passed from the register call */
  480. typedef void (*UA_Server_registerServerCallback)(const UA_RegisteredServer *registeredServer,
  481. void* data);
  482. /* Set the callback which is called if another server registeres or unregisters
  483. * with this instance. If called multiple times, previous data will be
  484. * overwritten.
  485. *
  486. * @param server
  487. * @param cb the callback
  488. * @param data data passed to the callback
  489. * @return UA_STATUSCODE_SUCCESS on success */
  490. void UA_EXPORT
  491. UA_Server_setRegisterServerCallback(UA_Server *server, UA_Server_registerServerCallback cb,
  492. void* data);
  493. #ifdef UA_ENABLE_DISCOVERY_MULTICAST
  494. /* Callback for server detected through mDNS. Data is passed from the register
  495. * call
  496. *
  497. * @param isServerAnnounce indicates if the server has just been detected. If
  498. * set to false, this means the server is shutting down.
  499. * @param isTxtReceived indicates if we already received the corresponding TXT
  500. * record with the path and caps data */
  501. typedef void (*UA_Server_serverOnNetworkCallback)(const UA_ServerOnNetwork *serverOnNetwork,
  502. UA_Boolean isServerAnnounce,
  503. UA_Boolean isTxtReceived, void* data);
  504. /* Set the callback which is called if another server is found through mDNS or
  505. * deleted. It will be called for any mDNS message from the remote server, thus
  506. * it may be called multiple times for the same instance. Also the SRV and TXT
  507. * records may arrive later, therefore for the first call the server
  508. * capabilities may not be set yet. If called multiple times, previous data will
  509. * be overwritten.
  510. *
  511. * @param server
  512. * @param cb the callback
  513. * @param data data passed to the callback
  514. * @return UA_STATUSCODE_SUCCESS on success */
  515. void UA_EXPORT
  516. UA_Server_setServerOnNetworkCallback(UA_Server *server,
  517. UA_Server_serverOnNetworkCallback cb,
  518. void* data);
  519. #endif /* UA_ENABLE_DISCOVERY_MULTICAST */
  520. #endif /* UA_ENABLE_DISCOVERY */
  521. /**
  522. * Information Model Callbacks
  523. * ---------------------------
  524. *
  525. * There are three places where a callback from an information model to
  526. * user-defined code can happen.
  527. *
  528. * - Custom node constructors and destructors
  529. * - Linking VariableNodes with an external data source
  530. * - MethodNode callbacks
  531. *
  532. * .. _node-lifecycle:
  533. *
  534. * Node Lifecycle: Constructors, Destructors and Node Contexts
  535. * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  536. *
  537. * To finalize the instantiation of a node, a (user-defined) constructor
  538. * callback is executed. There can be both a global constructor for all nodes
  539. * and node-type constructor specific to the TypeDefinition of the new node
  540. * (attached to an ObjectTypeNode or VariableTypeNode).
  541. *
  542. * In the hierarchy of ObjectTypes and VariableTypes, only the constructor of
  543. * the (lowest) type defined for the new node is executed. Note that every
  544. * Object and Variable can have only one ``isTypeOf`` reference. But type-nodes
  545. * can technically have several ``hasSubType`` references to implement multiple
  546. * inheritance. Issues of (multiple) inheritance in the constructor need to be
  547. * solved by the user.
  548. *
  549. * When a node is destroyed, the node-type destructor is called before the
  550. * global destructor. So the overall node lifecycle is as follows:
  551. *
  552. * 1. Global Constructor (set in the server config)
  553. * 2. Node-Type Constructor (for VariableType or ObjectTypes)
  554. * 3. (Usage-period of the Node)
  555. * 4. Node-Type Destructor
  556. * 5. Global Destructor
  557. *
  558. * The constructor and destructor callbacks can be set to ``NULL`` and are not
  559. * used in that case. If the node-type constructor fails, the global destructor
  560. * will be called before removing the node. The destructors are assumed to never
  561. * fail.
  562. *
  563. * Every node carries a user-context and a constructor-context pointer. The
  564. * user-context is used to attach custom data to a node. But the (user-defined)
  565. * constructors and destructors may replace the user-context pointer if they
  566. * wish to do so. The initial value for the constructor-context is ``NULL``.
  567. * When the ``AddNodes`` service is used over the network, the user-context
  568. * pointer of the new node is also initially set to ``NULL``. */
  569. /* To be set in the server config. */
  570. typedef struct {
  571. /* Can be NULL. May replace the nodeContext */
  572. UA_StatusCode (*constructor)(UA_Server *server,
  573. const UA_NodeId *sessionId, void *sessionContext,
  574. const UA_NodeId *nodeId, void **nodeContext);
  575. /* Can be NULL. The context cannot be replaced since the node is destroyed
  576. * immediately afterwards anyway. */
  577. void (*destructor)(UA_Server *server,
  578. const UA_NodeId *sessionId, void *sessionContext,
  579. const UA_NodeId *nodeId, void *nodeContext);
  580. } UA_GlobalNodeLifecycle;
  581. typedef struct {
  582. /* Can be NULL. May replace the nodeContext */
  583. UA_StatusCode (*constructor)(UA_Server *server,
  584. const UA_NodeId *sessionId, void *sessionContext,
  585. const UA_NodeId *typeNodeId, void *typeNodeContext,
  586. const UA_NodeId *nodeId, void **nodeContext);
  587. /* Can be NULL. May replace the nodeContext. */
  588. void (*destructor)(UA_Server *server,
  589. const UA_NodeId *sessionId, void *sessionContext,
  590. const UA_NodeId *typeNodeId, void *typeNodeContext,
  591. const UA_NodeId *nodeId, void **nodeContext);
  592. } UA_NodeTypeLifecycle;
  593. UA_StatusCode UA_EXPORT
  594. UA_Server_setNodeTypeLifecycle(UA_Server *server, UA_NodeId nodeId,
  595. UA_NodeTypeLifecycle lifecycle);
  596. UA_StatusCode UA_EXPORT
  597. UA_Server_getNodeContext(UA_Server *server, UA_NodeId nodeId,
  598. void **nodeContext);
  599. /* Careful! The user has to ensure that the destructor callbacks still work. */
  600. UA_StatusCode UA_EXPORT
  601. UA_Server_setNodeContext(UA_Server *server, UA_NodeId nodeId,
  602. void *nodeContext);
  603. /**
  604. * .. _datasource:
  605. *
  606. * Data Source Callback
  607. * ^^^^^^^^^^^^^^^^^^^^
  608. *
  609. * The server has a unique way of dealing with the content of variables. Instead
  610. * of storing a variant attached to the variable node, the node can point to a
  611. * function with a local data provider. Whenever the value attribute is read,
  612. * the function will be called and asked to provide a UA_DataValue return value
  613. * that contains the value content and additional timestamps.
  614. *
  615. * It is expected that the read callback is implemented. The write callback can
  616. * be set to a null-pointer. */
  617. typedef struct {
  618. /* Copies the data from the source into the provided value.
  619. *
  620. * !! ZERO-COPY OPERATIONS POSSIBLE !!
  621. * It is not required to return a copy of the actual content data. You can
  622. * return a pointer to memory owned by the user. Memory can be reused
  623. * between read callbacks of a DataSource, as the result is already encoded
  624. * on the network buffer between each read operation.
  625. *
  626. * To use zero-copy reads, set the value of the `value->value` Variant
  627. * without copying, e.g. with `UA_Variant_setScalar`. Then, also set
  628. * `value->value.storageType` to `UA_VARIANT_DATA_NODELETE` to prevent the
  629. * memory being cleaned up. Don't forget to also set `value->hasValue` to
  630. * true to indicate the presence of a value.
  631. *
  632. * @param server The server executing the callback
  633. * @param sessionId The identifier of the session
  634. * @param sessionContext Additional data attached to the session in the
  635. * access control layer
  636. * @param nodeId The identifier of the node being read from
  637. * @param nodeContext Additional data attached to the node by the user
  638. * @param includeSourceTimeStamp If true, then the datasource is expected to
  639. * set the source timestamp in the returned value
  640. * @param range If not null, then the datasource shall return only a
  641. * selection of the (nonscalar) data. Set
  642. * UA_STATUSCODE_BADINDEXRANGEINVALID in the value if this does not
  643. * apply
  644. * @param value The (non-null) DataValue that is returned to the client. The
  645. * data source sets the read data, the result status and optionally a
  646. * sourcetimestamp.
  647. * @return Returns a status code for logging. Error codes intended for the
  648. * original caller are set in the value. If an error is returned,
  649. * then no releasing of the value is done
  650. */
  651. UA_StatusCode (*read)(UA_Server *server, const UA_NodeId *sessionId,
  652. void *sessionContext, const UA_NodeId *nodeId,
  653. void *nodeContext, UA_Boolean includeSourceTimeStamp,
  654. const UA_NumericRange *range, UA_DataValue *value);
  655. /* Write into a data source. This method pointer can be NULL if the
  656. * operation is unsupported.
  657. *
  658. * @param server The server executing the callback
  659. * @param sessionId The identifier of the session
  660. * @param sessionContext Additional data attached to the session in the
  661. * access control layer
  662. * @param nodeId The identifier of the node being written to
  663. * @param nodeContext Additional data attached to the node by the user
  664. * @param range If not NULL, then the datasource shall return only a
  665. * selection of the (nonscalar) data. Set
  666. * UA_STATUSCODE_BADINDEXRANGEINVALID in the value if this does not
  667. * apply
  668. * @param value The (non-NULL) DataValue that has been written by the client.
  669. * The data source contains the written data, the result status and
  670. * optionally a sourcetimestamp
  671. * @return Returns a status code for logging. Error codes intended for the
  672. * original caller are set in the value. If an error is returned,
  673. * then no releasing of the value is done
  674. */
  675. UA_StatusCode (*write)(UA_Server *server, const UA_NodeId *sessionId,
  676. void *sessionContext, const UA_NodeId *nodeId,
  677. void *nodeContext, const UA_NumericRange *range,
  678. const UA_DataValue *value);
  679. } UA_DataSource;
  680. UA_StatusCode UA_EXPORT
  681. UA_Server_setVariableNode_dataSource(UA_Server *server, const UA_NodeId nodeId,
  682. const UA_DataSource dataSource);
  683. /**
  684. * .. _value-callback:
  685. *
  686. * Value Callback
  687. * ^^^^^^^^^^^^^^
  688. * Value Callbacks can be attached to variable and variable type nodes. If
  689. * not ``NULL``, they are called before reading and after writing respectively. */
  690. typedef struct {
  691. /* Called before the value attribute is read. It is possible to write into the
  692. * value attribute during onRead (using the write service). The node is
  693. * re-opened afterwards so that changes are considered in the following read
  694. * operation.
  695. *
  696. * @param handle Points to user-provided data for the callback.
  697. * @param nodeid The identifier of the node.
  698. * @param data Points to the current node value.
  699. * @param range Points to the numeric range the client wants to read from
  700. * (or NULL). */
  701. void (*onRead)(UA_Server *server, const UA_NodeId *sessionId,
  702. void *sessionContext, const UA_NodeId *nodeid,
  703. void *nodeContext, const UA_NumericRange *range,
  704. const UA_DataValue *value);
  705. /* Called after writing the value attribute. The node is re-opened after
  706. * writing so that the new value is visible in the callback.
  707. *
  708. * @param server The server executing the callback
  709. * @sessionId The identifier of the session
  710. * @sessionContext Additional data attached to the session
  711. * in the access control layer
  712. * @param nodeid The identifier of the node.
  713. * @param nodeUserContext Additional data attached to the node by
  714. * the user.
  715. * @param nodeConstructorContext Additional data attached to the node
  716. * by the type constructor(s).
  717. * @param range Points to the numeric range the client wants to write to (or
  718. * NULL). */
  719. void (*onWrite)(UA_Server *server, const UA_NodeId *sessionId,
  720. void *sessionContext, const UA_NodeId *nodeId,
  721. void *nodeContext, const UA_NumericRange *range,
  722. const UA_DataValue *data);
  723. } UA_ValueCallback;
  724. UA_StatusCode UA_EXPORT
  725. UA_Server_setVariableNode_valueCallback(UA_Server *server,
  726. const UA_NodeId nodeId,
  727. const UA_ValueCallback callback);
  728. /**
  729. * .. _local-monitoreditems:
  730. *
  731. * Local MonitoredItems
  732. * ^^^^^^^^^^^^^^^^^^^^
  733. *
  734. * MonitoredItems are used with the Subscription mechanism of OPC UA to
  735. * transported notifications for data changes and events. MonitoredItems can
  736. * also be registered locally. Notifications are then forwarded to a
  737. * user-defined callback instead of a remote client. */
  738. #ifdef UA_ENABLE_SUBSCRIPTIONS
  739. typedef void (*UA_Server_DataChangeNotificationCallback)
  740. (UA_Server *server, UA_UInt32 monitoredItemId, void *monitoredItemContext,
  741. const UA_NodeId *nodeId, void *nodeContext, UA_UInt32 attributeId,
  742. const UA_DataValue *value);
  743. typedef void (*UA_Server_EventNotificationCallback)
  744. (UA_Server *server, UA_UInt32 monId, void *monContext,
  745. size_t nEventFields, const UA_Variant *eventFields);
  746. /* Create a local MonitoredItem with a sampling interval that detects data
  747. * changes.
  748. *
  749. * @param server The server executing the MonitoredItem
  750. * @timestampsToReturn Shall timestamps be added to the value for the callback?
  751. * @item The parameters of the new MonitoredItem. Note that the attribute of the
  752. * ReadValueId (the node that is monitored) can not be
  753. * ``UA_ATTRIBUTEID_EVENTNOTIFIER``. A different callback type needs to be
  754. * registered for event notifications.
  755. * @monitoredItemContext A pointer that is forwarded with the callback
  756. * @callback The callback that is executed on detected data changes
  757. *
  758. * @return Returns a description of the created MonitoredItem. The structure
  759. * also contains a StatusCode (in case of an error) and the identifier of the
  760. * new MonitoredItem. */
  761. UA_MonitoredItemCreateResult UA_EXPORT
  762. UA_Server_createDataChangeMonitoredItem(UA_Server *server,
  763. UA_TimestampsToReturn timestampsToReturn,
  764. const UA_MonitoredItemCreateRequest item,
  765. void *monitoredItemContext,
  766. UA_Server_DataChangeNotificationCallback callback);
  767. /* UA_MonitoredItemCreateResult UA_EXPORT */
  768. /* UA_Server_createEventMonitoredItem(UA_Server *server, */
  769. /* UA_TimestampsToReturn timestampsToReturn, */
  770. /* const UA_MonitoredItemCreateRequest item, void *context, */
  771. /* UA_Server_EventNotificationCallback callback); */
  772. UA_StatusCode UA_EXPORT
  773. UA_Server_deleteMonitoredItem(UA_Server *server, UA_UInt32 monitoredItemId);
  774. #endif
  775. /**
  776. * Method Callbacks
  777. * ^^^^^^^^^^^^^^^^
  778. * Method callbacks are set to `NULL` (not executable) when a method node is
  779. * added over the network. In theory, it is possible to add a callback via
  780. * ``UA_Server_setMethodNode_callback`` within the global constructor when
  781. * adding methods over the network is really wanted. See the Section
  782. * :ref:`object-interaction` for calling methods on an object. */
  783. typedef UA_StatusCode
  784. (*UA_MethodCallback)(UA_Server *server, const UA_NodeId *sessionId,
  785. void *sessionContext, const UA_NodeId *methodId,
  786. void *methodContext, const UA_NodeId *objectId,
  787. void *objectContext, size_t inputSize,
  788. const UA_Variant *input, size_t outputSize,
  789. UA_Variant *output);
  790. #ifdef UA_ENABLE_METHODCALLS
  791. UA_StatusCode UA_EXPORT
  792. UA_Server_setMethodNode_callback(UA_Server *server,
  793. const UA_NodeId methodNodeId,
  794. UA_MethodCallback methodCallback);
  795. #endif
  796. /**
  797. * .. _object-interaction:
  798. *
  799. * Interacting with Objects
  800. * ------------------------
  801. * Objects in the information model are represented as ObjectNodes. Some
  802. * convenience functions are provided to simplify the interaction with objects.
  803. */
  804. /* Write an object property. The property is represented as a VariableNode with
  805. * a ``HasProperty`` reference from the ObjectNode. The VariableNode is
  806. * identified by its BrowseName. Writing the property sets the value attribute
  807. * of the VariableNode.
  808. *
  809. * @param server The server object
  810. * @param objectId The identifier of the object (node)
  811. * @param propertyName The name of the property
  812. * @param value The value to be set for the event attribute
  813. * @return The StatusCode for setting the event attribute */
  814. UA_StatusCode UA_EXPORT
  815. UA_Server_writeObjectProperty(UA_Server *server, const UA_NodeId objectId,
  816. const UA_QualifiedName propertyName,
  817. const UA_Variant value);
  818. /* Directly point to the scalar value instead of a variant */
  819. UA_StatusCode UA_EXPORT
  820. UA_Server_writeObjectProperty_scalar(UA_Server *server, const UA_NodeId objectId,
  821. const UA_QualifiedName propertyName,
  822. const void *value, const UA_DataType *type);
  823. /* Read an object property.
  824. *
  825. * @param server The server object
  826. * @param objectId The identifier of the object (node)
  827. * @param propertyName The name of the property
  828. * @param value Contains the property value after reading. Must not be NULL.
  829. * @return The StatusCode for setting the event attribute */
  830. UA_StatusCode UA_EXPORT
  831. UA_Server_readObjectProperty(UA_Server *server, const UA_NodeId objectId,
  832. const UA_QualifiedName propertyName,
  833. UA_Variant *value);
  834. #ifdef UA_ENABLE_METHODCALLS
  835. UA_CallMethodResult UA_EXPORT
  836. UA_Server_call(UA_Server *server, const UA_CallMethodRequest *request);
  837. #endif
  838. /**
  839. * .. _addnodes:
  840. *
  841. * Node Addition and Deletion
  842. * --------------------------
  843. * When creating dynamic node instances at runtime, chances are that you will
  844. * not care about the specific NodeId of the new node, as long as you can
  845. * reference it later. When passing numeric NodeIds with a numeric identifier 0,
  846. * the stack evaluates this as "select a random unassigned numeric NodeId in
  847. * that namespace". To find out which NodeId was actually assigned to the new
  848. * node, you may pass a pointer `outNewNodeId`, which will (after a successful
  849. * node insertion) contain the nodeId of the new node. You may also pass a
  850. * ``NULL`` pointer if this result is not needed.
  851. *
  852. * See the Section :ref:`node-lifecycle` on constructors and on attaching
  853. * user-defined data to nodes.
  854. *
  855. * The methods for node addition and deletion take mostly const arguments that
  856. * are not modified. When creating a node, a deep copy of the node identifier,
  857. * node attributes, etc. is created. Therefore, it is possible to call for
  858. * example ``UA_Server_addVariablenode`` with a value attribute (a
  859. * :ref:`variant`) pointing to a memory location on the stack. If you need
  860. * changes to a variable value to manifest at a specific memory location, please
  861. * use a :ref:`datasource` or a :ref:`value-callback`. */
  862. /* Protect against redundant definitions for server/client */
  863. #ifndef UA_DEFAULT_ATTRIBUTES_DEFINED
  864. #define UA_DEFAULT_ATTRIBUTES_DEFINED
  865. /* The default for variables is "BaseDataType" for the datatype, -2 for the
  866. * valuerank and a read-accesslevel. */
  867. UA_EXPORT extern const UA_VariableAttributes UA_VariableAttributes_default;
  868. UA_EXPORT extern const UA_VariableTypeAttributes UA_VariableTypeAttributes_default;
  869. /* Methods are executable by default */
  870. UA_EXPORT extern const UA_MethodAttributes UA_MethodAttributes_default;
  871. /* The remaining attribute definitions are currently all zeroed out */
  872. UA_EXPORT extern const UA_ObjectAttributes UA_ObjectAttributes_default;
  873. UA_EXPORT extern const UA_ObjectTypeAttributes UA_ObjectTypeAttributes_default;
  874. UA_EXPORT extern const UA_ReferenceTypeAttributes UA_ReferenceTypeAttributes_default;
  875. UA_EXPORT extern const UA_DataTypeAttributes UA_DataTypeAttributes_default;
  876. UA_EXPORT extern const UA_ViewAttributes UA_ViewAttributes_default;
  877. #endif
  878. /* Don't use this function. There are typed versions as inline functions. */
  879. UA_StatusCode UA_EXPORT
  880. __UA_Server_addNode(UA_Server *server, const UA_NodeClass nodeClass,
  881. const UA_NodeId *requestedNewNodeId,
  882. const UA_NodeId *parentNodeId,
  883. const UA_NodeId *referenceTypeId,
  884. const UA_QualifiedName browseName,
  885. const UA_NodeId *typeDefinition,
  886. const UA_NodeAttributes *attr,
  887. const UA_DataType *attributeType,
  888. void *nodeContext, UA_NodeId *outNewNodeId);
  889. static UA_INLINE UA_StatusCode
  890. UA_Server_addVariableNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  891. const UA_NodeId parentNodeId,
  892. const UA_NodeId referenceTypeId,
  893. const UA_QualifiedName browseName,
  894. const UA_NodeId typeDefinition,
  895. const UA_VariableAttributes attr,
  896. void *nodeContext, UA_NodeId *outNewNodeId) {
  897. return __UA_Server_addNode(server, UA_NODECLASS_VARIABLE, &requestedNewNodeId,
  898. &parentNodeId, &referenceTypeId, browseName,
  899. &typeDefinition, (const UA_NodeAttributes*)&attr,
  900. &UA_TYPES[UA_TYPES_VARIABLEATTRIBUTES],
  901. nodeContext, outNewNodeId);
  902. }
  903. static UA_INLINE UA_StatusCode
  904. UA_Server_addVariableTypeNode(UA_Server *server,
  905. const UA_NodeId requestedNewNodeId,
  906. const UA_NodeId parentNodeId,
  907. const UA_NodeId referenceTypeId,
  908. const UA_QualifiedName browseName,
  909. const UA_NodeId typeDefinition,
  910. const UA_VariableTypeAttributes attr,
  911. void *nodeContext, UA_NodeId *outNewNodeId) {
  912. return __UA_Server_addNode(server, UA_NODECLASS_VARIABLETYPE,
  913. &requestedNewNodeId, &parentNodeId, &referenceTypeId,
  914. browseName, &typeDefinition,
  915. (const UA_NodeAttributes*)&attr,
  916. &UA_TYPES[UA_TYPES_VARIABLETYPEATTRIBUTES],
  917. nodeContext, outNewNodeId);
  918. }
  919. static UA_INLINE UA_StatusCode
  920. UA_Server_addObjectNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  921. const UA_NodeId parentNodeId,
  922. const UA_NodeId referenceTypeId,
  923. const UA_QualifiedName browseName,
  924. const UA_NodeId typeDefinition,
  925. const UA_ObjectAttributes attr,
  926. void *nodeContext, UA_NodeId *outNewNodeId) {
  927. return __UA_Server_addNode(server, UA_NODECLASS_OBJECT, &requestedNewNodeId,
  928. &parentNodeId, &referenceTypeId, browseName,
  929. &typeDefinition, (const UA_NodeAttributes*)&attr,
  930. &UA_TYPES[UA_TYPES_OBJECTATTRIBUTES],
  931. nodeContext, outNewNodeId);
  932. }
  933. static UA_INLINE UA_StatusCode
  934. UA_Server_addObjectTypeNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  935. const UA_NodeId parentNodeId,
  936. const UA_NodeId referenceTypeId,
  937. const UA_QualifiedName browseName,
  938. const UA_ObjectTypeAttributes attr,
  939. void *nodeContext, UA_NodeId *outNewNodeId) {
  940. return __UA_Server_addNode(server, UA_NODECLASS_OBJECTTYPE, &requestedNewNodeId,
  941. &parentNodeId, &referenceTypeId, browseName,
  942. &UA_NODEID_NULL, (const UA_NodeAttributes*)&attr,
  943. &UA_TYPES[UA_TYPES_OBJECTTYPEATTRIBUTES],
  944. nodeContext, outNewNodeId);
  945. }
  946. static UA_INLINE UA_StatusCode
  947. UA_Server_addViewNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  948. const UA_NodeId parentNodeId,
  949. const UA_NodeId referenceTypeId,
  950. const UA_QualifiedName browseName,
  951. const UA_ViewAttributes attr,
  952. void *nodeContext, UA_NodeId *outNewNodeId) {
  953. return __UA_Server_addNode(server, UA_NODECLASS_VIEW, &requestedNewNodeId,
  954. &parentNodeId, &referenceTypeId, browseName,
  955. &UA_NODEID_NULL, (const UA_NodeAttributes*)&attr,
  956. &UA_TYPES[UA_TYPES_VIEWATTRIBUTES],
  957. nodeContext, outNewNodeId);
  958. }
  959. static UA_INLINE UA_StatusCode
  960. UA_Server_addReferenceTypeNode(UA_Server *server,
  961. const UA_NodeId requestedNewNodeId,
  962. const UA_NodeId parentNodeId,
  963. const UA_NodeId referenceTypeId,
  964. const UA_QualifiedName browseName,
  965. const UA_ReferenceTypeAttributes attr,
  966. void *nodeContext, UA_NodeId *outNewNodeId) {
  967. return __UA_Server_addNode(server, UA_NODECLASS_REFERENCETYPE,
  968. &requestedNewNodeId, &parentNodeId, &referenceTypeId,
  969. browseName, &UA_NODEID_NULL,
  970. (const UA_NodeAttributes*)&attr,
  971. &UA_TYPES[UA_TYPES_REFERENCETYPEATTRIBUTES],
  972. nodeContext, outNewNodeId);
  973. }
  974. static UA_INLINE UA_StatusCode
  975. UA_Server_addDataTypeNode(UA_Server *server,
  976. const UA_NodeId requestedNewNodeId,
  977. const UA_NodeId parentNodeId,
  978. const UA_NodeId referenceTypeId,
  979. const UA_QualifiedName browseName,
  980. const UA_DataTypeAttributes attr,
  981. void *nodeContext, UA_NodeId *outNewNodeId) {
  982. return __UA_Server_addNode(server, UA_NODECLASS_DATATYPE, &requestedNewNodeId,
  983. &parentNodeId, &referenceTypeId, browseName,
  984. &UA_NODEID_NULL, (const UA_NodeAttributes*)&attr,
  985. &UA_TYPES[UA_TYPES_DATATYPEATTRIBUTES],
  986. nodeContext, outNewNodeId);
  987. }
  988. UA_StatusCode UA_EXPORT
  989. UA_Server_addDataSourceVariableNode(UA_Server *server,
  990. const UA_NodeId requestedNewNodeId,
  991. const UA_NodeId parentNodeId,
  992. const UA_NodeId referenceTypeId,
  993. const UA_QualifiedName browseName,
  994. const UA_NodeId typeDefinition,
  995. const UA_VariableAttributes attr,
  996. const UA_DataSource dataSource,
  997. void *nodeContext, UA_NodeId *outNewNodeId);
  998. #ifdef UA_ENABLE_METHODCALLS
  999. UA_StatusCode UA_EXPORT
  1000. UA_Server_addMethodNodeEx(UA_Server *server, const UA_NodeId requestedNewNodeId,
  1001. const UA_NodeId parentNodeId,
  1002. const UA_NodeId referenceTypeId,
  1003. const UA_QualifiedName browseName,
  1004. const UA_MethodAttributes attr, UA_MethodCallback method,
  1005. size_t inputArgumentsSize, const UA_Argument *inputArguments,
  1006. const UA_NodeId inputArgumentsRequestedNewNodeId,
  1007. UA_NodeId *inputArgumentsOutNewNodeId,
  1008. size_t outputArgumentsSize, const UA_Argument *outputArguments,
  1009. const UA_NodeId outputArgumentsRequestedNewNodeId,
  1010. UA_NodeId *outputArgumentsOutNewNodeId,
  1011. void *nodeContext, UA_NodeId *outNewNodeId);
  1012. static UA_INLINE UA_StatusCode
  1013. UA_Server_addMethodNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  1014. const UA_NodeId parentNodeId, const UA_NodeId referenceTypeId,
  1015. const UA_QualifiedName browseName, const UA_MethodAttributes attr,
  1016. UA_MethodCallback method,
  1017. size_t inputArgumentsSize, const UA_Argument *inputArguments,
  1018. size_t outputArgumentsSize, const UA_Argument *outputArguments,
  1019. void *nodeContext, UA_NodeId *outNewNodeId) {
  1020. return UA_Server_addMethodNodeEx(server, requestedNewNodeId, parentNodeId,
  1021. referenceTypeId, browseName, attr, method,
  1022. inputArgumentsSize, inputArguments, UA_NODEID_NULL, NULL,
  1023. outputArgumentsSize, outputArguments, UA_NODEID_NULL, NULL,
  1024. nodeContext, outNewNodeId);
  1025. }
  1026. #endif
  1027. /**
  1028. * The method pair UA_Server_addNode_begin and _finish splits the AddNodes
  1029. * service in two parts. This is useful if the node shall be modified before
  1030. * finish the instantiation. For example to add children with specific NodeIds.
  1031. * Otherwise, mandatory children (e.g. of an ObjectType) are added with
  1032. * pseudo-random unique NodeIds. Existing children are detected during the
  1033. * _finish part via their matching BrowseName.
  1034. *
  1035. * The _begin method:
  1036. * - prepares the node and adds it to the nodestore
  1037. * - copies some unassigned attributes from the TypeDefinition node internally
  1038. * - adds the references to the parent (and the TypeDefinition if applicable)
  1039. * - performs type-checking of variables.
  1040. *
  1041. * You can add an object node without a parent if you set the parentNodeId and
  1042. * referenceTypeId to UA_NODE_ID_NULL. Then you need to add the parent reference
  1043. * and hasTypeDef reference yourself before calling the _finish method.
  1044. * Not that this is only allowed for object nodes.
  1045. *
  1046. * The _finish method:
  1047. * - copies mandatory children
  1048. * - calls the node constructor(s) at the end
  1049. * - may remove the node if it encounters an error.
  1050. *
  1051. * The special UA_Server_addMethodNode_finish method needs to be used for
  1052. * method nodes, since there you need to explicitly specifiy the input
  1053. * and output arguments which are added in the finish step (if not yet already there)
  1054. **/
  1055. /* The ``attr`` argument must have a type according to the NodeClass.
  1056. * ``VariableAttributes`` for variables, ``ObjectAttributes`` for objects, and
  1057. * so on. Missing attributes are taken from the TypeDefinition node if
  1058. * applicable. */
  1059. UA_StatusCode UA_EXPORT
  1060. UA_Server_addNode_begin(UA_Server *server, const UA_NodeClass nodeClass,
  1061. const UA_NodeId requestedNewNodeId,
  1062. const UA_NodeId parentNodeId,
  1063. const UA_NodeId referenceTypeId,
  1064. const UA_QualifiedName browseName,
  1065. const UA_NodeId typeDefinition,
  1066. const void *attr, const UA_DataType *attributeType,
  1067. void *nodeContext, UA_NodeId *outNewNodeId);
  1068. UA_StatusCode UA_EXPORT
  1069. UA_Server_addNode_finish(UA_Server *server, const UA_NodeId nodeId);
  1070. #ifdef UA_ENABLE_METHODCALLS
  1071. UA_StatusCode UA_EXPORT
  1072. UA_Server_addMethodNode_finish(UA_Server *server, const UA_NodeId nodeId,
  1073. UA_MethodCallback method,
  1074. size_t inputArgumentsSize, const UA_Argument* inputArguments,
  1075. size_t outputArgumentsSize, const UA_Argument* outputArguments);
  1076. #endif
  1077. /* Deletes a node and optionally all references leading to the node. */
  1078. UA_StatusCode UA_EXPORT
  1079. UA_Server_deleteNode(UA_Server *server, const UA_NodeId nodeId,
  1080. UA_Boolean deleteReferences);
  1081. /**
  1082. * Reference Management
  1083. * -------------------- */
  1084. UA_StatusCode UA_EXPORT
  1085. UA_Server_addReference(UA_Server *server, const UA_NodeId sourceId,
  1086. const UA_NodeId refTypeId,
  1087. const UA_ExpandedNodeId targetId, UA_Boolean isForward);
  1088. UA_StatusCode UA_EXPORT
  1089. UA_Server_deleteReference(UA_Server *server, const UA_NodeId sourceNodeId,
  1090. const UA_NodeId referenceTypeId, UA_Boolean isForward,
  1091. const UA_ExpandedNodeId targetNodeId,
  1092. UA_Boolean deleteBidirectional);
  1093. /**
  1094. * .. _events:
  1095. *
  1096. * Events
  1097. * ------
  1098. * The method ``UA_Server_createEvent`` creates an event and represents it as node. The node receives a unique `EventId`
  1099. * which is automatically added to the node.
  1100. * The method returns a `NodeId` to the object node which represents the event through ``outNodeId``. The `NodeId` can
  1101. * be used to set the attributes of the event. The generated `NodeId` is always numeric. ``outNodeId`` cannot be
  1102. * ``NULL``.
  1103. *
  1104. * Note: In order to see an event in UAExpert, the field `Time` must be given a value!
  1105. *
  1106. * The method ``UA_Server_triggerEvent`` "triggers" an event by adding it to all monitored items of the specified
  1107. * origin node and those of all its parents. Any filters specified by the monitored items are automatically applied.
  1108. * Using this method deletes the node generated by ``UA_Server_createEvent``. The `EventId` for the new event is
  1109. * generated automatically and is returned through ``outEventId``. ``NULL`` can be passed if the `EventId` is not
  1110. * needed. ``deleteEventNode`` specifies whether the node representation of the event should be deleted after invoking
  1111. * the method. This can be useful if events with the similar attributes are triggered frequently. ``UA_TRUE`` would
  1112. * cause the node to be deleted. */
  1113. #ifdef UA_ENABLE_SUBSCRIPTIONS_EVENTS
  1114. /* The EventQueueOverflowEventType is defined as abstract, therefore we can not
  1115. * create an instance of that type directly, but need to create a subtype. The
  1116. * following is an arbitrary number which shall refer to our internal overflow
  1117. * type. This is already posted on the OPC Foundation bug tracker under the
  1118. * following link for clarification:
  1119. * https://opcfoundation-onlineapplications.org/mantis/view.php?id=4206 */
  1120. # define UA_NS0ID_SIMPLEOVERFLOWEVENTTYPE 4035
  1121. /* Creates a node representation of an event
  1122. *
  1123. * @param server The server object
  1124. * @param eventType The type of the event for which a node should be created
  1125. * @param outNodeId The NodeId of the newly created node for the event
  1126. * @return The StatusCode of the UA_Server_createEvent method */
  1127. UA_StatusCode UA_EXPORT
  1128. UA_Server_createEvent(UA_Server *server, const UA_NodeId eventType,
  1129. UA_NodeId *outNodeId);
  1130. /* Triggers a node representation of an event by applying EventFilters and
  1131. adding the event to the appropriate queues.
  1132. * @param server The server object
  1133. * @param eventNodeId The NodeId of the node representation of the event which should be triggered
  1134. * @param outEvent the EventId of the new event
  1135. * @param deleteEventNode Specifies whether the node representation of the event should be deleted
  1136. * @return The StatusCode of the UA_Server_triggerEvent method */
  1137. UA_StatusCode UA_EXPORT
  1138. UA_Server_triggerEvent(UA_Server *server, const UA_NodeId eventNodeId, const UA_NodeId originId,
  1139. UA_ByteString *outEventId, const UA_Boolean deleteEventNode);
  1140. #endif /* UA_ENABLE_SUBSCRIPTIONS_EVENTS */
  1141. UA_StatusCode UA_EXPORT
  1142. UA_Server_updateCertificate(UA_Server *server,
  1143. const UA_ByteString *oldCertificate,
  1144. const UA_ByteString *newCertificate,
  1145. const UA_ByteString *newPrivateKey,
  1146. UA_Boolean closeSessions,
  1147. UA_Boolean closeSecureChannels);
  1148. /**
  1149. * Utility Functions
  1150. * ----------------- */
  1151. /* Add a new namespace to the server. Returns the index of the new namespace */
  1152. UA_UInt16 UA_EXPORT UA_Server_addNamespace(UA_Server *server, const char* name);
  1153. /* Get namespace by name from the server. */
  1154. UA_StatusCode UA_EXPORT
  1155. UA_Server_getNamespaceByName(UA_Server *server, const UA_String namespaceUri,
  1156. size_t* foundIndex);
  1157. #ifdef UA_ENABLE_HISTORIZING
  1158. UA_Boolean UA_EXPORT
  1159. UA_Server_AccessControl_allowHistoryUpdateUpdateData(UA_Server *server,
  1160. const UA_NodeId *sessionId, void *sessionContext,
  1161. const UA_NodeId *nodeId,
  1162. UA_PerformUpdateType performInsertReplace,
  1163. const UA_DataValue *value);
  1164. UA_Boolean UA_EXPORT
  1165. UA_Server_AccessControl_allowHistoryUpdateDeleteRawModified(UA_Server *server,
  1166. const UA_NodeId *sessionId, void *sessionContext,
  1167. const UA_NodeId *nodeId,
  1168. UA_DateTime startTimestamp,
  1169. UA_DateTime endTimestamp,
  1170. bool isDeleteModified);
  1171. #endif // UA_ENABLE_HISTORIZING
  1172. _UA_END_DECLS
  1173. #endif /* UA_SERVER_H_ */