paho-mqtt-cpp
MQTT C++ Client for POSIX and Windows
Loading...
Searching...
No Matches
topic.h
Go to the documentation of this file.
1
7
8/*******************************************************************************
9 * Copyright (c) 2013-2016 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_topic_h
25#define __mqtt_topic_h
26
27#include "MQTTAsync.h"
28#include "mqtt/delivery_token.h"
30#include "mqtt/message.h"
31#include "mqtt/types.h"
32#include <vector>
33
34namespace mqtt {
35
36class iasync_client;
37
39
43class topic
44{
46 iasync_client& cli_;
48 string name_;
50 int qos_;
52 bool retained_;
53
54public:
56 using ptr_t = std::shared_ptr<topic>;
58 using const_ptr_t = std::shared_ptr<const topic>;
59
67 topic(iasync_client& cli, const string& name,
68 int qos=message::DFLT_QOS, bool retained=message::DFLT_RETAINED)
69 : cli_(cli), name_(name), qos_(qos), retained_(retained) {}
78 static ptr_t create(iasync_client& cli, const string& name,
79 int qos=message::DFLT_QOS,
80 bool retained=message::DFLT_RETAINED) {
81 return std::make_shared<topic>(cli, name, qos, retained);
82 }
87 iasync_client& get_client() { return cli_; }
92 const string& get_name() const { return name_; }
99 static std::vector<std::string> split(const std::string& topic);
104 int get_qos() const { return qos_; }
109 bool get_retained() const { return retained_; }
114 void set_qos(int qos) {
116 qos_ = qos;
117 }
122 void set_retained(bool retained) { retained_ = retained; }
131 delivery_token_ptr publish(const void* payload, size_t n);
143 delivery_token_ptr publish(const void* payload, size_t n,
144 int qos, bool retained);
163 delivery_token_ptr publish(binary_ref payload, int qos, bool retained);
173 string to_string() const { return name_; }
174};
175
178
181
183// Topic Filter
185
198{
200 std::vector<string> fields_;
201
202public:
210 explicit topic_filter(const string& filter);
218 static bool has_wildcards(const string& topic);
225 bool has_wildcards() const;
233 bool matches(const string& topic) const;
234};
235
237// end namespace mqtt
238}
239
240#endif // __mqtt_topic_h
241
Definition iasync_client.h:59
static PAHO_MQTTPP_EXPORT const int DFLT_QOS
Definition message.h:59
static void validate_qos(int qos)
Definition message.h:324
static PAHO_MQTTPP_EXPORT const bool DFLT_RETAINED
Definition message.h:61
Definition subscribe_options.h:42
Definition topic.h:198
static bool has_wildcards(const string &topic)
bool has_wildcards() const
bool matches(const string &topic) const
topic_filter(const string &filter)
Definition topic.h:44
bool get_retained() const
Definition topic.h:109
static ptr_t create(iasync_client &cli, const string &name, int qos=message::DFLT_QOS, bool retained=message::DFLT_RETAINED)
Definition topic.h:78
iasync_client & get_client()
Definition topic.h:87
void set_qos(int qos)
Definition topic.h:114
delivery_token_ptr publish(const void *payload, size_t n)
delivery_token_ptr publish(const void *payload, size_t n, int qos, bool retained)
topic(iasync_client &cli, const string &name, int qos=message::DFLT_QOS, bool retained=message::DFLT_RETAINED)
Definition topic.h:67
int get_qos() const
Definition topic.h:104
std::shared_ptr< topic > ptr_t
Definition topic.h:56
void set_retained(bool retained)
Definition topic.h:122
token_ptr subscribe(const subscribe_options &opts=subscribe_options())
std::shared_ptr< const topic > const_ptr_t
Definition topic.h:58
delivery_token_ptr publish(binary_ref payload)
delivery_token_ptr publish(binary_ref payload, int qos, bool retained)
static std::vector< std::string > split(const std::string &topic)
const string & get_name() const
Definition topic.h:92
string to_string() const
Definition topic.h:173
Definition async_client.h:49
topic::ptr_t topic_ptr
Definition topic.h:177
delivery_token::ptr_t delivery_token_ptr
Definition delivery_token.h:125
token::ptr_t token_ptr
Definition token.h:506
topic::const_ptr_t const_topic_ptr
Definition topic.h:180