blob: 6738960f3d4059c01a8567c7dcfd9803cd54bcb2 [file] [log] [blame]
Yi Chou9d24b462020-12-04 01:12:57 +08001// 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 Choudee22a52020-12-07 15:06:22 +080011#include <base/files/file_path_watcher.h>
Yi Chou9d24b462020-12-04 01:12:57 +080012#include <base/files/file.h>
13#include <brillo/daemons/daemon.h>
14
Yi Chouf964bab2020-12-10 11:50:28 +080015#include "tpm2-simulator/tpm_executor.h"
16
Yi Chou9d24b462020-12-04 01:12:57 +080017namespace tpm2_simulator {
18
19class SimulatorDaemon final : public brillo::Daemon {
20 public:
Yi Chouf964bab2020-12-10 11:50:28 +080021 explicit SimulatorDaemon(TpmExecutor* tpm_executor);
Yi Chou9d24b462020-12-04 01:12:57 +080022 SimulatorDaemon(const SimulatorDaemon&) = delete;
23 SimulatorDaemon& operator=(const SimulatorDaemon&) = delete;
24 ~SimulatorDaemon() = default;
25
Yi Choudee22a52020-12-07 15:06:22 +080026 inline void set_sigstop_on_initialized(bool value) {
27 sigstop_on_initialized_ = value;
28 }
29
Yi Chou9d24b462020-12-04 01:12:57 +080030 protected:
31 int OnInit() override;
32 void OnCommand();
Yi Choudee22a52020-12-07 15:06:22 +080033 void OnTpmPathChange(const base::FilePath& path, bool error);
Yi Chouf964bab2020-12-10 11:50:28 +080034
35 TpmExecutor* const tpm_executor_;
Yi Choudee22a52020-12-07 15:06:22 +080036 bool initialized_{false};
37 bool sigstop_on_initialized_{true};
Yi Chou9d24b462020-12-04 01:12:57 +080038 std::string remain_request_;
Yi Choudee22a52020-12-07 15:06:22 +080039 std::unique_ptr<base::FilePathWatcher> tpm_watcher_;
Yi Chou9d24b462020-12-04 01:12:57 +080040 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_