aboutsummaryrefslogtreecommitdiff
path: root/src/interface
diff options
context:
space:
mode:
authorRussell Yanofsky <russ@yanofsky.org>2017-04-17 13:55:43 -0400
committerJohn Newbery <john@johnnewbery.com>2018-04-04 16:52:37 -0400
commit71e0d90876efd11e2a4aeb8f3f806c5a1fd54b42 (patch)
treeaef29169f36cb553e07ab75f27dbe87100ef0748 /src/interface
parentea73b84d2ddde22487dee0f71d7a619051e067f2 (diff)
downloadbitcoin-71e0d90876efd11e2a4aeb8f3f806c5a1fd54b42.tar.xz
Remove direct bitcoin calls from qt/bitcoin.cpp
Diffstat (limited to 'src/interface')
-rw-r--r--src/interface/handler.cpp33
-rw-r--r--src/interface/handler.h35
-rw-r--r--src/interface/node.cpp53
-rw-r--r--src/interface/node.h62
4 files changed, 183 insertions, 0 deletions
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 <interface/handler.h>
+
+#include <util.h>
+
+#include <boost/signals2/connection.hpp>
+#include <memory>
+#include <utility>
+
+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<Handler> MakeHandler(boost::signals2::connection connection)
+{
+ return MakeUnique<HandlerImpl>(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 <memory>
+
+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<Handler> 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 <interface/node.h>
+
+#include <chainparams.h>
+#include <init.h>
+#include <interface/handler.h>
+#include <scheduler.h>
+#include <ui_interface.h>
+#include <util.h>
+#include <warnings.h>
+
+#include <boost/thread/thread.hpp>
+
+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<Handler> handleInitMessage(InitMessageFn fn) override
+ {
+ return MakeHandler(::uiInterface.InitMessage.connect(fn));
+ }
+};
+
+} // namespace
+
+std::unique_ptr<Node> MakeNode() { return MakeUnique<NodeImpl>(); }
+
+} // 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 <functional>
+#include <memory>
+#include <string>
+
+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<void(const std::string& message)>;
+ virtual std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) = 0;
+};
+
+//! Return implementation of Node interface.
+std::unique_ptr<Node> MakeNode();
+
+} // namespace interface
+
+#endif // BITCOIN_INTERFACE_NODE_H