ua_plugin_pubsub.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. #include "ua_server_pubsub.h"
  13. #ifdef UA_ENABLE_PUBSUB
  14. /**
  15. * .. _pubsub_connection:
  16. *
  17. * PubSub Connection Plugin API
  18. * ============================
  19. *
  20. * The PubSub Connection API is the interface between concrete network implementations and the internal pubsub
  21. * code.
  22. *
  23. * The PubSub specification enables the creation of new connections on runtime. Wording:
  24. * 'Connection' -> OPC UA standard 'highlevel' perspective,
  25. * 'Channel' -> open62541 implementation 'lowlevel' perspective. A channel can be assigned with different
  26. * network implementations like UDP, MQTT, AMQP. The channel provides basis services
  27. * like send, regist, unregist, receive, close.
  28. */
  29. typedef enum {
  30. UA_PUBSUB_CHANNEL_RDY,
  31. UA_PUBSUB_CHANNEL_PUB,
  32. UA_PUBSUB_CHANNEL_SUB,
  33. UA_PUBSUB_CHANNEL_PUB_SUB,
  34. UA_PUBSUB_CHANNEL_ERROR,
  35. UA_PUBSUB_CHANNEL_CLOSED
  36. } UA_PubSubChannelState;
  37. struct UA_PubSubChannel;
  38. typedef struct UA_PubSubChannel UA_PubSubChannel;
  39. //interface structure between network plugin and internal implementation
  40. struct UA_PubSubChannel{
  41. UA_UInt32 publisherId; // unique identifier
  42. UA_PubSubChannelState state;
  43. UA_PubSubConnectionConfig *connectionConfig; //link to parent connection config
  44. UA_Int32 sockfd;
  45. void *handle; //implementation specific data
  46. /*@info for handle: each network implementation should provide an structure
  47. * UA_PubSubChannelData[ImplementationName] This structure can be used by the
  48. * network implementation to store network implementation specific data.*/
  49. /* Sending out the content of the buf parameter */
  50. UA_StatusCode (*send)(UA_PubSubChannel *channel, UA_ExtensionObject *transportSettings,
  51. const UA_ByteString *buf);
  52. /* Register to an specified message source, e.g. multicast group or topic */
  53. UA_StatusCode (*regist)(UA_PubSubChannel * channel, UA_ExtensionObject *transportSettings);
  54. /* Remove subscription to an specified message source, e.g. multicast group or topic */
  55. UA_StatusCode (*unregist)(UA_PubSubChannel * channel, UA_ExtensionObject *transportSettings);
  56. /* Receive messages. A regist to the message source is needed before. */
  57. UA_StatusCode (*receive)(UA_PubSubChannel * channel, UA_ByteString *,
  58. UA_ExtensionObject *transportSettings, UA_UInt32 timeout);
  59. /* Closing the connection and implicit free of the channel structures. */
  60. UA_StatusCode (*close)(UA_PubSubChannel *channel);
  61. };
  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 UA_PubSubTransportLayer{
  72. UA_String transportProfileUri;
  73. UA_PubSubChannel * (*createPubSubChannel)(UA_PubSubConnectionConfig *connectionConfig);
  74. } UA_PubSubTransportLayer;
  75. #endif /* UA_ENABLE_PUBSUB */
  76. #ifdef __cplusplus
  77. } // extern "C"
  78. #endif
  79. #endif /* UA_PLUGIN_PUBSUB_H_ */