refactor: Rename ambiguous interfaces::MakeHandler functions

This commit is contained in:
Ryan Ofsky 2022-10-12 10:42:38 -04:00
parent dd6e8bd71c
commit b19c4124b3
5 changed files with 28 additions and 28 deletions

View file

@ -20,10 +20,10 @@ public:
std::function<void()> m_cleanup; std::function<void()> m_cleanup;
}; };
class HandlerImpl : public interfaces::Handler class SignalHandler : public interfaces::Handler
{ {
public: public:
explicit HandlerImpl(boost::signals2::connection connection) : m_connection(std::move(connection)) {} explicit SignalHandler(boost::signals2::connection connection) : m_connection(std::move(connection)) {}
void disconnect() override { m_connection.disconnect(); } void disconnect() override { m_connection.disconnect(); }
@ -39,14 +39,14 @@ public:
} // namespace common } // namespace common
namespace interfaces { namespace interfaces {
std::unique_ptr<Handler> MakeHandler(std::function<void()> cleanup) std::unique_ptr<Handler> MakeCleanupHandler(std::function<void()> cleanup)
{ {
return std::make_unique<common::CleanupHandler>(std::move(cleanup)); return std::make_unique<common::CleanupHandler>(std::move(cleanup));
} }
std::unique_ptr<Handler> MakeHandler(boost::signals2::connection connection) std::unique_ptr<Handler> MakeSignalHandler(boost::signals2::connection connection)
{ {
return std::make_unique<common::HandlerImpl>(std::move(connection)); return std::make_unique<common::SignalHandler>(std::move(connection));
} }
std::unique_ptr<Echo> MakeEcho() { return std::make_unique<common::EchoImpl>(); } std::unique_ptr<Echo> MakeEcho() { return std::make_unique<common::EchoImpl>(); }

View file

@ -29,10 +29,10 @@ public:
}; };
//! Return handler wrapping a boost signal connection. //! Return handler wrapping a boost signal connection.
std::unique_ptr<Handler> MakeHandler(boost::signals2::connection connection); std::unique_ptr<Handler> MakeSignalHandler(boost::signals2::connection connection);
//! Return handler wrapping a cleanup function. //! Return handler wrapping a cleanup function.
std::unique_ptr<Handler> MakeHandler(std::function<void()> cleanup); std::unique_ptr<Handler> MakeCleanupHandler(std::function<void()> cleanup);
} // namespace interfaces } // namespace interfaces

View file

