server.h 59 KB

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