ua_server.h 30 KB

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