ua_server.h 59 KB

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