server.h 62 KB

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