server.h 59 KB

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