ua_server.h 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  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. 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. /**
  26. * .. _server:
  27. *
  28. * Server
  29. * ======
  30. *
  31. * .. include:: server_config.rst
  32. *
  33. * .. _server-lifecycle:
  34. *
  35. * Server Lifecycle
  36. * ---------------- */
  37. UA_Server UA_EXPORT * UA_Server_new(const UA_ServerConfig *config);
  38. void UA_EXPORT UA_Server_delete(UA_Server *server);
  39. /* Runs the main loop of the server. In each iteration, this calls into the
  40. * networklayers to see if messages have arrived.
  41. *
  42. * @param server The server object.
  43. * @param running The loop is run as long as *running is true.
  44. * Otherwise, the server shuts down.
  45. * @return Returns the statuscode of the UA_Server_run_shutdown method */
  46. UA_StatusCode UA_EXPORT
  47. UA_Server_run(UA_Server *server, volatile UA_Boolean *running);
  48. /* The prologue part of UA_Server_run (no need to use if you call
  49. * UA_Server_run) */
  50. UA_StatusCode UA_EXPORT
  51. UA_Server_run_startup(UA_Server *server);
  52. /* Executes a single iteration of the server's main loop.
  53. *
  54. * @param server The server object.
  55. * @param waitInternal Should we wait for messages in the networklayer?
  56. * Otherwise, the timouts for the networklayers are set to zero.
  57. * The default max wait time is 50millisec.
  58. * @return Returns how long we can wait until the next scheduled
  59. * callback (in ms) */
  60. UA_UInt16 UA_EXPORT
  61. UA_Server_run_iterate(UA_Server *server, UA_Boolean waitInternal);
  62. /* The epilogue part of UA_Server_run (no need to use if you call
  63. * UA_Server_run) */
  64. UA_StatusCode UA_EXPORT
  65. UA_Server_run_shutdown(UA_Server *server);
  66. /**
  67. * Repeated Callbacks
  68. * ------------------ */
  69. typedef void (*UA_ServerCallback)(UA_Server *server, void *data);
  70. /* Add a callback for cyclic repetition to the server.
  71. *
  72. * @param server The server object.
  73. * @param callback The callback that shall be added.
  74. * @param interval The callback shall be repeatedly executed with the given interval
  75. * (in ms). The interval must be larger than 5ms. The first execution
  76. * occurs at now() + interval at the latest.
  77. * @param callbackId Set to the identifier of the repeated callback . This can be used to cancel
  78. * the callback later on. If the pointer is null, the identifier is not set.
  79. * @return Upon success, UA_STATUSCODE_GOOD is returned.
  80. * An error code otherwise. */
  81. UA_StatusCode UA_EXPORT
  82. UA_Server_addRepeatedCallback(UA_Server *server, UA_ServerCallback callback,
  83. void *data, UA_UInt32 interval, UA_UInt64 *callbackId);
  84. UA_StatusCode UA_EXPORT
  85. UA_Server_changeRepeatedCallbackInterval(UA_Server *server, UA_UInt64 callbackId,
  86. UA_UInt32 interval);
  87. /* Remove a repeated callback.
  88. *
  89. * @param server The server object.
  90. * @param callbackId The id of the callback that shall be removed.
  91. * @return Upon success, UA_STATUSCODE_GOOD is returned.
  92. * An error code otherwise. */
  93. UA_StatusCode UA_EXPORT
  94. UA_Server_removeRepeatedCallback(UA_Server *server, UA_UInt64 callbackId);
  95. /**
  96. * Reading and Writing Node Attributes
  97. * -----------------------------------
  98. * The functions for reading and writing node attributes call the regular read
  99. * and write service in the background that are also used over the network.
  100. *
  101. * The following attributes cannot be read, since the local "admin" user always
  102. * has full rights.
  103. *
  104. * - UserWriteMask
  105. * - UserAccessLevel
  106. * - UserExecutable */
  107. /* Read an attribute of a node. The specialized functions below provide a more
  108. * concise syntax.
  109. *
  110. * @param server The server object.
  111. * @param item ReadValueIds contain the NodeId of the target node, the id of the
  112. * attribute to read and (optionally) an index range to read parts
  113. * of an array only. See the section on NumericRange for the format
  114. * used for array ranges.
  115. * @param timestamps Which timestamps to return for the attribute.
  116. * @return Returns a DataValue that contains either an error code, or a variant
  117. * with the attribute value and the timestamps. */
  118. UA_DataValue UA_EXPORT
  119. UA_Server_read(UA_Server *server, const UA_ReadValueId *item,
  120. UA_TimestampsToReturn timestamps);
  121. /* Don't use this function. There are typed versions for every supported
  122. * attribute. */
  123. UA_StatusCode UA_EXPORT
  124. __UA_Server_read(UA_Server *server, const UA_NodeId *nodeId,
  125. UA_AttributeId attributeId, void *v);
  126. static UA_INLINE UA_StatusCode
  127. UA_Server_readNodeId(UA_Server *server, const UA_NodeId nodeId,
  128. UA_NodeId *outNodeId) {
  129. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_NODEID, outNodeId);
  130. }
  131. static UA_INLINE UA_StatusCode
  132. UA_Server_readNodeClass(UA_Server *server, const UA_NodeId nodeId,
  133. UA_NodeClass *outNodeClass) {
  134. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_NODECLASS,
  135. outNodeClass);
  136. }
  137. static UA_INLINE UA_StatusCode
  138. UA_Server_readBrowseName(UA_Server *server, const UA_NodeId nodeId,
  139. UA_QualifiedName *outBrowseName) {
  140. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_BROWSENAME,
  141. outBrowseName);
  142. }
  143. static UA_INLINE UA_StatusCode
  144. UA_Server_readDisplayName(UA_Server *server, const UA_NodeId nodeId,
  145. UA_LocalizedText *outDisplayName) {
  146. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_DISPLAYNAME,
  147. outDisplayName);
  148. }
  149. static UA_INLINE UA_StatusCode
  150. UA_Server_readDescription(UA_Server *server, const UA_NodeId nodeId,
  151. UA_LocalizedText *outDescription) {
  152. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_DESCRIPTION,
  153. outDescription);
  154. }
  155. static UA_INLINE UA_StatusCode
  156. UA_Server_readWriteMask(UA_Server *server, const UA_NodeId nodeId,
  157. UA_UInt32 *outWriteMask) {
  158. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_WRITEMASK,
  159. outWriteMask);
  160. }
  161. static UA_INLINE UA_StatusCode
  162. UA_Server_readIsAbstract(UA_Server *server, const UA_NodeId nodeId,
  163. UA_Boolean *outIsAbstract) {
  164. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_ISABSTRACT,
  165. outIsAbstract);
  166. }
  167. static UA_INLINE UA_StatusCode
  168. UA_Server_readSymmetric(UA_Server *server, const UA_NodeId nodeId,
  169. UA_Boolean *outSymmetric) {
  170. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_SYMMETRIC,
  171. outSymmetric);
  172. }
  173. static UA_INLINE UA_StatusCode
  174. UA_Server_readInverseName(UA_Server *server, const UA_NodeId nodeId,
  175. UA_LocalizedText *outInverseName) {
  176. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_INVERSENAME,
  177. outInverseName);
  178. }
  179. static UA_INLINE UA_StatusCode
  180. UA_Server_readContainsNoLoop(UA_Server *server, const UA_NodeId nodeId,
  181. UA_Boolean *outContainsNoLoops) {
  182. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_CONTAINSNOLOOPS,
  183. outContainsNoLoops);
  184. }
  185. static UA_INLINE UA_StatusCode
  186. UA_Server_readEventNotifier(UA_Server *server, const UA_NodeId nodeId,
  187. UA_Byte *outEventNotifier) {
  188. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_EVENTNOTIFIER,
  189. outEventNotifier);
  190. }
  191. static UA_INLINE UA_StatusCode
  192. UA_Server_readValue(UA_Server *server, const UA_NodeId nodeId,
  193. UA_Variant *outValue) {
  194. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_VALUE, outValue);
  195. }
  196. static UA_INLINE UA_StatusCode
  197. UA_Server_readDataType(UA_Server *server, const UA_NodeId nodeId,
  198. UA_NodeId *outDataType) {
  199. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_DATATYPE,
  200. outDataType);
  201. }
  202. static UA_INLINE UA_StatusCode
  203. UA_Server_readValueRank(UA_Server *server, const UA_NodeId nodeId,
  204. UA_Int32 *outValueRank) {
  205. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_VALUERANK,
  206. outValueRank);
  207. }
  208. /* Returns a variant with an int32 array */
  209. static UA_INLINE UA_StatusCode
  210. UA_Server_readArrayDimensions(UA_Server *server, const UA_NodeId nodeId,
  211. UA_Variant *outArrayDimensions) {
  212. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_ARRAYDIMENSIONS,
  213. outArrayDimensions);
  214. }
  215. static UA_INLINE UA_StatusCode
  216. UA_Server_readAccessLevel(UA_Server *server, const UA_NodeId nodeId,
  217. UA_Byte *outAccessLevel) {
  218. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_ACCESSLEVEL,
  219. outAccessLevel);
  220. }
  221. static UA_INLINE UA_StatusCode
  222. UA_Server_readMinimumSamplingInterval(UA_Server *server, const UA_NodeId nodeId,
  223. UA_Double *outMinimumSamplingInterval) {
  224. return __UA_Server_read(server, &nodeId,
  225. UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL,
  226. outMinimumSamplingInterval);
  227. }
  228. static UA_INLINE UA_StatusCode
  229. UA_Server_readHistorizing(UA_Server *server, const UA_NodeId nodeId,
  230. UA_Boolean *outHistorizing) {
  231. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_HISTORIZING,
  232. outHistorizing);
  233. }
  234. static UA_INLINE UA_StatusCode
  235. UA_Server_readExecutable(UA_Server *server, const UA_NodeId nodeId,
  236. UA_Boolean *outExecutable) {
  237. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_EXECUTABLE,
  238. outExecutable);
  239. }
  240. /**
  241. * The following node attributes cannot be changed once a node has been created:
  242. *
  243. * - NodeClass
  244. * - NodeId
  245. * - Symmetric
  246. * - ContainsNoLoop
  247. *
  248. * The following attributes cannot be written from the server, as they are
  249. * specific to the different users and set by the access control callback:
  250. *
  251. * - UserWriteMask
  252. * - UserAccessLevel
  253. * - UserExecutable
  254. *
  255. * Historizing is currently unsupported */
  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_writeExecutable(UA_Server *server, const UA_NodeId nodeId,
  356. const UA_Boolean executable) {
  357. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_EXECUTABLE,
  358. &UA_TYPES[UA_TYPES_BOOLEAN], &executable); }
  359. /**
  360. * Browsing
  361. * -------- */
  362. UA_BrowseResult UA_EXPORT
  363. UA_Server_browse(UA_Server *server, UA_UInt32 maxrefs,
  364. const UA_BrowseDescription *descr);
  365. UA_BrowseResult UA_EXPORT
  366. UA_Server_browseNext(UA_Server *server, UA_Boolean releaseContinuationPoint,
  367. const UA_ByteString *continuationPoint);
  368. UA_BrowsePathResult UA_EXPORT
  369. UA_Server_translateBrowsePathToNodeIds(UA_Server *server,
  370. const UA_BrowsePath *browsePath);
  371. #ifndef HAVE_NODEITER_CALLBACK
  372. #define HAVE_NODEITER_CALLBACK
  373. /* Iterate over all nodes referenced by parentNodeId by calling the callback
  374. * function for each child node (in ifdef because GCC/CLANG handle include order
  375. * differently) */
  376. typedef UA_StatusCode
  377. (*UA_NodeIteratorCallback)(UA_NodeId childId, UA_Boolean isInverse,
  378. UA_NodeId referenceTypeId, void *handle);
  379. #endif
  380. UA_StatusCode UA_EXPORT
  381. UA_Server_forEachChildNodeCall(UA_Server *server, UA_NodeId parentNodeId,
  382. UA_NodeIteratorCallback callback, void *handle);
  383. #ifdef UA_ENABLE_DISCOVERY
  384. /**
  385. * Discovery
  386. * --------- */
  387. /* Register the given server instance at the discovery server.
  388. * This should be called periodically.
  389. * The semaphoreFilePath is optional. If the given file is deleted,
  390. * the server will automatically be unregistered. This could be
  391. * for example a pid file which is deleted if the server crashes.
  392. *
  393. * When the server shuts down you need to call unregister.
  394. *
  395. * @param server
  396. * @param discoveryServerUrl if set to NULL, the default value
  397. * 'opc.tcp://localhost:4840' will be used
  398. * @param semaphoreFilePath optional parameter pointing to semaphore file. */
  399. UA_StatusCode UA_EXPORT
  400. UA_Server_register_discovery(UA_Server *server, const char* discoveryServerUrl,
  401. const char* semaphoreFilePath);
  402. /* Unregister the given server instance from the discovery server.
  403. * This should only be called when the server is shutting down.
  404. * @param server
  405. * @param discoveryServerUrl if set to NULL, the default value
  406. * 'opc.tcp://localhost:4840' will be used */
  407. UA_StatusCode UA_EXPORT
  408. UA_Server_unregister_discovery(UA_Server *server, const char* discoveryServerUrl);
  409. /* Adds a periodic callback to register the server with the LDS (local discovery server)
  410. * periodically. The interval between each register call is given as second parameter.
  411. * It should be 10 minutes by default (= 10*60*1000).
  412. *
  413. * The delayFirstRegisterMs parameter indicates the delay for the first register call.
  414. * If it is 0, the first register call will be after intervalMs milliseconds,
  415. * otherwise the server's first register will be after delayFirstRegisterMs.
  416. *
  417. * When you manually unregister the server, you also need to cancel the
  418. * periodic callback, otherwise it will be automatically be registered again.
  419. *
  420. * If you call this method multiple times for the same discoveryServerUrl, the older
  421. * periodic callback will be removed.
  422. *
  423. * @param server
  424. * @param discoveryServerUrl if set to NULL, the default value
  425. * 'opc.tcp://localhost:4840' will be used
  426. * @param intervalMs
  427. * @param delayFirstRegisterMs
  428. * @param periodicCallbackId */
  429. UA_StatusCode UA_EXPORT
  430. UA_Server_addPeriodicServerRegisterCallback(UA_Server *server, const char* discoveryServerUrl,
  431. UA_UInt32 intervalMs,
  432. UA_UInt32 delayFirstRegisterMs,
  433. UA_UInt64 *periodicCallbackId);
  434. /* Callback for RegisterServer. Data is passed from the register call */
  435. typedef void (*UA_Server_registerServerCallback)(const UA_RegisteredServer *registeredServer,
  436. void* data);
  437. /* Set the callback which is called if another server registeres or unregisters
  438. * with this instance. If called multiple times, previous data will be
  439. * overwritten.
  440. *
  441. * @param server
  442. * @param cb the callback
  443. * @param data data passed to the callback
  444. * @return UA_STATUSCODE_SUCCESS on success */
  445. void UA_EXPORT
  446. UA_Server_setRegisterServerCallback(UA_Server *server, UA_Server_registerServerCallback cb,
  447. void* data);
  448. #ifdef UA_ENABLE_DISCOVERY_MULTICAST
  449. /* Callback for server detected through mDNS. Data is passed from the register
  450. * call
  451. *
  452. * @param isServerAnnounce indicates if the server has just been detected. If
  453. * set to false, this means the server is shutting down.
  454. * @param isTxtReceived indicates if we already received the corresponding TXT
  455. * record with the path and caps data */
  456. typedef void (*UA_Server_serverOnNetworkCallback)(const UA_ServerOnNetwork *serverOnNetwork,
  457. UA_Boolean isServerAnnounce,
  458. UA_Boolean isTxtReceived, void* data);
  459. /* Set the callback which is called if another server is found through mDNS or
  460. * deleted. It will be called for any mDNS message from the remote server, thus
  461. * it may be called multiple times for the same instance. Also the SRV and TXT
  462. * records may arrive later, therefore for the first call the server
  463. * capabilities may not be set yet. If called multiple times, previous data will
  464. * be overwritten.
  465. *
  466. * @param server
  467. * @param cb the callback
  468. * @param data data passed to the callback
  469. * @return UA_STATUSCODE_SUCCESS on success */
  470. void UA_EXPORT
  471. UA_Server_setServerOnNetworkCallback(UA_Server *server,
  472. UA_Server_serverOnNetworkCallback cb,
  473. void* data);
  474. #endif /* UA_ENABLE_DISCOVERY_MULTICAST */
  475. #endif /* UA_ENABLE_DISCOVERY */
  476. /**
  477. * Information Model Callbacks
  478. * ---------------------------
  479. *
  480. * There are three places where a callback from an information model to
  481. * user-defined code can happen.
  482. *
  483. * - Custom node constructors and destructors
  484. * - Linking VariableNodes with an external data source
  485. * - MethodNode callbacks
  486. *
  487. * .. _node-lifecycle:
  488. *
  489. * Node Lifecycle: Constructors, Destructors and Node Contexts
  490. * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  491. *
  492. * To finalize the instantiation of a node, a (user-defined) constructor
  493. * callback is executed. There can be both a global constructor for all nodes
  494. * and node-type constructor specific to the TypeDefinition of the new node
  495. * (attached to an ObjectTypeNode or VariableTypeNode).
  496. *
  497. * In the hierarchy of ObjectTypes and VariableTypes, only the constructor of
  498. * the (lowest) type defined for the new node is executed. Note that every
  499. * Object and Variable can have only one ``isTypeOf`` reference. But type-nodes
  500. * can technically have several ``hasSubType`` references to implement multiple
  501. * inheritance. Issues of (multiple) inheritance in the constructor need to be
  502. * solved by the user.
  503. *
  504. * When a node is destroyed, the node-type destructor is called before the
  505. * global destructor. So the overall node lifecycle is as follows:
  506. *
  507. * 1. Global Constructor (set in the server config)
  508. * 2. Node-Type Constructor (for VariableType or ObjectTypes)
  509. * 3. (Usage-period of the Node)
  510. * 4. Node-Type Destructor
  511. * 5. Global Destructor
  512. *
  513. * The constructor and destructor callbacks can be set to ``NULL`` and are not
  514. * used in that case. If the node-type constructor fails, the global destructor
  515. * will be called before removing the node. The destructors are assumed to never
  516. * fail.
  517. *
  518. * Every node carries a user-context and a constructor-context pointer. The
  519. * user-context is used to attach custom data to a node. But the (user-defined)
  520. * constructors and destructors may replace the user-context pointer if they
  521. * wish to do so. The initial value for the constructor-context is ``NULL``.
  522. * When the ``AddNodes`` service is used over the network, the user-context
  523. * pointer of the new node is also initially set to ``NULL``. */
  524. /* To be set in the server config. */
  525. typedef struct {
  526. /* Can be NULL. May replace the nodeContext */
  527. UA_StatusCode (*constructor)(UA_Server *server,
  528. const UA_NodeId *sessionId, void *sessionContext,
  529. const UA_NodeId *nodeId, void **nodeContext);
  530. /* Can be NULL. The context cannot be replaced since the node is destroyed
  531. * immediately afterwards anyway. */
  532. void (*destructor)(UA_Server *server,
  533. const UA_NodeId *sessionId, void *sessionContext,
  534. const UA_NodeId *nodeId, void *nodeContext);
  535. } UA_GlobalNodeLifecycle;
  536. typedef struct {
  537. /* Can be NULL. May replace the nodeContext */
  538. UA_StatusCode (*constructor)(UA_Server *server,
  539. const UA_NodeId *sessionId, void *sessionContext,
  540. const UA_NodeId *typeNodeId, void *typeNodeContext,
  541. const UA_NodeId *nodeId, void **nodeContext);
  542. /* Can be NULL. May replace the nodeContext. */
  543. void (*destructor)(UA_Server *server,
  544. const UA_NodeId *sessionId, void *sessionContext,
  545. const UA_NodeId *typeNodeId, void *typeNodeContext,
  546. const UA_NodeId *nodeId, void **nodeContext);
  547. } UA_NodeTypeLifecycle;
  548. UA_StatusCode UA_EXPORT
  549. UA_Server_setNodeTypeLifecycle(UA_Server *server, UA_NodeId nodeId,
  550. UA_NodeTypeLifecycle lifecycle);
  551. UA_StatusCode UA_EXPORT
  552. UA_Server_getNodeContext(UA_Server *server, UA_NodeId nodeId,
  553. void **nodeContext);
  554. /* Careful! The user has to ensure that the destructor callbacks still work. */
  555. UA_StatusCode UA_EXPORT
  556. UA_Server_setNodeContext(UA_Server *server, UA_NodeId nodeId,
  557. void *nodeContext);
  558. /**
  559. * .. _datasource:
  560. *
  561. * Data Source Callback
  562. * ^^^^^^^^^^^^^^^^^^^^
  563. *
  564. * The server has a unique way of dealing with the content of variables. Instead
  565. * of storing a variant attached to the variable node, the node can point to a
  566. * function with a local data provider. Whenever the value attribute is read,
  567. * the function will be called and asked to provide a UA_DataValue return value
  568. * that contains the value content and additional timestamps.
  569. *
  570. * It is expected that the read callback is implemented. The write callback can
  571. * be set to a null-pointer. */
  572. typedef struct {
  573. /* Copies the data from the source into the provided value.
  574. *
  575. * !! ZERO-COPY OPERATIONS POSSIBLE !!
  576. * It is not required to return a copy of the actual content data. You can
  577. * return a pointer to memory owned by the user. Memory can be reused
  578. * between read callbacks of a DataSource, as the result is already encoded
  579. * on the network buffer between each read operation.
  580. *
  581. * To use zero-copy reads, set the value of the `value->value` Variant
  582. * without copying, e.g. with `UA_Variant_setScalar`. Then, also set
  583. * `value->value.storageType` to `UA_VARIANT_DATA_NODELETE` to prevent the
  584. * memory being cleaned up. Don't forget to also set `value->hasValue` to
  585. * true to indicate the presence of a value.
  586. *
  587. * @param handle An optional pointer to user-defined data for the
  588. * specific data source
  589. * @param nodeid Id of the read node
  590. * @param includeSourceTimeStamp If true, then the datasource is expected to
  591. * set the source timestamp in the returned value
  592. * @param range If not null, then the datasource shall return only a
  593. * selection of the (nonscalar) data. Set
  594. * UA_STATUSCODE_BADINDEXRANGEINVALID in the value if this does not
  595. * apply.
  596. * @param value The (non-null) DataValue that is returned to the client. The
  597. * data source sets the read data, the result status and optionally a
  598. * sourcetimestamp.
  599. * @return Returns a status code for logging. Error codes intended for the
  600. * original caller are set in the value. If an error is returned,
  601. * then no releasing of the value is done. */
  602. UA_StatusCode (*read)(UA_Server *server, const UA_NodeId *sessionId,
  603. void *sessionContext, const UA_NodeId *nodeId,
  604. void *nodeContext, UA_Boolean includeSourceTimeStamp,
  605. const UA_NumericRange *range, UA_DataValue *value);
  606. /* Write into a data source. This method pointer can be NULL if the
  607. * operation is unsupported.
  608. *
  609. * @param handle An optional pointer to user-defined data for the
  610. * specific data source
  611. * @param nodeid Id of the node being written to
  612. * @param data The data to be written into the data source
  613. * @param range An optional data range. If the data source is scalar or does
  614. * not support writing of ranges, then an error code is returned.
  615. * @return Returns a status code that is returned to the user */
  616. UA_StatusCode (*write)(UA_Server *server, const UA_NodeId *sessionId,
  617. void *sessionContext, const UA_NodeId *nodeId,
  618. void *nodeContext, const UA_NumericRange *range,
  619. const UA_DataValue *value);
  620. } UA_DataSource;
  621. UA_StatusCode UA_EXPORT
  622. UA_Server_setVariableNode_dataSource(UA_Server *server, const UA_NodeId nodeId,
  623. const UA_DataSource dataSource);
  624. /**
  625. * .. _value-callback:
  626. *
  627. * Value Callback
  628. * ^^^^^^^^^^^^^^
  629. * Value Callbacks can be attached to variable and variable type nodes. If
  630. * not ``NULL``, they are called before reading and after writing respectively. */
  631. typedef struct {
  632. /* Called before the value attribute is read. It is possible to write into the
  633. * value attribute during onRead (using the write service). The node is
  634. * re-opened afterwards so that changes are considered in the following read
  635. * operation.
  636. *
  637. * @param handle Points to user-provided data for the callback.
  638. * @param nodeid The identifier of the node.
  639. * @param data Points to the current node value.
  640. * @param range Points to the numeric range the client wants to read from
  641. * (or NULL). */
  642. void (*onRead)(UA_Server *server, const UA_NodeId *sessionId,
  643. void *sessionContext, const UA_NodeId *nodeid,
  644. void *nodeContext, const UA_NumericRange *range,
  645. const UA_DataValue *value);
  646. /* Called after writing the value attribute. The node is re-opened after
  647. * writing so that the new value is visible in the callback.
  648. *
  649. * @param server The server executing the callback
  650. * @sessionId The identifier of the session
  651. * @sessionContext Additional data attached to the session
  652. * in the access control layer
  653. * @param nodeid The identifier of the node.
  654. * @param nodeUserContext Additional data attached to the node by
  655. * the user.
  656. * @param nodeConstructorContext Additional data attached to the node
  657. * by the type constructor(s).
  658. * @param range Points to the numeric range the client wants to write to (or
  659. * NULL). */
  660. void (*onWrite)(UA_Server *server, const UA_NodeId *sessionId,
  661. void *sessionContext, const UA_NodeId *nodeId,
  662. void *nodeContext, const UA_NumericRange *range,
  663. const UA_DataValue *data);
  664. } UA_ValueCallback;
  665. UA_StatusCode UA_EXPORT
  666. UA_Server_setVariableNode_valueCallback(UA_Server *server,
  667. const UA_NodeId nodeId,
  668. const UA_ValueCallback callback);
  669. /**
  670. * Method Callbacks
  671. * ^^^^^^^^^^^^^^^^
  672. * Method callbacks are set to `NULL` (not executable) when a method node is added
  673. * over the network. In theory, it is possible to add a callback via
  674. * ``UA_Server_setMethodNode_callback`` within the global constructor when adding
  675. * methods over the network is really wanted. */
  676. typedef UA_StatusCode
  677. (*UA_MethodCallback)(UA_Server *server, const UA_NodeId *sessionId,
  678. void *sessionContext, const UA_NodeId *methodId,
  679. void *methodContext, const UA_NodeId *objectId,
  680. void *objectContext, size_t inputSize,
  681. const UA_Variant *input, size_t outputSize,
  682. UA_Variant *output);
  683. #ifdef UA_ENABLE_METHODCALLS
  684. UA_StatusCode UA_EXPORT
  685. UA_Server_setMethodNode_callback(UA_Server *server,
  686. const UA_NodeId methodNodeId,
  687. UA_MethodCallback methodCallback);
  688. UA_CallMethodResult UA_EXPORT
  689. UA_Server_call(UA_Server *server, const UA_CallMethodRequest *request);
  690. #endif
  691. /**
  692. * .. _addnodes:
  693. *
  694. * Node Addition and Deletion
  695. * --------------------------
  696. * When creating dynamic node instances at runtime, chances are that you will
  697. * not care about the specific NodeId of the new node, as long as you can
  698. * reference it later. When passing numeric NodeIds with a numeric identifier 0,
  699. * the stack evaluates this as "select a random unassigned numeric NodeId in
  700. * that namespace". To find out which NodeId was actually assigned to the new
  701. * node, you may pass a pointer `outNewNodeId`, which will (after a successful
  702. * node insertion) contain the nodeId of the new node. You may also pass a
  703. * ``NULL`` pointer if this result is not needed.
  704. *
  705. * See the Section :ref:`node-lifecycle` on constructors and on attaching
  706. * user-defined data to nodes.
  707. *
  708. * The methods for node addition and deletion take mostly const arguments that
  709. * are not modified. When creating a node, a deep copy of the node identifier,
  710. * node attributes, etc. is created. Therefore, it is possible to call for
  711. * example ``UA_Server_addVariablenode`` with a value attribute (a
  712. * :ref:`variant`) pointing to a memory location on the stack. If you need
  713. * changes to a variable value to manifest at a specific memory location, please
  714. * use a :ref:`datasource` or a :ref:`value-callback`. */
  715. /* Protect against redundant definitions for server/client */
  716. #ifndef UA_DEFAULT_ATTRIBUTES_DEFINED
  717. #define UA_DEFAULT_ATTRIBUTES_DEFINED
  718. /* The default for variables is "BaseDataType" for the datatype, -2 for the
  719. * valuerank and a read-accesslevel. */
  720. UA_EXPORT extern const UA_VariableAttributes UA_VariableAttributes_default;
  721. UA_EXPORT extern const UA_VariableTypeAttributes UA_VariableTypeAttributes_default;
  722. /* Methods are executable by default */
  723. UA_EXPORT extern const UA_MethodAttributes UA_MethodAttributes_default;
  724. /* The remaining attribute definitions are currently all zeroed out */
  725. UA_EXPORT extern const UA_ObjectAttributes UA_ObjectAttributes_default;
  726. UA_EXPORT extern const UA_ObjectTypeAttributes UA_ObjectTypeAttributes_default;
  727. UA_EXPORT extern const UA_ReferenceTypeAttributes UA_ReferenceTypeAttributes_default;
  728. UA_EXPORT extern const UA_DataTypeAttributes UA_DataTypeAttributes_default;
  729. UA_EXPORT extern const UA_ViewAttributes UA_ViewAttributes_default;
  730. #endif
  731. /* Don't use this function. There are typed versions as inline functions. */
  732. UA_StatusCode UA_EXPORT
  733. __UA_Server_addNode(UA_Server *server, const UA_NodeClass nodeClass,
  734. const UA_NodeId *requestedNewNodeId,
  735. const UA_NodeId *parentNodeId,
  736. const UA_NodeId *referenceTypeId,
  737. const UA_QualifiedName browseName,
  738. const UA_NodeId *typeDefinition,
  739. const UA_NodeAttributes *attr,
  740. const UA_DataType *attributeType,
  741. void *nodeContext, UA_NodeId *outNewNodeId);
  742. static UA_INLINE UA_StatusCode
  743. UA_Server_addVariableNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  744. const UA_NodeId parentNodeId,
  745. const UA_NodeId referenceTypeId,
  746. const UA_QualifiedName browseName,
  747. const UA_NodeId typeDefinition,
  748. const UA_VariableAttributes attr,
  749. void *nodeContext, UA_NodeId *outNewNodeId) {
  750. return __UA_Server_addNode(server, UA_NODECLASS_VARIABLE, &requestedNewNodeId,
  751. &parentNodeId, &referenceTypeId, browseName,
  752. &typeDefinition, (const UA_NodeAttributes*)&attr,
  753. &UA_TYPES[UA_TYPES_VARIABLEATTRIBUTES],
  754. nodeContext, outNewNodeId);
  755. }
  756. static UA_INLINE UA_StatusCode
  757. UA_Server_addVariableTypeNode(UA_Server *server,
  758. const UA_NodeId requestedNewNodeId,
  759. const UA_NodeId parentNodeId,
  760. const UA_NodeId referenceTypeId,
  761. const UA_QualifiedName browseName,
  762. const UA_NodeId typeDefinition,
  763. const UA_VariableTypeAttributes attr,
  764. void *nodeContext, UA_NodeId *outNewNodeId) {
  765. return __UA_Server_addNode(server, UA_NODECLASS_VARIABLETYPE,
  766. &requestedNewNodeId, &parentNodeId, &referenceTypeId,
  767. browseName, &typeDefinition,
  768. (const UA_NodeAttributes*)&attr,
  769. &UA_TYPES[UA_TYPES_VARIABLETYPEATTRIBUTES],
  770. nodeContext, outNewNodeId);
  771. }
  772. static UA_INLINE UA_StatusCode
  773. UA_Server_addObjectNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  774. const UA_NodeId parentNodeId,
  775. const UA_NodeId referenceTypeId,
  776. const UA_QualifiedName browseName,
  777. const UA_NodeId typeDefinition,
  778. const UA_ObjectAttributes attr,
  779. void *nodeContext, UA_NodeId *outNewNodeId) {
  780. return __UA_Server_addNode(server, UA_NODECLASS_OBJECT, &requestedNewNodeId,
  781. &parentNodeId, &referenceTypeId, browseName,
  782. &typeDefinition, (const UA_NodeAttributes*)&attr,
  783. &UA_TYPES[UA_TYPES_OBJECTATTRIBUTES],
  784. nodeContext, outNewNodeId);
  785. }
  786. static UA_INLINE UA_StatusCode
  787. UA_Server_addObjectTypeNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  788. const UA_NodeId parentNodeId,
  789. const UA_NodeId referenceTypeId,
  790. const UA_QualifiedName browseName,
  791. const UA_ObjectTypeAttributes attr,
  792. void *nodeContext, UA_NodeId *outNewNodeId) {
  793. return __UA_Server_addNode(server, UA_NODECLASS_OBJECTTYPE, &requestedNewNodeId,
  794. &parentNodeId, &referenceTypeId, browseName,
  795. &UA_NODEID_NULL, (const UA_NodeAttributes*)&attr,
  796. &UA_TYPES[UA_TYPES_OBJECTTYPEATTRIBUTES],
  797. nodeContext, outNewNodeId);
  798. }
  799. static UA_INLINE UA_StatusCode
  800. UA_Server_addViewNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  801. const UA_NodeId parentNodeId,
  802. const UA_NodeId referenceTypeId,
  803. const UA_QualifiedName browseName,
  804. const UA_ViewAttributes attr,
  805. void *nodeContext, UA_NodeId *outNewNodeId) {
  806. return __UA_Server_addNode(server, UA_NODECLASS_VIEW, &requestedNewNodeId,
  807. &parentNodeId, &referenceTypeId, browseName,
  808. &UA_NODEID_NULL, (const UA_NodeAttributes*)&attr,
  809. &UA_TYPES[UA_TYPES_VIEWATTRIBUTES],
  810. nodeContext, outNewNodeId);
  811. }
  812. static UA_INLINE UA_StatusCode
  813. UA_Server_addReferenceTypeNode(UA_Server *server,
  814. const UA_NodeId requestedNewNodeId,
  815. const UA_NodeId parentNodeId,
  816. const UA_NodeId referenceTypeId,
  817. const UA_QualifiedName browseName,
  818. const UA_ReferenceTypeAttributes attr,
  819. void *nodeContext, UA_NodeId *outNewNodeId) {
  820. return __UA_Server_addNode(server, UA_NODECLASS_REFERENCETYPE,
  821. &requestedNewNodeId, &parentNodeId, &referenceTypeId,
  822. browseName, &UA_NODEID_NULL,
  823. (const UA_NodeAttributes*)&attr,
  824. &UA_TYPES[UA_TYPES_REFERENCETYPEATTRIBUTES],
  825. nodeContext, outNewNodeId);
  826. }
  827. static UA_INLINE UA_StatusCode
  828. UA_Server_addDataTypeNode(UA_Server *server,
  829. const UA_NodeId requestedNewNodeId,
  830. const UA_NodeId parentNodeId,
  831. const UA_NodeId referenceTypeId,
  832. const UA_QualifiedName browseName,
  833. const UA_DataTypeAttributes attr,
  834. void *nodeContext, UA_NodeId *outNewNodeId) {
  835. return __UA_Server_addNode(server, UA_NODECLASS_DATATYPE, &requestedNewNodeId,
  836. &parentNodeId, &referenceTypeId, browseName,
  837. &UA_NODEID_NULL, (const UA_NodeAttributes*)&attr,
  838. &UA_TYPES[UA_TYPES_DATATYPEATTRIBUTES],
  839. nodeContext, outNewNodeId);
  840. }
  841. UA_StatusCode UA_EXPORT
  842. UA_Server_addDataSourceVariableNode(UA_Server *server,
  843. const UA_NodeId requestedNewNodeId,
  844. const UA_NodeId parentNodeId,
  845. const UA_NodeId referenceTypeId,
  846. const UA_QualifiedName browseName,
  847. const UA_NodeId typeDefinition,
  848. const UA_VariableAttributes attr,
  849. const UA_DataSource dataSource,
  850. void *nodeContext, UA_NodeId *outNewNodeId);
  851. UA_StatusCode UA_EXPORT
  852. UA_Server_addMethodNodeEx(UA_Server *server, const UA_NodeId requestedNewNodeId,
  853. const UA_NodeId parentNodeId,
  854. const UA_NodeId referenceTypeId,
  855. const UA_QualifiedName browseName,
  856. const UA_MethodAttributes attr, UA_MethodCallback method,
  857. size_t inputArgumentsSize, const UA_Argument *inputArguments,
  858. const UA_NodeId inputArgumentsRequestedNewNodeId,
  859. UA_NodeId *inputArgumentsOutNewNodeId,
  860. size_t outputArgumentsSize, const UA_Argument *outputArguments,
  861. const UA_NodeId outputArgumentsRequestedNewNodeId,
  862. UA_NodeId *outputArgumentsOutNewNodeId,
  863. void *nodeContext, UA_NodeId *outNewNodeId);
  864. static UA_INLINE UA_StatusCode
  865. UA_Server_addMethodNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  866. const UA_NodeId parentNodeId, const UA_NodeId referenceTypeId,
  867. const UA_QualifiedName browseName, const UA_MethodAttributes attr,
  868. UA_MethodCallback method,
  869. size_t inputArgumentsSize, const UA_Argument *inputArguments,
  870. size_t outputArgumentsSize, const UA_Argument *outputArguments,
  871. void *nodeContext, UA_NodeId *outNewNodeId) {
  872. return UA_Server_addMethodNodeEx(server, requestedNewNodeId, parentNodeId,
  873. referenceTypeId, browseName, attr, method,
  874. inputArgumentsSize, inputArguments, UA_NODEID_NULL, NULL,
  875. outputArgumentsSize, outputArguments, UA_NODEID_NULL, NULL,
  876. nodeContext, outNewNodeId);
  877. }
  878. /**
  879. * The method pair UA_Server_addNode_begin and _finish splits the AddNodes
  880. * service in two parts. This is useful if the node shall be modified before
  881. * finish the instantiation. For example to add children with specific NodeIds.
  882. * Otherwise, mandatory children (e.g. of an ObjectType) are added with
  883. * pseudo-random unique NodeIds. Existing children are detected during the
  884. * _finish part via their matching BrowseName.
  885. *
  886. * The _begin method:
  887. * - prepares the node and adds it to the nodestore
  888. * - copies some unassigned attributes from the TypeDefinition node internally
  889. * - adds the references to the parent (and the TypeDefinition if applicable)
  890. * - performs type-checking of variables.
  891. *
  892. * You can add an object node without a parent if you set the parentNodeId and
  893. * referenceTypeId to UA_NODE_ID_NULL. Then you need to add the parent reference
  894. * and hasTypeDef reference yourself before calling the _finish method.
  895. * Not that this is only allowed for object nodes.
  896. *
  897. * The _finish method:
  898. * - copies mandatory children
  899. * - calls the node constructor(s) at the end
  900. * - may remove the node if it encounters an error.
  901. *
  902. * The special UA_Server_addMethodNode_finish method needs to be used for
  903. * method nodes, since there you need to explicitly specifiy the input
  904. * and output arguments which are added in the finish step (if not yet already there)
  905. **/
  906. /* The ``attr`` argument must have a type according to the NodeClass.
  907. * ``VariableAttributes`` for variables, ``ObjectAttributes`` for objects, and
  908. * so on. Missing attributes are taken from the TypeDefinition node if
  909. * applicable. */
  910. UA_StatusCode UA_EXPORT
  911. UA_Server_addNode_begin(UA_Server *server, const UA_NodeClass nodeClass,
  912. const UA_NodeId requestedNewNodeId,
  913. const UA_NodeId parentNodeId,
  914. const UA_NodeId referenceTypeId,
  915. const UA_QualifiedName browseName,
  916. const UA_NodeId typeDefinition,
  917. const void *attr, const UA_DataType *attributeType,
  918. void *nodeContext, UA_NodeId *outNewNodeId);
  919. UA_StatusCode UA_EXPORT
  920. UA_Server_addNode_finish(UA_Server *server, const UA_NodeId nodeId);
  921. UA_StatusCode UA_EXPORT
  922. UA_Server_addMethodNode_finish(UA_Server *server, const UA_NodeId nodeId,
  923. UA_MethodCallback method,
  924. size_t inputArgumentsSize, const UA_Argument* inputArguments,
  925. size_t outputArgumentsSize, const UA_Argument* outputArguments);
  926. /* Deletes a node and optionally all references leading to the node. */
  927. UA_StatusCode UA_EXPORT
  928. UA_Server_deleteNode(UA_Server *server, const UA_NodeId nodeId,
  929. UA_Boolean deleteReferences);
  930. /**
  931. * Reference Management
  932. * -------------------- */
  933. UA_StatusCode UA_EXPORT
  934. UA_Server_addReference(UA_Server *server, const UA_NodeId sourceId,
  935. const UA_NodeId refTypeId,
  936. const UA_ExpandedNodeId targetId, UA_Boolean isForward);
  937. UA_StatusCode UA_EXPORT
  938. UA_Server_deleteReference(UA_Server *server, const UA_NodeId sourceNodeId,
  939. const UA_NodeId referenceTypeId, UA_Boolean isForward,
  940. const UA_ExpandedNodeId targetNodeId,
  941. UA_Boolean deleteBidirectional);
  942. /**
  943. * Utility Functions
  944. * ----------------- */
  945. /* Add a new namespace to the server. Returns the index of the new namespace */
  946. UA_UInt16 UA_EXPORT UA_Server_addNamespace(UA_Server *server, const char* name);
  947. /**
  948. * Deprecated Server API
  949. * ---------------------
  950. * This file contains outdated API definitions that are kept for backwards
  951. * compatibility. Please switch to the new API, as the following definitions
  952. * will be removed eventually.
  953. *
  954. * UA_Job API
  955. * ^^^^^^^^^^
  956. * UA_Job was replaced since it unnecessarily exposed server internals to the
  957. * end-user. Please use plain UA_ServerCallbacks instead. The following UA_Job
  958. * definition contains just the fraction of the original struct that was useful
  959. * to end-users. */
  960. typedef enum {
  961. UA_JOBTYPE_METHODCALL
  962. } UA_JobType;
  963. typedef struct {
  964. UA_JobType type;
  965. union {
  966. struct {
  967. void *data;
  968. UA_ServerCallback method;
  969. } methodCall;
  970. } job;
  971. } UA_Job;
  972. UA_DEPRECATED static UA_INLINE UA_StatusCode
  973. UA_Server_addRepeatedJob(UA_Server *server, UA_Job job,
  974. UA_UInt32 interval, UA_Guid *jobId) {
  975. return UA_Server_addRepeatedCallback(server, job.job.methodCall.method,
  976. job.job.methodCall.data, interval,
  977. (UA_UInt64*)(uintptr_t)jobId);
  978. }
  979. UA_DEPRECATED static UA_INLINE UA_StatusCode
  980. UA_Server_removeRepeatedJob(UA_Server *server, UA_Guid jobId) {
  981. return UA_Server_removeRepeatedCallback(server,
  982. *(UA_UInt64*)(uintptr_t)&jobId);
  983. }
  984. #ifdef __cplusplus
  985. }
  986. #endif
  987. #endif /* UA_SERVER_H_ */