paho-mqtt-cpp
MQTT C++ Client for POSIX and Windows
subscribe_options.h
Go to the documentation of this file.
1 
8 /*******************************************************************************
9  * Copyright (c) 2019-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_subscribe_options_h
25 #define __mqtt_subscribe_options_h
26 
27 #include "MQTTAsync.h"
28 #include "MQTTSubscribeOpts.h"
29 #include "mqtt/types.h"
30 #include "mqtt/platform.h"
31 
32 namespace mqtt {
33 
35 
42 {
44  MQTTSubscribe_options opts_;
45 
47  friend class async_client;
48  friend class response_options;
49 
50 public:
52  using ptr_t = std::shared_ptr<subscribe_options>;
54  using const_ptr_t = std::shared_ptr<const subscribe_options>;
55 
57  PAHO_MQTTPP_EXPORT static const bool SUBSCRIBE_NO_LOCAL; // =true;
59  PAHO_MQTTPP_EXPORT static const bool SUBSCRIBE_LOCAL; // =false;
60 
65  PAHO_MQTTPP_EXPORT static const bool NO_RETAIN_AS_PUBLISHED; // =false;
67  PAHO_MQTTPP_EXPORT static const bool RETAIN_AS_PUBLISHED; // =true;
68 
77  };
78 
85  : opts_(MQTTSubscribe_options_initializer) {}
99  explicit subscribe_options(bool noLocal, byte retainAsPublished=false,
101  : opts_(MQTTSubscribe_options_initializer) {
102  opts_.noLocal = noLocal ? 1 : 0;
103  opts_.retainAsPublished = retainAsPublished ? 1 : 0;
104  opts_.retainHandling = (unsigned char) retainHandling;
105  }
111  bool get_no_local() const {
112  return to_bool(opts_.noLocal);
113  }
119  void set_no_local(bool on=true) {
120  opts_.noLocal = on ? 1 : 0;
121  }
127  bool get_retain_as_published() const {
128  return to_bool(opts_.retainAsPublished);
129  }
135  void set_retain_as_published(bool on) {
136  opts_.retainAsPublished = on ? 1 : 0;
137  }
147  return RetainHandling(opts_.retainHandling);
148  }
157  void set_retain_handling(RetainHandling retainHandling) {
158  opts_.retainHandling = (unsigned char) retainHandling;
159  }
160 };
161 
162 
165 
167 // end namespace mqtt
168 }
169 
170 #endif // __mqtt_subscribe_options_h
171 
uint8_t byte
Definition: types.h:37
subscribe_options(bool noLocal, byte retainAsPublished=false, RetainHandling retainHandling=SEND_RETAINED_ON_SUBSCRIBE)
Definition: subscribe_options.h:99
static PAHO_MQTTPP_EXPORT const bool SUBSCRIBE_NO_LOCAL
Definition: subscribe_options.h:57
Definition: async_client.h:107
void set_retain_as_published(bool on)
Definition: subscribe_options.h:135
bool to_bool(int n)
Definition: types.h:161
bool get_no_local() const
Definition: subscribe_options.h:111
std::shared_ptr< const subscribe_options > const_ptr_t
Definition: subscribe_options.h:54
RetainHandling
Definition: subscribe_options.h:70
Definition: subscribe_options.h:76
Definition: subscribe_options.h:72
static PAHO_MQTTPP_EXPORT const bool NO_RETAIN_AS_PUBLISHED
Definition: subscribe_options.h:65
void set_no_local(bool on=true)
Definition: subscribe_options.h:119
void set_retain_handling(RetainHandling retainHandling)
Definition: subscribe_options.h:157
bool get_retain_as_published() const
Definition: subscribe_options.h:127
subscribe_options::ptr_t subscribe_options_ptr
Definition: subscribe_options.h:164
Definition: subscribe_options.h:74
static PAHO_MQTTPP_EXPORT const bool RETAIN_AS_PUBLISHED
Definition: subscribe_options.h:67
static PAHO_MQTTPP_EXPORT const bool SUBSCRIBE_LOCAL
Definition: subscribe_options.h:59
Definition: subscribe_options.h:41
#define PAHO_MQTTPP_EXPORT
Definition: export.h:40
Definition: response_options.h:34
Definition: async_client.h:49
subscribe_options()
Definition: subscribe_options.h:84
auto get_retain_handling() const -> RetainHandling
Definition: subscribe_options.h:146
std::shared_ptr< subscribe_options > ptr_t
Definition: subscribe_options.h:52