ua_server.h 30 KB

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