ua_server.h 31 KB

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