handler.h raw
1 // Copyright (c) 2018-present The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5 #ifndef BITCOIN_INTERFACES_HANDLER_H
6 #define BITCOIN_INTERFACES_HANDLER_H
7
8 #include <functional>
9 #include <memory>
10
11 namespace btcsignals {
12 class connection;
13 } // namespace btcsignals
14
15 namespace interfaces {
16
17 //! Generic interface for managing an event handler or callback function
18 //! registered with another interface. Has a single disconnect method to cancel
19 //! the registration and prevent any future notifications.
20 class Handler
21 {
22 public:
23 virtual ~Handler() = default;
24
25 //! Disconnect the handler.
26 virtual void disconnect() = 0;
27 };
28
29 //! Return handler wrapping a btcsignals connection.
30 std::unique_ptr<Handler> MakeSignalHandler(btcsignals::connection connection);
31
32 //! Return handler wrapping a cleanup function.
33 std::unique_ptr<Handler> MakeCleanupHandler(std::function<void()> cleanup);
34
35 } // namespace interfaces
36
37 #endif // BITCOIN_INTERFACES_HANDLER_H
38