pubsub.h 4.4 KB

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