ua_server.h 30 KB

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