ua_server.h 56 KB

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