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 <string>
21#include <unordered_map>
22#include <unordered_set>
23#include <vector>
24
25#include <fruit/fruit.h>
26
40
41namespace cuttlefish {
42namespace run_cvd_impl {
43
45 public SetupFeature,
46 public LateInjected {
47 public:
50 AutoSnapshotControlFiles::Type& snapshot_control_files,
51 WebRtcController& webrtc_controller));
52
53 Result<void> LateInject(fruit::Injector<>& injector) override;
54
55 // ServerLoop
56 Result<void> Run() override;
57
58 // SetupFeature
59 std::string Name() const override { return "ServerLoop"; }
60
61 enum class DeviceStatus : int {
62 kUnknown = 0,
63 kActive = 1,
64 kSuspended = 2,
65 };
66
67 private:
68 std::unordered_set<SetupFeature*> Dependencies() const override {
70 }
71 Result<void> ResultSetup() override;
73 ProcessMonitor& process_monitor);
76 Result<void> HandleSnapshotTake(const run_cvd::SnapshotTake& snapshot_take);
80 const run_cvd::ScreenshotDisplay& request);
81
82 void HandleActionWithNoData(const LauncherAction action,
83 const SharedFD& client,
84 ProcessMonitor& process_monitor);
85
86 void DeleteFifos();
87 bool PowerwashFiles();
88 void RestartRunCvd(int notification_fd);
89 static bool CreateQcowOverlay(const std::string& crosvm_path,
90 const std::string& backing_file,
91 const std::string& output_overlay_path);
94
95 static std::unordered_map<std::string, std::string>
98 Result<void> TakeGuestSnapshot(VmmMode, const std::string&);
99 Result<void> TakeCrosvmGuestSnapshot(const Json::Value&);
100
103
104 /*
105 * This is needed to get the run_cvd side socket pair connected to
106 * secure_env. The socket pairs are used to send suspend/resume to
107 * secure_env, and get the responses.
108 */
109 AutoSnapshotControlFiles::Type& snapshot_control_files_;
111 std::vector<CommandSource*> command_sources_;
113 // mapping from the name of vm_manager to control_sock path
114 std::unordered_map<std::string, std::string> vm_name_to_control_sock_;
115 std::atomic<DeviceStatus> device_status_;
116};
117
118} // namespace run_cvd_impl
119} // namespace cuttlefish
Definition: expected.h:86
Definition: cuttlefish_config.h:269
Definition: cuttlefish_config.h:49
Definition: inject.h:25
Definition: process_monitor.h:44
Definition: server_loop.h:27
Definition: feature.h:48
Definition: shared_fd.h:129
Definition: webrtc_controller.h:28
Definition: server_loop_impl.h:46
void HandleActionWithNoData(const LauncherAction action, const SharedFD &client, ProcessMonitor &process_monitor)
Definition: server_loop_impl.cpp:203
const CuttlefishConfig::InstanceSpecific & instance_
Definition: server_loop_impl.h:102
bool PowerwashFiles()
Definition: server_loop_impl.cpp:340
Result< void > HandleExtended(const LauncherActionInfo &action_info, ProcessMonitor &process_monitor)
Definition: server_loop_impl.cpp:151
Result< void > HandleScreenshotDisplay(const run_cvd::ScreenshotDisplay &request)
Definition: server_loop_impl_webrtc.cpp:44
Result< void > HandleStopScreenRecording()
Definition: server_loop_impl_webrtc.cpp:36
static bool CreateQcowOverlay(const std::string &crosvm_path, const std::string &backing_file, const std::string &output_overlay_path)
Definition: server_loop_impl.cpp:46
Result< void > HandleResume(ProcessMonitor &process_monitor)
Definition: server_loop_impl_snapshot.cpp:184
Result< void > ResumeGuest()
Definition: server_loop_impl_snapshot.cpp:121
std::string Name() const override
Definition: server_loop_impl.h:59
WebRtcController & webrtc_controller_
Definition: server_loop_impl.h:110
std::unordered_map< std::string, std::string > vm_name_to_control_sock_
Definition: server_loop_impl.h:114
void RestartRunCvd(int notification_fd)
Definition: server_loop_impl.cpp:398
Result< std::string > VmControlSocket() const
Definition: server_loop_impl.cpp:428
std::atomic< DeviceStatus > device_status_
Definition: server_loop_impl.h:115
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:101
Result< void > HandleSuspend(ProcessMonitor &process_monitor)
Definition: server_loop_impl_snapshot.cpp:171
std::unordered_set< SetupFeature * > Dependencies() const override
Definition: server_loop_impl.h:68
Result< void > Run() override
Definition: server_loop_impl.cpp:80
DeviceStatus
Definition: server_loop_impl.h:61
Result< void > TakeCrosvmGuestSnapshot(const Json::Value &)
Definition: server_loop_impl_snapshot.cpp:197
Result< void > ResultSetup() override
Definition: server_loop_impl.cpp:142
Result< void > LateInject(fruit::Injector<> &injector) override
Definition: server_loop_impl.cpp:75
SharedFD server_
Definition: server_loop_impl.h:112
std::vector< CommandSource * > command_sources_
Definition: server_loop_impl.h:111
Result< void > SuspendGuest()
Definition: server_loop_impl_snapshot.cpp:95
void DeleteFifos()
Definition: server_loop_impl.cpp:305
Result< void > HandleStartScreenRecording()
Definition: server_loop_impl_webrtc.cpp:28
AutoSnapshotControlFiles::Type & snapshot_control_files_
Definition: server_loop_impl.h:109
static std::unordered_map< std::string, std::string > InitializeVmToControlSockPath(const CuttlefishConfig::InstanceSpecific &)
Definition: server_loop_impl_snapshot.cpp:42
Result< void > TakeGuestSnapshot(VmmMode, const std::string &)
Definition: server_loop_impl_snapshot.cpp:248
Result< void > HandleSnapshotTake(const run_cvd::SnapshotTake &snapshot_take)
Definition: server_loop_impl_snapshot.cpp:266
Definition: alloc_utils.cpp:23
LauncherAction
Definition: defs.h:51
VmmMode
Definition: vmm_mode.h:28
Definition: util.h:39