-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from volbil/rabbit
Generic event handler interface
- Loading branch information
Showing
36 changed files
with
443 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
// Copyright (c) 2018-2020 The Bitcoin Core developers | ||
// Copyright (c) 2020 The PIVX Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or https://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <interfaces/handler.h> | ||
|
||
#include <util/memory.h> | ||
|
||
#include <boost/signals2/connection.hpp> | ||
#include <utility> | ||
|
||
namespace interfaces { | ||
namespace { | ||
|
||
class HandlerImpl : public Handler | ||
{ | ||
public: | ||
explicit HandlerImpl(boost::signals2::connection connection) : m_connection(std::move(connection)) {} | ||
|
||
void disconnect() override { m_connection.disconnect(); } | ||
|
||
boost::signals2::scoped_connection m_connection; | ||
}; | ||
|
||
} // namespace | ||
|
||
std::unique_ptr<Handler> MakeHandler(boost::signals2::connection connection) | ||
{ | ||
return MakeUnique<HandlerImpl>(std::move(connection)); | ||
} | ||
|
||
} // namespace interfaces |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
// Copyright (c) 2018-2020 The Bitcoin Core developers | ||
// Copyright (c) 2020 The PIVX Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or https://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef RAPIDS_INTERFACES_HANDLER_H | ||
#define RAPIDS_INTERFACES_HANDLER_H | ||
|
||
#include <memory> | ||
|
||
namespace boost { | ||
namespace signals2 { | ||
class connection; | ||
} // namespace signals2 | ||
} // namespace boost | ||
|
||
namespace interfaces { | ||
|
||
//! Generic interface for managing an event handler or callback function | ||
//! registered with another interface. Has a single disconnect method to cancel | ||
//! the registration and prevent any future notifications. | ||
class Handler | ||
{ | ||
public: | ||
virtual ~Handler() {} | ||
|
||
//! Disconnect the handler. | ||
virtual void disconnect() = 0; | ||
}; | ||
|
||
//! Return handler wrapping a boost signal connection. | ||
std::unique_ptr<Handler> MakeHandler(boost::signals2::connection connection); | ||
|
||
} // namespace interfaces | ||
|
||
#endif // RAPIDS_INTERFACES_HANDLER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.