Android-cuttlefish cvd tool
server_loop_impl.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <atomic>
20#include <ostream>
21#include <string>
22#include <string_view>
23#include <unordered_map>
24#include <unordered_set>
25#include <vector>
26
27#include "fruit/fruit.h"
28
42
43namespace cuttlefish {
44namespace run_cvd_impl {
45
47 public SetupFeature,
48 public LateInjected {
49 public:
52 AutoSnapshotControlFiles::Type& snapshot_control_files,
53 WebRtcController& webrtc_controller));
54
55 Result<void> LateInject(fruit::Injector<>& injector) override;
56
57 // ServerLoop
58 Result<void> Run() override;
59
60 // SetupFeature
61 std::string Name() const override { return "ServerLoop"; }
62
63 enum class DeviceStatus : int {
64 kUnknown = 0,
65 kActive = 1,
66 kSuspended = 2,
67 kGuestOff = 3,
68 };
69
70 private:
71 std::unordered_set<SetupFeature*> Dependencies() const override {
73 }
74 Result<void> ResultSetup() override;
76 ProcessMonitor& process_monitor);
79 Result<void> HandleSnapshotTake(const run_cvd::SnapshotTake& snapshot_take);
83 const run_cvd::ScreenshotDisplay& request);
84
85 void HandleActionWithNoData(LauncherAction action, const SharedFD& client,
86 ProcessMonitor& process_monitor);
87
88 void DeleteFifos();
89 bool PowerwashFiles();
90 void RestartRunCvd(int notification_fd);
93
94 static std::unordered_map<std::string, std::string>
97 Result<void> TakeGuestSnapshot(VmmMode, const std::string&);
98 Result<void> TakeCrosvmGuestSnapshot(const Json::Value&);
99
102
103 /*
104 * This is needed to get the run_cvd side socket pair connected to
105 * secure_env. The socket pairs are used to send suspend/resume to
106 * secure_env, and get the responses.
107 */
108 AutoSnapshotControlFiles::Type& snapshot_control_files_;
110 std::vector<CommandSource*> command_sources_;
112 // mapping from the name of vm_manager to control_sock path
113 std::unordered_map<std::string, std::string> vm_name_to_control_sock_;
114 std::atomic<DeviceStatus> device_status_;
115};
116
118std::ostream& operator<<(std::ostream& out,
120
121template <typename Sink>
123 sink.Append(format_as(status));
124}
125
126} // namespace run_cvd_impl
127} // namespace cuttlefish
Definition: cuttlefish_config.h:264
Definition: cuttlefish_config.h:54
Definition: inject.h:25
Definition: process_monitor.h:53
Definition: server_loop.h:27
Definition: feature.h:48
Definition: shared_fd.h:125
Definition: webrtc_controller.h:27
Definition: server_loop_impl.h:48
const CuttlefishConfig::InstanceSpecific instance_
Definition: server_loop_impl.h:101
bool PowerwashFiles()
Definition: server_loop_impl.cpp:421
Result< void > HandleExtended(const LauncherActionInfo &action_info, ProcessMonitor &process_monitor)
Definition: server_loop_impl.cpp:212
Result< void > HandleScreenshotDisplay(const run_cvd::ScreenshotDisplay &request)
Definition: server_loop_impl_webrtc.cpp:42
Result< void > HandleStopScreenRecording()
Definition: server_loop_impl_webrtc.cpp:34
Result< void > HandleResume(ProcessMonitor &process_monitor)
Definition: server_loop_impl_snapshot.cpp:201
Result< void > ResumeGuest()
Definition: server_loop_impl_snapshot.cpp:138
std::string Name() const override
Definition: server_loop_impl.h:61
WebRtcController & webrtc_controller_
Definition: server_loop_impl.h:109
std::unordered_map< std::string, std::string > vm_name_to_control_sock_
Definition: server_loop_impl.h:113
void RestartRunCvd(int notification_fd)
Definition: server_loop_impl.cpp:504
Result< std::string > VmControlSocket() const
Definition: server_loop_impl.cpp:540
std::atomic< DeviceStatus > device_status_
Definition: server_loop_impl.h:114
INJECT(ServerLoopImpl(const CuttlefishConfig &config, const CuttlefishConfig::InstanceSpecific &instance, AutoSnapshotControlFiles::Type &snapshot_control_files, WebRtcController &webrtc_controller))
const CuttlefishConfig & config_
Definition: server_loop_impl.h:100
Result< void > HandleSuspend(ProcessMonitor &process_monitor)
Definition: server_loop_impl_snapshot.cpp:188
std::unordered_set< SetupFeature * > Dependencies() const override
Definition: server_loop_impl.h:71
Result< void > Run() override
Definition: server_loop_impl.cpp:121
DeviceStatus
Definition: server_loop_impl.h:63
Result< void > TakeCrosvmGuestSnapshot(const Json::Value &)
Definition: server_loop_impl_snapshot.cpp:214
Result< void > ResultSetup() override
Definition: server_loop_impl.cpp:203
Result< void > LateInject(fruit::Injector<> &injector) override
Definition: server_loop_impl.cpp:116
SharedFD server_
Definition: server_loop_impl.h:111
std::vector< CommandSource * > command_sources_
Definition: server_loop_impl.h:110
Result< void > SuspendGuest()
Definition: server_loop_impl_snapshot.cpp:112
void DeleteFifos()
Definition: server_loop_impl.cpp:392
Result< void > HandleStartScreenRecording()
Definition: server_loop_impl_webrtc.cpp:26
AutoSnapshotControlFiles::Type & snapshot_control_files_
Definition: server_loop_impl.h:108
static std::unordered_map< std::string, std::string > InitializeVmToControlSockPath(const CuttlefishConfig::InstanceSpecific &)
Definition: server_loop_impl_snapshot.cpp:55
void HandleActionWithNoData(LauncherAction action, const SharedFD &client, ProcessMonitor &process_monitor)
Definition: server_loop_impl.cpp:274
Result< void > TakeGuestSnapshot(VmmMode, const std::string &)
Definition: server_loop_impl_snapshot.cpp:264
Result< void > HandleSnapshotTake(const run_cvd::SnapshotTake &snapshot_take)
Definition: server_loop_impl_snapshot.cpp:276
int status()
Definition: health.cpp:44
std::ostream & operator<<(std::ostream &out, ServerLoopImpl::DeviceStatus status)
Definition: server_loop_impl.cpp:79
std::string_view format_as(ServerLoopImpl::DeviceStatus status)
Definition: server_loop_impl.cpp:66
void AbslStringify(Sink &sink, ServerLoopImpl::DeviceStatus status)
Definition: server_loop_impl.h:122
Definition: alloc_driver.h:21
LauncherAction
Definition: defs.h:53
VmmMode
Definition: vmm_mode.h:28
tl::expected< T, StackTraceError< E > > Result
Definition: result_type.h:30
Definition: util.h:38