ua_server.h 36 KB

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