ua_server.h 30 KB

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