ua_server_pubsub.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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 "ua_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. * PubSub Information Model Representation
  67. * -----------
  68. * The complete PubSub configuration is available inside the information model.
  69. * The entry point is the node 'PublishSubscribe, located under the Server node.
  70. * The standard defines for PubSub no new Service set. The configuration can optionally
  71. * done over methods inside the information model. The information model representation
  72. * of the current PubSub configuration is generated automatically. This feature
  73. * can enabled/disable by changing the UA_ENABLE_PUBSUB_INFORMATIONMODEL option.
  74. *
  75. * Connections
  76. * -----------
  77. * The PubSub connections are the abstraction between the concrete transport protocol
  78. * and the PubSub functionality. It is possible to create multiple connections with
  79. * different transport protocols at runtime.
  80. *
  81. * Take a look on the PubSub Tutorials for mor details about the API usage.
  82. */
  83. typedef struct {
  84. UA_String name;
  85. UA_Boolean enabled;
  86. union { /* std: valid types UInt or String */
  87. UA_UInt32 numeric;
  88. UA_String string;
  89. } publisherId;
  90. UA_String transportProfileUri;
  91. UA_Variant address;
  92. size_t connectionPropertiesSize;
  93. UA_KeyValuePair *connectionProperties;
  94. UA_Variant connectionTransportSettings;
  95. } UA_PubSubConnectionConfig;
  96. UA_StatusCode
  97. UA_Server_addPubSubConnection(UA_Server *server,
  98. const UA_PubSubConnectionConfig *connectionConfig,
  99. UA_NodeId *connectionIdentifier);
  100. /* Returns a deep copy of the config */
  101. UA_StatusCode
  102. UA_Server_getPubSubConnectionConfig(UA_Server *server,
  103. const UA_NodeId connection,
  104. UA_PubSubConnectionConfig *config);
  105. /* Remove Connection, identified by the NodeId. Deletion of Connection
  106. * removes all contained WriterGroups and Writers. */
  107. UA_StatusCode
  108. UA_Server_removePubSubConnection(UA_Server *server, const UA_NodeId connection);
  109. /**
  110. * PublishedDataSets
  111. * -----------------
  112. * The PublishedDataSets (PDS) are containers for the published information. The
  113. * PDS contain the published variables and meta informations. The metadata is
  114. * commonly autogenerated or given as constant argument as part of the template
  115. * functions. The template functions are standard defined and intended for
  116. * configuration tools. You should normally create a empty PDS and call the
  117. * functions to add new fields. */
  118. /* The UA_PUBSUB_DATASET_PUBLISHEDITEMS has currently no additional members and
  119. * thus no dedicated config structure. */
  120. typedef enum {
  121. UA_PUBSUB_DATASET_PUBLISHEDITEMS,
  122. UA_PUBSUB_DATASET_PUBLISHEDEVENTS,
  123. UA_PUBSUB_DATASET_PUBLISHEDITEMS_TEMPLATE,
  124. UA_PUBSUB_DATASET_PUBLISHEDEVENTS_TEMPLATE,
  125. } UA_PublishedDataSetType;
  126. typedef struct {
  127. UA_DataSetMetaDataType metaData;
  128. size_t variablesToAddSize;
  129. UA_PublishedVariableDataType *variablesToAdd;
  130. } UA_PublishedDataItemsTemplateConfig;
  131. typedef struct {
  132. UA_NodeId eventNotfier;
  133. UA_ContentFilter filter;
  134. } UA_PublishedEventConfig;
  135. typedef struct {
  136. UA_DataSetMetaDataType metaData;
  137. UA_NodeId eventNotfier;
  138. size_t selectedFieldsSize;
  139. UA_SimpleAttributeOperand *selectedFields;
  140. UA_ContentFilter filter;
  141. } UA_PublishedEventTemplateConfig;
  142. /* Configuration structure for PublishedDataSet */
  143. typedef struct {
  144. UA_String name;
  145. UA_PublishedDataSetType publishedDataSetType;
  146. union {
  147. /* The UA_PUBSUB_DATASET_PUBLISHEDITEMS has currently no additional members
  148. * and thus no dedicated config structure.*/
  149. UA_PublishedDataItemsTemplateConfig itemsTemplate;
  150. UA_PublishedEventConfig event;
  151. UA_PublishedEventTemplateConfig eventTemplate;
  152. } config;
  153. } UA_PublishedDataSetConfig;
  154. void
  155. UA_PublishedDataSetConfig_deleteMembers(UA_PublishedDataSetConfig *pdsConfig);
  156. typedef struct {
  157. UA_StatusCode addResult;
  158. size_t fieldAddResultsSize;
  159. UA_StatusCode *fieldAddResults;
  160. UA_ConfigurationVersionDataType configurationVersion;
  161. } UA_AddPublishedDataSetResult;
  162. UA_AddPublishedDataSetResult
  163. UA_Server_addPublishedDataSet(UA_Server *server,
  164. const UA_PublishedDataSetConfig *publishedDataSetConfig,
  165. UA_NodeId *pdsIdentifier);
  166. /* Returns a deep copy of the config */
  167. UA_StatusCode
  168. UA_Server_getPublishedDataSetConfig(UA_Server *server, const UA_NodeId pds,
  169. UA_PublishedDataSetConfig *config);
  170. /* Remove PublishedDataSet, identified by the NodeId. Deletion of PDS removes
  171. * all contained and linked PDS Fields. Connected WriterGroups will be also
  172. * removed. */
  173. UA_StatusCode
  174. UA_Server_removePublishedDataSet(UA_Server *server, const UA_NodeId pds);
  175. /**
  176. * DataSetFields
  177. * -------------
  178. * The description of published variables is named DataSetField. Each
  179. * DataSetField contains the selection of one information model node. The
  180. * DataSetField has additional parameters for the publishing, sampling and error
  181. * handling process. */
  182. typedef struct{
  183. UA_ConfigurationVersionDataType configurationVersion;
  184. UA_String fieldNameAlias;
  185. UA_Boolean promotedField;
  186. UA_PublishedVariableDataType publishParameters;
  187. } UA_DataSetVariableConfig;
  188. typedef enum {
  189. UA_PUBSUB_DATASETFIELD_VARIABLE,
  190. UA_PUBSUB_DATASETFIELD_EVENT
  191. } UA_DataSetFieldType;
  192. typedef struct {
  193. UA_DataSetFieldType dataSetFieldType;
  194. union {
  195. UA_DataSetVariableConfig variable;
  196. //events need other config later
  197. } field;
  198. } UA_DataSetFieldConfig;
  199. void
  200. UA_DataSetFieldConfig_deleteMembers(UA_DataSetFieldConfig *dataSetFieldConfig);
  201. typedef struct {
  202. UA_StatusCode result;
  203. UA_ConfigurationVersionDataType configurationVersion;
  204. } UA_DataSetFieldResult;
  205. UA_DataSetFieldResult
  206. UA_Server_addDataSetField(UA_Server *server,
  207. const UA_NodeId publishedDataSet,
  208. const UA_DataSetFieldConfig *fieldConfig,
  209. UA_NodeId *fieldIdentifier);
  210. /* Returns a deep copy of the config */
  211. UA_StatusCode
  212. UA_Server_getDataSetFieldConfig(UA_Server *server, const UA_NodeId dsf,
  213. UA_DataSetFieldConfig *config);
  214. UA_DataSetFieldResult
  215. UA_Server_removeDataSetField(UA_Server *server, const UA_NodeId dsf);
  216. /**
  217. * WriterGroup
  218. * -----------
  219. * All WriterGroups are created within a PubSubConnection and automatically
  220. * deleted if the connection is removed. The WriterGroup is primary used as
  221. * container for :ref:`dsw` and network message settings. The WriterGroup can be
  222. * imagined as producer of the network messages. The creation of network
  223. * messages is controlled by parameters like the publish interval, which is e.g.
  224. * contained in the WriterGroup. */
  225. typedef enum {
  226. UA_PUBSUB_ENCODING_BINARY,
  227. UA_PUBSUB_ENCODING_JSON,
  228. UA_PUBSUB_ENCODING_UADP
  229. } UA_PubSubEncodingType;
  230. typedef struct {
  231. UA_String name;
  232. UA_Boolean enabled;
  233. UA_UInt16 writerGroupId;
  234. UA_Duration publishingInterval;
  235. UA_Double keepAliveTime;
  236. UA_Byte priority;
  237. UA_MessageSecurityMode securityMode;
  238. UA_ExtensionObject transportSettings;
  239. UA_ExtensionObject messageSettings;
  240. size_t groupPropertiesSize;
  241. UA_KeyValuePair *groupProperties;
  242. UA_PubSubEncodingType encodingMimeType;
  243. /* non std. config parameter. maximum count of embedded DataSetMessage in
  244. * one NetworkMessage */
  245. UA_UInt16 maxEncapsulatedDataSetMessageCount;
  246. } UA_WriterGroupConfig;
  247. void
  248. UA_WriterGroupConfig_deleteMembers(UA_WriterGroupConfig *writerGroupConfig);
  249. /* Add a new WriterGroup to an existing Connection */
  250. UA_StatusCode
  251. UA_Server_addWriterGroup(UA_Server *server, const UA_NodeId connection,
  252. const UA_WriterGroupConfig *writerGroupConfig,
  253. UA_NodeId *writerGroupIdentifier);
  254. /* Returns a deep copy of the config */
  255. UA_StatusCode
  256. UA_Server_getWriterGroupConfig(UA_Server *server, const UA_NodeId writerGroup,
  257. UA_WriterGroupConfig *config);
  258. UA_StatusCode
  259. UA_Server_updateWriterGroupConfig(UA_Server *server, UA_NodeId writerGroupIdentifier,
  260. const UA_WriterGroupConfig *config);
  261. UA_StatusCode
  262. UA_Server_removeWriterGroup(UA_Server *server, const UA_NodeId writerGroup);
  263. /**
  264. * .. _dsw:
  265. *
  266. * DataSetWriter
  267. * -------------
  268. * The DataSetWriters are the glue between the WriterGroups and the
  269. * PublishedDataSets. The DataSetWriter contain configuration parameters and
  270. * flags which influence the creation of DataSet messages. These messages are
  271. * encapsulated inside the network message. The DataSetWriter must be linked
  272. * with an existing PublishedDataSet and be contained within a WriterGroup. */
  273. typedef struct {
  274. UA_String name;
  275. UA_UInt16 dataSetWriterId;
  276. UA_DataSetFieldContentMask dataSetFieldContentMask;
  277. UA_UInt32 keyFrameCount;
  278. UA_ExtensionObject messageSettings;
  279. UA_String dataSetName;
  280. size_t dataSetWriterPropertiesSize;
  281. UA_KeyValuePair *dataSetWriterProperties;
  282. } UA_DataSetWriterConfig;
  283. void
  284. UA_DataSetWriterConfig_deleteMembers(UA_DataSetWriterConfig *pdsConfig);
  285. /* Add a new DataSetWriter to a existing WriterGroup. The DataSetWriter must be
  286. * coupled with a PublishedDataSet on creation.
  287. *
  288. * Part 14, 7.1.5.2.1 defines: The link between the PublishedDataSet and
  289. * DataSetWriter shall be created when an instance of the DataSetWriterType is
  290. * created. */
  291. UA_StatusCode
  292. UA_Server_addDataSetWriter(UA_Server *server,
  293. const UA_NodeId writerGroup, const UA_NodeId dataSet,
  294. const UA_DataSetWriterConfig *dataSetWriterConfig,
  295. UA_NodeId *writerIdentifier);
  296. /* Returns a deep copy of the config */
  297. UA_StatusCode
  298. UA_Server_getDataSetWriterConfig(UA_Server *server, const UA_NodeId dsw,
  299. UA_DataSetWriterConfig *config);
  300. UA_StatusCode
  301. UA_Server_removeDataSetWriter(UA_Server *server, const UA_NodeId dsw);
  302. #endif /* UA_ENABLE_PUBSUB */
  303. _UA_END_DECLS
  304. #endif /* UA_SERVER_PUBSUB_H */