ua_server.h 32 KB

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