Kagome
Polkadot Runtime Engine in C++17
app_state_manager_impl.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_APP_STATE_MANAGER
7 #define KAGOME_APP_STATE_MANAGER
8 
10 
11 #include <condition_variable>
12 #include <csignal>
13 #include <mutex>
14 #include <queue>
15 
16 #include "log/logger.hpp"
17 
18 namespace kagome::application {
19 
21  public:
23  AppStateManagerImpl(const AppStateManagerImpl &) = delete;
24  AppStateManagerImpl(AppStateManagerImpl &&) noexcept = delete;
25 
26  ~AppStateManagerImpl() override;
27 
29  AppStateManagerImpl &operator=(AppStateManagerImpl &&) noexcept = delete;
30 
31  void atPrepare(OnPrepare &&cb) override;
32  void atLaunch(OnLaunch &&cb) override;
33  void atShutdown(OnShutdown &&cb) override;
34 
35  void run() override;
36  void shutdown() override;
37 
38  State state() const override {
39  return state_;
40  }
41 
42  protected:
43  void reset();
44 
45  void doPrepare() override;
46  void doLaunch() override;
47  void doShutdown() override;
48 
49  private:
50  static std::weak_ptr<AppStateManager> wp_to_myself;
51  static void shuttingDownSignalsHandler(int);
52 
54 
55  std::atomic<State> state_ = State::Init;
56 
57  std::recursive_mutex mutex_;
58 
59  std::mutex cv_mutex_;
60  std::condition_variable cv_;
61 
62  std::queue<OnPrepare> prepare_;
63  std::queue<OnLaunch> launch_;
64  std::queue<OnShutdown> shutdown_;
65 
66  std::atomic_bool shutdown_requested_{false};
67  };
68 
69 } // namespace kagome::application
70 
71 #endif // KAGOME_APP_STATE_MANAGER
static std::weak_ptr< AppStateManager > wp_to_myself
void run() override
Start application life cycle.
AppStateManagerImpl & operator=(AppStateManagerImpl const &)=delete
State state() const override
Get current stage.
void atShutdown(OnShutdown &&cb) override
Execute.
void atPrepare(OnPrepare &&cb) override
Execute.
std::shared_ptr< soralog::Logger > Logger
Definition: logger.hpp:23
void atLaunch(OnLaunch &&cb) override
Execute.
void shutdown() override
Initiate shutting down (at any time)