PahoMqttCpp
MQTT C++ Client for POSIX and Windows
Loading...
Searching...
No Matches
will_options.h
Go to the documentation of this file.
1
7
8/*******************************************************************************
9 * Copyright (c) 2016 Guilherme M. Ferreira <guilherme.maciel.ferreira@gmail.com>
10 * Copyright (c) 2016-2023 Frank Pagliughi <fpagliughi@mindspring.com>
11 *
12 * All rights reserved. This program and the accompanying materials
13 * are made available under the terms of the Eclipse Public License v2.0
14 * and Eclipse Distribution License v1.0 which accompany this distribution.
15 *
16 * The Eclipse Public License is available at
17 * http://www.eclipse.org/legal/epl-v20.html
18 * and the Eclipse Distribution License is available at
19 * http://www.eclipse.org/org/documents/edl-v10.php.
20 *
21 * Contributors:
22 * Guilherme M. Ferreira - initial implementation and documentation
23 * Frank Pagliughi - added copy & move operations
24 *******************************************************************************/
25
26#ifndef __mqtt_will_options_h
27#define __mqtt_will_options_h
28
29#include "MQTTAsync.h"
30#include "mqtt/message.h"
31#include "mqtt/platform.h"
32#include "mqtt/topic.h"
33#include "mqtt/types.h"
34
35namespace mqtt {
36
37class connect_options;
38
40
50{
51public:
53 static constexpr int DFLT_QOS = 0;
55 static constexpr bool DFLT_RETAINED = false;
56
57private:
59 static constexpr MQTTAsync_willOptions DFLT_C_STRUCT MQTTAsync_willOptions_initializer;
60
62 MQTTAsync_willOptions opts_{DFLT_C_STRUCT};
63
65 string_ref topic_;
66
68 binary_ref payload_;
69
77 properties props_;
78
80 friend class connect_options;
81
93 const char* c_str(const string_ref& sr) { return sr ? sr.to_string().c_str() : nullptr; }
94
95public:
97 using ptr_t = std::shared_ptr<will_options>;
99 using const_ptr_t = std::shared_ptr<const will_options>;
101 using unique_ptr_t = std::unique_ptr<will_options>;
102
118 string_ref top, const void* payload, size_t payload_len, int qos = DFLT_QOS,
119 bool retained = DFLT_RETAINED, const properties& props = properties()
120 );
132 const topic& top, const void* payload, size_t payload_len, int qos = DFLT_QOS,
133 bool retained = DFLT_RETAINED, const properties& props = properties()
134 );
146 string_ref top, binary_ref payload, int qos = DFLT_QOS, bool retained = DFLT_RETAINED,
147 const properties& props = properties()
148 );
160 string_ref top, const string& payload, int qos = DFLT_QOS, bool retained = DFLT_QOS,
161 const properties& props = properties()
162 );
191#if defined(UNIT_TESTS)
192 const MQTTAsync_willOptions& c_struct() const { return opts_; }
193#endif
198 string get_topic() const { return topic_ ? topic_.to_string() : string(); }
203 const binary_ref& get_payload() const { return payload_; }
208 string get_payload_str() const { return payload_ ? payload_.to_string() : string(); }
213 int get_qos() const { return opts_.qos; }
218 bool is_retained() const { return opts_.retained != 0; }
224 return message::create(topic_, payload_, opts_.qos, to_bool(opts_.retained));
225 }
240 void set_payload(string msg) { set_payload(binary_ref(std::move(msg))); }
245 void set_qos(const int qos) { opts_.qos = qos; }
251 void set_retained(bool retained) { opts_.retained = to_int(retained); }
256 const properties& get_properties() const { return props_; }
261 void set_properties(const properties& props) { props_ = props; }
266 void set_properties(properties&& props) { props_ = std::move(props); }
267};
268
271
274
277
279} // namespace mqtt
280
281#endif // __mqtt_will_options_h
const blob & to_string() const
Definition buffer_ref.h:258
Definition connect_options.h:50
Definition message.h:57
static ptr_t create(string_ref topic, const void *payload, size_t len, int qos, bool retained, const properties &props=properties())
Definition message.h:175
Definition properties.h:293
Definition topic.h:45
Definition will_options.h:50
will_options & operator=(const will_options &opt)
void set_payload(binary_ref msg)
will_options(string_ref top, binary_ref payload, int qos=DFLT_QOS, bool retained=DFLT_RETAINED, const properties &props=properties())
const binary_ref & get_payload() const
Definition will_options.h:203
void set_qos(const int qos)
Definition will_options.h:245
bool is_retained() const
Definition will_options.h:218
will_options(const message &msg)
void set_retained(bool retained)
Definition will_options.h:251
const properties & get_properties() const
Definition will_options.h:256
will_options(const topic &top, const void *payload, size_t payload_len, int qos=DFLT_QOS, bool retained=DFLT_RETAINED, const properties &props=properties())
void set_topic(string_ref top)
void set_payload(string msg)
Definition will_options.h:240
static constexpr int DFLT_QOS
Definition will_options.h:53
const_message_ptr get_message() const
Definition will_options.h:223
will_options(will_options &&opt)
will_options(string_ref top, const string &payload, int qos=DFLT_QOS, bool retained=DFLT_QOS, const properties &props=properties())
will_options & operator=(will_options &&opt)
string get_payload_str() const
Definition will_options.h:208
void set_properties(const properties &props)
Definition will_options.h:261
string get_topic() const
Definition will_options.h:198
int get_qos() const
Definition will_options.h:213
static constexpr bool DFLT_RETAINED
Definition will_options.h:55
will_options(string_ref top, const void *payload, size_t payload_len, int qos=DFLT_QOS, bool retained=DFLT_RETAINED, const properties &props=properties())
std::shared_ptr< will_options > ptr_t
Definition will_options.h:97
will_options(const will_options &opt)
std::shared_ptr< const will_options > const_ptr_t
Definition will_options.h:99
std::unique_ptr< will_options > unique_ptr_t
Definition will_options.h:101
void set_properties(properties &&props)
Definition will_options.h:266
Definition async_client.h:60
bool to_bool(int n)
Definition types.h:107
will_options::ptr_t will_options_ptr
Definition will_options.h:270
will_options::unique_ptr_t will_options_unique_ptr
Definition will_options.h:276
will_options::const_ptr_t const_will_options_ptr
Definition will_options.h:273
std::string string
Definition types.h:43
buffer_ref< char > binary_ref
Definition buffer_ref.h:305
message::const_ptr_t const_message_ptr
Definition message.h:372
int to_int(bool b)
Definition types.h:113