forked from dashpay/dash
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
multiprocess: Add Ipc and Init interface definitions
- Loading branch information
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |