Paho C++  1.0
The Paho MQTT C++ Client Library
 All Classes Files Functions Variables Typedefs Friends
disconnect_options.h
Go to the documentation of this file.
1 
7 /****************************************************************************
8  * Copyright (c) 2016-2017 Frank Pagliughi <fpagliughi@mindspring.com>
9  *
10  * All rights reserved. This program and the accompanying materials
11  * are made available under the terms of the Eclipse Public License v1.0
12  * and Eclipse Distribution License v1.0 which accompany this distribution.
13  *
14  * The Eclipse Public License is available at
15  * http://www.eclipse.org/legal/epl-v10.html
16  * and the Eclipse Distribution License is available at
17  * http://www.eclipse.org/org/documents/edl-v10.php.
18  *
19  * Contributors:
20  * Frank Pagliughi - initial implementation and documentation
21  ***************************************************************************/
22 
23 #ifndef __mqtt_disconnect_options_h
24 #define __mqtt_disconnect_options_h
25 
26 #include "MQTTAsync.h"
27 #include "mqtt/token.h"
28 #include <chrono>
29 
30 namespace mqtt {
31 
33 
38 {
40  static const MQTTAsync_disconnectOptions DFLT_C_STRUCT;
41 
43  MQTTAsync_disconnectOptions opts_;
44 
46  token_ptr tok_;
47 
49  friend class async_client;
50  friend class disconnect_options_test;
51 
52 public:
62  disconnect_options(int timeout, const token_ptr& tok);
68  template <class Rep, class Period>
69  disconnect_options(const std::chrono::duration<Rep, Period>& to,
70  const token_ptr& tok) : disconnect_options() {
71  set_timeout(to);
72  set_token(tok);
73  }
98  std::chrono::milliseconds get_timeout() const {
99  return std::chrono::milliseconds(opts_.timeout);
100  }
106  void set_timeout(int timeout) { opts_.timeout = timeout; }
113  template <class Rep, class Period>
114  void set_timeout(const std::chrono::duration<Rep, Period>& to) {
115  // TODO: check range
116  set_timeout((int) to_milliseconds_count(to));
117  }
122  void set_token(const token_ptr& tok);
127  token_ptr get_token() const { return tok_; }
128 };
129 
131 // end namespace 'mqtt'
132 }
133 
134 #endif // __mqtt_disconnect_options_h
Lightweight client for talking to an MQTT server using non-blocking methods that allow an operation t...
Definition: async_client.h:60
disconnect_options(const std::chrono::duration< Rep, Period > &to, const token_ptr &tok)
Creates disconnect options tied to the specific token.
Definition: disconnect_options.h:69
void set_timeout(int timeout)
Sets the timeout for disconnecting.
Definition: disconnect_options.h:106
std::chrono::milliseconds get_timeout() const
Gets the timeout used for disconnecting.
Definition: disconnect_options.h:98
void set_token(const token_ptr &tok)
Sets the callback context to a delivery token.
void set_timeout(const std::chrono::duration< Rep, Period > &to)
Sets the connect timeout with a chrono duration.
Definition: disconnect_options.h:114
token_ptr get_token() const
Gets the callback context to a delivery token.
Definition: disconnect_options.h:127
Options for disconnecting from an MQTT broker.
Definition: disconnect_options.h:37
disconnect_options()
Create an empty delivery response object.
Declaration of MQTT token class.
disconnect_options & operator=(const disconnect_options &opt)
Copy assignment.