Loading...
Searching...
No Matches
subscribe_options.h
Go to the documentation of this file.
/*******************************************************************************
* Copyright (c) 2019-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:
* Frank Pagliughi - initial implementation and documentation
*******************************************************************************/
#ifndef __mqtt_subscribe_options_h
#define __mqtt_subscribe_options_h
#include "MQTTAsync.h"
#include "MQTTSubscribeOpts.h"
#include "mqtt/platform.h"
#include "mqtt/types.h"
namespace mqtt {
class subscribe_options
{
MQTTSubscribe_options opts_;
friend class async_client;
friend class response_options;
public:
using ptr_t = std::shared_ptr<subscribe_options>;
using const_ptr_t = std::shared_ptr<const subscribe_options>;
static constexpr bool NO_LOCAL = true;
static constexpr bool LOCAL = false;
[[deprecated("Use NO_LOCAL")]] static constexpr bool SUBSCRIBE_NO_LOCAL = true;
[[deprecated("Use LOCAL")]] static constexpr bool SUBSCRIBE_LOCAL = false;
static constexpr bool NO_RETAIN_AS_PUBLISHED = false;
static constexpr bool RETAIN_AS_PUBLISHED = true;
enum RetainHandling {
SEND_RETAINED_ON_SUBSCRIBE = 0,
SEND_RETAINED_ON_NEW = 1,
DONT_SEND_RETAINED = 2
};
subscribe_options() : opts_(MQTTSubscribe_options_initializer) {}
explicit subscribe_options(
bool noLocal, bool retainAsPublished = false,
RetainHandling retainHandling = SEND_RETAINED_ON_SUBSCRIBE
)
: opts_(MQTTSubscribe_options_initializer) {
opts_.noLocal = noLocal ? 1 : 0;
opts_.retainAsPublished = retainAsPublished ? 1 : 0;
opts_.retainHandling = (unsigned char)retainHandling;
}
explicit subscribe_options(MQTTSubscribe_options opts) : opts_{opts} {}
#if defined(UNIT_TESTS)
const auto& c_struct() const { return opts_; }
#endif
bool get_no_local() const { return to_bool(opts_.noLocal); }
void set_no_local(bool on = true) { opts_.noLocal = on ? 1 : 0; }
bool get_retain_as_published() const { return to_bool(opts_.retainAsPublished); }
void set_retain_as_published(bool on = true) { opts_.retainAsPublished = on ? 1 : 0; }
auto get_retain_handling() const -> RetainHandling {
return RetainHandling(opts_.retainHandling);
}
void set_retain_handling(RetainHandling retainHandling) {
opts_.retainHandling = (unsigned char)retainHandling;
}
};
using subscribe_options_ptr = subscribe_options::ptr_t;
} // namespace mqtt
#endif // __mqtt_subscribe_options_h
mqtt::async_client
Definition async_client.h:137
mqtt::response_options
Definition response_options.h:51
mqtt::subscribe_options
Definition subscribe_options.h:49
mqtt::subscribe_options::RetainHandling
RetainHandling
Definition subscribe_options.h:82
mqtt::subscribe_options::SEND_RETAINED_ON_NEW
@ SEND_RETAINED_ON_NEW
Definition subscribe_options.h:86
mqtt::subscribe_options::DONT_SEND_RETAINED
@ DONT_SEND_RETAINED
Definition subscribe_options.h:88
mqtt::subscribe_options::SEND_RETAINED_ON_SUBSCRIBE
@ SEND_RETAINED_ON_SUBSCRIBE
Definition subscribe_options.h:84
mqtt::subscribe_options::subscribe_options
subscribe_options()
Definition subscribe_options.h:96
mqtt::subscribe_options::get_retain_handling
auto get_retain_handling() const -> RetainHandling
Definition subscribe_options.h:164
mqtt::subscribe_options::NO_RETAIN_AS_PUBLISHED
static constexpr bool NO_RETAIN_AS_PUBLISHED
Definition subscribe_options.h:77
mqtt::subscribe_options::subscribe_options
subscribe_options(MQTTSubscribe_options opts)
Definition subscribe_options.h:123
mqtt::subscribe_options::get_no_local
bool get_no_local() const
Definition subscribe_options.h:137
mqtt::subscribe_options::LOCAL
static constexpr bool LOCAL
Definition subscribe_options.h:66
mqtt::subscribe_options::SUBSCRIBE_NO_LOCAL
static constexpr bool SUBSCRIBE_NO_LOCAL
Definition subscribe_options.h:69
mqtt::subscribe_options::const_ptr_t
std::shared_ptr< const subscribe_options > const_ptr_t
Definition subscribe_options.h:61
mqtt::subscribe_options::set_retain_as_published
void set_retain_as_published(bool on=true)
Definition subscribe_options.h:155
mqtt::subscribe_options::SUBSCRIBE_LOCAL
static constexpr bool SUBSCRIBE_LOCAL
Definition subscribe_options.h:71
mqtt::subscribe_options::set_no_local
void set_no_local(bool on=true)
Definition subscribe_options.h:143
mqtt::subscribe_options::get_retain_as_published
bool get_retain_as_published() const
Definition subscribe_options.h:149
mqtt::subscribe_options::ptr_t
std::shared_ptr< subscribe_options > ptr_t
Definition subscribe_options.h:59
mqtt::subscribe_options::set_retain_handling
void set_retain_handling(RetainHandling retainHandling)
Definition subscribe_options.h:175
mqtt::subscribe_options::RETAIN_AS_PUBLISHED
static constexpr bool RETAIN_AS_PUBLISHED
Definition subscribe_options.h:79
mqtt::subscribe_options::subscribe_options
subscribe_options(bool noLocal, bool retainAsPublished=false, RetainHandling retainHandling=SEND_RETAINED_ON_SUBSCRIBE)
Definition subscribe_options.h:110
mqtt::subscribe_options::NO_LOCAL
static constexpr bool NO_LOCAL
Definition subscribe_options.h:64
mqtt
Definition async_client.h:60
mqtt::subscribe_options_ptr
subscribe_options::ptr_t subscribe_options_ptr
Definition subscribe_options.h:181
mqtt::to_bool
bool to_bool(int n)
Definition types.h:107
platform.h
types.h