response_options.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /////////////////////////////////////////////////////////////////////////////
  2. /// @file response_options.h
  3. /// Implementation of the class 'response_options'
  4. /// @date 26-Aug-2016
  5. /////////////////////////////////////////////////////////////////////////////
  6. #ifndef __mqtt_response_options_h
  7. #define __mqtt_response_options_h
  8. #include "MQTTAsync.h"
  9. #include "mqtt/token.h"
  10. #include "mqtt/delivery_token.h"
  11. #include "subscribe_options.h"
  12. namespace mqtt {
  13. class response_options_test;
  14. class delivery_response_options_test;
  15. class token_test;
  16. /////////////////////////////////////////////////////////////////////////////
  17. // response_options
  18. /////////////////////////////////////////////////////////////////////////////
  19. /**
  20. * The response options for various asynchronous calls.
  21. *
  22. * This is an internal data structure, only used within the library.
  23. Therefor it is not totally fleshed out, but rather only exposes the
  24. functionality currently required by the library.
  25. */
  26. class response_options
  27. {
  28. /** The underlying C structure */
  29. MQTTAsync_responseOptions opts_;
  30. /** The token to which we are connected */
  31. token::weak_ptr_t tok_;
  32. /** A list of subscription options for subscribe-many */
  33. std::vector<MQTTSubscribe_options> subOpts_;
  34. /** The client has special access */
  35. friend class async_client;
  36. friend class response_options_test;
  37. friend class token_test;
  38. public:
  39. /**
  40. * Create an empty response object.
  41. */
  42. explicit response_options(int mqttVersion=MQTTVERSION_DEFAULT);
  43. /**
  44. * Creates a response object with the specified callbacks.
  45. * @param tok A token to be used as the context.
  46. */
  47. response_options(const token_ptr& tok, int mqttVersion=MQTTVERSION_DEFAULT);
  48. /**
  49. * Sets the callback context to a generic token.
  50. * @param tok The token to be used as the callback context.
  51. */
  52. void set_token(const token_ptr& tok);
  53. /**
  54. * Sets the options for a single topic subscription.
  55. * @param opts The subscribe options.
  56. */
  57. void set_subscribe_options(const subscribe_options& opts);
  58. /**
  59. * Sets the options for a multi-topic subscription.
  60. * @param opts A vector of the subscribe options.
  61. */
  62. void set_subscribe_options(const std::vector<subscribe_options>& opts);
  63. };
  64. /////////////////////////////////////////////////////////////////////////////
  65. // delivery_response_options
  66. /////////////////////////////////////////////////////////////////////////////
  67. /**
  68. * The response options for asynchronous calls targeted at delivery.
  69. * Each of these objects is tied to a specific delivery_token.
  70. */
  71. class delivery_response_options
  72. {
  73. /** The underlying C structure */
  74. MQTTAsync_responseOptions opts_;
  75. /** The delivery token to which we are connected */
  76. delivery_token::weak_ptr_t dtok_;
  77. /** The client has special access */
  78. friend class async_client;
  79. friend class delivery_response_options_test;
  80. public:
  81. /**
  82. * Create an empty delivery response object.
  83. */
  84. delivery_response_options(int mqttVersion=MQTTVERSION_DEFAULT);
  85. /**
  86. * Creates a response object tied to the specific delivery token.
  87. * @param dtok A delivery token to be used as the context.
  88. */
  89. delivery_response_options(const delivery_token_ptr& dtok,
  90. int mqttVersion=MQTTVERSION_DEFAULT);
  91. /**
  92. * Sets the callback context to a delivery token.
  93. * @param dtok The delivery token to be used as the callback context.
  94. */
  95. void set_token(const delivery_token_ptr& dtok) {
  96. dtok_ = dtok;
  97. opts_.context = dtok.get();
  98. }
  99. };
  100. /////////////////////////////////////////////////////////////////////////////
  101. // end namespace 'mqtt'
  102. }
  103. #endif // __mqtt_response_options_h