ua_server.h 37 KB

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