Paho C++  1.0
The Paho MQTT C++ Client Library
 All Classes Files Functions Variables Typedefs Friends
topic.h
Go to the documentation of this file.
1 
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 v1.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-v10.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"
29 #include "mqtt/message.h"
30 #include "mqtt/types.h"
31 #include <vector>
32 
33 namespace mqtt {
34 
35 class iasync_client;
36 
38 
42 class topic
43 {
45  iasync_client& cli_;
47  string name_;
49  int qos_;
51  bool retained_;
52 
53 public:
55  using ptr_t = std::shared_ptr<topic>;
57  using const_ptr_t = std::shared_ptr<const topic>;
58 
66  topic(iasync_client& cli, const string& name,
67  int qos=message::DFLT_QOS, bool retained=message::DFLT_RETAINED)
68  : cli_(cli), name_(name), qos_(qos), retained_(retained) {}
77  static ptr_t create(iasync_client& cli, const string& name,
78  int qos=message::DFLT_QOS,
79  bool retained=message::DFLT_RETAINED) {
80  return std::make_shared<topic>(cli, name, qos, retained);
81  }
86  iasync_client& get_client() { return cli_; }
91  const string& get_name() const { return name_; }
96  int get_qos() const { return qos_; }
101  bool get_retained() const { return retained_; }
106  void set_qos(int qos) {
108  qos_ = qos;
109  }
114  void set_retained(bool retained) { retained_ = retained; }
123  delivery_token_ptr publish(const void* payload, size_t n);
135  delivery_token_ptr publish(const void* payload, size_t n,
136  int qos, bool retained);
144  delivery_token_ptr publish(binary_ref payload);
155  delivery_token_ptr publish(binary_ref payload, int qos, bool retained);
160  string to_string() const { return name_; }
161 };
162 
164 using topic_ptr = topic::ptr_t ;
165 
167 using const_topic_ptr = topic::const_ptr_t ;
168 
170 // end namespace mqtt
171 }
172 
173 #endif // __mqtt_topic_h
174 
Basic types and type conversions for the Paho MQTT C++ library.
topic(iasync_client &cli, const string &name, int qos=message::DFLT_QOS, bool retained=message::DFLT_RETAINED)
Construct an MQTT topic destination for messages.
Definition: topic.h:66
std::shared_ptr< const topic > const_ptr_t
A smart/shared pointer to this class.
Definition: topic.h:57
const string & get_name() const
Gets the name of the topic.
Definition: topic.h:91
bool get_retained() const
Gets the default retained flag used for this topic.
Definition: topic.h:101
void set_qos(int qos)
Sets the default quality of service for this topic.
Definition: topic.h:106
Represents a topic destination, used for publish/subscribe messaging.
Definition: topic.h:42
Declaration of MQTT message class.
iasync_client & get_client()
Gets a reference to the MQTT client used by this topic.
Definition: topic.h:86
Enables an application to communicate with an MQTT server using non-blocking methods.
Definition: iasync_client.h:57
delivery_token_ptr publish(const void *payload, size_t n)
Publishes a message on the topic using the default QoS and retained flag.
std::shared_ptr< topic > ptr_t
A smart/shared pointer to this class.
Definition: topic.h:55
static constexpr bool DFLT_RETAINED
The default retained flag.
Definition: message.h:58
static ptr_t create(iasync_client &cli, const string &name, int qos=message::DFLT_QOS, bool retained=message::DFLT_RETAINED)
Creates a new topic.
Definition: topic.h:77
string to_string() const
Returns a string representation of this topic.
Definition: topic.h:160
void set_retained(bool retained)
Sets the default retained flag used for this topic.
Definition: topic.h:114
Declaration of MQTT delivery_token class.
static void validate_qos(int qos)
Determines if the QOS value is a valid one.
Definition: message.h:320
static constexpr int DFLT_QOS
The default QoS for a message.
Definition: message.h:56
int get_qos() const
Gets the default quality of service for this topic.
Definition: topic.h:96