| 44 | }; |
| 45 | |
| 46 | class Daemon : public IDaemon |
| 47 | { |
| 48 | private: |
| 49 | enum class MessageType |
| 50 | { |
| 51 | Init = 0, |
| 52 | Exception, |
| 53 | Exit, |
| 54 | Reload |
| 55 | }; |
| 56 | |
| 57 | struct Message |
| 58 | { |
| 59 | MessageType m_type; |
| 60 | std::variant< |
| 61 | std::nullopt_t, |
| 62 | const std::vector<std::wstring>*, |
| 63 | std::exception_ptr> m_arg; |
| 64 | }; |
| 65 | |
| 66 | std::mutex m_queueLock; |
| 67 | std::condition_variable m_queueCV; |
| 68 | std::queue<Message> m_msgQueue; |
| 69 | |
| 70 | struct Service |
| 71 | { |
| 72 | std::unique_ptr<SystemTray> m_systemTray; |
| 73 | std::unique_ptr<QueryService> m_queryService; |
| 74 | std::unique_ptr<RpcServer> m_rpcServer; |
| 75 | std::unique_ptr<ProcessMonitor> m_processMonitor; |
| 76 | std::unique_ptr<Prefetch> m_prefetch; |
| 77 | }; |
| 78 | |
| 79 | std::unique_ptr<Service> m_service; |
| 80 | |
| 81 | void NotifyException(std::exception_ptr exception) override |
| 82 | { |
| 83 | std::unique_lock ul(m_queueLock); |
| 84 | m_msgQueue.emplace(MessageType::Exception, exception); |
| 85 | m_queueCV.notify_one(); |
| 86 | } |
| 87 | |
| 88 | void NotifyExit() override |
| 89 | { |
| 90 | std::unique_lock ul(m_queueLock); |
| 91 | m_msgQueue.emplace(MessageType::Exit, std::nullopt); |
| 92 | m_queueCV.notify_one(); |
| 93 | } |
| 94 | |
| 95 | void NotifyReload() override |
| 96 | { |
| 97 | std::unique_lock ul(m_queueLock); |
| 98 | m_msgQueue.emplace(MessageType::Reload, std::nullopt); |
| 99 | m_queueCV.notify_one(); |
| 100 | } |
| 101 | |
| 102 | public: |
| 103 | int DaemonMain(const std::vector<std::wstring>& cmdline) |