123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- /////////////////////////////////////////////////////////////////////////////
- /// @file response_options.h
- /// Implementation of the class 'response_options'
- /// @date 26-Aug-2016
- /////////////////////////////////////////////////////////////////////////////
- namespace mqtt {
- class token_test;
- /////////////////////////////////////////////////////////////////////////////
- // response_options
- /////////////////////////////////////////////////////////////////////////////
- class response_options
- {
-
- MQTTAsync_responseOptions opts_;
-
- token::weak_ptr_t tok_;
-
- properties props_;
-
- std::vector<MQTTSubscribe_options> subOpts_;
-
- friend class async_client;
-
- void update_c_struct();
- public:
-
- explicit response_options(int mqttVersion=MQTTVERSION_DEFAULT);
-
- response_options(const token_ptr& tok, int mqttVersion=MQTTVERSION_DEFAULT);
-
- response_options(const response_options& other);
-
- response_options& operator=(const response_options& rhs);
-
-
- const MQTTAsync_responseOptions& c_struct() const { return opts_; }
-
-
- void set_mqtt_version(int mqttVersion);
-
- void set_token(const token_ptr& tok);
-
- void set_properties(const properties& props) {
- props_ = props;
- opts_.properties = props_.c_struct();
- }
-
- void set_properties(properties&& props) {
- props_ = std::move(props);
- opts_.properties = props_.c_struct();
- }
-
- void set_subscribe_options(const subscribe_options& opts);
-
- void set_subscribe_options(const std::vector<subscribe_options>& opts);
- };
- /////////////////////////////////////////////////////////////////////////////
- class response_options_builder
- {
-
- response_options opts_;
- public:
-
- using self = response_options_builder;
-
- explicit response_options_builder(int mqttVersion=MQTTVERSION_DEFAULT)
- : opts_(mqttVersion) {}
-
- auto mqtt_version(int mqttVersion) -> self& {
- opts_.set_mqtt_version(mqttVersion);
- return *this;
- }
-
- auto token(const token_ptr& tok) -> self& {
- opts_.set_token(tok);
- return *this;
- }
-
- auto properties(mqtt::properties&& props) -> self& {
- opts_.set_properties(std::move(props));
- return *this;
- }
-
- auto properties(const mqtt::properties& props) -> self& {
- opts_.set_properties(props);
- return *this;
- }
-
- auto subscribe_opts(const subscribe_options& opts) -> self& {
- opts_.set_subscribe_options(opts);
- return *this;
- }
-
- auto subscribe_opts(const std::vector<subscribe_options>& opts) -> self& {
- opts_.set_subscribe_options(opts);
- return *this;
- }
-
- response_options finalize() { return opts_; }
- };
- /////////////////////////////////////////////////////////////////////////////
- // delivery_response_options
- /////////////////////////////////////////////////////////////////////////////
- /**
- * The response options for asynchronous calls targeted at delivery.
- * Each of these objects is tied to a specific delivery_token.
- */
- class delivery_response_options
- {
- /** The underlying C structure */
- MQTTAsync_responseOptions opts_;
- /** The delivery token to which we are connected */
- delivery_token::weak_ptr_t dtok_;
- /** The client has special access */
- friend class async_client;
- public:
- /**
- * Create an empty delivery response object.
- */
- delivery_response_options(int mqttVersion=MQTTVERSION_DEFAULT);
- /**
- * Creates a response object tied to the specific delivery token.
- * @param dtok A delivery token to be used as the context.
- * @param mqttVersion The MQTT version for the response
- */
- delivery_response_options(const delivery_token_ptr& dtok,
- int mqttVersion=MQTTVERSION_DEFAULT);
- /**
- * Expose the underlying C struct for the unit tests.
- */
-
- const MQTTAsync_responseOptions& c_struct() const { return opts_; }
-
- /**
- * Sets the callback context to a delivery token.
- * @param dtok The delivery token to be used as the callback context.
- */
- void set_token(const delivery_token_ptr& dtok) {
- dtok_ = dtok;
- opts_.context = dtok.get();
- }
- };
- /////////////////////////////////////////////////////////////////////////////
- // end namespace 'mqtt'
- }
|