ua_server.h 46 KB

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