Loading...
Searching...
No Matches
response_options.h
Go to the documentation of this file.
/*******************************************************************************
* Copyright (c) 2019-2025 Frank Pagliughi <fpagliughi@mindspring.com>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v20.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Frank Pagliughi - initial implementation and documentation
*******************************************************************************/
#ifndef __mqtt_response_options_h
#define __mqtt_response_options_h
#include "MQTTAsync.h"
#include "mqtt/delivery_token.h"
#include "mqtt/token.h"
#include "subscribe_options.h"
namespace mqtt {
class token_test;
// response_options
class response_options
{
MQTTAsync_responseOptions opts_ MQTTAsync_responseOptions_initializer;
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) {
set_mqtt_version(mqttVersion);
}
response_options(const token_ptr& tok, int mqttVersion = MQTTVERSION_DEFAULT);
response_options(const response_options& other);
response_options(response_options&& other);
response_options& operator=(const response_options& rhs);
response_options& operator=(response_options&& rhs);
#if defined(UNIT_TESTS)
const auto& c_struct() const { return opts_; }
#endif
void set_mqtt_version(int mqttVersion);
void set_token(const token_ptr& tok);
const properties& get_properties() const { return props_; }
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();
}
subscribe_options get_subscribe_options() const {
return subscribe_options{opts_.subscribeOptions};
}
std::vector<subscribe_options> get_subscribe_many_options() const;
void set_subscribe_options(const subscribe_options& opts);
void set_subscribe_many_options(const std::vector<subscribe_options>& opts);
void set_subscribe_options(const std::vector<subscribe_options>& opts) {
set_subscribe_many_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_many_opts(const std::vector<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
class delivery_response_options
{
MQTTAsync_responseOptions opts_;
delivery_token::weak_ptr_t dtok_;
friend class async_client;
public:
delivery_response_options(int mqttVersion = MQTTVERSION_DEFAULT);
delivery_response_options(
const delivery_token_ptr& dtok, int mqttVersion = MQTTVERSION_DEFAULT
);
#if defined(UNIT_TESTS)
const MQTTAsync_responseOptions& c_struct() const { return opts_; }
#endif
void set_token(const delivery_token_ptr& dtok) {
dtok_ = dtok;
opts_.context = dtok.get();
}
};
} // namespace mqtt
#endif // __mqtt_response_options_h
mqtt::async_client
Definition async_client.h:137
mqtt::delivery_response_options
Definition response_options.h:264
mqtt::delivery_response_options::set_token
void set_token(const delivery_token_ptr &dtok)
Definition response_options.h:297
mqtt::delivery_response_options::delivery_response_options
delivery_response_options(int mqttVersion=MQTTVERSION_DEFAULT)
mqtt::delivery_response_options::delivery_response_options
delivery_response_options(const delivery_token_ptr &dtok, int mqttVersion=MQTTVERSION_DEFAULT)
mqtt::delivery_token::weak_ptr_t
std::weak_ptr< delivery_token > weak_ptr_t
Definition delivery_token.h:62
mqtt::properties
Definition properties.h:293
mqtt::properties::properties
properties()
Definition properties.h:358
mqtt::properties::c_struct
const MQTTProperties & c_struct() const
Definition properties.h:389
mqtt::response_options_builder
Definition response_options.h:179
mqtt::response_options_builder::properties
auto properties(mqtt::properties &&props) -> self &
Definition response_options.h:212
mqtt::response_options_builder::subscribe_opts
auto subscribe_opts(const subscribe_options &opts) -> self &
Definition response_options.h:228
mqtt::response_options_builder::properties
auto properties(const mqtt::properties &props) -> self &
Definition response_options.h:220
mqtt::response_options_builder::token
auto token(const token_ptr &tok) -> self &
Definition response_options.h:204
mqtt::response_options_builder::subscribe_opts
auto subscribe_opts(const std::vector< subscribe_options > &opts) -> self &
Definition response_options.h:244
mqtt::response_options_builder::finalize
response_options finalize()
Definition response_options.h:252
mqtt::response_options_builder::mqtt_version
auto mqtt_version(int mqttVersion) -> self &
Definition response_options.h:196
mqtt::response_options_builder::subscribe_many_opts
auto subscribe_many_opts(const std::vector< subscribe_options > &opts) -> self &
Definition response_options.h:236
mqtt::response_options_builder::response_options_builder
response_options_builder(int mqttVersion=MQTTVERSION_DEFAULT)
Definition response_options.h:189
mqtt::response_options
Definition response_options.h:51
mqtt::response_options::get_subscribe_many_options
std::vector< subscribe_options > get_subscribe_many_options() const
mqtt::response_options::response_options
response_options(int mqttVersion=MQTTVERSION_DEFAULT)
Definition response_options.h:75
mqtt::response_options::set_token
void set_token(const token_ptr &tok)
mqtt::response_options::response_options
response_options(const token_ptr &tok, int mqttVersion=MQTTVERSION_DEFAULT)
mqtt::response_options::get_subscribe_options
subscribe_options get_subscribe_options() const
Definition response_options.h:145
mqtt::response_options::set_subscribe_options
void set_subscribe_options(const subscribe_options &opts)
mqtt::response_options::operator=
response_options & operator=(const response_options &rhs)
mqtt::response_options::set_subscribe_options
void set_subscribe_options(const std::vector< subscribe_options > &opts)
Definition response_options.h:168
mqtt::response_options::set_mqtt_version
void set_mqtt_version(int mqttVersion)
mqtt::response_options::response_options
response_options(response_options &&other)
mqtt::response_options::set_properties
void set_properties(properties &&props)
Definition response_options.h:137
mqtt::response_options::set_subscribe_many_options
void set_subscribe_many_options(const std::vector< subscribe_options > &opts)
mqtt::response_options::set_properties
void set_properties(const properties &props)
Definition response_options.h:129
mqtt::response_options::response_options
response_options(const response_options &other)
mqtt::response_options::get_properties
const properties & get_properties() const
Definition response_options.h:124
mqtt::response_options::operator=
response_options & operator=(response_options &&rhs)
mqtt::subscribe_options
Definition subscribe_options.h:49
mqtt::token::weak_ptr_t
std::weak_ptr< token > weak_ptr_t
Definition token.h:61
delivery_token.h
mqtt
Definition async_client.h:60
mqtt::token_ptr
token::ptr_t token_ptr
Definition token.h:513
mqtt::delivery_token_ptr
delivery_token::ptr_t delivery_token_ptr
Definition delivery_token.h:127
subscribe_options.h
token.h