Bitcoin Core 32.99.0
P2P Digital Currency
Loading...
Searching...
No Matches
ipc.h
Go to the documentation of this file.
1// Copyright (c) 2021-present 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 <ipc/types.h>
9#include <util/result.h>
10
11#include <functional>
12#include <memory>
13#include <string>
14#include <typeindex>
15#include <utility>
16
17namespace ipc {
18struct Context;
19} // namespace ipc
20
21namespace interfaces {
22class Init;
23
54class Ipc
55{
56public:
57 virtual ~Ipc() = default;
58
60 virtual std::unique_ptr<Init> spawnProcess(const char* exe_name) = 0;
61
65 virtual bool startSpawnedProcess(int argc, char* argv[], int& exit_status) = 0;
66
72 virtual std::unique_ptr<Init> connectAddress(std::string& address) = 0;
73
75 static util::Result<ipc::ListenAddress> parseListenAddress(std::string address);
76
82
84 virtual void disconnectIncoming() = 0;
85
88 template<typename Interface>
89 void addCleanup(Interface& iface, std::function<void()> cleanup)
90 {
91 addCleanup(typeid(Interface), &iface, std::move(cleanup));
92 }
93
95 virtual ipc::Context& context() = 0;
96
97protected:
100 virtual void addCleanup(std::type_index type, void* iface, std::function<void()> cleanup) = 0;
101};
102
104std::unique_ptr<Ipc> MakeIpc(const char* exe_name, const char* process_argv0, Init& init);
105} // namespace interfaces
106
107#endif // BITCOIN_INTERFACES_IPC_H
int exit_status
Definition init.h:13
Initial interface created when a process is first started, and used to give and get access to other i...
Definition init.h:39
Interface providing access to interprocess-communication (IPC) functionality.
Definition ipc.h:55
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(ipc::ListenAddress &listen_address)=0
Listen on a configured socket address exposing this process's init interface and accepting at most li...
virtual void disconnectIncoming()=0
Disconnect any incoming connections that are still connected.
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:89
static util::Result< ipc::ListenAddress > parseListenAddress(std::string address)
Parse an IPC listening address and its per-listener options.
Definition listen.cpp:29
virtual std::unique_ptr< Init > connectAddress(std::string &address)=0
Connect to a socket address and return a pointer to its Init interface.
is a home for public enum and struct type definitions that are used internally by ipc code,...
Definition basic.cpp:11
std::unique_ptr< Ipc > MakeIpc(const char *exe_name, const char *process_argv0, Init &init)
Return implementation of Ipc interface.
Definition ipc.h:17
Context struct used to give IPC protocol implementations or implementation hooks access to applicatio...
Definition context.h:15
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:82