paho-mqtt-cpp
MQTT C++ Client for POSIX and Windows
create_options.h
Go to the documentation of this file.
1 
8 /*******************************************************************************
9  * Copyright (c) 2020-2023 Frank Pagliughi <fpagliughi@mindspring.com>
10  *
11  * All rights reserved. This program and the accompanying materials
12  * are made available under the terms of the Eclipse Public License v2.0
13  * and Eclipse Distribution License v1.0 which accompany this distribution.
14  *
15  * The Eclipse Public License is available at
16  * http://www.eclipse.org/legal/epl-v20.html
17  * and the Eclipse Distribution License is available at
18  * http://www.eclipse.org/org/documents/edl-v10.php.
19  *
20  * Contributors:
21  * Frank Pagliughi - initial implementation and documentation
22  *******************************************************************************/
23 
24 #ifndef __mqtt_create_options_h
25 #define __mqtt_create_options_h
26 
27 #include "MQTTAsync.h"
28 #include "mqtt/types.h"
29 
30 namespace mqtt {
31 
33 
38 {
40  static const MQTTAsync_createOptions DFLT_C_STRUCT;
41 
43  MQTTAsync_createOptions opts_;
44 
46  friend class async_client;
47  friend class create_options_builder;
48 
49 public:
51  using ptr_t = std::shared_ptr<create_options>;
53  using const_ptr_t = std::shared_ptr<const create_options>;
54 
63  explicit create_options(int mqttVersion);
70  create_options(int mqttVersion, int maxBufferedMessages);
76  return to_bool(opts_.sendWhileDisconnected);
77  }
88  void set_send_while_disconnected(bool on, bool anyTime=false) {
89  opts_.sendWhileDisconnected = to_int(on);
90  opts_.allowDisconnectedSendAtAnyTime = to_int(anyTime);
91  }
97  return opts_.maxBufferedMessages;
98  }
104  opts_.maxBufferedMessages = n;
105  }
110  int mqtt_version() const { return opts_.MQTTVersion; }
115  void set_mqtt_version(int ver) { opts_.MQTTVersion = ver; }
125  return to_bool(opts_.deleteOldestMessages);
126  }
134  opts_.deleteOldestMessages = to_int(on);
135  }
142  bool get_restore_messages() const {
143  return to_bool(opts_.restoreMessages);
144  }
151  void set_restore_messages(bool on) {
152  opts_.restoreMessages = to_int(on);
153  }
159  bool get_persist_qos0() const {
160  return to_bool(opts_.persistQoS0);
161  }
167  void set_persist_qos0(bool on) {
168  opts_.persistQoS0 = to_int(on);
169  }
170 };
171 
174 
176 
181 {
183  create_options opts_;
184 
185 public:
204  auto send_while_disconnected(bool on=true, bool anyTime=false) -> self& {
205  opts_.opts_.sendWhileDisconnected = to_int(on);
206  opts_.opts_.allowDisconnectedSendAtAnyTime = to_int(anyTime);
207  return *this;
208  }
214  auto max_buffered_messages(int n) -> self& {
215  opts_.opts_.maxBufferedMessages = n;
216  return *this;
217  }
222  auto mqtt_version(int ver) -> self& {
223  opts_.opts_.MQTTVersion = ver;
224  return *this;
225  }
233  auto delete_oldest_messages(bool on=true) -> self& {
234  opts_.opts_.deleteOldestMessages = to_int(on);
235  return *this;
236  }
245  auto restore_messages(bool on=true) -> self& {
246  opts_.opts_.restoreMessages = to_int(on);
247  return *this;
248  }
255  auto persist_qos0(bool on=true) -> self& {
256  opts_.opts_.persistQoS0 = to_int(on);
257  return *this;
258  }
263  create_options finalize() { return opts_; }
264 };
265 
267 // end namespace mqtt
268 }
269 
270 #endif // __mqtt_create_options_h
271 
auto send_while_disconnected(bool on=true, bool anyTime=false) -> self &
Definition: create_options.h:204
Definition: async_client.h:107
void set_restore_messages(bool on)
Definition: create_options.h:151
auto persist_qos0(bool on=true) -> self &
Definition: create_options.h:255
create_options finalize()
Definition: create_options.h:263
void set_max_buffered_messages(int n)
Definition: create_options.h:103
bool to_bool(int n)
Definition: types.h:161
std::shared_ptr< const create_options > const_ptr_t
Definition: create_options.h:53
Definition: create_options.h:37
void set_delete_oldest_messages(bool on)
Definition: create_options.h:133
int get_max_buffered_messages() const
Definition: create_options.h:96
auto max_buffered_messages(int n) -> self &
Definition: create_options.h:214
Definition: create_options.h:180
void set_persist_qos0(bool on)
Definition: create_options.h:167
auto restore_messages(bool on=true) -> self &
Definition: create_options.h:245
create_options_builder()
Definition: create_options.h:191
void set_mqtt_version(int ver)
Definition: create_options.h:115
auto delete_oldest_messages(bool on=true) -> self &
Definition: create_options.h:233
int mqtt_version() const
Definition: create_options.h:110
void set_send_while_disconnected(bool on, bool anyTime=false)
Definition: create_options.h:88
create_options::ptr_t create_options_ptr
Definition: create_options.h:173
std::shared_ptr< create_options > ptr_t
Definition: create_options.h:51
int to_int(bool b)
Definition: types.h:167
bool get_delete_oldest_messages() const
Definition: create_options.h:124
Definition: async_client.h:49
bool get_send_while_disconnected() const
Definition: create_options.h:75
auto mqtt_version(int ver) -> self &
Definition: create_options.h:222
bool get_restore_messages() const
Definition: create_options.h:142
bool get_persist_qos0() const
Definition: create_options.h:159