Line data Source code
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_IPC_PROCESS_H
6 : #define BITCOIN_IPC_PROCESS_H
7 :
8 : #include <util/fs.h>
9 :
10 : #include <memory>
11 : #include <ipc/util.h>
12 : #include <string>
13 :
14 : namespace ipc {
15 : class Protocol;
16 :
17 : //! IPC process interface for spawning bitcoin processes and serving requests
18 : //! in processes that have been spawned.
19 : //!
20 : //! There will be different implementations of this interface depending on the
21 : //! platform (e.g. unix, windows).
22 2 : class Process
23 : {
24 : public:
25 : virtual ~Process() = default;
26 :
27 : //! Spawn process and return socket id for communicating with it.
28 : virtual std::tuple<mp::ProcessId, mp::SocketId> spawn(const std::string& new_exe_name, const fs::path& argv0_path) = 0;
29 :
30 : //! Wait for spawned process to exit and return its exit code.
31 : virtual int waitSpawned(mp::ProcessId pid) = 0;
32 :
33 : //! Parse command line and determine if current process is a spawned child
34 : //! process. If so, return true and a socket id for communicating
35 : //! with the parent process.
36 : virtual bool checkSpawned(int argc, char* argv[], mp::SocketId& socket) = 0;
37 :
38 : //! Canonicalize and connect to address, returning socket id.
39 : virtual mp::SocketId connect(const fs::path& data_dir,
40 : const std::string& dest_exe_name,
41 : std::string& address) = 0;
42 :
43 : //! Create listening socket, bind and canonicalize address, and return socket id.
44 : virtual mp::SocketId bind(const fs::path& data_dir,
45 : const std::string& exe_name,
46 : std::string& address) = 0;
47 : };
48 :
49 : //! Constructor for Process interface. Implementation will vary depending on
50 : //! the platform (unix or windows).
51 : std::unique_ptr<Process> MakeProcess();
52 : } // namespace ipc
53 :
54 : #endif // BITCOIN_IPC_PROCESS_H
|