ua_server_pubsub.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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_PubSubConnections | UA_Server_addPubSubConnection
  46. * | +----------------------+
  47. * | | |
  48. * | | | +-----------------------+
  49. * | | +--->| UA_PubSubWriterGroups |
  50. * | | +-----------------------+
  51. * | |
  52. * | | +-----------------------+
  53. * | +-------->| UA_PubSubReaderGroups |
  54. * | +-----------------------+
  55. * |
  56. * | +---------------------------+
  57. * +------>| UA_PubSubPublishedDataSet | UA_Server_addPublishedDataSet
  58. * +---------------------------+
  59. *
  60. * Connections
  61. * -----------
  62. * The PubSub connections are the abstraction between the concrete transport protocol
  63. * and the PubSub functionality. It is possible to create multiple connections with
  64. * different transport protocols at runtime.
  65. *
  66. * Take a look on the PubSub Tutorials for mor details about the API usage.
  67. * Connections
  68. * -----------
  69. */
  70. typedef struct{
  71. UA_String name;
  72. UA_Boolean enabled;
  73. union{ //std: valid types UInt or String
  74. UA_UInt32 numeric;
  75. UA_String string;
  76. }publisherId;
  77. UA_String transportProfileUri;
  78. UA_Variant address;
  79. size_t connectionPropertiesSize;
  80. UA_KeyValuePair *connectionProperties;
  81. UA_Variant connectionTransportSettings;
  82. } UA_PubSubConnectionConfig;
  83. /**
  84. * Connection handling
  85. * ^^^^^^^^^^^^^^^^^^^
  86. */
  87. UA_StatusCode
  88. UA_Server_addPubSubConnection(UA_Server *server, const UA_PubSubConnectionConfig *connectionConfig,
  89. UA_NodeId *connectionIdentifier);
  90. UA_StatusCode
  91. UA_Server_removePubSubConnection(UA_Server *server, UA_NodeId connectionIdentifier);
  92. UA_StatusCode
  93. UA_PubSubConnection_getConfig(UA_Server *server, UA_NodeId connectionIdentifier,
  94. UA_PubSubConnectionConfig *config);
  95. /**
  96. * PublishedDataSets
  97. * -----------------
  98. * The PublishedDataSets (PDS) are containers for the published information. The PDS contain
  99. * the published variables and meta informations. The metainformations are commonly autogenerated
  100. * or given as constant argument as part of the template functions. The template functions are standard
  101. * defined and should only be used for configuration tools. You should normally
  102. * create a empty PDS and call the functions to add new fields.
  103. */
  104. typedef struct {
  105. UA_StatusCode addResult;
  106. size_t fieldAddResultsSize;
  107. UA_StatusCode *fieldAddResults;
  108. UA_ConfigurationVersionDataType configurationVersion;
  109. } UA_AddPublishedDataSetResult;
  110. typedef enum {
  111. UA_PUBSUB_DATASET_PUBLISHEDITEMS,
  112. UA_PUBSUB_DATASET_PUBLISHEDEVENTS,
  113. UA_PUBSUB_DATASET_PUBLISHEDITEMS_TEMPLATE,
  114. UA_PUBSUB_DATASET_PUBLISHEDEVENTS_TEMPLATE,
  115. } UA_PublishedDataSetType;
  116. /* The UA_PUBSUB_DATASET_PUBLISHEDITEMS has currently no additional members
  117. * and thus no dedicated config structure.
  118. */
  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 PubSubDataSet */
  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. /**
  148. * PublishedDataSet handling
  149. * ^^^^^^^^^^^^^^^^^^^^^^^^^
  150. */
  151. UA_AddPublishedDataSetResult
  152. UA_Server_addPublishedDataSet(UA_Server *server, const UA_PublishedDataSetConfig *publishedDataSetConfig,
  153. UA_NodeId *pdsIdentifier);
  154. UA_StatusCode
  155. UA_Server_removePublishedDataSet(UA_Server *server, UA_NodeId pdsIdentifier);
  156. UA_StatusCode
  157. UA_PublishedDataSet_getConfig(UA_Server *server, UA_NodeId publishedDataSetIdentifier,
  158. UA_PublishedDataSetConfig *config);
  159. void
  160. UA_PublishedDataSetConfig_deleteMembers(UA_PublishedDataSetConfig *pdsConfig);
  161. #ifdef __cplusplus
  162. } // extern "C"
  163. #endif
  164. #endif /* UA_SERVER_PUBSUB_H */