123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- #ifndef __mqtt_will_options_h
- #define __mqtt_will_options_h
- #include "MQTTAsync.h"
- #include "mqtt/types.h"
- #include "mqtt/message.h"
- #include "mqtt/topic.h"
- #include "mqtt/platform.h"
- namespace mqtt {
- class connect_options;
- class will_options
- {
- public:
-
- PAHO_MQTTPP_EXPORT static const int DFLT_QOS;
-
- PAHO_MQTTPP_EXPORT static const bool DFLT_RETAINED;
- private:
-
- PAHO_MQTTPP_EXPORT static const MQTTAsync_willOptions DFLT_C_STRUCT;
-
- MQTTAsync_willOptions opts_;
-
- string_ref topic_;
-
- binary_ref payload_;
-
- properties props_;
-
- friend class connect_options;
-
- const char* c_str(const string_ref& sr) {
- return sr ? sr.to_string().c_str() : nullptr;
- }
- public:
-
- using ptr_t = std::shared_ptr<will_options>;
-
- using const_ptr_t = std::shared_ptr<const will_options>;
-
- using unique_ptr_t = std::unique_ptr<will_options>;
-
- will_options();
-
- will_options(string_ref top, const void *payload, size_t payload_len,
- int qos=DFLT_QOS, bool retained=DFLT_RETAINED,
- const properties& props=properties());
-
- will_options(const topic& top, const void *payload, size_t payload_len,
- int qos=DFLT_QOS, bool retained=DFLT_RETAINED,
- const properties& props=properties());
-
- will_options(string_ref top, binary_ref payload,
- int qos=DFLT_QOS, bool retained=DFLT_RETAINED,
- const properties& props=properties());
-
- will_options(string_ref top, const string& payload,
- int qos=DFLT_QOS, bool retained=DFLT_QOS,
- const properties& props=properties());
-
- will_options(const message& msg);
-
- will_options(const will_options& opt);
-
- will_options(will_options&& opt);
-
- will_options& operator=(const will_options& opt);
-
- will_options& operator=(will_options&& opt);
-
- #if defined(UNIT_TESTS)
- const MQTTAsync_willOptions& c_struct() const { return opts_; }
- #endif
-
- string get_topic() const { return topic_ ? topic_.to_string() : string(); }
-
- const binary_ref& get_payload() const { return payload_; }
-
- string get_payload_str() const { return payload_ ? payload_.to_string() : string(); }
-
- int get_qos() const { return opts_.qos; }
-
- bool is_retained() const { return opts_.retained != 0; }
-
- const_message_ptr get_message() const {
- return message::create(topic_, payload_, opts_.qos, to_bool(opts_.retained));
- }
-
- void set_topic(string_ref top);
-
- void set_payload(binary_ref msg);
-
- void set_payload(string msg) { set_payload(binary_ref(std::move(msg))); }
-
- void set_qos(const int qos) { opts_.qos = qos; }
-
- void set_retained(bool retained) { opts_.retained = to_int(retained); }
-
- const properties& get_properties() const { return props_; }
-
- void set_properties(const properties& props) { props_ = props; }
-
- void set_properties(properties&& props) { props_ = std::move(props); }
- };
- using will_options_ptr = will_options::ptr_t;
- using const_will_options_ptr = will_options::const_ptr_t;
- using will_options_unique_ptr = will_options::unique_ptr_t;
- }
- #endif
|