Skip to content

Commit 6ec6e9d

Browse files
authored
Merge pull request #444 from jonesmz/virtual-functions
Use virtual functions for notifications from mqtt_cpp::endpoint to other code, instead of multiple std::functions
2 parents a17c6b2 + 7438bef commit 6ec6e9d

10 files changed

+2749
-1525
lines changed

include/mqtt/async_client.hpp

+65-64
Large diffs are not rendered by default.

include/mqtt/attributes.hpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright Takatoshi Kondo 2018
2+
//
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#if !defined(MQTT_ATTRIBUTES_HPP)
8+
#define MQTT_ATTRIBUTES_HPP
9+
10+
#include <mqtt/namespace.hpp>
11+
12+
#ifdef _MSC_VER
13+
14+
#define MQTT_ALWAYS_INLINE
15+
16+
#else // GCC or Clang
17+
18+
#define MQTT_ALWAYS_INLINE [[gnu::always_inline]]
19+
20+
#endif // _MSC_VER
21+
22+
#endif // MQTT_ATTRIBUTES_HPP

include/mqtt/callable_overlay.hpp

+2,131
Large diffs are not rendered by default.

include/mqtt/client.hpp

+81-130
Large diffs are not rendered by default.

include/mqtt/endpoint.hpp

+313-1,190
Large diffs are not rendered by default.

include/mqtt/exception.hpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,32 @@
1919
namespace MQTT_NS {
2020

2121
struct protocol_error : std::exception {
22-
virtual char const* what() const noexcept {
22+
char const* what() const noexcept override final {
2323
return "protocol error";
2424
}
2525
};
2626

2727
struct remaining_length_error : std::exception {
28-
virtual char const* what() const noexcept {
28+
char const* what() const noexcept override final {
2929
return "remaining length error";
3030
}
3131
};
3232

3333
struct variable_length_error : std::exception {
34-
virtual char const* what() const noexcept {
34+
char const* what() const noexcept override final {
3535
return "variable length error";
3636
}
3737
};
3838

3939
struct utf8string_length_error : std::exception {
40-
virtual char const* what() const noexcept {
40+
char const* what() const noexcept override final {
4141
return "utf8string length error";
4242
}
4343
};
4444

4545
struct utf8string_contents_error : std::exception {
4646
utf8string_contents_error(utf8string::validation r):r(r) {}
47-
virtual char const* what() const noexcept {
47+
char const* what() const noexcept override final {
4848
if (r == utf8string::validation::ill_formed) {
4949
return "utf8string ill_formed";
5050
}
@@ -57,13 +57,13 @@ struct utf8string_contents_error : std::exception {
5757
};
5858

5959
struct will_message_length_error : std::exception {
60-
virtual char const* what() const noexcept {
60+
char const* what() const noexcept override final {
6161
return "will message length error";
6262
}
6363
};
6464

6565
struct password_length_error : std::exception {
66-
virtual char const* what() const noexcept {
66+
char const* what() const noexcept override final {
6767
return "password length error";
6868
}
6969
};
@@ -74,7 +74,7 @@ struct bytes_transferred_error : std::exception {
7474
ss << "bytes transferred error. expected: " << expected << " actual: " << actual;
7575
msg = ss.str();
7676
}
77-
virtual char const* what() const noexcept {
77+
char const* what() const noexcept override final {
7878
return msg.data();
7979
}
8080
std::string msg;
@@ -95,19 +95,19 @@ struct write_bytes_transferred_error : bytes_transferred_error {
9595
};
9696

9797
struct packet_id_exhausted_error : std::exception {
98-
virtual char const* what() const noexcept {
98+
char const* what() const noexcept override final {
9999
return "packet_id exhausted error";
100100
}
101101
};
102102

103103
struct property_parse_error : std::exception {
104-
virtual char const* what() const noexcept {
104+
char const* what() const noexcept override final {
105105
return "property parse error";
106106
}
107107
};
108108

109109
struct property_length_error : std::exception {
110-
virtual char const* what() const noexcept {
110+
char const* what() const noexcept override final {
111111
return "property length error";
112112
}
113113
};

include/mqtt/server.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <mqtt/endpoint.hpp>
2828
#include <mqtt/null_strand.hpp>
2929
#include <mqtt/move.hpp>
30+
#include <mqtt/callable_overlay.hpp>
3031

3132
namespace MQTT_NS {
3233

@@ -41,7 +42,7 @@ template <
4142
class server {
4243
public:
4344
using socket_t = tcp_endpoint<as::ip::tcp::socket, Strand>;
44-
using endpoint_t = endpoint<Mutex, LockGuard, PacketIdBytes>;
45+
using endpoint_t = callable_overlay<endpoint<Mutex, LockGuard, PacketIdBytes>>;
4546

4647
/**
4748
* @brief Accept handler
@@ -183,7 +184,7 @@ template <
183184
class server_tls {
184185
public:
185186
using socket_t = tcp_endpoint<as::ssl::stream<as::ip::tcp::socket>, Strand>;
186-
using endpoint_t = endpoint<Mutex, LockGuard, PacketIdBytes>;
187+
using endpoint_t = callable_overlay<endpoint<Mutex, LockGuard, PacketIdBytes>>;
187188

188189
/**
189190
* @brief Accept handler
@@ -386,7 +387,7 @@ template <
386387
class server_ws {
387388
public:
388389
using socket_t = ws_endpoint<as::ip::tcp::socket, Strand>;
389-
using endpoint_t = endpoint<Mutex, LockGuard, PacketIdBytes>;
390+
using endpoint_t = callable_overlay<endpoint<Mutex, LockGuard, PacketIdBytes>>;
390391

391392
/**
392393
* @brief Accept handler
@@ -596,7 +597,7 @@ template <
596597
class server_tls_ws {
597598
public:
598599
using socket_t = ws_endpoint<as::ssl::stream<as::ip::tcp::socket>, Strand>;
599-
using endpoint_t = endpoint<Mutex, LockGuard, PacketIdBytes>;
600+
using endpoint_t = callable_overlay<endpoint<Mutex, LockGuard, PacketIdBytes>>;
600601

601602
/**
602603
* @brief Accept handler

0 commit comments

Comments
 (0)