diff options
-rw-r--r-- | src/init.cpp | 12 | ||||
-rw-r--r-- | src/interfaces/node.cpp | 22 | ||||
-rw-r--r-- | src/noui.cpp | 6 | ||||
-rw-r--r-- | src/ui_interface.cpp | 52 | ||||
-rw-r--r-- | src/ui_interface.h | 37 |
5 files changed, 95 insertions, 34 deletions
diff --git a/src/init.cpp b/src/init.cpp index 482107c06f..2131a6adc0 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -328,12 +328,12 @@ static void registerSignalHandler(int signal, void(*handler)(int)) static void OnRPCStarted() { - uiInterface.NotifyBlockTip.connect(&RPCNotifyBlockChange); + uiInterface.NotifyBlockTip_connect(&RPCNotifyBlockChange); } static void OnRPCStopped() { - uiInterface.NotifyBlockTip.disconnect(&RPCNotifyBlockChange); + uiInterface.NotifyBlockTip_disconnect(&RPCNotifyBlockChange); RPCNotifyBlockChange(false, nullptr); g_best_block_cv.notify_all(); LogPrint(BCLog::RPC, "RPC stopped.\n"); @@ -1287,7 +1287,7 @@ bool AppInitMain() */ if (gArgs.GetBoolArg("-server", false)) { - uiInterface.InitMessage.connect(SetRPCWarmupStatus); + uiInterface.InitMessage_connect(SetRPCWarmupStatus); if (!AppInitServers()) return InitError(_("Unable to start HTTP server. See debug log for details.")); } @@ -1644,13 +1644,13 @@ bool AppInitMain() // Either install a handler to notify us when genesis activates, or set fHaveGenesis directly. // No locking, as this happens before any background thread is started. if (chainActive.Tip() == nullptr) { - uiInterface.NotifyBlockTip.connect(BlockNotifyGenesisWait); + uiInterface.NotifyBlockTip_connect(BlockNotifyGenesisWait); } else { fHaveGenesis = true; } if (gArgs.IsArgSet("-blocknotify")) - uiInterface.NotifyBlockTip.connect(BlockNotifyCallback); + uiInterface.NotifyBlockTip_connect(BlockNotifyCallback); std::vector<fs::path> vImportFiles; for (const std::string& strFile : gArgs.GetArgs("-loadblock")) { @@ -1668,7 +1668,7 @@ bool AppInitMain() while (!fHaveGenesis && !ShutdownRequested()) { condvar_GenesisWait.wait_for(lock, std::chrono::milliseconds(500)); } - uiInterface.NotifyBlockTip.disconnect(BlockNotifyGenesisWait); + uiInterface.NotifyBlockTip_disconnect(BlockNotifyGenesisWait); } if (ShutdownRequested()) { diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp index 106dd38f60..1da58fe487 100644 --- a/src/interfaces/node.cpp +++ b/src/interfaces/node.cpp @@ -233,44 +233,44 @@ class NodeImpl : public Node } std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) override { - return MakeHandler(::uiInterface.InitMessage.connect(fn)); + return MakeHandler(::uiInterface.InitMessage_connect(fn)); } std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) override { - return MakeHandler(::uiInterface.ThreadSafeMessageBox.connect(fn)); + return MakeHandler(::uiInterface.ThreadSafeMessageBox_connect(fn)); } std::unique_ptr<Handler> handleQuestion(QuestionFn fn) override { - return MakeHandler(::uiInterface.ThreadSafeQuestion.connect(fn)); + return MakeHandler(::uiInterface.ThreadSafeQuestion_connect(fn)); } std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) override { - return MakeHandler(::uiInterface.ShowProgress.connect(fn)); + return MakeHandler(::uiInterface.ShowProgress_connect(fn)); } std::unique_ptr<Handler> handleLoadWallet(LoadWalletFn fn) override { CHECK_WALLET( - return MakeHandler(::uiInterface.LoadWallet.connect([fn](std::shared_ptr<CWallet> wallet) { fn(MakeWallet(wallet)); }))); + return MakeHandler(::uiInterface.LoadWallet_connect([fn](std::shared_ptr<CWallet> wallet) { fn(MakeWallet(wallet)); }))); } std::unique_ptr<Handler> handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) override { - return MakeHandler(::uiInterface.NotifyNumConnectionsChanged.connect(fn)); + return MakeHandler(::uiInterface.NotifyNumConnectionsChanged_connect(fn)); } std::unique_ptr<Handler> handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn) override { - return MakeHandler(::uiInterface.NotifyNetworkActiveChanged.connect(fn)); + return MakeHandler(::uiInterface.NotifyNetworkActiveChanged_connect(fn)); } std::unique_ptr<Handler> handleNotifyAlertChanged(NotifyAlertChangedFn fn) override { - return MakeHandler(::uiInterface.NotifyAlertChanged.connect(fn)); + return MakeHandler(::uiInterface.NotifyAlertChanged_connect(fn)); } std::unique_ptr<Handler> handleBannedListChanged(BannedListChangedFn fn) override { - return MakeHandler(::uiInterface.BannedListChanged.connect(fn)); + return MakeHandler(::uiInterface.BannedListChanged_connect(fn)); } std::unique_ptr<Handler> handleNotifyBlockTip(NotifyBlockTipFn fn) override { - return MakeHandler(::uiInterface.NotifyBlockTip.connect([fn](bool initial_download, const CBlockIndex* block) { + return MakeHandler(::uiInterface.NotifyBlockTip_connect([fn](bool initial_download, const CBlockIndex* block) { fn(initial_download, block->nHeight, block->GetBlockTime(), GuessVerificationProgress(Params().TxData(), block)); })); @@ -278,7 +278,7 @@ class NodeImpl : public Node std::unique_ptr<Handler> handleNotifyHeaderTip(NotifyHeaderTipFn fn) override { return MakeHandler( - ::uiInterface.NotifyHeaderTip.connect([fn](bool initial_download, const CBlockIndex* block) { + ::uiInterface.NotifyHeaderTip_connect([fn](bool initial_download, const CBlockIndex* block) { fn(initial_download, block->nHeight, block->GetBlockTime(), GuessVerificationProgress(Params().TxData(), block)); })); diff --git a/src/noui.cpp b/src/noui.cpp index 59eec19c2c..e6d01e7b26 100644 --- a/src/noui.cpp +++ b/src/noui.cpp @@ -52,7 +52,7 @@ static void noui_InitMessage(const std::string& message) void noui_connect() { // Connect bitcoind signal handlers - uiInterface.ThreadSafeMessageBox.connect(noui_ThreadSafeMessageBox); - uiInterface.ThreadSafeQuestion.connect(noui_ThreadSafeQuestion); - uiInterface.InitMessage.connect(noui_InitMessage); + uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox); + uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion); + uiInterface.InitMessage_connect(noui_InitMessage); } diff --git a/src/ui_interface.cpp b/src/ui_interface.cpp index 336d193b4e..22b4768059 100644 --- a/src/ui_interface.cpp +++ b/src/ui_interface.cpp @@ -5,8 +5,60 @@ #include <ui_interface.h> #include <util.h> +#include <boost/signals2/last_value.hpp> +#include <boost/signals2/signal.hpp> + CClientUIInterface uiInterface; +struct UISignals { + boost::signals2::signal<CClientUIInterface::ThreadSafeMessageBoxSig, boost::signals2::last_value<bool>> ThreadSafeMessageBox; + boost::signals2::signal<CClientUIInterface::ThreadSafeQuestionSig, boost::signals2::last_value<bool>> ThreadSafeQuestion; + boost::signals2::signal<CClientUIInterface::InitMessageSig> InitMessage; + boost::signals2::signal<CClientUIInterface::NotifyNumConnectionsChangedSig> NotifyNumConnectionsChanged; + boost::signals2::signal<CClientUIInterface::NotifyNetworkActiveChangedSig> NotifyNetworkActiveChanged; + boost::signals2::signal<CClientUIInterface::NotifyAlertChangedSig> NotifyAlertChanged; + boost::signals2::signal<CClientUIInterface::LoadWalletSig> LoadWallet; + boost::signals2::signal<CClientUIInterface::ShowProgressSig> ShowProgress; + boost::signals2::signal<CClientUIInterface::NotifyBlockTipSig> NotifyBlockTip; + boost::signals2::signal<CClientUIInterface::NotifyHeaderTipSig> NotifyHeaderTip; + boost::signals2::signal<CClientUIInterface::BannedListChangedSig> BannedListChanged; +} g_ui_signals; + +#define ADD_SIGNALS_IMPL_WRAPPER(signal_name) \ + boost::signals2::connection CClientUIInterface::signal_name##_connect(std::function<signal_name##Sig> fn) \ + { \ + return g_ui_signals.signal_name.connect(fn); \ + } \ + void CClientUIInterface::signal_name##_disconnect(std::function<signal_name##Sig> fn) \ + { \ + return g_ui_signals.signal_name.disconnect(&fn); \ + } + +ADD_SIGNALS_IMPL_WRAPPER(ThreadSafeMessageBox); +ADD_SIGNALS_IMPL_WRAPPER(ThreadSafeQuestion); +ADD_SIGNALS_IMPL_WRAPPER(InitMessage); +ADD_SIGNALS_IMPL_WRAPPER(NotifyNumConnectionsChanged); +ADD_SIGNALS_IMPL_WRAPPER(NotifyNetworkActiveChanged); +ADD_SIGNALS_IMPL_WRAPPER(NotifyAlertChanged); +ADD_SIGNALS_IMPL_WRAPPER(LoadWallet); +ADD_SIGNALS_IMPL_WRAPPER(ShowProgress); +ADD_SIGNALS_IMPL_WRAPPER(NotifyBlockTip); +ADD_SIGNALS_IMPL_WRAPPER(NotifyHeaderTip); +ADD_SIGNALS_IMPL_WRAPPER(BannedListChanged); + +bool CClientUIInterface::ThreadSafeMessageBox(const std::string& message, const std::string& caption, unsigned int style) { return g_ui_signals.ThreadSafeMessageBox(message, caption, style); } +bool CClientUIInterface::ThreadSafeQuestion(const std::string& message, const std::string& non_interactive_message, const std::string& caption, unsigned int style) { return g_ui_signals.ThreadSafeQuestion(message, non_interactive_message, caption, style); } +void CClientUIInterface::InitMessage(const std::string& message) { return g_ui_signals.InitMessage(message); } +void CClientUIInterface::NotifyNumConnectionsChanged(int newNumConnections) { return g_ui_signals.NotifyNumConnectionsChanged(newNumConnections); } +void CClientUIInterface::NotifyNetworkActiveChanged(bool networkActive) { return g_ui_signals.NotifyNetworkActiveChanged(networkActive); } +void CClientUIInterface::NotifyAlertChanged() { return g_ui_signals.NotifyAlertChanged(); } +void CClientUIInterface::LoadWallet(std::shared_ptr<CWallet> wallet) { return g_ui_signals.LoadWallet(wallet); } +void CClientUIInterface::ShowProgress(const std::string& title, int nProgress, bool resume_possible) { return g_ui_signals.ShowProgress(title, nProgress, resume_possible); } +void CClientUIInterface::NotifyBlockTip(bool b, const CBlockIndex* i) { return g_ui_signals.NotifyBlockTip(b, i); } +void CClientUIInterface::NotifyHeaderTip(bool b, const CBlockIndex* i) { return g_ui_signals.NotifyHeaderTip(b, i); } +void CClientUIInterface::BannedListChanged() { return g_ui_signals.BannedListChanged(); } + + bool InitError(const std::string& str) { uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_ERROR); diff --git a/src/ui_interface.h b/src/ui_interface.h index a570573991..992c585b10 100644 --- a/src/ui_interface.h +++ b/src/ui_interface.h @@ -6,15 +6,18 @@ #ifndef BITCOIN_UI_INTERFACE_H #define BITCOIN_UI_INTERFACE_H +#include <functional> #include <memory> #include <stdint.h> #include <string> -#include <boost/signals2/last_value.hpp> -#include <boost/signals2/signal.hpp> - class CWallet; class CBlockIndex; +namespace boost { +namespace signals2 { +class connection; +} +} // namespace boost /** General change type (added, updated, removed). */ enum ChangeType @@ -72,43 +75,49 @@ public: MSG_ERROR = (ICON_ERROR | BTN_OK | MODAL) }; +#define ADD_SIGNALS_DECL_WRAPPER(signal_name, rtype, args...) \ + rtype signal_name(args); \ + using signal_name##Sig = rtype(args); \ + boost::signals2::connection signal_name##_connect(std::function<signal_name##Sig> fn); \ + void signal_name##_disconnect(std::function<signal_name##Sig> fn); + /** Show message box. */ - boost::signals2::signal<bool (const std::string& message, const std::string& caption, unsigned int style), boost::signals2::last_value<bool> > ThreadSafeMessageBox; + ADD_SIGNALS_DECL_WRAPPER(ThreadSafeMessageBox, bool, const std::string& message, const std::string& caption, unsigned int style); /** If possible, ask the user a question. If not, falls back to ThreadSafeMessageBox(noninteractive_message, caption, style) and returns false. */ - boost::signals2::signal<bool (const std::string& message, const std::string& noninteractive_message, const std::string& caption, unsigned int style), boost::signals2::last_value<bool> > ThreadSafeQuestion; + ADD_SIGNALS_DECL_WRAPPER(ThreadSafeQuestion, bool, const std::string& message, const std::string& noninteractive_message, const std::string& caption, unsigned int style); /** Progress message during initialization. */ - boost::signals2::signal<void (const std::string &message)> InitMessage; + ADD_SIGNALS_DECL_WRAPPER(InitMessage, void, const std::string& message); /** Number of network connections changed. */ - boost::signals2::signal<void (int newNumConnections)> NotifyNumConnectionsChanged; + ADD_SIGNALS_DECL_WRAPPER(NotifyNumConnectionsChanged, void, int newNumConnections); /** Network activity state changed. */ - boost::signals2::signal<void (bool networkActive)> NotifyNetworkActiveChanged; + ADD_SIGNALS_DECL_WRAPPER(NotifyNetworkActiveChanged, void, bool networkActive); /** * Status bar alerts changed. */ - boost::signals2::signal<void ()> NotifyAlertChanged; + ADD_SIGNALS_DECL_WRAPPER(NotifyAlertChanged, void, ); /** A wallet has been loaded. */ - boost::signals2::signal<void (std::shared_ptr<CWallet> wallet)> LoadWallet; + ADD_SIGNALS_DECL_WRAPPER(LoadWallet, void, std::shared_ptr<CWallet> wallet); /** * Show progress e.g. for verifychain. * resume_possible indicates shutting down now will result in the current progress action resuming upon restart. */ - boost::signals2::signal<void (const std::string &title, int nProgress, bool resume_possible)> ShowProgress; + ADD_SIGNALS_DECL_WRAPPER(ShowProgress, void, const std::string& title, int nProgress, bool resume_possible); /** New block has been accepted */ - boost::signals2::signal<void (bool, const CBlockIndex *)> NotifyBlockTip; + ADD_SIGNALS_DECL_WRAPPER(NotifyBlockTip, void, bool, const CBlockIndex*); /** Best header has changed */ - boost::signals2::signal<void (bool, const CBlockIndex *)> NotifyHeaderTip; + ADD_SIGNALS_DECL_WRAPPER(NotifyHeaderTip, void, bool, const CBlockIndex*); /** Banlist did change. */ - boost::signals2::signal<void (void)> BannedListChanged; + ADD_SIGNALS_DECL_WRAPPER(BannedListChanged, void, void); }; /** Show warning message **/ |