server_pubsub.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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) 2017-2018 Fraunhofer IOSB (Author: Andreas Ebner)
  6. */
  7. #ifndef UA_SERVER_PUBSUB_H
  8. #define UA_SERVER_PUBSUB_H
  9. #include <open62541/server.h>
  10. _UA_BEGIN_DECLS
  11. #ifdef UA_ENABLE_PUBSUB
  12. /**
  13. * .. _pubsub:
  14. *
  15. * Publish/Subscribe
  16. * =================
  17. *
  18. * Work in progress!
  19. * This part will be a new chapter later.
  20. *
  21. * TODO: write general PubSub introduction
  22. *
  23. * The Publish/Subscribe (PubSub) extension for OPC UA enables fast and efficient
  24. * 1:m communication. The PubSub extension is protocol agnostic and can be used
  25. * with broker based protocols like MQTT and AMQP or brokerless implementations like UDP-Multicasting.
  26. *
  27. * The PubSub API uses the following scheme:
  28. *
  29. * 1. Create a configuration for the needed PubSub element.
  30. *
  31. * 2. Call the add[element] function and pass in the configuration.
  32. *
  33. * 3. The add[element] function returns the unique nodeId of the internally created element.
  34. *
  35. * Take a look on the PubSub Tutorials for mor details about the API usage.::
  36. *
  37. * +-----------+
  38. * | UA_Server |
  39. * +-----------+
  40. * | |
  41. * | |
  42. * | |
  43. * | | +----------------------+
  44. * | +--> UA_PubSubConnection | UA_Server_addPubSubConnection
  45. * | +----------------------+
  46. * | | |
  47. * | | | +----------------+
  48. * | | +----> UA_WriterGroup | UA_PubSubConnection_addWriterGroup
  49. * | | +----------------+
  50. * | | |
  51. * | | | +------------------+
  52. * | | +----> UA_DataSetWriter | UA_WriterGroup_addDataSetWriter +-+
  53. * | | +------------------+ |
  54. * | | |
  55. * | | +----------------+ | r
  56. * | +---------> UA_ReaderGroup | | e
  57. * | +----------------+ | f
  58. * | |
  59. * | +---------------------------+ |
  60. * +-------> UA_PubSubPublishedDataSet | UA_Server_addPublishedDataSet <-+
  61. * +---------------------------+
  62. * |
  63. * | +-----------------+
  64. * +----> UA_DataSetField | UA_PublishedDataSet_addDataSetField
  65. * +-----------------+
  66. *
  67. * PubSub compile flags
  68. * --------------------
  69. *
  70. * **UA_ENABLE_PUBSUB**
  71. * Enable the experimental OPC UA PubSub support. The option will include the PubSub UDP multicast plugin. Disabled by default.
  72. * **UA_ENABLE_PUBSUB_DELTAFRAMES**
  73. * The PubSub messages differentiate between keyframe (all published values contained) and deltaframe (only changed values contained) messages.
  74. * Deltaframe messages creation consumes some additional ressources and can be disabled with this flag. Disabled by default.
  75. * Compile the human-readable name of the StatusCodes into the binary. Disabled by default.
  76. * **UA_ENABLE_PUBSUB_INFORMATIONMODEL**
  77. * Enable the information model representation of the PubSub configuration. For more details take a look at the following section `PubSub Information Model Representation`. Disabled by default.
  78. *
  79. * PubSub Information Model Representation
  80. * ---------------------------------------
  81. * .. _pubsub_informationmodel:
  82. *
  83. * The complete PubSub configuration is available inside the information model.
  84. * The entry point is the node 'PublishSubscribe, located under the Server node.
  85. * The standard defines for PubSub no new Service set. The configuration can optionally
  86. * done over methods inside the information model. The information model representation
  87. * of the current PubSub configuration is generated automatically. This feature
  88. * can enabled/disable by changing the UA_ENABLE_PUBSUB_INFORMATIONMODEL option.
  89. *
  90. * Connections
  91. * -----------
  92. * The PubSub connections are the abstraction between the concrete transport protocol
  93. * and the PubSub functionality. It is possible to create multiple connections with
  94. * different transport protocols at runtime.
  95. *
  96. * Take a look on the PubSub Tutorials for mor details about the API usage.
  97. */
  98. typedef enum {
  99. UA_PUBSUB_PUBLISHERID_NUMERIC,
  100. UA_PUBSUB_PUBLISHERID_STRING
  101. } UA_PublisherIdType;
  102. typedef struct {
  103. UA_String name;
  104. UA_Boolean enabled;
  105. UA_PublisherIdType publisherIdType;
  106. union { /* std: valid types UInt or String */
  107. UA_UInt32 numeric;
  108. UA_String string;
  109. } publisherId;
  110. UA_String transportProfileUri;
  111. UA_Variant address;
  112. size_t connectionPropertiesSize;
  113. UA_KeyValuePair *connectionProperties;
  114. UA_Variant connectionTransportSettings;
  115. } UA_PubSubConnectionConfig;
  116. UA_StatusCode UA_EXPORT
  117. UA_Server_addPubSubConnection(UA_Server *server,
  118. const UA_PubSubConnectionConfig *connectionConfig,
  119. UA_NodeId *connectionIdentifier);
  120. /* Returns a deep copy of the config */
  121. UA_StatusCode UA_EXPORT
  122. UA_Server_getPubSubConnectionConfig(UA_Server *server,
  123. const UA_NodeId connection,
  124. UA_PubSubConnectionConfig *config);
  125. /* Remove Connection, identified by the NodeId. Deletion of Connection
  126. * removes all contained WriterGroups and Writers. */
  127. UA_StatusCode UA_EXPORT
  128. UA_Server_removePubSubConnection(UA_Server *server, const UA_NodeId connection);
  129. /**
  130. * PublishedDataSets
  131. * -----------------
  132. * The PublishedDataSets (PDS) are containers for the published information. The
  133. * PDS contain the published variables and meta informations. The metadata is
  134. * commonly autogenerated or given as constant argument as part of the template
  135. * functions. The template functions are standard defined and intended for
  136. * configuration tools. You should normally create a empty PDS and call the
  137. * functions to add new fields. */
  138. /* The UA_PUBSUB_DATASET_PUBLISHEDITEMS has currently no additional members and
  139. * thus no dedicated config structure. */
  140. typedef enum {
  141. UA_PUBSUB_DATASET_PUBLISHEDITEMS,
  142. UA_PUBSUB_DATASET_PUBLISHEDEVENTS,
  143. UA_PUBSUB_DATASET_PUBLISHEDITEMS_TEMPLATE,
  144. UA_PUBSUB_DATASET_PUBLISHEDEVENTS_TEMPLATE,
  145. } UA_PublishedDataSetType;
  146. typedef struct {
  147. UA_DataSetMetaDataType metaData;
  148. size_t variablesToAddSize;
  149. UA_PublishedVariableDataType *variablesToAdd;
  150. } UA_PublishedDataItemsTemplateConfig;
  151. typedef struct {
  152. UA_NodeId eventNotfier;
  153. UA_ContentFilter filter;
  154. } UA_PublishedEventConfig;
  155. typedef struct {
  156. UA_DataSetMetaDataType metaData;
  157. UA_NodeId eventNotfier;
  158. size_t selectedFieldsSize;
  159. UA_SimpleAttributeOperand *selectedFields;
  160. UA_ContentFilter filter;
  161. } UA_PublishedEventTemplateConfig;
  162. /* Configuration structure for PublishedDataSet */
  163. typedef struct {
  164. UA_String name;
  165. UA_PublishedDataSetType publishedDataSetType;
  166. union {
  167. /* The UA_PUBSUB_DATASET_PUBLISHEDITEMS has currently no additional members
  168. * and thus no dedicated config structure.*/
  169. UA_PublishedDataItemsTemplateConfig itemsTemplate;
  170. UA_PublishedEventConfig event;
  171. UA_PublishedEventTemplateConfig eventTemplate;
  172. } config;
  173. } UA_PublishedDataSetConfig;
  174. void UA_EXPORT
  175. UA_PublishedDataSetConfig_deleteMembers(UA_PublishedDataSetConfig *pdsConfig);
  176. typedef struct {
  177. UA_StatusCode addResult;
  178. size_t fieldAddResultsSize;
  179. UA_StatusCode *fieldAddResults;
  180. UA_ConfigurationVersionDataType configurationVersion;
  181. } UA_AddPublishedDataSetResult;
  182. UA_AddPublishedDataSetResult UA_EXPORT
  183. UA_Server_addPublishedDataSet(UA_Server *server,
  184. const UA_PublishedDataSetConfig *publishedDataSetConfig,
  185. UA_NodeId *pdsIdentifier);
  186. /* Returns a deep copy of the config */
  187. UA_StatusCode UA_EXPORT
  188. UA_Server_getPublishedDataSetConfig(UA_Server *server, const UA_NodeId pds,
  189. UA_PublishedDataSetConfig *config);
  190. /* Remove PublishedDataSet, identified by the NodeId. Deletion of PDS removes
  191. * all contained and linked PDS Fields. Connected WriterGroups will be also
  192. * removed. */
  193. UA_StatusCode UA_EXPORT
  194. UA_Server_removePublishedDataSet(UA_Server *server, const UA_NodeId pds);
  195. /**
  196. * DataSetFields
  197. * -------------
  198. * The description of published variables is named DataSetField. Each
  199. * DataSetField contains the selection of one information model node. The
  200. * DataSetField has additional parameters for the publishing, sampling and error
  201. * handling process. */
  202. typedef struct{
  203. UA_ConfigurationVersionDataType configurationVersion;
  204. UA_String fieldNameAlias;
  205. UA_Boolean promotedField;
  206. UA_PublishedVariableDataType publishParameters;
  207. } UA_DataSetVariableConfig;
  208. typedef enum {
  209. UA_PUBSUB_DATASETFIELD_VARIABLE,
  210. UA_PUBSUB_DATASETFIELD_EVENT
  211. } UA_DataSetFieldType;
  212. typedef struct {
  213. UA_DataSetFieldType dataSetFieldType;
  214. union {
  215. UA_DataSetVariableConfig variable;
  216. //events need other config later
  217. } field;
  218. } UA_DataSetFieldConfig;
  219. void UA_EXPORT
  220. UA_DataSetFieldConfig_deleteMembers(UA_DataSetFieldConfig *dataSetFieldConfig);
  221. typedef struct {
  222. UA_StatusCode result;
  223. UA_ConfigurationVersionDataType configurationVersion;
  224. } UA_DataSetFieldResult;
  225. UA_DataSetFieldResult UA_EXPORT
  226. UA_Server_addDataSetField(UA_Server *server,
  227. const UA_NodeId publishedDataSet,
  228. const UA_DataSetFieldConfig *fieldConfig,
  229. UA_NodeId *fieldIdentifier);
  230. /* Returns a deep copy of the config */
  231. UA_StatusCode UA_EXPORT
  232. UA_Server_getDataSetFieldConfig(UA_Server *server, const UA_NodeId dsf,
  233. UA_DataSetFieldConfig *config);
  234. UA_DataSetFieldResult UA_EXPORT
  235. UA_Server_removeDataSetField(UA_Server *server, const UA_NodeId dsf);
  236. /**
  237. * WriterGroup
  238. * -----------
  239. * All WriterGroups are created within a PubSubConnection and automatically
  240. * deleted if the connection is removed. The WriterGroup is primary used as
  241. * container for :ref:`dsw` and network message settings. The WriterGroup can be
  242. * imagined as producer of the network messages. The creation of network
  243. * messages is controlled by parameters like the publish interval, which is e.g.
  244. * contained in the WriterGroup. */
  245. typedef enum {
  246. UA_PUBSUB_ENCODING_BINARY,
  247. UA_PUBSUB_ENCODING_JSON,
  248. UA_PUBSUB_ENCODING_UADP
  249. } UA_PubSubEncodingType;
  250. typedef struct {
  251. UA_String name;
  252. UA_Boolean enabled;
  253. UA_UInt16 writerGroupId;
  254. UA_Duration publishingInterval;
  255. UA_Double keepAliveTime;
  256. UA_Byte priority;
  257. UA_MessageSecurityMode securityMode;
  258. UA_ExtensionObject transportSettings;
  259. UA_ExtensionObject messageSettings;
  260. size_t groupPropertiesSize;
  261. UA_KeyValuePair *groupProperties;
  262. UA_PubSubEncodingType encodingMimeType;
  263. /* non std. config parameter. maximum count of embedded DataSetMessage in
  264. * one NetworkMessage */
  265. UA_UInt16 maxEncapsulatedDataSetMessageCount;
  266. } UA_WriterGroupConfig;
  267. void UA_EXPORT
  268. UA_WriterGroupConfig_deleteMembers(UA_WriterGroupConfig *writerGroupConfig);
  269. /* Add a new WriterGroup to an existing Connection */
  270. UA_StatusCode UA_EXPORT
  271. UA_Server_addWriterGroup(UA_Server *server, const UA_NodeId connection,
  272. const UA_WriterGroupConfig *writerGroupConfig,
  273. UA_NodeId *writerGroupIdentifier);
  274. /* Returns a deep copy of the config */
  275. UA_StatusCode UA_EXPORT
  276. UA_Server_getWriterGroupConfig(UA_Server *server, const UA_NodeId writerGroup,
  277. UA_WriterGroupConfig *config);
  278. UA_StatusCode UA_EXPORT
  279. UA_Server_updateWriterGroupConfig(UA_Server *server, UA_NodeId writerGroupIdentifier,
  280. const UA_WriterGroupConfig *config);
  281. UA_StatusCode UA_EXPORT
  282. UA_Server_removeWriterGroup(UA_Server *server, const UA_NodeId writerGroup);
  283. /**
  284. * .. _dsw:
  285. *
  286. * DataSetWriter
  287. * -------------
  288. * The DataSetWriters are the glue between the WriterGroups and the
  289. * PublishedDataSets. The DataSetWriter contain configuration parameters and
  290. * flags which influence the creation of DataSet messages. These messages are
  291. * encapsulated inside the network message. The DataSetWriter must be linked
  292. * with an existing PublishedDataSet and be contained within a WriterGroup. */
  293. typedef struct {
  294. UA_String name;
  295. UA_UInt16 dataSetWriterId;
  296. UA_DataSetFieldContentMask dataSetFieldContentMask;
  297. UA_UInt32 keyFrameCount;
  298. UA_ExtensionObject messageSettings;
  299. UA_String dataSetName;
  300. size_t dataSetWriterPropertiesSize;
  301. UA_KeyValuePair *dataSetWriterProperties;
  302. } UA_DataSetWriterConfig;
  303. void UA_EXPORT
  304. UA_DataSetWriterConfig_deleteMembers(UA_DataSetWriterConfig *pdsConfig);
  305. /* Add a new DataSetWriter to a existing WriterGroup. The DataSetWriter must be
  306. * coupled with a PublishedDataSet on creation.
  307. *
  308. * Part 14, 7.1.5.2.1 defines: The link between the PublishedDataSet and
  309. * DataSetWriter shall be created when an instance of the DataSetWriterType is
  310. * created. */
  311. UA_StatusCode UA_EXPORT
  312. UA_Server_addDataSetWriter(UA_Server *server,
  313. const UA_NodeId writerGroup, const UA_NodeId dataSet,
  314. const UA_DataSetWriterConfig *dataSetWriterConfig,
  315. UA_NodeId *writerIdentifier);
  316. /* Returns a deep copy of the config */
  317. UA_StatusCode UA_EXPORT
  318. UA_Server_getDataSetWriterConfig(UA_Server *server, const UA_NodeId dsw,
  319. UA_DataSetWriterConfig *config);
  320. UA_StatusCode UA_EXPORT
  321. UA_Server_removeDataSetWriter(UA_Server *server, const UA_NodeId dsw);
  322. #endif /* UA_ENABLE_PUBSUB */
  323. _UA_END_DECLS
  324. #endif /* UA_SERVER_PUBSUB_H */