Yi Chou | 9d24b46 | 2020-12-04 01:12:57 +0800 | [diff] [blame] | 1 | // Copyright 2021 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef TPM2_SIMULATOR_SIMULATOR_H_ |
| 6 | #define TPM2_SIMULATOR_SIMULATOR_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | |
Yi Chou | dee22a5 | 2020-12-07 15:06:22 +0800 | [diff] [blame] | 11 | #include <base/files/file_path_watcher.h> |
Yi Chou | 9d24b46 | 2020-12-04 01:12:57 +0800 | [diff] [blame] | 12 | #include <base/files/file.h> |
| 13 | #include <brillo/daemons/daemon.h> |
| 14 | |
Yi Chou | f964bab | 2020-12-10 11:50:28 +0800 | [diff] [blame] | 15 | #include "tpm2-simulator/tpm_executor.h" |
| 16 | |
Yi Chou | 9d24b46 | 2020-12-04 01:12:57 +0800 | [diff] [blame] | 17 | namespace tpm2_simulator { |
| 18 | |
| 19 | class SimulatorDaemon final : public brillo::Daemon { |
| 20 | public: |
Yi Chou | f964bab | 2020-12-10 11:50:28 +0800 | [diff] [blame] | 21 | explicit SimulatorDaemon(TpmExecutor* tpm_executor); |
Yi Chou | 9d24b46 | 2020-12-04 01:12:57 +0800 | [diff] [blame] | 22 | SimulatorDaemon(const SimulatorDaemon&) = delete; |
| 23 | SimulatorDaemon& operator=(const SimulatorDaemon&) = delete; |
| 24 | ~SimulatorDaemon() = default; |
| 25 | |
Yi Chou | dee22a5 | 2020-12-07 15:06:22 +0800 | [diff] [blame] | 26 | inline void set_sigstop_on_initialized(bool value) { |
| 27 | sigstop_on_initialized_ = value; |
| 28 | } |
| 29 | |
Yi Chou | 9d24b46 | 2020-12-04 01:12:57 +0800 | [diff] [blame] | 30 | protected: |
| 31 | int OnInit() override; |
| 32 | void OnCommand(); |
Yi Chou | dee22a5 | 2020-12-07 15:06:22 +0800 | [diff] [blame] | 33 | void OnTpmPathChange(const base::FilePath& path, bool error); |
Yi Chou | f964bab | 2020-12-10 11:50:28 +0800 | [diff] [blame] | 34 | |
| 35 | TpmExecutor* const tpm_executor_; |
Yi Chou | dee22a5 | 2020-12-07 15:06:22 +0800 | [diff] [blame] | 36 | bool initialized_{false}; |
| 37 | bool sigstop_on_initialized_{true}; |
Yi Chou | 9d24b46 | 2020-12-04 01:12:57 +0800 | [diff] [blame] | 38 | std::string remain_request_; |
Yi Chou | dee22a5 | 2020-12-07 15:06:22 +0800 | [diff] [blame] | 39 | std::unique_ptr<base::FilePathWatcher> tpm_watcher_; |
Yi Chou | 9d24b46 | 2020-12-04 01:12:57 +0800 | [diff] [blame] | 40 | base::ScopedFD command_fd_; |
| 41 | std::unique_ptr<base::FileDescriptorWatcher::Controller> command_fd_watcher_; |
| 42 | }; |
| 43 | |
| 44 | } // namespace tpm2_simulator |
| 45 | |
| 46 | #endif // TPM2_SIMULATOR_SIMULATOR_H_ |