ua_server.h 52 KB

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