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