ua_server_pubsub.h 13 KB

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