ua_server.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/.*/
  4. /*
  5. * Copyright (C) 2014 the contributors as stated in the AUTHORS file
  6. *
  7. * This file is part of open62541. open62541 is free software: you can
  8. * redistribute it and/or modify it under the terms of the GNU Lesser General
  9. * Public License, version 3 (as published by the Free Software Foundation) with
  10. * a static linking exception as stated in the LICENSE file provided with
  11. * open62541.
  12. *
  13. * open62541 is distributed in the hope that it will be useful, but WITHOUT ANY
  14. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  15. * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. */
  18. #ifndef UA_SERVER_H_
  19. #define UA_SERVER_H_
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. #include "ua_config.h"
  24. #include "ua_types.h"
  25. #include "ua_types_generated.h"
  26. #include "ua_types_generated_handling.h"
  27. #include "ua_nodeids.h"
  28. #include "ua_log.h"
  29. #include "ua_job.h"
  30. #include "ua_connection.h"
  31. /**
  32. * .. _server:
  33. *
  34. * Server
  35. * ======
  36. *
  37. * Network Layer
  38. * -------------
  39. * Interface to the binary network layers. The functions in the network layer
  40. * are never called in parallel but only sequentially from the server's main
  41. * loop. So the network layer does not need to be thread-safe. */
  42. struct UA_ServerNetworkLayer;
  43. typedef struct UA_ServerNetworkLayer UA_ServerNetworkLayer;
  44. struct UA_ServerNetworkLayer {
  45. void *handle; // pointer to internal data
  46. UA_String discoveryUrl;
  47. /* Starts listening on the the networklayer.
  48. *
  49. * @param nl The network layer
  50. * @param logger The logger
  51. * @return Returns UA_STATUSCODE_GOOD or an error code. */
  52. UA_StatusCode (*start)(UA_ServerNetworkLayer *nl, UA_Logger logger);
  53. /* Gets called from the main server loop and returns the jobs (accumulated
  54. * messages and close events) for dispatch.
  55. *
  56. * @param nl The network layer
  57. * @param jobs When the returned integer is >0, *jobs points to an array of
  58. * UA_Job of the returned size.
  59. * @param timeout The timeout during which an event must arrive in
  60. * microseconds
  61. * @return The size of the jobs array. If the result is negative,
  62. * an error has occurred. */
  63. size_t (*getJobs)(UA_ServerNetworkLayer *nl, UA_Job **jobs, UA_UInt16 timeout);
  64. /* Closes the network connection and returns all the jobs that need to be
  65. * finished before the network layer can be safely deleted.
  66. *
  67. * @param nl The network layer
  68. * @param jobs When the returned integer is >0, jobs points to an array of
  69. * UA_Job of the returned size.
  70. * @return The size of the jobs array. If the result is negative,
  71. * an error has occurred. */
  72. size_t (*stop)(UA_ServerNetworkLayer *nl, UA_Job **jobs);
  73. /** Deletes the network content. Call only after stopping. */
  74. void (*deleteMembers)(UA_ServerNetworkLayer *nl);
  75. };
  76. /**
  77. * Server Configuration
  78. * --------------------
  79. * The following structure is passed to a new server for configuration. */
  80. typedef struct {
  81. UA_String username;
  82. UA_String password;
  83. } UA_UsernamePasswordLogin;
  84. typedef struct {
  85. UA_UInt32 min;
  86. UA_UInt32 max;
  87. } UA_UInt32Range;
  88. typedef struct {
  89. UA_Double min;
  90. UA_Double max;
  91. } UA_DoubleRange;
  92. typedef struct {
  93. UA_UInt16 nThreads; /* only if multithreading is enabled */
  94. UA_Logger logger;
  95. /* Server Description */
  96. UA_BuildInfo buildInfo;
  97. UA_ApplicationDescription applicationDescription;
  98. UA_ByteString serverCertificate;
  99. /* Networking */
  100. size_t networkLayersSize;
  101. UA_ServerNetworkLayer *networkLayers;
  102. /* Login */
  103. UA_Boolean enableAnonymousLogin;
  104. UA_Boolean enableUsernamePasswordLogin;
  105. size_t usernamePasswordLoginsSize;
  106. UA_UsernamePasswordLogin* usernamePasswordLogins;
  107. /* Limits for SecureChannels */
  108. UA_UInt16 maxSecureChannels;
  109. UA_UInt32 maxSecurityTokenLifetime; /* in ms */
  110. /* Limits for Sessions */
  111. UA_UInt16 maxSessions;
  112. UA_Double maxSessionTimeout; /* in ms */
  113. /* Limits for Subscriptions */
  114. UA_DoubleRange publishingIntervalLimits;
  115. UA_UInt32Range lifeTimeCountLimits;
  116. UA_UInt32Range keepAliveCountLimits;
  117. UA_UInt32 maxNotificationsPerPublish;
  118. UA_UInt32 maxRetransmissionQueueSize; /* 0 -> unlimited size */
  119. /* Limits for MonitoredItems */
  120. UA_DoubleRange samplingIntervalLimits;
  121. UA_UInt32Range queueSizeLimits; /* Negotiated with the client */
  122. } UA_ServerConfig;
  123. /* Add a new namespace to the server. Returns the index of the new namespace */
  124. UA_UInt16 UA_EXPORT UA_Server_addNamespace(UA_Server *server, const char* name);
  125. /**
  126. * Server Lifecycle
  127. * ---------------- */
  128. UA_Server UA_EXPORT * UA_Server_new(const UA_ServerConfig config);
  129. void UA_EXPORT UA_Server_delete(UA_Server *server);
  130. /* Runs the main loop of the server. In each iteration, this calls into the
  131. * networklayers to see if jobs have arrived and checks if repeated jobs need to
  132. * be triggered.
  133. *
  134. * @param server The server object.
  135. * @param running The loop is run as long as *running is true.
  136. * Otherwise, the server shuts down.
  137. * @return Returns the statuscode of the UA_Server_run_shutdown method */
  138. UA_StatusCode UA_EXPORT
  139. UA_Server_run(UA_Server *server, volatile UA_Boolean *running);
  140. /* The prologue part of UA_Server_run (no need to use if you call
  141. * UA_Server_run) */
  142. UA_StatusCode UA_EXPORT UA_Server_run_startup(UA_Server *server);
  143. /* Executes a single iteration of the server's main loop.
  144. *
  145. * @param server The server object.
  146. * @param waitInternal Should we wait for messages in the networklayer?
  147. * Otherwise, the timouts for the networklayers are set to zero.
  148. * The default max wait time is 50millisec.
  149. * @return Returns how long we can wait until the next scheduled
  150. * job (in millisec) */
  151. UA_UInt16 UA_EXPORT
  152. UA_Server_run_iterate(UA_Server *server, UA_Boolean waitInternal);
  153. /* The epilogue part of UA_Server_run (no need to use if you call
  154. * UA_Server_run) */
  155. UA_StatusCode UA_EXPORT UA_Server_run_shutdown(UA_Server *server);
  156. /**
  157. * Repeated jobs
  158. * ------------- */
  159. /* Add a job for cyclic repetition to the server.
  160. *
  161. * @param server The server object.
  162. * @param job The job that shall be added.
  163. * @param interval The job shall be repeatedly executed with the given interval
  164. * (in ms). The interval must be larger than 5ms. The first execution
  165. * occurs at now() + interval at the latest.
  166. * @param jobId Set to the guid of the repeated job. This can be used to cancel
  167. * the job later on. If the pointer is null, the guid is not set.
  168. * @return Upon success, UA_STATUSCODE_GOOD is returned.
  169. * An error code otherwise. */
  170. UA_StatusCode UA_EXPORT
  171. UA_Server_addRepeatedJob(UA_Server *server, UA_Job job,
  172. UA_UInt32 interval, UA_Guid *jobId);
  173. /* Remove repeated job.
  174. *
  175. * @param server The server object.
  176. * @param jobId The id of the job that shall be removed.
  177. * @return Upon sucess, UA_STATUSCODE_GOOD is returned.
  178. * An error code otherwise. */
  179. UA_StatusCode UA_EXPORT
  180. UA_Server_removeRepeatedJob(UA_Server *server, UA_Guid jobId);
  181. /**
  182. * Reading and Writing Node Attributes
  183. * -----------------------------------
  184. * The functions for reading and writing node attributes call the regular read
  185. * and write service in the background that are also used over the network.
  186. *
  187. * The following attributes cannot be read, since the local "admin" user always
  188. * has full rights.
  189. *
  190. * - UserWriteMask
  191. * - UserAccessLevel
  192. * - UserExecutable */
  193. /* Read an attribute of a node. The specialized functions below provide a more
  194. * concise syntax.
  195. *
  196. * @param server The server object.
  197. * @param item ReadValueIds contain the NodeId of the target node, the id of the
  198. * attribute to read and (optionally) an index range to read parts
  199. * of an array only. See the section on NumericRange for the format
  200. * used for array ranges.
  201. * @param timestamps Which timestamps to return for the attribute.
  202. * @return Returns a DataValue that contains either an error code, or a variant
  203. * with the attribute value and the timestamps. */
  204. UA_DataValue UA_EXPORT
  205. UA_Server_read(UA_Server *server, const UA_ReadValueId *item,
  206. UA_TimestampsToReturn timestamps);
  207. /* Don't use this function. There are typed versions for every supported
  208. * attribute. */
  209. UA_StatusCode UA_EXPORT
  210. __UA_Server_read(UA_Server *server, const UA_NodeId *nodeId,
  211. UA_AttributeId attributeId, void *v);
  212. static UA_INLINE UA_StatusCode
  213. UA_Server_readNodeId(UA_Server *server, const UA_NodeId nodeId,
  214. UA_NodeId *outNodeId) {
  215. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_NODEID, outNodeId);
  216. }
  217. static UA_INLINE UA_StatusCode
  218. UA_Server_readNodeClass(UA_Server *server, const UA_NodeId nodeId,
  219. UA_NodeClass *outNodeClass) {
  220. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_NODECLASS,
  221. outNodeClass);
  222. }
  223. static UA_INLINE UA_StatusCode
  224. UA_Server_readBrowseName(UA_Server *server, const UA_NodeId nodeId,
  225. UA_QualifiedName *outBrowseName) {
  226. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_BROWSENAME,
  227. outBrowseName);
  228. }
  229. static UA_INLINE UA_StatusCode
  230. UA_Server_readDisplayName(UA_Server *server, const UA_NodeId nodeId,
  231. UA_LocalizedText *outDisplayName) {
  232. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_DISPLAYNAME,
  233. outDisplayName);
  234. }
  235. static UA_INLINE UA_StatusCode
  236. UA_Server_readDescription(UA_Server *server, const UA_NodeId nodeId,
  237. UA_LocalizedText *outDescription) {
  238. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_DESCRIPTION,
  239. outDescription);
  240. }
  241. static UA_INLINE UA_StatusCode
  242. UA_Server_readWriteMask(UA_Server *server, const UA_NodeId nodeId,
  243. UA_UInt32 *outWriteMask) {
  244. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_WRITEMASK,
  245. outWriteMask);
  246. }
  247. static UA_INLINE UA_StatusCode
  248. UA_Server_readIsAbstract(UA_Server *server, const UA_NodeId nodeId,
  249. UA_Boolean *outIsAbstract) {
  250. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_ISABSTRACT,
  251. outIsAbstract);
  252. }
  253. static UA_INLINE UA_StatusCode
  254. UA_Server_readSymmetric(UA_Server *server, const UA_NodeId nodeId,
  255. UA_Boolean *outSymmetric) {
  256. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_SYMMETRIC,
  257. outSymmetric);
  258. }
  259. static UA_INLINE UA_StatusCode
  260. UA_Server_readInverseName(UA_Server *server, const UA_NodeId nodeId,
  261. UA_LocalizedText *outInverseName) {
  262. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_INVERSENAME,
  263. outInverseName);
  264. }
  265. static UA_INLINE UA_StatusCode
  266. UA_Server_readContainsNoLoop(UA_Server *server, const UA_NodeId nodeId,
  267. UA_Boolean *outContainsNoLoops) {
  268. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_CONTAINSNOLOOPS,
  269. outContainsNoLoops);
  270. }
  271. static UA_INLINE UA_StatusCode
  272. UA_Server_readEventNotifier(UA_Server *server, const UA_NodeId nodeId,
  273. UA_Byte *outEventNotifier) {
  274. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_EVENTNOTIFIER,
  275. outEventNotifier);
  276. }
  277. static UA_INLINE UA_StatusCode
  278. UA_Server_readValue(UA_Server *server, const UA_NodeId nodeId,
  279. UA_Variant *outValue) {
  280. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_VALUE, outValue);
  281. }
  282. static UA_INLINE UA_StatusCode
  283. UA_Server_readDataType(UA_Server *server, const UA_NodeId nodeId,
  284. UA_NodeId *outDataType) {
  285. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_DATATYPE,
  286. outDataType);
  287. }
  288. static UA_INLINE UA_StatusCode
  289. UA_Server_readValueRank(UA_Server *server, const UA_NodeId nodeId,
  290. UA_Int32 *outValueRank) {
  291. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_VALUERANK,
  292. outValueRank);
  293. }
  294. /* Returns a variant with an int32 array */
  295. static UA_INLINE UA_StatusCode
  296. UA_Server_readArrayDimensions(UA_Server *server, const UA_NodeId nodeId,
  297. UA_Variant *outArrayDimensions) {
  298. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_ARRAYDIMENSIONS,
  299. outArrayDimensions);
  300. }
  301. static UA_INLINE UA_StatusCode
  302. UA_Server_readAccessLevel(UA_Server *server, const UA_NodeId nodeId,
  303. UA_Byte *outAccessLevel) {
  304. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_ACCESSLEVEL,
  305. outAccessLevel);
  306. }
  307. static UA_INLINE UA_StatusCode
  308. UA_Server_readMinimumSamplingInterval(UA_Server *server, const UA_NodeId nodeId,
  309. UA_Double *outMinimumSamplingInterval) {
  310. return __UA_Server_read(server, &nodeId,
  311. UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL,
  312. outMinimumSamplingInterval);
  313. }
  314. static UA_INLINE UA_StatusCode
  315. UA_Server_readHistorizing(UA_Server *server, const UA_NodeId nodeId,
  316. UA_Boolean *outHistorizing) {
  317. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_HISTORIZING,
  318. outHistorizing);
  319. }
  320. static UA_INLINE UA_StatusCode
  321. UA_Server_readExecutable(UA_Server *server, const UA_NodeId nodeId,
  322. UA_Boolean *outExecutable) {
  323. return __UA_Server_read(server, &nodeId, UA_ATTRIBUTEID_EXECUTABLE,
  324. outExecutable);
  325. }
  326. /**
  327. * The following node attributes cannot be changed once a node has been created:
  328. *
  329. * - NodeClass
  330. * - NodeId
  331. * - Symmetric
  332. * - ContainsNoLoop
  333. *
  334. * The following attributes cannot be written from the server, as they are
  335. * specific to the different users:
  336. *
  337. * - UserWriteMask
  338. * - UserAccessLevel
  339. * - UserExecutable
  340. *
  341. * Historizing is currently unsupported */
  342. /* Overwrite an attribute of a node. The specialized functions below provide a
  343. * more concise syntax.
  344. *
  345. * @param server The server object.
  346. * @param value WriteValues contain the NodeId of the target node, the id of the
  347. * attribute to overwritten, the actual value and (optionally) an
  348. * index range to replace parts of an array only. of an array only.
  349. * See the section on NumericRange for the format used for array
  350. * ranges.
  351. * @return Returns a status code. */
  352. UA_StatusCode UA_EXPORT
  353. UA_Server_write(UA_Server *server, const UA_WriteValue *value);
  354. /* Don't use this function. There are typed versions with no additional
  355. * overhead. */
  356. UA_StatusCode UA_EXPORT
  357. __UA_Server_write(UA_Server *server, const UA_NodeId *nodeId,
  358. const UA_AttributeId attributeId,
  359. const UA_DataType *attr_type, const void *attr);
  360. static UA_INLINE UA_StatusCode
  361. UA_Server_writeBrowseName(UA_Server *server, const UA_NodeId nodeId,
  362. const UA_QualifiedName browseName) {
  363. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_BROWSENAME,
  364. &UA_TYPES[UA_TYPES_QUALIFIEDNAME], &browseName);
  365. }
  366. static UA_INLINE UA_StatusCode
  367. UA_Server_writeDisplayName(UA_Server *server, const UA_NodeId nodeId,
  368. const UA_LocalizedText displayName) {
  369. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_DISPLAYNAME,
  370. &UA_TYPES[UA_TYPES_LOCALIZEDTEXT], &displayName);
  371. }
  372. static UA_INLINE UA_StatusCode
  373. UA_Server_writeDescription(UA_Server *server, const UA_NodeId nodeId,
  374. const UA_LocalizedText description) {
  375. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_DESCRIPTION,
  376. &UA_TYPES[UA_TYPES_LOCALIZEDTEXT], &description);
  377. }
  378. static UA_INLINE UA_StatusCode
  379. UA_Server_writeWriteMask(UA_Server *server, const UA_NodeId nodeId,
  380. const UA_UInt32 writeMask) {
  381. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_WRITEMASK,
  382. &UA_TYPES[UA_TYPES_UINT32], &writeMask);
  383. }
  384. static UA_INLINE UA_StatusCode
  385. UA_Server_writeIsAbstract(UA_Server *server, const UA_NodeId nodeId,
  386. const UA_Boolean isAbstract) {
  387. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_ISABSTRACT,
  388. &UA_TYPES[UA_TYPES_BOOLEAN], &isAbstract);
  389. }
  390. static UA_INLINE UA_StatusCode
  391. UA_Server_writeInverseName(UA_Server *server, const UA_NodeId nodeId,
  392. const UA_LocalizedText inverseName) {
  393. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_INVERSENAME,
  394. &UA_TYPES[UA_TYPES_LOCALIZEDTEXT], &inverseName);
  395. }
  396. static UA_INLINE UA_StatusCode
  397. UA_Server_writeEventNotifier(UA_Server *server, const UA_NodeId nodeId,
  398. const UA_Byte eventNotifier) {
  399. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_EVENTNOTIFIER,
  400. &UA_TYPES[UA_TYPES_BYTE], &eventNotifier);
  401. }
  402. static UA_INLINE UA_StatusCode
  403. UA_Server_writeValue(UA_Server *server, const UA_NodeId nodeId,
  404. const UA_Variant value) {
  405. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_VALUE,
  406. &UA_TYPES[UA_TYPES_VARIANT], &value);
  407. }
  408. static UA_INLINE UA_StatusCode
  409. UA_Server_writeDataType(UA_Server *server, const UA_NodeId nodeId,
  410. const UA_NodeId dataType) {
  411. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_DATATYPE,
  412. &UA_TYPES[UA_TYPES_NODEID], &dataType);
  413. }
  414. static UA_INLINE UA_StatusCode
  415. UA_Server_writeValueRank(UA_Server *server, const UA_NodeId nodeId,
  416. const UA_Int32 valueRank) {
  417. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_VALUERANK,
  418. &UA_TYPES[UA_TYPES_INT32], &valueRank);
  419. }
  420. static UA_INLINE UA_StatusCode
  421. UA_Server_writeArrayDimensions(UA_Server *server, const UA_NodeId nodeId,
  422. const UA_Variant arrayDimensions) {
  423. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_VALUE,
  424. &UA_TYPES[UA_TYPES_VARIANT], &arrayDimensions);
  425. }
  426. static UA_INLINE UA_StatusCode
  427. UA_Server_writeAccessLevel(UA_Server *server, const UA_NodeId nodeId,
  428. const UA_Byte accessLevel) {
  429. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_ACCESSLEVEL,
  430. &UA_TYPES[UA_TYPES_BYTE], &accessLevel);
  431. }
  432. static UA_INLINE UA_StatusCode
  433. UA_Server_writeMinimumSamplingInterval(UA_Server *server, const UA_NodeId nodeId,
  434. const UA_Double miniumSamplingInterval) {
  435. return __UA_Server_write(server, &nodeId,
  436. UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL,
  437. &UA_TYPES[UA_TYPES_DOUBLE],
  438. &miniumSamplingInterval);
  439. }
  440. static UA_INLINE UA_StatusCode
  441. UA_Server_writeExecutable(UA_Server *server, const UA_NodeId nodeId,
  442. const UA_Boolean executable) {
  443. return __UA_Server_write(server, &nodeId, UA_ATTRIBUTEID_EXECUTABLE,
  444. &UA_TYPES[UA_TYPES_BOOLEAN], &executable); }
  445. /**
  446. * Browsing
  447. * -------- */
  448. UA_BrowseResult UA_EXPORT
  449. UA_Server_browse(UA_Server *server, UA_UInt32 maxrefs,
  450. const UA_BrowseDescription *descr);
  451. UA_BrowseResult UA_EXPORT
  452. UA_Server_browseNext(UA_Server *server, UA_Boolean releaseContinuationPoint,
  453. const UA_ByteString *continuationPoint);
  454. #ifndef HAVE_NODEITER_CALLBACK
  455. #define HAVE_NODEITER_CALLBACK
  456. /* Iterate over all nodes referenced by parentNodeId by calling the callback
  457. * function for each child node (in ifdef because GCC/CLANG handle include order
  458. * differently) */
  459. typedef UA_StatusCode
  460. (*UA_NodeIteratorCallback)(UA_NodeId childId, UA_Boolean isInverse,
  461. UA_NodeId referenceTypeId, void *handle);
  462. #endif
  463. UA_StatusCode UA_EXPORT
  464. UA_Server_forEachChildNodeCall(UA_Server *server, UA_NodeId parentNodeId,
  465. UA_NodeIteratorCallback callback, void *handle);
  466. /**
  467. * Method Call
  468. * ----------- */
  469. #ifdef UA_ENABLE_METHODCALLS
  470. UA_CallMethodResult UA_EXPORT
  471. UA_Server_call(UA_Server *server, const UA_CallMethodRequest *request);
  472. #endif
  473. /**
  474. * Node Management
  475. * ---------------
  476. *
  477. * Callback Mechanisms
  478. * ^^^^^^^^^^^^^^^^^^^
  479. * There are four mechanisms for callbacks from the node-based information model
  480. * into userspace:
  481. *
  482. * - Datasources for variable nodes, where the variable content is managed
  483. * externally
  484. * - Value-callbacks for variable nodes, where userspace is notified when a
  485. * read/write occurs
  486. * - Object lifecycle management, where a user-defined constructor and
  487. * destructor is added to an object type
  488. * - Method callbacks, where a user-defined method is exposed in the information
  489. * model
  490. *
  491. * .. _datasource:
  492. *
  493. * Data Source Callback
  494. * ~~~~~~~~~~~~~~~~~~~~
  495. *
  496. * The server has a unique way of dealing with the content of variables. Instead
  497. * of storing a variant attached to the variable node, the node can point to a
  498. * function with a local data provider. Whenever the value attribute is read,
  499. * the function will be called and asked to provide a UA_DataValue return value
  500. * that contains the value content and additional timestamps.
  501. *
  502. * It is expected that the read callback is implemented. The write callback can
  503. * be set to a null-pointer. */
  504. typedef struct {
  505. void *handle; /* A custom pointer to reuse the same datasource functions for
  506. multiple sources */
  507. /* Copies the data from the source into the provided value.
  508. *
  509. * @param handle An optional pointer to user-defined data for the
  510. * specific data source
  511. * @param nodeid Id of the read node
  512. * @param includeSourceTimeStamp If true, then the datasource is expected to
  513. * set the source timestamp in the returned value
  514. * @param range If not null, then the datasource shall return only a
  515. * selection of the (nonscalar) data. Set
  516. * UA_STATUSCODE_BADINDEXRANGEINVALID in the value if this does not
  517. * apply.
  518. * @param value The (non-null) DataValue that is returned to the client. The
  519. * data source sets the read data, the result status and optionally a
  520. * sourcetimestamp.
  521. * @return Returns a status code for logging. Error codes intended for the
  522. * original caller are set in the value. If an error is returned,
  523. * then no releasing of the value is done. */
  524. UA_StatusCode (*read)(void *handle, const UA_NodeId nodeid,
  525. UA_Boolean includeSourceTimeStamp,
  526. const UA_NumericRange *range, UA_DataValue *value);
  527. /* Write into a data source. The write member of UA_DataSource can be empty
  528. * if the operation is unsupported.
  529. *
  530. * @param handle An optional pointer to user-defined data for the
  531. * specific data source
  532. * @param nodeid Id of the node being written to
  533. * @param data The data to be written into the data source
  534. * @param range An optional data range. If the data source is scalar or does
  535. * not support writing of ranges, then an error code is returned.
  536. * @return Returns a status code that is returned to the user
  537. */
  538. UA_StatusCode (*write)(void *handle, const UA_NodeId nodeid,
  539. const UA_Variant *data, const UA_NumericRange *range);
  540. } UA_DataSource;
  541. UA_StatusCode UA_EXPORT
  542. UA_Server_setVariableNode_dataSource(UA_Server *server, const UA_NodeId nodeId,
  543. const UA_DataSource dataSource);
  544. /**
  545. * .. _value-callback:
  546. *
  547. * Value Callback
  548. * ~~~~~~~~~~~~~~
  549. * Value Callbacks can be attached to variable and variable type nodes. If
  550. * not-null, they are called before reading and after writing respectively. */
  551. typedef struct {
  552. /* Pointer to user-provided data for the callback */
  553. void *handle;
  554. /* Called before the value attribute is read. It is possible to write into the
  555. * value attribute during onRead (using the write service). The node is
  556. * re-opened afterwards so that changes are considered in the following read
  557. * operation.
  558. *
  559. * @param handle Points to user-provided data for the callback.
  560. * @param nodeid The identifier of the node.
  561. * @param data Points to the current node value.
  562. * @param range Points to the numeric range the client wants to read from
  563. * (or NULL). */
  564. void (*onRead)(void *handle, const UA_NodeId nodeid,
  565. const UA_Variant *data, const UA_NumericRange *range);
  566. /* Called after writing the value attribute. The node is re-opened after
  567. * writing so that the new value is visible in the callback.
  568. *
  569. * @param handle Points to user-provided data for the callback.
  570. * @param nodeid The identifier of the node.
  571. * @param data Points to the current node value (after writing).
  572. * @param range Points to the numeric range the client wants to write to (or
  573. * NULL). */
  574. void (*onWrite)(void *handle, const UA_NodeId nodeid,
  575. const UA_Variant *data, const UA_NumericRange *range);
  576. } UA_ValueCallback;
  577. UA_StatusCode UA_EXPORT
  578. UA_Server_setVariableNode_valueCallback(UA_Server *server, const UA_NodeId nodeId,
  579. const UA_ValueCallback callback);
  580. /**
  581. * .. _object-lifecycle:
  582. *
  583. * Object Lifecycle Management Callbacks
  584. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  585. * Lifecycle management adds constructor and destructor callbacks to
  586. * object types. */
  587. typedef struct {
  588. /* Returns the instance handle that is then attached to the node */
  589. void * (*constructor)(const UA_NodeId instance);
  590. void (*destructor)(const UA_NodeId instance, void *instanceHandle);
  591. } UA_ObjectLifecycleManagement;
  592. UA_StatusCode UA_EXPORT
  593. UA_Server_setObjectTypeNode_lifecycleManagement(UA_Server *server,
  594. UA_NodeId nodeId,
  595. UA_ObjectLifecycleManagement olm);
  596. /**
  597. * Method Callbacks
  598. * ~~~~~~~~~~~~~~~~ */
  599. typedef UA_StatusCode
  600. (*UA_MethodCallback)(void *methodHandle, const UA_NodeId objectId,
  601. size_t inputSize, const UA_Variant *input,
  602. size_t outputSize, UA_Variant *output);
  603. #ifdef UA_ENABLE_METHODCALLS
  604. UA_StatusCode UA_EXPORT
  605. UA_Server_setMethodNode_callback(UA_Server *server, const UA_NodeId methodNodeId,
  606. UA_MethodCallback method, void *handle);
  607. #endif
  608. /**
  609. * .. _addnodes:
  610. *
  611. * Node Addition and Deletion
  612. * ^^^^^^^^^^^^^^^^^^^^^^^^^^
  613. *
  614. * When creating dynamic node instances at runtime, chances are that you will
  615. * not care about the specific NodeId of the new node, as long as you can
  616. * reference it later. When passing numeric NodeIds with a numeric identifier 0,
  617. * the stack evaluates this as "select a random unassigned numeric NodeId in
  618. * that namespace". To find out which NodeId was actually assigned to the new
  619. * node, you may pass a pointer `outNewNodeId`, which will (after a successfull
  620. * node insertion) contain the nodeId of the new node. You may also pass NULL
  621. * pointer if this result is not relevant. The namespace index for nodes you
  622. * create should never be 0, as that index is reserved for OPC UA's
  623. * self-description (namespace * 0).
  624. *
  625. * The methods for node addition and deletion take mostly const arguments that
  626. * are not modified. When creating a node, a deep copy of the node identifier,
  627. * node attributes, etc. is created. Therefore, it is possible to call for
  628. * example `UA_Server_addVariablenode` with a value attribute (a :ref:`variant`)
  629. * pointing to a memory location on the stack. If you need changes to a variable
  630. * value to manifest at a specific memory location, please use a
  631. * :ref:`datasource` or a :ref:`value-callback`. */
  632. /* The instantiation callback is used to track the addition of new nodes. It is
  633. * also called for all sub-nodes contained in an object or variable type node
  634. * that is instantiated. */
  635. typedef struct {
  636. UA_StatusCode (*method)(const UA_NodeId objectId,
  637. const UA_NodeId typeDefinitionId, void *handle);
  638. void *handle;
  639. } UA_InstantiationCallback;
  640. /* Don't use this function. There are typed versions as inline functions. */
  641. UA_StatusCode UA_EXPORT
  642. __UA_Server_addNode(UA_Server *server, const UA_NodeClass nodeClass,
  643. const UA_NodeId requestedNewNodeId,
  644. const UA_NodeId parentNodeId,
  645. const UA_NodeId referenceTypeId,
  646. const UA_QualifiedName browseName,
  647. const UA_NodeId typeDefinition,
  648. const UA_NodeAttributes *attr,
  649. const UA_DataType *attributeType,
  650. UA_InstantiationCallback *instantiationCallback,
  651. UA_NodeId *outNewNodeId);
  652. static UA_INLINE UA_StatusCode
  653. UA_Server_addVariableNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  654. const UA_NodeId parentNodeId,
  655. const UA_NodeId referenceTypeId,
  656. const UA_QualifiedName browseName,
  657. const UA_NodeId typeDefinition,
  658. const UA_VariableAttributes attr,
  659. UA_InstantiationCallback *instantiationCallback,
  660. UA_NodeId *outNewNodeId) {
  661. return __UA_Server_addNode(server, UA_NODECLASS_VARIABLE, requestedNewNodeId,
  662. parentNodeId, referenceTypeId, browseName,
  663. typeDefinition, (const UA_NodeAttributes*)&attr,
  664. &UA_TYPES[UA_TYPES_VARIABLEATTRIBUTES],
  665. instantiationCallback, outNewNodeId);
  666. }
  667. static UA_INLINE UA_StatusCode
  668. UA_Server_addVariableTypeNode(UA_Server *server,
  669. const UA_NodeId requestedNewNodeId,
  670. const UA_NodeId parentNodeId,
  671. const UA_NodeId referenceTypeId,
  672. const UA_QualifiedName browseName,
  673. const UA_NodeId typeDefinition,
  674. const UA_VariableTypeAttributes attr,
  675. UA_InstantiationCallback *instantiationCallback,
  676. UA_NodeId *outNewNodeId) {
  677. return __UA_Server_addNode(server, UA_NODECLASS_VARIABLETYPE,
  678. requestedNewNodeId, parentNodeId, referenceTypeId,
  679. browseName, typeDefinition,
  680. (const UA_NodeAttributes*)&attr,
  681. &UA_TYPES[UA_TYPES_VARIABLETYPEATTRIBUTES],
  682. instantiationCallback, outNewNodeId);
  683. }
  684. static UA_INLINE UA_StatusCode
  685. UA_Server_addObjectNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  686. const UA_NodeId parentNodeId,
  687. const UA_NodeId referenceTypeId,
  688. const UA_QualifiedName browseName,
  689. const UA_NodeId typeDefinition,
  690. const UA_ObjectAttributes attr,
  691. UA_InstantiationCallback *instantiationCallback,
  692. UA_NodeId *outNewNodeId) {
  693. return __UA_Server_addNode(server, UA_NODECLASS_OBJECT, requestedNewNodeId,
  694. parentNodeId, referenceTypeId, browseName,
  695. typeDefinition, (const UA_NodeAttributes*)&attr,
  696. &UA_TYPES[UA_TYPES_OBJECTATTRIBUTES],
  697. instantiationCallback, outNewNodeId);
  698. }
  699. static UA_INLINE UA_StatusCode
  700. UA_Server_addObjectTypeNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  701. const UA_NodeId parentNodeId,
  702. const UA_NodeId referenceTypeId,
  703. const UA_QualifiedName browseName,
  704. const UA_ObjectTypeAttributes attr,
  705. UA_InstantiationCallback *instantiationCallback,
  706. UA_NodeId *outNewNodeId) {
  707. return __UA_Server_addNode(server, UA_NODECLASS_OBJECTTYPE, requestedNewNodeId,
  708. parentNodeId, referenceTypeId, browseName,
  709. UA_NODEID_NULL, (const UA_NodeAttributes*)&attr,
  710. &UA_TYPES[UA_TYPES_OBJECTTYPEATTRIBUTES],
  711. instantiationCallback, outNewNodeId);
  712. }
  713. static UA_INLINE UA_StatusCode
  714. UA_Server_addViewNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  715. const UA_NodeId parentNodeId,
  716. const UA_NodeId referenceTypeId,
  717. const UA_QualifiedName browseName,
  718. const UA_ViewAttributes attr,
  719. UA_InstantiationCallback *instantiationCallback,
  720. UA_NodeId *outNewNodeId) {
  721. return __UA_Server_addNode(server, UA_NODECLASS_VIEW, requestedNewNodeId,
  722. parentNodeId, referenceTypeId, browseName,
  723. UA_NODEID_NULL, (const UA_NodeAttributes*)&attr,
  724. &UA_TYPES[UA_TYPES_VIEWATTRIBUTES],
  725. instantiationCallback, outNewNodeId);
  726. }
  727. static UA_INLINE UA_StatusCode
  728. UA_Server_addReferenceTypeNode(UA_Server *server,
  729. const UA_NodeId requestedNewNodeId,
  730. const UA_NodeId parentNodeId,
  731. const UA_NodeId referenceTypeId,
  732. const UA_QualifiedName browseName,
  733. const UA_ReferenceTypeAttributes attr,
  734. UA_InstantiationCallback *instantiationCallback,
  735. UA_NodeId *outNewNodeId) {
  736. return __UA_Server_addNode(server, UA_NODECLASS_REFERENCETYPE,
  737. requestedNewNodeId, parentNodeId, referenceTypeId,
  738. browseName, UA_NODEID_NULL,
  739. (const UA_NodeAttributes*)&attr,
  740. &UA_TYPES[UA_TYPES_REFERENCETYPEATTRIBUTES],
  741. instantiationCallback, outNewNodeId);
  742. }
  743. static UA_INLINE UA_StatusCode
  744. UA_Server_addDataTypeNode(UA_Server *server,
  745. const UA_NodeId requestedNewNodeId,
  746. const UA_NodeId parentNodeId,
  747. const UA_NodeId referenceTypeId,
  748. const UA_QualifiedName browseName,
  749. const UA_DataTypeAttributes attr,
  750. UA_InstantiationCallback *instantiationCallback,
  751. UA_NodeId *outNewNodeId) {
  752. return __UA_Server_addNode(server, UA_NODECLASS_DATATYPE, requestedNewNodeId,
  753. parentNodeId, referenceTypeId, browseName,
  754. UA_NODEID_NULL, (const UA_NodeAttributes*)&attr,
  755. &UA_TYPES[UA_TYPES_DATATYPEATTRIBUTES],
  756. instantiationCallback, outNewNodeId);
  757. }
  758. UA_StatusCode UA_EXPORT
  759. UA_Server_addDataSourceVariableNode(UA_Server *server,
  760. const UA_NodeId requestedNewNodeId,
  761. const UA_NodeId parentNodeId,
  762. const UA_NodeId referenceTypeId,
  763. const UA_QualifiedName browseName,
  764. const UA_NodeId typeDefinition,
  765. const UA_VariableAttributes attr,
  766. const UA_DataSource dataSource,
  767. UA_NodeId *outNewNodeId);
  768. #ifdef UA_ENABLE_METHODCALLS
  769. UA_StatusCode UA_EXPORT
  770. UA_Server_addMethodNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
  771. const UA_NodeId parentNodeId,
  772. const UA_NodeId referenceTypeId,
  773. const UA_QualifiedName browseName,
  774. const UA_MethodAttributes attr,
  775. UA_MethodCallback method, void *handle,
  776. size_t inputArgumentsSize,
  777. const UA_Argument* inputArguments,
  778. size_t outputArgumentsSize,
  779. const UA_Argument* outputArguments,
  780. UA_NodeId *outNewNodeId);
  781. #endif
  782. UA_StatusCode UA_EXPORT
  783. UA_Server_deleteNode(UA_Server *server, const UA_NodeId nodeId,
  784. UA_Boolean deleteReferences);
  785. /**
  786. * Reference Management
  787. * -------------------- */
  788. UA_StatusCode UA_EXPORT
  789. UA_Server_addReference(UA_Server *server, const UA_NodeId sourceId,
  790. const UA_NodeId refTypeId,
  791. const UA_ExpandedNodeId targetId, UA_Boolean isForward);
  792. UA_StatusCode UA_EXPORT
  793. UA_Server_deleteReference(UA_Server *server, const UA_NodeId sourceNodeId,
  794. const UA_NodeId referenceTypeId, UA_Boolean isForward,
  795. const UA_ExpandedNodeId targetNodeId,
  796. UA_Boolean deleteBidirectional);
  797. #ifdef __cplusplus
  798. }
  799. #endif
  800. #endif /* UA_SERVER_H_ */