ua_plugin_pubsub.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. Callback is used for mqtt. */
  51. UA_StatusCode (*regist)(UA_PubSubChannel * channel, UA_ExtensionObject *transportSettings,
  52. void (*callback)(UA_ByteString *encodedBuffer, UA_ByteString *topic));
  53. /* Remove subscription to an specified message source, e.g. multicast group or topic */
  54. UA_StatusCode (*unregist)(UA_PubSubChannel * channel, UA_ExtensionObject *transportSettings);
  55. /* Receive messages. A regist to the message source is needed before. */
  56. UA_StatusCode (*receive)(UA_PubSubChannel * channel, UA_ByteString *,
  57. UA_ExtensionObject *transportSettings, UA_UInt32 timeout);
  58. /* Closing the connection and implicit free of the channel structures. */
  59. UA_StatusCode (*close)(UA_PubSubChannel *channel);
  60. /* Giving the connection protocoll time to process inbound and outbound traffic. */
  61. UA_StatusCode (*yield)(UA_PubSubChannel *channel, UA_UInt16 timeout);
  62. };
  63. /**
  64. * The UA_PubSubTransportLayer is used for the creation of new connections. Whenever on runtime a new
  65. * connection is request, the internal PubSub implementation call * the 'createPubSubChannel' function.
  66. * The 'transportProfileUri' contains the standard defined transport profile information
  67. * and is used to identify the type of connections which can be created by the
  68. * TransportLayer. The server config contains a list of UA_PubSubTransportLayer.
  69. * Take a look in the tutorial_pubsub_connection to get informations about the TransportLayer handling.
  70. */
  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
  77. * layer to the server configuration. The list memory is allocated and will be freed with
  78. * 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. */
  85. UA_StatusCode UA_EXPORT
  86. UA_ServerConfig_addPubSubTransportLayer(UA_ServerConfig *config,
  87. UA_PubSubTransportLayer *pubsubTransportLayer);
  88. #endif /* UA_ENABLE_PUBSUB */
  89. _UA_END_DECLS
  90. #endif /* UA_PLUGIN_PUBSUB_H_ */