mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-10 13:20:38 +02:00
multiprocess: Add Ipc and Init interface definitions
This commit is contained in:
parent
5d62d7f6cd
commit
745c9cebd5
@ -159,6 +159,8 @@ BITCOIN_CORE_H = \
|
||||
init/common.h \
|
||||
interfaces/chain.h \
|
||||
interfaces/handler.h \
|
||||
interfaces/init.h \
|
||||
interfaces/ipc.h \
|
||||
interfaces/node.h \
|
||||
interfaces/wallet.h \
|
||||
key.h \
|
||||
@ -559,6 +561,7 @@ libbitcoin_util_a_SOURCES = \
|
||||
compat/strnlen.cpp \
|
||||
fs.cpp \
|
||||
interfaces/handler.cpp \
|
||||
interfaces/init.cpp \
|
||||
logging.cpp \
|
||||
random.cpp \
|
||||
randomenv.cpp \
|
||||
|
15
src/interfaces/init.cpp
Normal file
15
src/interfaces/init.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
// 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/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<WalletClient> Init::makeWalletClient(Chain& chain) { return {}; }
|
||||
Ipc* Init::ipc() { return nullptr; }
|
||||
} // namespace interfaces
|
36
src/interfaces/init.h
Normal file
36
src/interfaces/init.h
Normal file
@ -0,0 +1,36 @@
|
||||
// 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.
|
||||
|
||||
#ifndef BITCOIN_INTERFACES_INIT_H
|
||||
#define BITCOIN_INTERFACES_INIT_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
struct NodeContext;
|
||||
|
||||
namespace interfaces {
|
||||
class Chain;
|
||||
class Ipc;
|
||||
class Node;
|
||||
class WalletClient;
|
||||
|
||||
//! Initial interface created when a process is first started, and used to give
|
||||
//! and get access to other interfaces (Node, Chain, Wallet, etc).
|
||||
//!
|
||||
//! There is a different Init interface implementation for each process
|
||||
//! (bitcoin-gui, bitcoin-node, bitcoin-wallet, bitcoind, bitcoin-qt) and each
|
||||
//! implementation can implement the make methods for interfaces it supports.
|
||||
//! The default make methods all return null.
|
||||
class Init
|
||||
{
|
||||
public:
|
||||
virtual ~Init() = default;
|
||||
virtual std::unique_ptr<Node> makeNode();
|
||||
virtual std::unique_ptr<Chain> makeChain();
|
||||
virtual std::unique_ptr<WalletClient> makeWalletClient(Chain& chain);
|
||||
virtual Ipc* ipc();
|
||||
};
|
||||
} // namespace interfaces
|
||||
|
||||
#endif // BITCOIN_INTERFACES_INIT_H
|
48
src/interfaces/ipc.h
Normal file
48
src/interfaces/ipc.h
Normal file
@ -0,0 +1,48 @@
|
||||
// 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.
|
||||
|
||||
#ifndef BITCOIN_INTERFACES_IPC_H
|
||||
#define BITCOIN_INTERFACES_IPC_H
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <typeindex>
|
||||
|
||||
namespace interfaces {
|
||||
class Init;
|
||||
|
||||
//! Interface providing access to interprocess-communication (IPC)
|
||||
//! functionality.
|
||||
class Ipc
|
||||
{
|
||||
public:
|
||||
virtual ~Ipc() = default;
|
||||
|
||||
//! Spawn a child process returning pointer to its Init interface.
|
||||
virtual std::unique_ptr<Init> spawnProcess(const char* exe_name) = 0;
|
||||
|
||||
//! If this is a spawned process, block and handle requests from the parent
|
||||
//! process by forwarding them to this process's Init interface, then return
|
||||
//! true. If this is not a spawned child process, return false.
|
||||
virtual bool startSpawnedProcess(int argc, char* argv[], int& exit_status) = 0;
|
||||
|
||||
//! Add cleanup callback to remote interface that will run when the
|
||||
//! interface is deleted.
|
||||
template<typename Interface>
|
||||
void addCleanup(Interface& iface, std::function<void()> cleanup)
|
||||
{
|
||||
addCleanup(typeid(Interface), &iface, std::move(cleanup));
|
||||
}
|
||||
|
||||
protected:
|
||||
//! Internal implementation of public addCleanup method (above) as a
|
||||
//! type-erased virtual function, since template functions can't be virtual.
|
||||
virtual void addCleanup(std::type_index type, void* iface, std::function<void()> cleanup) = 0;
|
||||
};
|
||||
|
||||
//! Return implementation of Ipc interface.
|
||||
std::unique_ptr<Ipc> MakeIpc(const char* exe_name, const char* process_argv0, Init& init);
|
||||
} // namespace interfaces
|
||||
|
||||
#endif // BITCOIN_INTERFACES_IPC_H
|
Loading…
x
Reference in New Issue
Block a user