Bitcoin Core  29.1.0
P2P Digital Currency
protocol.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_IPC_PROTOCOL_H
6 #define BITCOIN_IPC_PROTOCOL_H
7 
8 #include <interfaces/init.h>
9 
10 #include <functional>
11 #include <memory>
12 #include <typeindex>
13 
14 namespace ipc {
15 struct Context;
16 
21 class Protocol
22 {
23 public:
24  virtual ~Protocol() = default;
25 
35  virtual std::unique_ptr<interfaces::Init> connect(int fd, const char* exe_name) = 0;
36 
40  virtual void listen(int listen_fd, const char* exe_name, interfaces::Init& init) = 0;
41 
53  //
59  virtual void serve(int fd, const char* exe_name, interfaces::Init& init, const std::function<void()>& ready_fn = {}) = 0;
60 
63  virtual void addCleanup(std::type_index type, void* iface, std::function<void()> cleanup) = 0;
64 
66  virtual Context& context() = 0;
67 };
68 } // namespace ipc
69 
70 #endif // BITCOIN_IPC_PROTOCOL_H
virtual Context & context()=0
Context accessor.
Context struct used to give IPC protocol implementations or implementation hooks access to applicatio...
Definition: context.h:14
virtual void serve(int fd, const char *exe_name, interfaces::Init &init, const std::function< void()> &ready_fn={})=0
Handle requests on provided socket descriptor, forwarding them to the provided Init interface...
virtual ~Protocol()=default
virtual std::unique_ptr< interfaces::Init > connect(int fd, const char *exe_name)=0
Return Init interface that forwards requests over given socket descriptor.
Definition: ipc.h:12
virtual void addCleanup(std::type_index type, void *iface, std::function< void()> cleanup)=0
Add cleanup callback to interface that will run when the interface is deleted.
IPC protocol interface for calling IPC methods over sockets.
Definition: protocol.h:21
virtual void listen(int listen_fd, const char *exe_name, interfaces::Init &init)=0
Listen for connections on provided socket descriptor, accept them, and handle requests on accepted co...
Initial interface created when a process is first started, and used to give and get access to other i...
Definition: init.h:30