Bitcoin Core  22.99.0
P2P Digital Currency
ipc.h
Go to the documentation of this file.
1 // Copyright (c) 2021 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_INTERFACES_IPC_H
6 #define BITCOIN_INTERFACES_IPC_H
7 
8 #include <functional>
9 #include <memory>
10 #include <typeindex>
11 
12 namespace ipc {
13 struct Context;
14 } // namespace ipc
15 
16 namespace interfaces {
17 class Init;
18 
44 class Ipc
45 {
46 public:
47  virtual ~Ipc() = default;
48 
50  virtual std::unique_ptr<Init> spawnProcess(const char* exe_name) = 0;
51 
55  virtual bool startSpawnedProcess(int argc, char* argv[], int& exit_status) = 0;
56 
59  template<typename Interface>
60  void addCleanup(Interface& iface, std::function<void()> cleanup)
61  {
62  addCleanup(typeid(Interface), &iface, std::move(cleanup));
63  }
64 
66  virtual ipc::Context& context() = 0;
67 
68 protected:
71  virtual void addCleanup(std::type_index type, void* iface, std::function<void()> cleanup) = 0;
72 };
73 
75 std::unique_ptr<Ipc> MakeIpc(const char* exe_name, const char* process_argv0, Init& init);
76 } // namespace interfaces
77 
78 #endif // BITCOIN_INTERFACES_IPC_H
interfaces
Definition: dummywallet.cpp:11
interfaces::MakeIpc
std::unique_ptr< Ipc > MakeIpc(const char *exe_name, const char *process_argv0, Init &init)
Return implementation of Ipc interface.
Definition: interfaces.cpp:74
ipc
Definition: ipc.h:12
interfaces::Ipc::addCleanup
void addCleanup(Interface &iface, std::function< void()> cleanup)
Add cleanup callback to remote interface that will run when the interface is deleted.
Definition: ipc.h:60
interfaces::Ipc::startSpawnedProcess
virtual bool startSpawnedProcess(int argc, char *argv[], int &exit_status)=0
If this is a spawned process, block and handle requests from the parent process by forwarding them to...
ipc::Context
Context struct used to give IPC protocol implementations or implementation hooks access to applicatio...
Definition: context.h:14
interfaces::Ipc::context
virtual ipc::Context & context()=0
IPC context struct accessor (see struct definition for more description).
init
Definition: bitcoin-node.cpp:16
interfaces::Ipc::spawnProcess
virtual std::unique_ptr< Init > spawnProcess(const char *exe_name)=0
Spawn a child process returning pointer to its Init interface.
interfaces::Ipc::~Ipc
virtual ~Ipc()=default
interfaces::Ipc
Interface providing access to interprocess-communication (IPC) functionality.
Definition: ipc.h:44