Branch data 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_INTERFACES_INIT_H
6 : : #define BITCOIN_INTERFACES_INIT_H
7 : :
8 : : // This header is associated with several source files, and IWYU
9 : : // reaches different conclusions across them about whether these
10 : : // headers should be included or their classes forward-declared.
11 : : // Keep the includes so the result is the same for every file.
12 : : // IWYU pragma: begin_keep
13 : : #include <interfaces/chain.h>
14 : : #include <interfaces/echo.h>
15 : : #include <interfaces/mining.h>
16 : : #include <interfaces/node.h>
17 : : #include <interfaces/rpc.h>
18 : : #include <interfaces/wallet.h>
19 : : // IWYU pragma: end_keep
20 : :
21 : : #include <memory>
22 : : #include <stdexcept>
23 : :
24 : : namespace node {
25 : : struct NodeContext;
26 : : } // namespace node
27 : :
28 : : namespace interfaces {
29 : : class Ipc;
30 : :
31 : : //! Initial interface created when a process is first started, and used to give
32 : : //! and get access to other interfaces (Node, Chain, Wallet, etc).
33 : : //!
34 : : //! There is a different Init interface implementation for each process
35 : : //! (bitcoin-gui, bitcoin-node, bitcoin-wallet, bitcoind, bitcoin-qt) and each
36 : : //! implementation can implement the make methods for interfaces it supports.
37 : : //! The default make methods all return null.
38 [ + - ]: 1384 : class Init
39 : : {
40 : : public:
41 : 49 : virtual ~Init() = default;
42 : 0 : virtual std::unique_ptr<Node> makeNode() { return nullptr; }
43 : 0 : virtual std::unique_ptr<Chain> makeChain() { return nullptr; }
44 : 0 : virtual std::unique_ptr<Mining> makeMining() { return nullptr; }
45 : 0 : virtual std::unique_ptr<WalletLoader> makeWalletLoader(Chain& chain) { return nullptr; }
46 : 0 : virtual std::unique_ptr<Echo> makeEcho() { return nullptr; }
47 : 0 : virtual std::unique_ptr<Rpc> makeRpc() { return nullptr; }
48 : 2492 : virtual Ipc* ipc() { return nullptr; }
49 : 1298 : virtual bool canListenIpc() { return false; }
50 : 0 : virtual const char* exeName() { return nullptr; }
51 [ # # ]: 0 : virtual void makeMiningOld2() { throw std::runtime_error("Old mining interface (@2) not supported. Please update your client!"); }
52 : : };
53 : :
54 : : //! Return implementation of Init interface for the node process. If the argv
55 : : //! indicates that this is a child process spawned to handle requests from a
56 : : //! parent process, this blocks and handles requests, then returns null and a
57 : : //! status code to exit with. If this returns non-null, the caller can start up
58 : : //! normally and use the Init object to spawn and connect to other processes
59 : : //! while it is running.
60 : : std::unique_ptr<Init> MakeNodeInit(node::NodeContext& node, int argc, char* argv[], int& exit_status);
61 : :
62 : : //! Return implementation of Init interface for the wallet process.
63 : : std::unique_ptr<Init> MakeWalletInit(int argc, char* argv[], int& exit_status);
64 : :
65 : : //! Return implementation of Init interface for the gui process.
66 : : std::unique_ptr<Init> MakeGuiInit(int argc, char* argv[]);
67 : :
68 : : //! Return implementation of Init interface for a basic IPC client that doesn't
69 : : //! provide any IPC services itself.
70 : : //!
71 : : //! When an IPC client connects to a socket or spawns a process, it gets a pointer
72 : : //! to an Init object allowing it to create objects and threads on the remote
73 : : //! side of the IPC connection. But the client also needs to provide a local Init
74 : : //! object to allow the remote side of the connection to create objects and
75 : : //! threads on this side. This function just returns a basic Init object
76 : : //! allowing remote connections to only create local threads, not other objects
77 : : //! (because its Init::make* methods return null.)
78 : : //!
79 : : //! @param exe_name Current executable name, which is just passed to the IPC
80 : : //! system and used for logging.
81 : : //!
82 : : //! @param process_argv0 Optional string containing argv[0] value passed to
83 : : //! main(). This is passed to the IPC system and used to locate binaries by
84 : : //! relative path if subprocesses are spawned.
85 : : std::unique_ptr<Init> MakeBasicInit(const char* exe_name, const char* process_argv0="");
86 : : } // namespace interfaces
87 : :
88 : : #endif // BITCOIN_INTERFACES_INIT_H
|