123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- /////////////////////////////////////////////////////////////////////////////
- /// @file create_options.h
- /// Declaration of MQTT create_options class
- /// @date Oct 17, 2020
- /// @author Frank Pagliughi
- /////////////////////////////////////////////////////////////////////////////
- namespace mqtt {
- /////////////////////////////////////////////////////////////////////////////
- class create_options
- {
-
- static const MQTTAsync_createOptions DFLT_C_STRUCT;
-
- MQTTAsync_createOptions opts_;
-
- friend class async_client;
- friend class create_options_builder;
- public:
-
- using ptr_t = std::shared_ptr<create_options>;
-
- using const_ptr_t = std::shared_ptr<const create_options>;
-
- create_options();
-
- explicit create_options(int mqttVersion);
-
- create_options(int mqttVersion, int maxBufferedMessages);
-
- bool get_send_while_disconnected() const {
- return to_bool(opts_.sendWhileDisconnected);
- }
-
- void set_send_while_disconnected(bool on, bool anyTime=false) {
- opts_.sendWhileDisconnected = to_int(on);
- opts_.allowDisconnectedSendAtAnyTime = to_int(anyTime);
- }
-
- int get_max_buffered_messages() const {
- return opts_.maxBufferedMessages;
- }
-
- void set_max_buffered_messages(int n) {
- opts_.maxBufferedMessages = n;
- }
-
- int mqtt_version() const { return opts_.MQTTVersion; }
-
- void set_mqtt_version(int ver) { opts_.MQTTVersion = ver; }
-
- bool get_delete_oldest_messages() const {
- return to_bool(opts_.deleteOldestMessages);
- }
-
- void set_delete_oldest_messages(bool on) {
- opts_.deleteOldestMessages = to_int(on);
- }
-
- bool get_restore_messages() const {
- return to_bool(opts_.restoreMessages);
- }
-
- void set_restore_messages(bool on) {
- opts_.restoreMessages = to_int(on);
- }
-
- bool get_persist_qos0() const {
- return to_bool(opts_.persistQoS0);
- }
-
- void set_persist_qos0(bool on) {
- opts_.persistQoS0 = to_int(on);
- }
- };
- using create_options_ptr = create_options::ptr_t;
- /////////////////////////////////////////////////////////////////////////////
- class create_options_builder
- {
-
- create_options opts_;
- public:
-
- using self = create_options_builder;
-
- create_options_builder() {}
-
- auto send_while_disconnected(bool on=true, bool anyTime=false) -> self& {
- opts_.opts_.sendWhileDisconnected = to_int(on);
- opts_.opts_.allowDisconnectedSendAtAnyTime = to_int(anyTime);
- return *this;
- }
-
- auto max_buffered_messages(int n) -> self& {
- opts_.opts_.maxBufferedMessages = n;
- return *this;
- }
-
- auto mqtt_version(int ver) -> self& {
- opts_.opts_.MQTTVersion = ver;
- return *this;
- }
-
- auto delete_oldest_messages(bool on=true) -> self& {
- opts_.opts_.deleteOldestMessages = to_int(on);
- return *this;
- }
-
- auto restore_messages(bool on=true) -> self& {
- opts_.opts_.restoreMessages = to_int(on);
- return *this;
- }
-
- auto persist_qos0(bool on=true) -> self& {
- opts_.opts_.persistQoS0 = to_int(on);
- return *this;
- }
-
- create_options finalize() { return opts_; }
- };
- /////////////////////////////////////////////////////////////////////////////
- // end namespace mqtt
- }
|