Bitcoin Core 28.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
12namespace ipc {
13struct Context;
14} // namespace ipc
15
16namespace interfaces {
17class Init;
18
49class Ipc
50{
51public:
52 virtual ~Ipc() = default;
53
55 virtual std::unique_ptr<Init> spawnProcess(const char* exe_name) = 0;
56
60 virtual bool startSpawnedProcess(int argc, char* argv[], int& exit_status) = 0;
61
67 virtual std::unique_ptr<Init> connectAddress(std::string& address) = 0;
68
71 virtual void listenAddress(std::string& address) = 0;
72
75 template<typename Interface>
76 void addCleanup(Interface& iface, std::function<void()> cleanup)
77 {
78 addCleanup(typeid(Interface), &iface, std::move(cleanup));
79 }
80
82 virtual ipc::Context& context() = 0;
83
84protected:
87 virtual void addCleanup(std::type_index type, void* iface, std::function<void()> cleanup) = 0;
88};
89
91std::unique_ptr<Ipc> MakeIpc(const char* exe_name, const char* process_argv0, Init& init);
92} // namespace interfaces
93
94#endif // BITCOIN_INTERFACES_IPC_H
int exit_status
Initial interface created when a process is first started, and used to give and get access to other i...
Definition: init.h:31
Interface providing access to interprocess-communication (IPC) functionality.
Definition: ipc.h:50
virtual ipc::Context & context()=0
IPC context struct accessor (see struct definition for more description).
virtual std::unique_ptr< Init > spawnProcess(const char *exe_name)=0
Spawn a child process returning pointer to its Init interface.
virtual void listenAddress(std::string &address)=0
Connect to a socket address and make a client interface proxy object using provided callback.
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...
virtual ~Ipc()=default
virtual void addCleanup(std::type_index type, void *iface, std::function< void()> cleanup)=0
Internal implementation of public addCleanup method (above) as a type-erased virtual function,...
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:76
virtual std::unique_ptr< Init > connectAddress(std::string &address)=0
Connect to a socket address and make a client interface proxy object using provided callback.
std::unique_ptr< Ipc > MakeIpc(const char *exe_name, const char *process_argv0, Init &init)
Return implementation of Ipc interface.
Definition: interfaces.cpp:104
Definition: ipc.h:12
Context struct used to give IPC protocol implementations or implementation hooks access to applicatio...
Definition: context.h:15