parent
ea73b84d2d
commit
71e0d90876
@ -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
|
@ -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
|
@ -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
|
@ -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
|
Loading…
Reference in new issue