Loading...
Searching...
No Matches
will_options.h
Go to the documentation of this file.
/*******************************************************************************
* Copyright (c) 2016 Guilherme M. Ferreira <guilherme.maciel.ferreira@gmail.com>
* Copyright (c) 2016-2023 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:
* Guilherme M. Ferreira - initial implementation and documentation
* Frank Pagliughi - added copy & move operations
*******************************************************************************/
#ifndef __mqtt_will_options_h
#define __mqtt_will_options_h
#include "MQTTAsync.h"
#include "mqtt/message.h"
#include "mqtt/platform.h"
#include "mqtt/topic.h"
#include "mqtt/types.h"
namespace mqtt {
class connect_options;
class will_options
{
public:
static constexpr int DFLT_QOS = 0;
static constexpr bool DFLT_RETAINED = false;
private:
static constexpr MQTTAsync_willOptions DFLT_C_STRUCT MQTTAsync_willOptions_initializer;
MQTTAsync_willOptions opts_{DFLT_C_STRUCT};
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_RETAINED,
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;
} // namespace mqtt
#endif // __mqtt_will_options_h
mqtt::buffer_ref::to_string
const blob & to_string() const
Definition buffer_ref.h:258
mqtt::connect_options
Definition connect_options.h:50
mqtt::message
Definition message.h:57
mqtt::message::create
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
mqtt::properties
Definition properties.h:293
mqtt::topic
Definition topic.h:54
mqtt::will_options::operator=
will_options & operator=(const will_options &opt)
mqtt::will_options::set_payload
void set_payload(binary_ref msg)
mqtt::will_options::will_options
will_options(string_ref top, binary_ref payload, int qos=DFLT_QOS, bool retained=DFLT_RETAINED, const properties &props=properties())
mqtt::will_options::get_payload
const binary_ref & get_payload() const
Definition will_options.h:203
mqtt::will_options::set_qos
void set_qos(const int qos)
Definition will_options.h:245
mqtt::will_options::is_retained
bool is_retained() const
Definition will_options.h:218
mqtt::will_options::will_options
will_options(const message &msg)
mqtt::will_options::set_retained
void set_retained(bool retained)
Definition will_options.h:251
mqtt::will_options::get_properties
const properties & get_properties() const
Definition will_options.h:256
mqtt::will_options::will_options
will_options(const topic &top, const void *payload, size_t payload_len, int qos=DFLT_QOS, bool retained=DFLT_RETAINED, const properties &props=properties())
mqtt::will_options::set_topic
void set_topic(string_ref top)
mqtt::will_options::set_payload
void set_payload(string msg)
Definition will_options.h:240
mqtt::will_options::DFLT_QOS
static constexpr int DFLT_QOS
Definition will_options.h:53
mqtt::will_options::get_message
const_message_ptr get_message() const
Definition will_options.h:223
mqtt::will_options::will_options
will_options(will_options &&opt)
mqtt::will_options::operator=
will_options & operator=(will_options &&opt)
mqtt::will_options::will_options
will_options(string_ref top, const string &payload, int qos=DFLT_QOS, bool retained=DFLT_RETAINED, const properties &props=properties())
mqtt::will_options::get_payload_str
string get_payload_str() const
Definition will_options.h:208
mqtt::will_options::set_properties
void set_properties(const properties &props)
Definition will_options.h:261
mqtt::will_options::will_options
will_options()
mqtt::will_options::connect_options
friend class connect_options
Definition will_options.h:80
mqtt::will_options::get_topic
string get_topic() const
Definition will_options.h:198
mqtt::will_options::get_qos
int get_qos() const
Definition will_options.h:213
mqtt::will_options::DFLT_RETAINED
static constexpr bool DFLT_RETAINED
Definition will_options.h:55
mqtt::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())
mqtt::will_options::ptr_t
std::shared_ptr< will_options > ptr_t
Definition will_options.h:97
mqtt::will_options::will_options
will_options(const will_options &opt)
mqtt::will_options::const_ptr_t
std::shared_ptr< const will_options > const_ptr_t
Definition will_options.h:99
mqtt::will_options::unique_ptr_t
std::unique_ptr< will_options > unique_ptr_t
Definition will_options.h:101
mqtt::will_options::set_properties
void set_properties(properties &&props)
Definition will_options.h:266
message.h
mqtt
Definition async_client.h:60
mqtt::const_will_options_ptr
will_options::const_ptr_t const_will_options_ptr
Definition will_options.h:273
mqtt::binary_ref
buffer_ref< char > binary_ref
Definition buffer_ref.h:305
mqtt::to_bool
bool to_bool(int n)
Definition types.h:107
mqtt::const_message_ptr
message::const_ptr_t const_message_ptr
Definition message.h:372
mqtt::string
std::string string
Definition types.h:43
mqtt::will_options_ptr
will_options::ptr_t will_options_ptr
Definition will_options.h:270
mqtt::to_int
int to_int(bool b)
Definition types.h:113
mqtt::will_options_unique_ptr
will_options::unique_ptr_t will_options_unique_ptr
Definition will_options.h:276
mqtt::string_ref
buffer_ref< char > string_ref
Definition buffer_ref.h:297
platform.h
topic.h
types.h