ua_server.h 37 KB

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