mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-11 20:32:35 -03:00
refactor: Move src/interfaces/*.cpp files to libbitcoin_common.a
These belong in libbitcoin_common.a, not libbitcoin_util.a, because they aren't general-purpose utilities, they just contain common code that is used by both the node and the wallet. Another reason to reason to not include these in libbitcoin_util.a is to prevent them from being used by the kernel library.
This commit is contained in:
parent
a035b6a0c4
commit
82e272a109
5 changed files with 35 additions and 63 deletions
|
@ -633,6 +633,7 @@ libbitcoin_common_a_SOURCES = \
|
||||||
chainparams.cpp \
|
chainparams.cpp \
|
||||||
coins.cpp \
|
coins.cpp \
|
||||||
common/bloom.cpp \
|
common/bloom.cpp \
|
||||||
|
common/interfaces.cpp \
|
||||||
common/run_command.cpp \
|
common/run_command.cpp \
|
||||||
compressor.cpp \
|
compressor.cpp \
|
||||||
core_read.cpp \
|
core_read.cpp \
|
||||||
|
@ -678,9 +679,6 @@ libbitcoin_util_a_SOURCES = \
|
||||||
chainparamsbase.cpp \
|
chainparamsbase.cpp \
|
||||||
clientversion.cpp \
|
clientversion.cpp \
|
||||||
fs.cpp \
|
fs.cpp \
|
||||||
interfaces/echo.cpp \
|
|
||||||
interfaces/handler.cpp \
|
|
||||||
interfaces/init.cpp \
|
|
||||||
logging.cpp \
|
logging.cpp \
|
||||||
random.cpp \
|
random.cpp \
|
||||||
randomenv.cpp \
|
randomenv.cpp \
|
||||||
|
|
|
@ -1,17 +1,26 @@
|
||||||
// Copyright (c) 2018-2021 The Bitcoin Core developers
|
// Copyright (c) 2021 The Bitcoin Core developers
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#include <interfaces/echo.h>
|
||||||
#include <interfaces/handler.h>
|
#include <interfaces/handler.h>
|
||||||
|
|
||||||
|
|
||||||
#include <boost/signals2/connection.hpp>
|
#include <boost/signals2/connection.hpp>
|
||||||
|
#include <memory>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace interfaces {
|
namespace common {
|
||||||
namespace {
|
namespace {
|
||||||
|
class CleanupHandler : public interfaces::Handler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit CleanupHandler(std::function<void()> cleanup) : m_cleanup(std::move(cleanup)) {}
|
||||||
|
~CleanupHandler() override { if (!m_cleanup) return; m_cleanup(); m_cleanup = nullptr; }
|
||||||
|
void disconnect() override { if (!m_cleanup) return; m_cleanup(); m_cleanup = nullptr; }
|
||||||
|
std::function<void()> m_cleanup;
|
||||||
|
};
|
||||||
|
|
||||||
class HandlerImpl : public Handler
|
class HandlerImpl : public interfaces::Handler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit HandlerImpl(boost::signals2::connection connection) : m_connection(std::move(connection)) {}
|
explicit HandlerImpl(boost::signals2::connection connection) : m_connection(std::move(connection)) {}
|
||||||
|
@ -21,25 +30,24 @@ public:
|
||||||
boost::signals2::scoped_connection m_connection;
|
boost::signals2::scoped_connection m_connection;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CleanupHandler : public Handler
|
class EchoImpl : public interfaces::Echo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit CleanupHandler(std::function<void()> cleanup) : m_cleanup(std::move(cleanup)) {}
|
std::string echo(const std::string& echo) override { return echo; }
|
||||||
~CleanupHandler() override { if (!m_cleanup) return; m_cleanup(); m_cleanup = nullptr; }
|
|
||||||
void disconnect() override { if (!m_cleanup) return; m_cleanup(); m_cleanup = nullptr; }
|
|
||||||
std::function<void()> m_cleanup;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
} // namespace common
|
||||||
|
|
||||||
|
namespace interfaces {
|
||||||
|
std::unique_ptr<Handler> MakeHandler(std::function<void()> cleanup)
|
||||||
|
{
|
||||||
|
return std::make_unique<common::CleanupHandler>(std::move(cleanup));
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<Handler> MakeHandler(boost::signals2::connection connection)
|
std::unique_ptr<Handler> MakeHandler(boost::signals2::connection connection)
|
||||||
{
|
{
|
||||||
return std::make_unique<HandlerImpl>(std::move(connection));
|
return std::make_unique<common::HandlerImpl>(std::move(connection));
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<Handler> MakeHandler(std::function<void()> cleanup)
|
|
||||||
{
|
|
||||||
return std::make_unique<CleanupHandler>(std::move(cleanup));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<Echo> MakeEcho() { return std::make_unique<common::EchoImpl>(); }
|
||||||
} // namespace interfaces
|
} // namespace interfaces
|
|
@ -1,18 +0,0 @@
|
||||||
// Copyright (c) 2021 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 <interfaces/echo.h>
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace interfaces {
|
|
||||||
namespace {
|
|
||||||
class EchoImpl : public Echo
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
std::string echo(const std::string& echo) override { return echo; }
|
|
||||||
};
|
|
||||||
} // namespace
|
|
||||||
std::unique_ptr<Echo> MakeEcho() { return std::make_unique<EchoImpl>(); }
|
|
||||||
} // namespace interfaces
|
|
|
@ -1,17 +0,0 @@
|
||||||
// Copyright (c) 2021 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 <interfaces/chain.h>
|
|
||||||
#include <interfaces/echo.h>
|
|
||||||
#include <interfaces/init.h>
|
|
||||||
#include <interfaces/node.h>
|
|
||||||
#include <interfaces/wallet.h>
|
|
||||||
|
|
||||||
namespace interfaces {
|
|
||||||
std::unique_ptr<Node> Init::makeNode() { return {}; }
|
|
||||||
std::unique_ptr<Chain> Init::makeChain() { return {}; }
|
|
||||||
std::unique_ptr<WalletLoader> Init::makeWalletLoader(Chain& chain) { return {}; }
|
|
||||||
std::unique_ptr<Echo> Init::makeEcho() { return {}; }
|
|
||||||
Ipc* Init::ipc() { return nullptr; }
|
|
||||||
} // namespace interfaces
|
|
|
@ -5,6 +5,11 @@
|
||||||
#ifndef BITCOIN_INTERFACES_INIT_H
|
#ifndef BITCOIN_INTERFACES_INIT_H
|
||||||
#define BITCOIN_INTERFACES_INIT_H
|
#define BITCOIN_INTERFACES_INIT_H
|
||||||
|
|
||||||
|
#include <interfaces/chain.h>
|
||||||
|
#include <interfaces/echo.h>
|
||||||
|
#include <interfaces/node.h>
|
||||||
|
#include <interfaces/wallet.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace node {
|
namespace node {
|
||||||
|
@ -12,11 +17,7 @@ struct NodeContext;
|
||||||
} // namespace node
|
} // namespace node
|
||||||
|
|
||||||
namespace interfaces {
|
namespace interfaces {
|
||||||
class Chain;
|
|
||||||
class Echo;
|
|
||||||
class Ipc;
|
class Ipc;
|
||||||
class Node;
|
|
||||||
class WalletLoader;
|
|
||||||
|
|
||||||
//! Initial interface created when a process is first started, and used to give
|
//! Initial interface created when a process is first started, and used to give
|
||||||
//! and get access to other interfaces (Node, Chain, Wallet, etc).
|
//! and get access to other interfaces (Node, Chain, Wallet, etc).
|
||||||
|
@ -29,11 +30,11 @@ class Init
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~Init() = default;
|
virtual ~Init() = default;
|
||||||
virtual std::unique_ptr<Node> makeNode();
|
virtual std::unique_ptr<Node> makeNode() { return nullptr; }
|
||||||
virtual std::unique_ptr<Chain> makeChain();
|
virtual std::unique_ptr<Chain> makeChain() { return nullptr; }
|
||||||
virtual std::unique_ptr<WalletLoader> makeWalletLoader(Chain& chain);
|
virtual std::unique_ptr<WalletLoader> makeWalletLoader(Chain& chain) { return nullptr; }
|
||||||
virtual std::unique_ptr<Echo> makeEcho();
|
virtual std::unique_ptr<Echo> makeEcho() { return nullptr; }
|
||||||
virtual Ipc* ipc();
|
virtual Ipc* ipc() { return nullptr; }
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Return implementation of Init interface for the node process. If the argv
|
//! Return implementation of Init interface for the node process. If the argv
|
||||||
|
|
Loading…
Reference in a new issue