From 71e0d90876efd11e2a4aeb8f3f806c5a1fd54b42 Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Mon, 17 Apr 2017 13:55:43 -0400 Subject: Remove direct bitcoin calls from qt/bitcoin.cpp --- src/interface/handler.cpp | 33 +++++++++++++++++++++++++ src/interface/handler.h | 35 ++++++++++++++++++++++++++ src/interface/node.cpp | 53 ++++++++++++++++++++++++++++++++++++++++ src/interface/node.h | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 183 insertions(+) create mode 100644 src/interface/handler.cpp create mode 100644 src/interface/handler.h create mode 100644 src/interface/node.cpp create mode 100644 src/interface/node.h (limited to 'src/interface') diff --git a/src/interface/handler.cpp b/src/interface/handler.cpp new file mode 100644 index 0000000000..4b27f374f4 --- /dev/null +++ b/src/interface/handler.cpp @@ -0,0 +1,33 @@ +// Copyright (c) 2018 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include + +#include + +#include +#include +#include + +namespace interface { +namespace { + +class HandlerImpl : public Handler +{ +public: + 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 MakeHandler(boost::signals2::connection connection) +{ + return MakeUnique(std::move(connection)); +} + +} // namespace interface diff --git a/src/interface/handler.h b/src/interface/handler.h new file mode 100644 index 0000000000..a76334bfbf --- /dev/null +++ b/src/interface/handler.h @@ -0,0 +1,35 @@ +// Copyright (c) 2018 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_INTERFACE_HANDLER_H +#define BITCOIN_INTERFACE_HANDLER_H + +#include + +namespace boost { +namespace signals2 { +class connection; +} // namespace signals2 +} // namespace boost + +namespace interface { + +//! 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 MakeHandler(boost::signals2::connection connection); + +} // namespace interface + +#endif // BITCOIN_INTERFACE_HANDLER_H diff --git a/src/interface/node.cpp b/src/interface/node.cpp new file mode 100644 index 0000000000..4e3fa6ceb9 --- /dev/null +++ b/src/interface/node.cpp @@ -0,0 +1,53 @@ +// Copyright (c) 2018 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace interface { +namespace { + +class NodeImpl : public Node +{ + void parseParameters(int argc, const char* const argv[]) override + { + gArgs.ParseParameters(argc, argv); + } + void readConfigFile(const std::string& conf_path) override { gArgs.ReadConfigFile(conf_path); } + void selectParams(const std::string& network) override { SelectParams(network); } + void initLogging() override { InitLogging(); } + void initParameterInteraction() override { InitParameterInteraction(); } + std::string getWarnings(const std::string& type) override { return GetWarnings(type); } + bool baseInitialize() override + { + return AppInitBasicSetup() && AppInitParameterInteraction() && AppInitSanityChecks() && + AppInitLockDataDirectory(); + } + bool appInitMain() override { return AppInitMain(); } + void appShutdown() override + { + Interrupt(); + Shutdown(); + } + void startShutdown() override { StartShutdown(); } + std::unique_ptr handleInitMessage(InitMessageFn fn) override + { + return MakeHandler(::uiInterface.InitMessage.connect(fn)); + } +}; + +} // namespace + +std::unique_ptr MakeNode() { return MakeUnique(); } + +} // namespace interface diff --git a/src/interface/node.h b/src/interface/node.h new file mode 100644 index 0000000000..b69ef160a3 --- /dev/null +++ b/src/interface/node.h @@ -0,0 +1,62 @@ +// Copyright (c) 2018 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_INTERFACE_NODE_H +#define BITCOIN_INTERFACE_NODE_H + +#include +#include +#include + +namespace interface { + +class Handler; + +//! Top-level interface for a bitcoin node (bitcoind process). +class Node +{ +public: + virtual ~Node() {} + + //! Set command line arguments. + virtual void parseParameters(int argc, const char* const argv[]) = 0; + + //! Load settings from configuration file. + virtual void readConfigFile(const std::string& conf_path) = 0; + + //! Choose network parameters. + virtual void selectParams(const std::string& network) = 0; + + //! Init logging. + virtual void initLogging() = 0; + + //! Init parameter interaction. + virtual void initParameterInteraction() = 0; + + //! Get warnings. + virtual std::string getWarnings(const std::string& type) = 0; + + //! Initialize app dependencies. + virtual bool baseInitialize() = 0; + + //! Start node. + virtual bool appInitMain() = 0; + + //! Stop node. + virtual void appShutdown() = 0; + + //! Start shutdown. + virtual void startShutdown() = 0; + + //! Register handler for init messages. + using InitMessageFn = std::function; + virtual std::unique_ptr handleInitMessage(InitMessageFn fn) = 0; +}; + +//! Return implementation of Node interface. +std::unique_ptr MakeNode(); + +} // namespace interface + +#endif // BITCOIN_INTERFACE_NODE_H -- cgit v1.2.3