ua_server.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  1. /*
  2. * Copyright (C) 2014 the contributors as stated in the AUTHORS file
  3. *
  4. * This file is part of open62541. open62541 is free software: you can
  5. * redistribute it and/or modify it under the terms of the GNU Lesser General
  6. * Public License, version 3 (as published by the Free Software Foundation) with
  7. * a static linking exception as stated in the LICENSE file provided with
  8. * open62541.
  9. *
  10. * open62541 is distributed in the hope that it will be useful, but WITHOUT ANY
  11. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  13. * details.
  14. */
  15. #ifndef UA_SERVER_H_
  16. #define UA_SERVER_H_
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #include "ua_config.h"
  21. #include "ua_types.h"
  22. #include "ua_types_generated.h"
  23. #include "ua_types_generated_handling.h"
  24. #include "ua_nodeids.h"
  25. #include "ua_log.h"
  26. #include "ua_job.h"
  27. #include "ua_connection.h"
  28. /**
  29. * Server
  30. * ======
  31. *
  32. * Network Layer
  33. * -------------
  34. * Interface to the binary network layers. The functions in the network layer
  35. * are never called in parallel but only sequentially from the server's main
  36. * loop. So the network layer does not need to be thread-safe. */
  37. struct UA_ServerNetworkLayer;
  38. typedef struct UA_ServerNetworkLayer UA_ServerNetworkLayer;
  39. struct UA_ServerNetworkLayer {
  40. void *handle; // pointer to internal data
  41. UA_String discoveryUrl;
  42. /* Starts listening on the the networklayer.
  43. *
  44. * @param nl The network layer
  45. * @param logger The logger
  46. * @return Returns UA_STATUSCODE_GOOD or an error code. */
  47. UA_StatusCode (*start)(UA_ServerNetworkLayer *nl, UA_Logger logger);
  48. /* Gets called from the main server loop and returns the jobs (accumulated
  49. * messages and close events) for dispatch.
  50. *
  51. * @param nl The network layer
  52. * @param jobs When the returned integer is >0, *jobs points to an array of
  53. * UA_Job of the returned size.
  54. * @param timeout The timeout during which an event must arrive in
  55. * microseconds
  56. * @return The size of the jobs array. If the result is negative,
  57. * an error has occurred. */
  58. size_t (*getJobs)(UA_ServerNetworkLayer *nl, UA_Job **jobs, UA_UInt16 timeout);
  59. /* Closes the network connection and returns all the jobs that need to be
  60. * finished before the network layer can be safely deleted.
  61. *
  62. * @param nl The network layer
  63. * @param jobs When the returned integer is >0, jobs points to an array of
  64. * UA_Job of the returned size.
  65. * @return The size of the jobs array. If the result is negative,
  66. * an error has occurred. */
  67. size_t (*stop)(UA_ServerNetworkLayer *nl, UA_Job **jobs);
  68. /** Deletes the network content. Call only after stopping. */
  69. void (*deleteMembers)(UA_ServerNetworkLayer *nl);
  70. };
  71. /**
  72. * Server Configuration
  73. * --------------------
  74. * The following structure is passed to a new server for configuration. */
  75. typedef struct {
  76. UA_String username;
  77. UA_String password;
  78. } UA_UsernamePasswordLogin;
  79. typedef struct {
  80. UA_UInt32 min;
  81. UA_UInt32 max;
  82. } UA_UInt32Range;
  83. typedef struct {
  84. UA_Double min;
  85. UA_Double max;
  86. } UA_DoubleRange;
  87. typedef struct {
  88. UA_UInt16 nThreads; /* only if multithreading is enabled */
  89. UA_Logger logger;
  90. /* Server Description */
  91. UA_BuildInfo buildInfo;
  92. UA_ApplicationDescription applicationDescription;
  93. UA_ByteString serverCertificate;
  94. /* Networking */
  95. size_t networkLayersSize;
  96. UA_ServerNetworkLayer *networkLayers;
  97. /* Login */
  98. UA_Boolean enableAnonymousLogin;
  99. UA_Boolean enableUsernamePasswordLogin;
  100. size_t usernamePasswordLoginsSize;
  101. UA_UsernamePasswordLogin* usernamePasswordLogins;
  102. /* Limits for SecureChannels */
  103. UA_UInt16 maxSecureChannels;
  104. UA_UInt32 maxSecurityTokenLifetime; /* in ms */
  105. /* Limits for Sessions */
  106. UA_UInt16 maxSessions;
  107. UA_Double maxSessionTimeout; /* in ms */
  108. /* Limits for Subscriptions */
  109. UA_DoubleRange publishingIntervalLimits;
  110. UA_UInt32Range lifeTimeCountLimits;
  111. UA_UInt32Range keepAliveCountLimits;
  112. UA_UInt32 maxNotificationsPerPublish;
  113. /* Limits for MonitoredItems */
  114. UA_DoubleRange samplingIntervalLimits;
  115. UA_UInt32Range queueSizeLimits;
  116. #ifdef UA_ENABLE_DISCOVERY
  117. /* Discovery */
  118. // timeout in seconds when to automatically remove a registered server from the list,
  119. // if it doesn't re-register within the given time frame. A value of 0 disables automatic removal.
  120. // Default is 60 Minutes (60*60). Must be bigger than 10 seconds, because cleanup is only triggered approximately
  121. // ervery 10 seconds.
  122. // The server will still be removed depending on the state of the semaphore file.
  123. UA_UInt32 discoveryCleanupTimeout;
  124. #endif
  125. } UA_ServerConfig;
  126. /* Add a new namespace to the server. Returns the index of the new namespace */
  127. UA_UInt16 UA_EXPORT UA_Server_addNamespace(UA_Server *server, const char* name);
  128. /**
  129. * Server Lifecycle
  130. * ---------------- */
  131. UA_Server UA_EXPORT * UA_Server_new(const UA_ServerConfig config);
  132. void UA_EXPORT UA_Server_delete(UA_Server *server);
  133. /* Runs the main loop of the server. In each iteration, this calls into the
  134. * networklayers to see if jobs have arrived and checks if repeated jobs need to
  135. * be triggered.
  136. *
  137. * @param server The server object.
  138. * @param running The loop is run as long as *running is true.
  139. * Otherwise, the server shuts down.
  140. * @return Returns the statuscode of the UA_Server_run_shutdown method */
  141. UA_StatusCode UA_EXPORT
  142. UA_Server_run(UA_Server *server, volatile UA_Boolean *running);
  143. /* The prologue part of UA_Server_run (no need to use if you call
  144. * UA_Server_run) */
  145. UA_StatusCode UA_EXPORT UA_Server_run_startup(UA_Server *server);
  146. /* Executes a single iteration of the server's main loop.
  147. *
  148. * @param server The server object.
  149. * @param waitInternal Should we wait for messages in the networklayer?
  150. * Otherwise, the timouts for the networklayers are set to zero.
  151. * The default max wait time is 50millisec.
  152. * @return Returns how long we can wait until the next scheduled
  153. * job (in millisec) */
  154. UA_UInt16 UA_EXPORT
  155. UA_Server_run_iterate(UA_Server *server, UA_Boolean waitInternal);
  156. /* The epilogue part of UA_Server_run (no need to use if you call
  157. * UA_Server_run) */
  158. UA_StatusCode UA_EXPORT UA_Server_run_shutdown(UA_Server *server);
  159. /**
  160. * Repeated jobs
  161. * ------------- */
  162. /* Add a job for cyclic repetition to the server.
  163. *
  164. * @param server The server object.
  165. * @param job The job that shall be added.
  166. * @param interval The job shall be repeatedly executed with the given interval
  167. * (in ms). The interval must be larger than 5ms. The first execution
  168. * occurs at now() + interval at the latest.
  169. * @param jobId Set to the guid of the repeated job. This can be used to cancel
  170. * the job later on. If the pointer is null, the guid is not set.
  171. * @return Upon success, UA_STATUSCODE_GOOD is returned.
  172. * An error code otherwise. */
  173. UA_StatusCode UA_EXPORT
  174. UA_Server_addRepeatedJob(UA_Server *server, UA_Job job,
  175. UA_UInt32 interval, UA_Guid *jobId);
  176. /* Remove repeated job. The entry will be removed asynchronously during the next
  177. * iteration of the server main loop.
  178. *
  179. * @param server The server object.
  180. * @param jobId The id of the job that shall be removed.
  181. * @return Upon sucess, UA_STATUSCODE_GOOD is returned.
  182. * An error code otherwise. */
  183. UA_StatusCode UA_EXPORT
  184. UA_Server_removeRepeatedJob(UA_Server *server, UA_Guid jobId);
  185. /**
  186. * Reading and Writing Node Attributes
  187. * -----------------------------------
  188. * The functions for reading and writing node attributes call the regular read
  189. * and write service in the background that are also used over the network.
  190. *
  191. * The following attributes cannot be read, since the local "admin" user always
  192. * has full rights.
  193. *
  194. * - UserWriteMask
  195. * - UserAccessLevel
  196. * - UserExecutable */
  197. /* Read an attribute of a node. The specialized functions below provide a more
  198. * concise syntax.
  199. *
  200. * @param server The server object.
  201. * @param item ReadValueIds contain the NodeId of the target node, the id of the
  202. * attribute to read and (optionally) an index range to read parts
  203. * of an array only. See the section on NumericRange for the format
  204. * used for array ranges.
  205. * @param timestamps Which timestamps to return for the attribute.
  206. * @return Returns a DataValue that contains either an error code, or a variant
  207. * with the attribute value and the timestamps. */
  208. UA_DataValue UA_EXPORT
  209. UA_Server_read(UA_Server *server, const UA_ReadValueId *item,
  210. UA_TimestampsToReturn timestamps);
  211. /* Don't use this function. There are typed versions for every supported
  212. * attribute. */
  213. UA_StatusCode UA_EXPORT
  214. __UA_Server_read(UA_Server *server, const UA_NodeId *nodeId,
  215. UA_AttributeId attributeId, void *v);
  216. static UA_INLINE UA_StatusCode
  217. UA_Server_readNodeId(UA_Server *server, const UA_NodeId nodeId,
  218. UA_NodeId *outNodeId) {
  219. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_NODEID, outNodeId);
  220. }
  221. static UA_INLINE UA_StatusCode
  222. UA_Server_readNodeClass(UA_Server *server, const UA_NodeId nodeId,
  223. UA_NodeClass *outNodeClass) {
  224. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_NODECLASS,
  225. outNodeClass);
  226. }
  227. static UA_INLINE UA_StatusCode
  228. UA_Server_readBrowseName(UA_Server *server, const UA_NodeId nodeId,
  229. UA_QualifiedName *outBrowseName) {
  230. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_BROWSENAME,
  231. outBrowseName);
  232. }
  233. static UA_INLINE UA_StatusCode
  234. UA_Server_readDisplayName(UA_Server *server, const UA_NodeId nodeId,
  235. UA_LocalizedText *outDisplayName) {
  236. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_DISPLAYNAME,
  237. outDisplayName);
  238. }
  239. static UA_INLINE UA_StatusCode
  240. UA_Server_readDescription(UA_Server *server, const UA_NodeId nodeId,
  241. UA_LocalizedText *outDescription) {
  242. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_DESCRIPTION,
  243. outDescription);
  244. }
  245. static UA_INLINE UA_StatusCode
  246. UA_Server_readWriteMask(UA_Server *server, const UA_NodeId nodeId,
  247. UA_UInt32 *outWriteMask) {
  248. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_WRITEMASK,
  249. outWriteMask);
  250. }
  251. static UA_INLINE UA_StatusCode
  252. UA_Server_readIsAbstract(UA_Server *server, const UA_NodeId nodeId,
  253. UA_Boolean *outIsAbstract) {
  254. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_ISABSTRACT,
  255. outIsAbstract);
  256. }
  257. static UA_INLINE UA_StatusCode
  258. UA_Server_readSymmetric(UA_Server *server, const UA_NodeId nodeId,
  259. UA_Boolean *outSymmetric) {
  260. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_SYMMETRIC,
  261. outSymmetric);
  262. }
  263. static UA_INLINE UA_StatusCode
  264. UA_Server_readInverseName(UA_Server *server, const UA_NodeId nodeId,
  265. UA_LocalizedText *outInverseName) {
  266. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_INVERSENAME,
  267. outInverseName);
  268. }
  269. static UA_INLINE UA_StatusCode
  270. UA_Server_readContainsNoLoop(UA_Server *server, const UA_NodeId nodeId,
  271. UA_Boolean *outContainsNoLoops) {
  272. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_CONTAINSNOLOOPS,
  273. outContainsNoLoops);
  274. }
  275. static UA_INLINE UA_StatusCode
  276. UA_Server_readEventNotifier(UA_Server *server, const UA_NodeId nodeId,
  277. UA_Byte *outEventNotifier) {
  278. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_EVENTNOTIFIER,
  279. outEventNotifier);
  280. }
  281. static UA_INLINE UA_StatusCode
  282. UA_Server_readValue(UA_Server *server, const UA_NodeId nodeId,
  283. UA_Variant *outValue) {
  284. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_VALUE, outValue);
  285. }
  286. static UA_INLINE UA_StatusCode
  287. UA_Server_readDataType(UA_Server *server, const UA_NodeId nodeId,
  288. UA_NodeId *outDataType) {
  289. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_DATATYPE,
  290. outDataType);
  291. }
  292. static UA_INLINE UA_StatusCode
  293. UA_Server_readValueRank(UA_Server *server, const UA_NodeId nodeId,
  294. UA_Int32 *outValueRank) {
  295. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_VALUERANK,
  296. outValueRank);
  297. }
  298. /* Returns a variant with an int32 array */
  299. static UA_INLINE UA_StatusCode
  300. UA_Server_readArrayDimensions(UA_Server *server, const UA_NodeId nodeId,
  301. UA_Variant *outArrayDimensions) {
  302. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_ARRAYDIMENSIONS,
  303. outArrayDimensions);
  304. }
  305. static UA_INLINE UA_StatusCode
  306. UA_Server_readAccessLevel(UA_Server *server, const UA_NodeId nodeId,
  307. UA_UInt32 *outAccessLevel) {
  308. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_ACCESSLEVEL,
  309. outAccessLevel);
  310. }
  311. static UA_INLINE UA_StatusCode
  312. UA_Server_readMinimumSamplingInterval(UA_Server *server, const UA_NodeId nodeId,
  313. UA_Double *outMinimumSamplingInterval) {
  314. return __UA_Server_read(server, &nodeId,
  315. UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL,
  316. outMinimumSamplingInterval);
  317. }
  318. static UA_INLINE UA_StatusCode
  319. UA_Server_readHistorizing(UA_Server *server, const UA_NodeId nodeId,
  320. UA_Boolean *outHistorizing) {
  321. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_HISTORIZING,
  322. outHistorizing);
  323. }
  324. static UA_INLINE UA_StatusCode
  325. UA_Server_readExecutable(UA_Server *server, const UA_NodeId nodeId,
  326. UA_Boolean *outExecutable) {
  327. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_EXECUTABLE,
  328. outExecutable);
  329. }
  330. /**
  331. * The following node attributes cannot be changed once a node has been created:
  332. *
  333. * - NodeClass
  334. * - NodeId
  335. * - Symmetric
  336. * - ContainsNoLoop
  337. *
  338. * The following attributes cannot be written from the server, as they are
  339. * specific to the different users:
  340. *
  341. * - UserWriteMask
  342. * - UserAccessLevel
  343. * - UserExecutable
  344. *
  345. * The following attributes are currently taken from the value variant and not
  346. * stored separately in the nodes:
  347. *
  348. * - DataType
  349. * - ValueRank
  350. * - ArrayDimensions
  351. *
  352. * Historizing is currently unsupported */
  353. /* Overwrite an attribute of a node. The specialized functions below provide a
  354. * more concise syntax.
  355. *
  356. * @param server The server object.
  357. * @param value WriteValues contain the NodeId of the target node, the id of the
  358. * attribute to overwritten, the actual value and (optionally) an
  359. * index range to replace parts of an array only. of an array only.
  360. * See the section on NumericRange for the format used for array
  361. * ranges.
  362. * @return Returns a status code. */
  363. UA_StatusCode UA_EXPORT
  364. UA_Server_write(UA_Server *server, const UA_WriteValue *value);
  365. /* Don't use this function. There are typed versions with no additional
  366. * overhead. */
  367. UA_StatusCode UA_EXPORT
  368. __UA_Server_write(UA_Server *server, const UA_NodeId *nodeId,
  369. const UA_AttributeId attributeId,
  370. const UA_DataType *type, const void *value);
  371. static UA_INLINE UA_StatusCode
  372. UA_Server_writeBrowseName(UA_Server *server, const UA_NodeId nodeId,
  373. const UA_QualifiedName browseName) {
  374. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_BROWSENAME,
  375. &UA_TYPES[UA_TYPES_QUALIFIEDNAME], &browseName);
  376. }
  377. static UA_INLINE UA_StatusCode
  378. UA_Server_writeDisplayName(UA_Server *server, const UA_NodeId nodeId,
  379. const UA_LocalizedText displayName) {
  380. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_DISPLAYNAME,
  381. &UA_TYPES[UA_TYPES_LOCALIZEDTEXT], &displayName);
  382. }
  383. static UA_INLINE UA_StatusCode
  384. UA_Server_writeDescription(UA_Server *server, const UA_NodeId nodeId,
  385. const UA_LocalizedText description) {
  386. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_DESCRIPTION,
  387. &UA_TYPES[UA_TYPES_LOCALIZEDTEXT], &description);
  388. }
  389. static UA_INLINE UA_StatusCode
  390. UA_Server_writeWriteMask(UA_Server *server, const UA_NodeId nodeId,
  391. const UA_UInt32 writeMask) {
  392. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_WRITEMASK,
  393. &UA_TYPES[UA_TYPES_UINT32], &writeMask);
  394. }
  395. static UA_INLINE UA_StatusCode
  396. UA_Server_writeIsAbstract(UA_Server *server, const UA_NodeId nodeId,
  397. const UA_Boolean isAbstract) {
  398. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_ISABSTRACT,
  399. &UA_TYPES[UA_TYPES_BOOLEAN], &isAbstract);
  400. }
  401. static UA_INLINE UA_StatusCode
  402. UA_Server_writeInverseName(UA_Server *server, const UA_NodeId nodeId,
  403. const UA_LocalizedText inverseName) {
  404. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_INVERSENAME,
  405. &UA_TYPES[UA_TYPES_LOCALIZEDTEXT], &inverseName);
  406. }
  407. static UA_INLINE UA_StatusCode
  408. UA_Server_writeEventNotifier(UA_Server *server, const UA_NodeId nodeId,
  409. const UA_Byte eventNotifier) {
  410. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_EVENTNOTIFIER,
  411. &UA_TYPES[UA_TYPES_BYTE], &eventNotifier);
  412. }
  413. static UA_INLINE UA_StatusCode
  414. UA_Server_writeValue(UA_Server *server, const UA_NodeId nodeId,
  415. const UA_Variant value) {
  416. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_VALUE,
  417. &UA_TYPES[UA_TYPES_VARIANT], &value);
  418. }
  419. static UA_INLINE UA_StatusCode
  420. UA_Server_writeAccessLevel(UA_Server *server, const UA_NodeId nodeId,
  421. const UA_UInt32 accessLevel) {
  422. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_ACCESSLEVEL,
  423. &UA_TYPES[UA_TYPES_UINT32], &accessLevel);
  424. }
  425. static UA_INLINE UA_StatusCode
  426. UA_Server_writeMinimumSamplingInterval(UA_Server *server, const UA_NodeId nodeId,
  427. const UA_Double miniumSamplingInterval) {
  428. return __UA_Server_write(server, &nodeId,
  429. UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL,
  430. &UA_TYPES[UA_TYPES_DOUBLE],
  431. &miniumSamplingInterval);
  432. }
  433. static UA_INLINE UA_StatusCode
  434. UA_Server_writeExecutable(UA_Server *server, const UA_NodeId nodeId,
  435. const UA_Boolean executable) {
  436. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_EXECUTABLE,
  437. &UA_TYPES[UA_TYPES_BOOLEAN], &executable); }
  438. /**
  439. * Browsing
  440. * -------- */
  441. UA_BrowseResult UA_EXPORT
  442. UA_Server_browse(UA_Server *server, UA_UInt32 maxrefs,
  443. const UA_BrowseDescription *descr);
  444. UA_BrowseResult UA_EXPORT
  445. UA_Server_browseNext(UA_Server *server, UA_Boolean releaseContinuationPoint,
  446. const UA_ByteString *continuationPoint);
  447. #ifndef HAVE_NODEITER_CALLBACK
  448. #define HAVE_NODEITER_CALLBACK
  449. /* Iterate over all nodes referenced by parentNodeId by calling the callback
  450. * function for each child node (in ifdef because GCC/CLANG handle include order
  451. * differently) */
  452. typedef UA_StatusCode
  453. (*UA_NodeIteratorCallback)(UA_NodeId childId, UA_Boolean isInverse,
  454. UA_NodeId referenceTypeId, void *handle);
  455. #endif
  456. UA_StatusCode UA_EXPORT
  457. UA_Server_forEachChildNodeCall(UA_Server *server, UA_NodeId parentNodeId,
  458. UA_NodeIteratorCallback callback, void *handle);
  459. #ifdef UA_ENABLE_DISCOVERY
  460. /**
  461. * Discovery
  462. * --------- */
  463. /*
  464. * Register the given server instance at the discovery server.
  465. * This should be called periodically.
  466. * The semaphoreFilePath is optional. If the given file is deleted,
  467. * the server will automatically be unregistered. This could be
  468. * for example a pid file which is deleted if the server crashes.
  469. *
  470. * When the server shuts down you need to call unregister.
  471. */
  472. UA_StatusCode UA_EXPORT
  473. UA_Server_register_discovery(UA_Server *server, const char* discoveryServerUrl, const char* semaphoreFilePath);
  474. /**
  475. * Unregister the given server instance from the discovery server.
  476. * This should only be called when the server is shutting down.
  477. */
  478. UA_StatusCode UA_EXPORT
  479. UA_Server_unregister_discovery(UA_Server *server, const char* discoveryServerUrl);
  480. #endif
  481. /**
  482. * Method Call
  483. * ----------- */
  484. #ifdef UA_ENABLE_METHODCALLS
  485. UA_CallMethodResult UA_EXPORT
  486. UA_Server_call(UA_Server *server, const UA_CallMethodRequest *request);
  487. #endif
  488. /**
  489. * Node Management
  490. * ---------------
  491. *
  492. * Callback Mechanisms
  493. * ^^^^^^^^^^^^^^^^^^^
  494. * There are four mechanisms for callbacks from the node-based information model
  495. * into userspace:
  496. *
  497. * - Datasources for variable nodes, where the variable content is managed
  498. * externally
  499. * - Value-callbacks for variable nodes, where userspace is notified when a
  500. * read/write occurs
  501. * - Object lifecycle management, where a user-defined constructor and
  502. * destructor is added to an object type
  503. * - Method callbacks, where a user-defined method is exposed in the information
  504. * model
  505. *
  506. * Data Source Callback
  507. * ~~~~~~~~~~~~~~~~~~~~
  508. *
  509. * The server has a unique way of dealing with the content of variables. Instead
  510. * of storing a variant attached to the variable node, the node can point to a
  511. * function with a local data provider. Whenever the value attribute is read,
  512. * the function will be called and asked to provide a UA_DataValue return value
  513. * that contains the value content and additional timestamps.
  514. *
  515. * It is expected that the read callback is implemented. The write callback can
  516. * be set to a null-pointer. */
  517. typedef struct {
  518. void *handle; /* A custom pointer to reuse the same datasource functions for
  519. multiple sources */
  520. /* Copies the data from the source into the provided value.
  521. *
  522. * @param handle An optional pointer to user-defined data for the
  523. * specific data source
  524. * @param nodeid Id of the read node
  525. * @param includeSourceTimeStamp If true, then the datasource is expected to
  526. * set the source timestamp in the returned value
  527. * @param range If not null, then the datasource shall return only a
  528. * selection of the (nonscalar) data. Set
  529. * UA_STATUSCODE_BADINDEXRANGEINVALID in the value if this does not
  530. * apply.
  531. * @param value The (non-null) DataValue that is returned to the client. The
  532. * data source sets the read data, the result status and optionally a
  533. * sourcetimestamp.
  534. * @return Returns a status code for logging. Error codes intended for the
  535. * original caller are set in the value. If an error is returned,
  536. * then no releasing of the value is done. */
  537. UA_StatusCode (*read)(void *handle, const UA_NodeId nodeid,
  538. UA_Boolean includeSourceTimeStamp,
  539. const UA_NumericRange *range, UA_DataValue *value);
  540. /* Write into a data source. The write member of UA_DataSource can be empty
  541. * if the operation is unsupported.
  542. *
  543. * @param handle An optional pointer to user-defined data for the
  544. * specific data source
  545. * @param nodeid Id of the node being written to
  546. * @param data The data to be written into the data source
  547. * @param range An optional data range. If the data source is scalar or does
  548. * not support writing of ranges, then an error code is returned.
  549. * @return Returns a status code that is returned to the user
  550. */
  551. UA_StatusCode (*write)(void *handle, const UA_NodeId nodeid,
  552. const UA_Variant *data, const UA_NumericRange *range);
  553. } UA_DataSource;
  554. UA_StatusCode UA_EXPORT
  555. UA_Server_setVariableNode_dataSource(UA_Server *server, const UA_NodeId nodeId,
  556. const UA_DataSource dataSource);
  557. /**
  558. * Value Callback
  559. * ~~~~~~~~~~~~~~
  560. * Value Callbacks can be attached to variable and variable type nodes. If
  561. * not-null, they are called before reading and after writing respectively. */
  562. typedef struct {
  563. void *handle;
  564. void (*onRead)(void *handle, const UA_NodeId nodeid,
  565. const UA_Variant *data, const UA_NumericRange *range);
  566. void (*onWrite)(void *handle, const UA_NodeId nodeid,
  567. const UA_Variant *data, const UA_NumericRange *range);
  568. } UA_ValueCallback;
  569. UA_StatusCode UA_EXPORT
  570. UA_Server_setVariableNode_valueCallback(UA_Server *server, const UA_NodeId nodeId,
  571. const UA_ValueCallback callback);
  572. /**
  573. * Object Lifecycle Management Callbacks
  574. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  575. * Lifecycle management adds constructor and destructor callbacks to
  576. * object types. */
  577. typedef struct {
  578. /* Returns the instance handle that is then attached to the node */
  579. void * (*constructor)(const UA_NodeId instance);
  580. void (*destructor)(const UA_NodeId instance, void *instanceHandle);
  581. } UA_ObjectLifecycleManagement;
  582. UA_StatusCode UA_EXPORT
  583. UA_Server_setObjectTypeNode_lifecycleManagement(UA_Server *server,
  584. UA_NodeId nodeId,
  585. UA_ObjectLifecycleManagement olm);
  586. /**
  587. * Method Callbacks
  588. * ~~~~~~~~~~~~~~~~ */
  589. typedef UA_StatusCode
  590. (*UA_MethodCallback)(void *methodHandle, const UA_NodeId objectId,
  591. size_t inputSize, const UA_Variant *input,
  592. size_t outputSize, UA_Variant *output);
  593. #ifdef UA_ENABLE_METHODCALLS
  594. UA_StatusCode UA_EXPORT
  595. UA_Server_setMethodNode_callback(UA_Server *server, const UA_NodeId methodNodeId,
  596. UA_MethodCallback method, void *handle);
  597. #endif
  598. /**
  599. * .. _addnodes:
  600. *
  601. * Node Addition and Deletion
  602. * ^^^^^^^^^^^^^^^^^^^^^^^^^^
  603. *
  604. * When creating dynamic node instances at runtime, chances are that you will
  605. * not care about the specific NodeId of the new node, as long as you can
  606. * reference it later. When passing numeric NodeIds with a numeric identifier 0,
  607. * the stack evaluates this as "select a randome free NodeId in that namespace".
  608. * To find out which NodeId was actually assigned to the new node, you may pass
  609. * a pointer `outNewNodeId`, which will (after a successfull node insertion)
  610. * contain the nodeId of the new node. You may also pass NULL pointer if this
  611. * result is not relevant. The namespace index for nodes you create should never
  612. * be 0, as that index is reserved for OPC UA's self-description (namespace 0). */
  613. /* The instantiation callback is used to track the addition of new nodes. It is
  614. * also called for all sub-nodes contained in an object or variable type node
  615. * that is instantiated. */
  616. typedef struct {
  617. UA_StatusCode (*method)(const UA_NodeId objectId,
  618. const UA_NodeId typeDefinitionId, void *handle);
  619. void *handle;
  620. } UA_InstantiationCallback;
  621. /* Don't use this function. There are typed versions as inline functions. */
  622. UA_StatusCode UA_EXPORT
  623. __UA_Server_addNode(UA_Server *server, const UA_NodeClass nodeClass,
  624. const UA_NodeId requestedNewNodeId,
  625. const UA_NodeId parentNodeId,
  626. const UA_NodeId referenceTypeId,
  627. const UA_QualifiedName browseName,
  628. const UA_NodeId typeDefinition,
  629. const UA_NodeAttributes *attr,
  630. const UA_DataType *attributeType,
  631. UA_InstantiationCallback *instantiationCallback,
  632. UA_NodeId *outNewNodeId);
  633. static UA_INLINE UA_StatusCode
  634. UA_Server_addVariableNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  635. const UA_NodeId parentNodeId,
  636. const UA_NodeId referenceTypeId,
  637. const UA_QualifiedName browseName,
  638. const UA_NodeId typeDefinition,
  639. const UA_VariableAttributes attr,
  640. UA_InstantiationCallback *instantiationCallback,
  641. UA_NodeId *outNewNodeId) {
  642. return __UA_Server_addNode(server, UA_NODECLASS_VARIABLE, requestedNewNodeId,
  643. parentNodeId, referenceTypeId, browseName,
  644. typeDefinition, (const UA_NodeAttributes*)&attr,
  645. &UA_TYPES[UA_TYPES_VARIABLEATTRIBUTES],
  646. instantiationCallback, outNewNodeId);
  647. }
  648. static UA_INLINE UA_StatusCode
  649. UA_Server_addVariableTypeNode(UA_Server *server,
  650. const UA_NodeId requestedNewNodeId,
  651. const UA_NodeId parentNodeId,
  652. const UA_NodeId referenceTypeId,
  653. const UA_QualifiedName browseName,
  654. const UA_VariableTypeAttributes attr,
  655. UA_InstantiationCallback *instantiationCallback,
  656. UA_NodeId *outNewNodeId) {
  657. return __UA_Server_addNode(server, UA_NODECLASS_VARIABLETYPE,
  658. requestedNewNodeId, parentNodeId, referenceTypeId,
  659. browseName, UA_NODEID_NULL,
  660. (const UA_NodeAttributes*)&attr,
  661. &UA_TYPES[UA_TYPES_VARIABLETYPEATTRIBUTES],
  662. instantiationCallback, outNewNodeId);
  663. }
  664. static UA_INLINE UA_StatusCode
  665. UA_Server_addObjectNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  666. const UA_NodeId parentNodeId,
  667. const UA_NodeId referenceTypeId,
  668. const UA_QualifiedName browseName,
  669. const UA_NodeId typeDefinition,
  670. const UA_ObjectAttributes attr,
  671. UA_InstantiationCallback *instantiationCallback,
  672. UA_NodeId *outNewNodeId) {
  673. return __UA_Server_addNode(server, UA_NODECLASS_OBJECT, requestedNewNodeId,
  674. parentNodeId, referenceTypeId, browseName,
  675. typeDefinition, (const UA_NodeAttributes*)&attr,
  676. &UA_TYPES[UA_TYPES_OBJECTATTRIBUTES],
  677. instantiationCallback, outNewNodeId);
  678. }
  679. static UA_INLINE UA_StatusCode
  680. UA_Server_addObjectTypeNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  681. const UA_NodeId parentNodeId,
  682. const UA_NodeId referenceTypeId,
  683. const UA_QualifiedName browseName,
  684. const UA_ObjectTypeAttributes attr,
  685. UA_InstantiationCallback *instantiationCallback,
  686. UA_NodeId *outNewNodeId) {
  687. return __UA_Server_addNode(server, UA_NODECLASS_OBJECTTYPE, requestedNewNodeId,
  688. parentNodeId, referenceTypeId, browseName,
  689. UA_NODEID_NULL, (const UA_NodeAttributes*)&attr,
  690. &UA_TYPES[UA_TYPES_OBJECTTYPEATTRIBUTES],
  691. instantiationCallback, outNewNodeId);
  692. }
  693. static UA_INLINE UA_StatusCode
  694. UA_Server_addViewNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  695. const UA_NodeId parentNodeId,
  696. const UA_NodeId referenceTypeId,
  697. const UA_QualifiedName browseName,
  698. const UA_ViewAttributes attr,
  699. UA_InstantiationCallback *instantiationCallback,
  700. UA_NodeId *outNewNodeId) {
  701. return __UA_Server_addNode(server, UA_NODECLASS_VIEW, requestedNewNodeId,
  702. parentNodeId, referenceTypeId, browseName,
  703. UA_NODEID_NULL, (const UA_NodeAttributes*)&attr,
  704. &UA_TYPES[UA_TYPES_VIEWATTRIBUTES],
  705. instantiationCallback, outNewNodeId);
  706. }
  707. static UA_INLINE UA_StatusCode
  708. UA_Server_addReferenceTypeNode(UA_Server *server,
  709. const UA_NodeId requestedNewNodeId,
  710. const UA_NodeId parentNodeId,
  711. const UA_NodeId referenceTypeId,
  712. const UA_QualifiedName browseName,
  713. const UA_ReferenceTypeAttributes attr,
  714. UA_InstantiationCallback *instantiationCallback,
  715. UA_NodeId *outNewNodeId) {
  716. return __UA_Server_addNode(server, UA_NODECLASS_REFERENCETYPE,
  717. requestedNewNodeId, parentNodeId, referenceTypeId,
  718. browseName, UA_NODEID_NULL,
  719. (const UA_NodeAttributes*)&attr,
  720. &UA_TYPES[UA_TYPES_REFERENCETYPEATTRIBUTES],
  721. instantiationCallback, outNewNodeId);
  722. }
  723. static UA_INLINE UA_StatusCode
  724. UA_Server_addDataTypeNode(UA_Server *server,
  725. const UA_NodeId requestedNewNodeId,
  726. const UA_NodeId parentNodeId,
  727. const UA_NodeId referenceTypeId,
  728. const UA_QualifiedName browseName,
  729. const UA_DataTypeAttributes attr,
  730. UA_InstantiationCallback *instantiationCallback,
  731. UA_NodeId *outNewNodeId) {
  732. return __UA_Server_addNode(server, UA_NODECLASS_DATATYPE, requestedNewNodeId,
  733. parentNodeId, referenceTypeId, browseName,
  734. UA_NODEID_NULL, (const UA_NodeAttributes*)&attr,
  735. &UA_TYPES[UA_TYPES_DATATYPEATTRIBUTES],
  736. instantiationCallback, outNewNodeId);
  737. }
  738. UA_StatusCode UA_EXPORT
  739. UA_Server_addDataSourceVariableNode(UA_Server *server,
  740. const UA_NodeId requestedNewNodeId,
  741. const UA_NodeId parentNodeId,
  742. const UA_NodeId referenceTypeId,
  743. const UA_QualifiedName browseName,
  744. const UA_NodeId typeDefinition,
  745. const UA_VariableAttributes attr,
  746. const UA_DataSource dataSource,
  747. UA_NodeId *outNewNodeId);
  748. #ifdef UA_ENABLE_METHODCALLS
  749. UA_StatusCode UA_EXPORT
  750. UA_Server_addMethodNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  751. const UA_NodeId parentNodeId,
  752. const UA_NodeId referenceTypeId,
  753. const UA_QualifiedName browseName,
  754. const UA_MethodAttributes attr,
  755. UA_MethodCallback method, void *handle,
  756. size_t inputArgumentsSize,
  757. const UA_Argument* inputArguments,
  758. size_t outputArgumentsSize,
  759. const UA_Argument* outputArguments,
  760. UA_NodeId *outNewNodeId);
  761. #endif
  762. UA_StatusCode UA_EXPORT
  763. UA_Server_deleteNode(UA_Server *server, const UA_NodeId nodeId,
  764. UA_Boolean deleteReferences);
  765. /**
  766. * Reference Management
  767. * -------------------- */
  768. UA_StatusCode UA_EXPORT
  769. UA_Server_addReference(UA_Server *server, const UA_NodeId sourceId,
  770. const UA_NodeId refTypeId,
  771. const UA_ExpandedNodeId targetId, UA_Boolean isForward);
  772. UA_StatusCode UA_EXPORT
  773. UA_Server_deleteReference(UA_Server *server, const UA_NodeId sourceNodeId,
  774. const UA_NodeId referenceTypeId, UA_Boolean isForward,
  775. const UA_ExpandedNodeId targetNodeId,
  776. UA_Boolean deleteBidirectional);
  777. #ifdef __cplusplus
  778. }
  779. #endif
  780. #endif /* UA_SERVER_H_ */