ua_server_pubsub.h 12 KB

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