ua_server.h 56 KB

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