paho-mqtt-cpp
MQTT C++ Client for POSIX and Windows
Loading...
Searching...
No Matches
server_response.h
Go to the documentation of this file.
1
7
8/*******************************************************************************
9 * Copyright (c) 2019 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_server_response_h
25#define __mqtt_server_response_h
26
27#include "MQTTAsync.h"
28#include "mqtt/types.h"
29#include "mqtt/properties.h"
30
31#include <iostream>
32
33namespace mqtt {
34
39{
41 properties props_;
42
43public:
53 : props_(props) {}
59 : props_(std::move(props)) {}
63 virtual ~server_response() {}
68 const properties& get_properties() const { return props_; }
69};
70
75{
77 string serverURI_;
79 int mqttVersion_;
81 bool sessionPresent_;
82
83 friend class token;
84
85 connect_response(const MQTTAsync_successData5* rsp) :
87 serverURI_(string(rsp->alt.connect.serverURI)),
88 mqttVersion_(rsp->alt.connect.MQTTVersion),
89 sessionPresent_(to_bool(rsp->alt.connect.sessionPresent)) {
90 }
91
92 connect_response(const MQTTAsync_successData* rsp) :
93 serverURI_(string(rsp->alt.connect.serverURI)),
94 mqttVersion_(rsp->alt.connect.MQTTVersion),
95 sessionPresent_(to_bool(rsp->alt.connect.sessionPresent)) {
96 }
97
98public:
103 string get_server_uri() const { return serverURI_; }
108 int get_mqtt_version() const { return mqttVersion_; }
116 bool is_session_present() const { return sessionPresent_; }
117};
118
123{
125 std::vector<ReasonCode> reasonCodes_;
126
127 friend class token;
128
133 subscribe_response(MQTTAsync_successData5* rsp)
135 if (rsp->alt.sub.reasonCodeCount < 2)
136 reasonCodes_.push_back(ReasonCode(rsp->reasonCode));
137 else if (rsp->alt.sub.reasonCodes) {
138 for (int i=0; i<rsp->alt.sub.reasonCodeCount; ++i)
139 reasonCodes_.push_back(ReasonCode(rsp->alt.sub.reasonCodes[i]));
140 }
141 }
142
148 subscribe_response(size_t n, MQTTAsync_successData* rsp) {
149 if (n < 2)
150 reasonCodes_.push_back(ReasonCode(rsp->alt.qos));
151 else if (rsp->alt.qosList) {
152 for (size_t i=0; i<n; ++i)
153 reasonCodes_.push_back(ReasonCode(rsp->alt.qosList[i]));
154 }
155 }
156
157public:
168 const std::vector<ReasonCode>& get_reason_codes() const {
169 return reasonCodes_;
170 }
171};
172
177{
179 std::vector<ReasonCode> reasonCodes_;
180
181 friend class token;
182
183 unsubscribe_response(MQTTAsync_successData5* rsp)
185 if (rsp->alt.unsub.reasonCodeCount < 2)
186 reasonCodes_.push_back(ReasonCode(rsp->reasonCode));
187 else if (rsp->alt.unsub.reasonCodes) {
188 for (int i=0; i<rsp->alt.unsub.reasonCodeCount; ++i)
189 reasonCodes_.push_back(ReasonCode(rsp->alt.unsub.reasonCodes[i]));
190 }
191 }
192
193 unsubscribe_response(MQTTAsync_successData* /*rsp*/) {}
194
195public:
204 const std::vector<ReasonCode>& get_reason_codes() const {
205 return reasonCodes_;
206 }
207};
208
210// end namespace mqtt
211}
212
213#endif // __mqtt_server_response_h
214
Definition: server_response.h:75
bool is_session_present() const
Definition: server_response.h:116
string get_server_uri() const
Definition: server_response.h:103
int get_mqtt_version() const
Definition: server_response.h:108
Definition: properties.h:256
Definition: server_response.h:39
server_response()
Definition: server_response.h:47
virtual ~server_response()
Definition: server_response.h:63
const properties & get_properties() const
Definition: server_response.h:68
server_response(properties &&props)
Definition: server_response.h:58
server_response(const properties &props)
Definition: server_response.h:52
Definition: token.h:53
Definition: server_response.h:177
const std::vector< ReasonCode > & get_reason_codes() const
Definition: server_response.h:204
Definition: async_client.h:49
ReasonCode
Definition: types.h:57
bool to_bool(int n)
Definition: types.h:161
std::string string
Definition: types.h:40
Definition: server_response.h:123
const std::vector< ReasonCode > & get_reason_codes() const
Definition: server_response.h:168
std::vector< ReasonCode > reasonCodes_
Definition: server_response.h:125
subscribe_response(size_t n, MQTTAsync_successData *rsp)
Definition: server_response.h:148
subscribe_response(MQTTAsync_successData5 *rsp)
Definition: server_response.h:133