@ -64,7 +64,7 @@ using interfaces::BlockTip;
using interfaces::Chain; using interfaces::Chain;
using interfaces::FoundBlock; using interfaces::FoundBlock;
using interfaces::Handler; using interfaces::Handler;
using interfaces::MakeHandler; using interfaces::MakeSignalHandler;
using interfaces::Node; using interfaces::Node;
using interfaces::WalletLoader; using interfaces::WalletLoader;
@ -336,50 +336,50 @@ public:
} }
std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) override std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) override
{ {
return MakeHandler(::uiInterface.InitMessage_connect(fn)); return MakeSignalHandler(::uiInterface.InitMessage_connect(fn));
} }
std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) override std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) override
{ {
return MakeHandler(::uiInterface.ThreadSafeMessageBox_connect(fn)); return MakeSignalHandler(::uiInterface.ThreadSafeMessageBox_connect(fn));
} }
std::unique_ptr<Handler> handleQuestion(QuestionFn fn) override std::unique_ptr<Handler> handleQuestion(QuestionFn fn) override
{ {
return MakeHandler(::uiInterface.ThreadSafeQuestion_connect(fn)); return MakeSignalHandler(::uiInterface.ThreadSafeQuestion_connect(fn));
} }
std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) override std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) override
{ {
return MakeHandler(::uiInterface.ShowProgress_connect(fn)); return MakeSignalHandler(::uiInterface.ShowProgress_connect(fn));
} }
std::unique_ptr<Handler> handleInitWallet(InitWalletFn fn) override std::unique_ptr<Handler> handleInitWallet(InitWalletFn fn) override
{ {
return MakeHandler(::uiInterface.InitWallet_connect(fn)); return MakeSignalHandler(::uiInterface.InitWallet_connect(fn));
} }
std::unique_ptr<Handler> handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) override std::unique_ptr<Handler> handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) override
{ {
return MakeHandler(::uiInterface.NotifyNumConnectionsChanged_connect(fn)); return MakeSignalHandler(::uiInterface.NotifyNumConnectionsChanged_connect(fn));
} }
std::unique_ptr<Handler> handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn) override std::unique_ptr<Handler> handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn) override
{ {
return MakeHandler(::uiInterface.NotifyNetworkActiveChanged_connect(fn)); return MakeSignalHandler(::uiInterface.NotifyNetworkActiveChanged_connect(fn));
} }
std::unique_ptr<Handler> handleNotifyAlertChanged(NotifyAlertChangedFn fn) override std::unique_ptr<Handler> handleNotifyAlertChanged(NotifyAlertChangedFn fn) override
{ {
return MakeHandler(::uiInterface.NotifyAlertChanged_connect(fn)); return MakeSignalHandler(::uiInterface.NotifyAlertChanged_connect(fn));
} }
std::unique_ptr<Handler> handleBannedListChanged(BannedListChangedFn fn) override std::unique_ptr<Handler> handleBannedListChanged(BannedListChangedFn fn) override
{ {
return MakeHandler(::uiInterface.BannedListChanged_connect(fn)); return MakeSignalHandler(::uiInterface.BannedListChanged_connect(fn));
} }
std::unique_ptr<Handler> handleNotifyBlockTip(NotifyBlockTipFn fn) override std::unique_ptr<Handler> handleNotifyBlockTip(NotifyBlockTipFn fn) override
{ {
return MakeHandler(::uiInterface.NotifyBlockTip_connect([fn](SynchronizationState sync_state, const CBlockIndex* block) { return MakeSignalHandler(::uiInterface.NotifyBlockTip_connect([fn](SynchronizationState sync_state, const CBlockIndex* block) {
fn(sync_state, BlockTip{block->nHeight, block->GetBlockTime(), block->GetBlockHash()}, fn(sync_state, BlockTip{block->nHeight, block->GetBlockTime(), block->GetBlockHash()},
GuessVerificationProgress(Params().TxData(), block)); GuessVerificationProgress(Params().TxData(), block));
})); }));
} }
std::unique_ptr<Handler> handleNotifyHeaderTip(NotifyHeaderTipFn fn) override std::unique_ptr<Handler> handleNotifyHeaderTip(NotifyHeaderTipFn fn) override
{ {
return MakeHandler( return MakeSignalHandler(
::uiInterface.NotifyHeaderTip_connect([fn](SynchronizationState sync_state, int64_t height, int64_t timestamp, bool presync) { ::uiInterface.NotifyHeaderTip_connect([fn](SynchronizationState sync_state, int64_t height, int64_t timestamp, bool presync) {
fn(sync_state, BlockTip{(int)height, timestamp, uint256{}}, presync); fn(sync_state, BlockTip{(int)height, timestamp, uint256{}}, presync);
})); }));

View file

@ -36,7 +36,7 @@
using interfaces::Chain; using interfaces::Chain;
using interfaces::FoundBlock; using interfaces::FoundBlock;
using interfaces::Handler; using interfaces::Handler;
using interfaces::MakeHandler; using interfaces::MakeSignalHandler;
using interfaces::Wallet; using interfaces::Wallet;
using interfaces::WalletAddress; using interfaces::WalletAddress;
using interfaces::WalletBalances; using interfaces::WalletBalances;
@ -486,34 +486,34 @@ public:
bool isLegacy() override { return m_wallet->IsLegacy(); } bool isLegacy() override { return m_wallet->IsLegacy(); }
std::unique_ptr<Handler> handleUnload(UnloadFn fn) override std::unique_ptr<Handler> handleUnload(UnloadFn fn) override
{ {
return MakeHandler(m_wallet->NotifyUnload.connect(fn)); return MakeSignalHandler(m_wallet->NotifyUnload.connect(fn));
} }
std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) override std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) override
{ {
return MakeHandler(m_wallet->ShowProgress.connect(fn)); return MakeSignalHandler(m_wallet->ShowProgress.connect(fn));
} }
std::unique_ptr<Handler> handleStatusChanged(StatusChangedFn fn) override std::unique_ptr<Handler> handleStatusChanged(StatusChangedFn fn) override
{ {
return MakeHandler(m_wallet->NotifyStatusChanged.connect([fn](CWallet*) { fn(); })); return MakeSignalHandler(m_wallet->NotifyStatusChanged.connect([fn](CWallet*) { fn(); }));
} }
std::unique_ptr<Handler> handleAddressBookChanged(AddressBookChangedFn fn) override std::unique_ptr<Handler> handleAddressBookChanged(AddressBookChangedFn fn) override
{ {
return MakeHandler(m_wallet->NotifyAddressBookChanged.connect( return MakeSignalHandler(m_wallet->NotifyAddressBookChanged.connect(
[fn](const CTxDestination& address, const std::string& label, bool is_mine, [fn](const CTxDestination& address, const std::string& label, bool is_mine,
const std::string& purpose, ChangeType status) { fn(address, label, is_mine, purpose, status); })); const std::string& purpose, ChangeType status) { fn(address, label, is_mine, purpose, status); }));
} }
std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn) override std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn) override
{ {
return MakeHandler(m_wallet->NotifyTransactionChanged.connect( return MakeSignalHandler(m_wallet->NotifyTransactionChanged.connect(
[fn](const uint256& txid, ChangeType status) { fn(txid, status); })); [fn](const uint256& txid, ChangeType status) { fn(txid, status); }));
} }
std::unique_ptr<Handler> handleWatchOnlyChanged(WatchOnlyChangedFn fn) override std::unique_ptr<Handler> handleWatchOnlyChanged(WatchOnlyChangedFn fn) override
{ {
return MakeHandler(m_wallet->NotifyWatchonlyChanged.connect(fn)); return MakeSignalHandler(m_wallet->NotifyWatchonlyChanged.connect(fn));
} }
std::unique_ptr<Handler> handleCanGetAddressesChanged(CanGetAddressesChangedFn fn) override std::unique_ptr<Handler> handleCanGetAddressesChanged(CanGetAddressesChangedFn fn) override
{ {
return MakeHandler(m_wallet->NotifyCanGetAddressesChanged.connect(fn)); return MakeSignalHandler(m_wallet->NotifyCanGetAddressesChanged.connect(fn));
} }
CWallet* wallet() override { return m_wallet.get(); } CWallet* wallet() override { return m_wallet.get(); }

View file

@ -171,7 +171,7 @@ std::unique_ptr<interfaces::Handler> HandleLoadWallet(WalletContext& context, Lo
{ {
LOCK(context.wallets_mutex); LOCK(context.wallets_mutex);
auto it = context.wallet_load_fns.emplace(context.wallet_load_fns.end(), std::move(load_wallet)); auto it = context.wallet_load_fns.emplace(context.wallet_load_fns.end(), std::move(load_wallet));
return interfaces::MakeHandler([&context, it] { LOCK(context.wallets_mutex); context.wallet_load_fns.erase(it); }); return interfaces::MakeCleanupHandler([&context, it] { LOCK(context.wallets_mutex); context.wallet_load_fns.erase(it); });
} }
void NotifyWalletLoaded(WalletContext& context, const std::shared_ptr<CWallet>& wallet) void NotifyWalletLoaded(WalletContext& context, const std::shared_ptr<CWallet>& wallet)