ua_plugin_pubsub.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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_PLUGIN_PUBSUB_H_
  8. #define UA_PLUGIN_PUBSUB_H_
  9. #include "ua_server_pubsub.h"
  10. _UA_BEGIN_DECLS
  11. #ifdef UA_ENABLE_PUBSUB
  12. /**
  13. * .. _pubsub_connection:
  14. *
  15. * PubSub Connection Plugin API
  16. * ============================
  17. *
  18. * The PubSub Connection API is the interface between concrete network implementations and the internal pubsub
  19. * code.
  20. *
  21. * The PubSub specification enables the creation of new connections on runtime. Wording:
  22. * 'Connection' -> OPC UA standard 'highlevel' perspective,
  23. * 'Channel' -> open62541 implementation 'lowlevel' perspective. A channel can be assigned with different
  24. * network implementations like UDP, MQTT, AMQP. The channel provides basis services
  25. * like send, regist, unregist, receive, close.
  26. */
  27. typedef enum {
  28. UA_PUBSUB_CHANNEL_RDY,
  29. UA_PUBSUB_CHANNEL_PUB,
  30. UA_PUBSUB_CHANNEL_SUB,
  31. UA_PUBSUB_CHANNEL_PUB_SUB,
  32. UA_PUBSUB_CHANNEL_ERROR,
  33. UA_PUBSUB_CHANNEL_CLOSED
  34. } UA_PubSubChannelState;
  35. struct UA_PubSubChannel;
  36. typedef struct UA_PubSubChannel UA_PubSubChannel;
  37. /* Interface structure between network plugin and internal implementation */
  38. struct UA_PubSubChannel {
  39. UA_UInt32 publisherId; /* unique identifier */
  40. UA_PubSubChannelState state;
  41. UA_PubSubConnectionConfig *connectionConfig; /* link to parent connection config */
  42. UA_SOCKET sockfd;
  43. void *handle; /* implementation specific data */
  44. /*@info for handle: each network implementation should provide an structure
  45. * UA_PubSubChannelData[ImplementationName] This structure can be used by the
  46. * network implementation to store network implementation specific data.*/
  47. /* Sending out the content of the buf parameter */
  48. UA_StatusCode (*send)(UA_PubSubChannel *channel, UA_ExtensionObject *transportSettings,
  49. const UA_ByteString *buf);
  50. /* Register to an specified message source, e.g. multicast group or topic */
  51. UA_StatusCode (*regist)(UA_PubSubChannel * channel, UA_ExtensionObject *transportSettings);
  52. /* Remove subscription to an specified message source, e.g. multicast group or topic */
  53. UA_StatusCode (*unregist)(UA_PubSubChannel * channel, UA_ExtensionObject *transportSettings);
  54. /* Receive messages. A regist to the message source is needed before. */
  55. UA_StatusCode (*receive)(UA_PubSubChannel * channel, UA_ByteString *,
  56. UA_ExtensionObject *transportSettings, UA_UInt32 timeout);
  57. /* Closing the connection and implicit free of the channel structures. */
  58. UA_StatusCode (*close)(UA_PubSubChannel *channel);
  59. };
  60. /**
  61. * The UA_PubSubTransportLayer is used for the creation of new connections. Whenever on runtime a new
  62. * connection is request, the internal PubSub implementation call * the 'createPubSubChannel' function.
  63. * The 'transportProfileUri' contains the standard defined transport profile information
  64. * and is used to identify the type of connections which can be created by the
  65. * TransportLayer. The server config contains a list of UA_PubSubTransportLayer.
  66. * Take a look in the tutorial_pubsub_connection to get informations about the TransportLayer handling.
  67. */
  68. typedef struct {
  69. UA_String transportProfileUri;
  70. UA_PubSubChannel * (*createPubSubChannel)(UA_PubSubConnectionConfig *connectionConfig);
  71. } UA_PubSubTransportLayer;
  72. /**
  73. * The UA_ServerConfig_addPubSubTransportLayer is used to add a transport
  74. * layer to the server configuration. The list memory is allocated and will be freed with
  75. * UA_PubSubManager_delete.
  76. *
  77. * .. note:: If the UA_String transportProfileUri was dynamically allocated
  78. * the memory has to be freed when no longer required.
  79. *
  80. * .. note:: This has to be done before the server is started with UA_Server_run.
  81. */
  82. UA_StatusCode
  83. UA_ServerConfig_addPubSubTransportLayer(UA_ServerConfig *config,
  84. UA_PubSubTransportLayer *pubsubTransportLayer);
  85. #endif /* UA_ENABLE_PUBSUB */
  86. _UA_END_DECLS
  87. #endif /* UA_PLUGIN_PUBSUB_H_ */