init.h raw

   1  // Copyright (c) 2021-2022 The Limenka 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 LIMENKA_INTERFACES_INIT_H
   6  #define LIMENKA_INTERFACES_INIT_H
   7  
   8  #include <interfaces/chain.h>
   9  #include <interfaces/echo.h>
  10  #include <interfaces/mining.h>
  11  #include <interfaces/node.h>
  12  #include <interfaces/wallet.h>
  13  
  14  #include <memory>
  15  
  16  namespace node {
  17  struct NodeContext;
  18  } // namespace node
  19  
  20  namespace interfaces {
  21  class Ipc;
  22  
  23  //! Initial interface created when a process is first started, and used to give
  24  //! and get access to other interfaces (Node, Chain, Wallet, etc).
  25  //!
  26  //! There is a different Init interface implementation for each process
  27  //! (limenka-gui, limenka-node, limenka-wallet, limenkad, limenka-qt) and each
  28  //! implementation can implement the make methods for interfaces it supports.
  29  //! The default make methods all return null.
  30  class Init
  31  {
  32  public:
  33      virtual ~Init() = default;
  34      virtual std::unique_ptr<Node> makeNode() { return nullptr; }
  35      virtual std::unique_ptr<Chain> makeChain() { return nullptr; }
  36      virtual std::unique_ptr<Mining> makeMining() { return nullptr; }
  37      virtual std::unique_ptr<WalletLoader> makeWalletLoader(Chain& chain) { return nullptr; }
  38      virtual std::unique_ptr<Echo> makeEcho() { return nullptr; }
  39      virtual Ipc* ipc() { return nullptr; }
  40      virtual bool canListenIpc() { return false; }
  41  };
  42  
  43  //! Return implementation of Init interface for the node process. If the argv
  44  //! indicates that this is a child process spawned to handle requests from a
  45  //! parent process, this blocks and handles requests, then returns null and a
  46  //! status code to exit with. If this returns non-null, the caller can start up
  47  //! normally and use the Init object to spawn and connect to other processes
  48  //! while it is running.
  49  std::unique_ptr<Init> MakeNodeInit(node::NodeContext& node, int argc, char* argv[], int& exit_status);
  50  
  51  //! Return implementation of Init interface for the wallet process.
  52  std::unique_ptr<Init> MakeWalletInit(int argc, char* argv[], int& exit_status);
  53  
  54  //! Return implementation of Init interface for the gui process.
  55  std::unique_ptr<Init> MakeGuiInit(int argc, char* argv[]);
  56  } // namespace interfaces
  57  
  58  #endif // LIMENKA_INTERFACES_INIT_H
  59