1
- // Copyright (c) 2018- 2021 The Bitcoin Core developers
1
+ // Copyright (c) 2021 The Bitcoin Core developers
2
2
// Distributed under the MIT software license, see the accompanying
3
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
4
5
+ #include < interfaces/echo.h>
5
6
#include < interfaces/handler.h>
6
7
7
-
8
8
#include < boost/signals2/connection.hpp>
9
+ #include < memory>
9
10
#include < utility>
10
11
11
- namespace interfaces {
12
+ namespace common {
12
13
namespace {
14
+ class CleanupHandler : public interfaces ::Handler
15
+ {
16
+ public:
17
+ explicit CleanupHandler (std::function<void ()> cleanup) : m_cleanup(std::move(cleanup)) {}
18
+ ~CleanupHandler () override { if (!m_cleanup) return ; m_cleanup (); m_cleanup = nullptr ; }
19
+ void disconnect () override { if (!m_cleanup) return ; m_cleanup (); m_cleanup = nullptr ; }
20
+ std::function<void ()> m_cleanup;
21
+ };
13
22
14
- class HandlerImpl : public Handler
23
+ class HandlerImpl : public interfaces :: Handler
15
24
{
16
25
public:
17
26
explicit HandlerImpl (boost::signals2::connection connection) : m_connection(std::move(connection)) {}
@@ -21,25 +30,24 @@ class HandlerImpl : public Handler
21
30
boost::signals2::scoped_connection m_connection;
22
31
};
23
32
24
- class CleanupHandler : public Handler
33
+ class EchoImpl : public interfaces ::Echo
25
34
{
26
35
public:
27
- explicit CleanupHandler (std::function<void ()> cleanup) : m_cleanup(std::move(cleanup)) {}
28
- ~CleanupHandler () override { if (!m_cleanup) return ; m_cleanup (); m_cleanup = nullptr ; }
29
- void disconnect () override { if (!m_cleanup) return ; m_cleanup (); m_cleanup = nullptr ; }
30
- std::function<void ()> m_cleanup;
36
+ std::string echo (const std::string& echo) override { return echo; }
31
37
};
32
-
33
38
} // namespace
39
+ } // namespace common
34
40
35
- std::unique_ptr<Handler> MakeHandler (boost::signals2::connection connection)
41
+ namespace interfaces {
42
+ std::unique_ptr<Handler> MakeHandler (std::function<void ()> cleanup)
36
43
{
37
- return std::make_unique<HandlerImpl >(std::move (connection ));
44
+ return std::make_unique<common::CleanupHandler >(std::move (cleanup ));
38
45
}
39
46
40
- std::unique_ptr<Handler> MakeHandler (std::function< void ()> cleanup )
47
+ std::unique_ptr<Handler> MakeHandler (boost::signals2::connection connection )
41
48
{
42
- return std::make_unique<CleanupHandler >(std::move (cleanup ));
49
+ return std::make_unique<common::HandlerImpl >(std::move (connection ));
43
50
}
44
51
52
+ std::unique_ptr<Echo> MakeEcho () { return std::make_unique<common::EchoImpl>(); }
45
53
} // namespace interfaces
0 commit comments