aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Mayle <fmayle@google.com>2024-03-11 17:38:43 -0700
committerFrederick Mayle <fmayle@google.com>2024-03-12 18:27:01 -0700
commita07575c135109c5a945ac3af531470214b7f105a (patch)
tree3b9d007147db344706c38b0831ebdc3db59f59f8
parent2508869b53cc158f96d3cf46b769003482c691d4 (diff)
downloadcuttlefish-a07575c135109c5a945ac3af531470214b7f105a.tar.gz
move ExtendedLauncherAction proto deserialization into RPC function
As soon as we receive an extended action request, deserialize it and pass around the proto. Since the proto tracks the type of request, we can ignore the ExtendedActionType field. It will be deleted in a follow up commit. Test: launch CF Change-Id: I8c848b6eb36d6b7ef99fcf570961659693745d0e
-rw-r--r--host/commands/run_cvd/server_loop_impl.cpp33
-rw-r--r--host/commands/run_cvd/server_loop_impl.h12
-rw-r--r--host/commands/run_cvd/server_loop_impl_record.cpp19
-rw-r--r--host/commands/run_cvd/server_loop_impl_snapshot.cpp25
-rw-r--r--host/commands/secure_env/suspend_resume_handler.cpp22
-rw-r--r--host/commands/secure_env/suspend_resume_handler.h1
-rw-r--r--host/libs/command_util/util.cc9
-rw-r--r--host/libs/command_util/util.h3
8 files changed, 39 insertions, 85 deletions
diff --git a/host/commands/run_cvd/server_loop_impl.cpp b/host/commands/run_cvd/server_loop_impl.cpp
index 2cd6240a2..29fdfd61d 100644
--- a/host/commands/run_cvd/server_loop_impl.cpp
+++ b/host/commands/run_cvd/server_loop_impl.cpp
@@ -116,8 +116,6 @@ Result<void> ServerLoopImpl::Run() {
continue;
}
auto result = HandleExtended(launcher_action, process_monitor);
- const auto launcher_action_type_code =
- static_cast<std::uint32_t>(launcher_action.type);
auto response = LauncherResponse::kSuccess;
if (!result.ok()) {
LOG(ERROR) << "Failed to handle extended action request.";
@@ -126,8 +124,7 @@ Result<void> ServerLoopImpl::Run() {
}
const auto n_written = client->Write(&response, sizeof(response));
if (n_written != sizeof(response)) {
- LOG(ERROR) << "Failed to write response to "
- << launcher_action_type_code;
+ LOG(ERROR) << "Failed to write response";
}
// extended operations for now are 1 time request-response exchanges.
// thus, we will close the client FD.
@@ -147,43 +144,47 @@ Result<void> ServerLoopImpl::ResultSetup() {
Result<void> ServerLoopImpl::HandleExtended(
const LauncherActionInfo& action_info, ProcessMonitor& process_monitor) {
+ using ActionsCase =
+ ::cuttlefish::run_cvd::ExtendedLauncherAction::ActionsCase;
+
CF_EXPECT(action_info.action == LauncherAction::kExtended);
- switch (action_info.type) {
- case ExtendedActionType::kSuspend: {
+ switch (action_info.extended_action.actions_case()) {
+ case ActionsCase::kSuspend: {
LOG(DEBUG) << "Run_cvd received suspend request.";
if (device_status_.load() == DeviceStatus::kActive) {
- CF_EXPECT(HandleSuspend(action_info.serialized_data, process_monitor));
+ CF_EXPECT(HandleSuspend(process_monitor));
}
device_status_ = DeviceStatus::kSuspended;
return {};
}
- case ExtendedActionType::kResume: {
+ case ActionsCase::kResume: {
LOG(DEBUG) << "Run_cvd received resume request.";
if (device_status_.load() == DeviceStatus::kSuspended) {
- CF_EXPECT(HandleResume(action_info.serialized_data, process_monitor));
+ CF_EXPECT(HandleResume(process_monitor));
}
device_status_ = DeviceStatus::kActive;
return {};
}
- case ExtendedActionType::kSnapshotTake: {
+ case ActionsCase::kSnapshotTake: {
LOG(DEBUG) << "Run_cvd received snapshot request.";
CF_EXPECT(device_status_.load() == DeviceStatus::kSuspended,
"The device is not suspended, and snapshot cannot be taken");
- CF_EXPECT(HandleSnapshotTake(action_info.serialized_data));
+ CF_EXPECT(
+ HandleSnapshotTake(action_info.extended_action.snapshot_take()));
return {};
}
- case ExtendedActionType::kStartScreenRecording: {
+ case ActionsCase::kStartScreenRecording: {
LOG(DEBUG) << "Run_cvd received start screen recording request.";
- CF_EXPECT(HandleStartScreenRecording(action_info.serialized_data));
+ CF_EXPECT(HandleStartScreenRecording());
return {};
}
- case ExtendedActionType::kStopScreenRecording: {
+ case ActionsCase::kStopScreenRecording: {
LOG(DEBUG) << "Run_cvd received stop screen recording request.";
- CF_EXPECT(HandleStopScreenRecording(action_info.serialized_data));
+ CF_EXPECT(HandleStopScreenRecording());
return {};
}
default:
- return CF_ERR("Unsupported ExtendedActionType");
+ return CF_ERR("Unsupported ExtendedLauncherAction");
}
}
diff --git a/host/commands/run_cvd/server_loop_impl.h b/host/commands/run_cvd/server_loop_impl.h
index 81494e2a7..1577f283e 100644
--- a/host/commands/run_cvd/server_loop_impl.h
+++ b/host/commands/run_cvd/server_loop_impl.h
@@ -71,13 +71,11 @@ class ServerLoopImpl : public ServerLoop,
Result<void> ResultSetup() override;
Result<void> HandleExtended(const LauncherActionInfo& action_info,
ProcessMonitor& process_monitor);
- Result<void> HandleSuspend(const std::string& serialized_data,
- ProcessMonitor& process_monitor);
- Result<void> HandleResume(const std::string& serialized_data,
- ProcessMonitor& process_monitor);
- Result<void> HandleSnapshotTake(const std::string& serialized_data);
- Result<void> HandleStartScreenRecording(const std::string& serialized_data);
- Result<void> HandleStopScreenRecording(const std::string& serialized_data);
+ Result<void> HandleSuspend(ProcessMonitor& process_monitor);
+ Result<void> HandleResume(ProcessMonitor& process_monitor);
+ Result<void> HandleSnapshotTake(const run_cvd::SnapshotTake& snapshot_take);
+ Result<void> HandleStartScreenRecording();
+ Result<void> HandleStopScreenRecording();
void HandleActionWithNoData(const LauncherAction action,
const SharedFD& client,
diff --git a/host/commands/run_cvd/server_loop_impl_record.cpp b/host/commands/run_cvd/server_loop_impl_record.cpp
index a9e91eb62..3feb852f1 100644
--- a/host/commands/run_cvd/server_loop_impl_record.cpp
+++ b/host/commands/run_cvd/server_loop_impl_record.cpp
@@ -21,19 +21,11 @@
#include "common/libs/utils/result.h"
#include "host/libs/command_util/runner/defs.h"
#include "host/libs/command_util/util.h"
-#include "run_cvd.pb.h"
namespace cuttlefish {
namespace run_cvd_impl {
-Result<void> ServerLoopImpl::HandleStartScreenRecording(
- const std::string& serialized_data) {
- run_cvd::ExtendedLauncherAction extended_action;
- CF_EXPECT(extended_action.ParseFromString(serialized_data),
- "Failed to load ExtendedLauncherAction proto.");
- CF_EXPECT_EQ(
- extended_action.actions_case(),
- run_cvd::ExtendedLauncherAction::ActionsCase::kStartScreenRecording);
+Result<void> ServerLoopImpl::HandleStartScreenRecording() {
LOG(INFO) << "Sending the request to start screen recording.";
CF_EXPECT(webrtc_recorder_.SendStartRecordingCommand(),
@@ -41,14 +33,7 @@ Result<void> ServerLoopImpl::HandleStartScreenRecording(
return {};
}
-Result<void> ServerLoopImpl::HandleStopScreenRecording(
- const std::string& serialized_data) {
- run_cvd::ExtendedLauncherAction extended_action;
- CF_EXPECT(extended_action.ParseFromString(serialized_data),
- "Failed to load ExtendedLauncherAction proto.");
- CF_EXPECT_EQ(
- extended_action.actions_case(),
- run_cvd::ExtendedLauncherAction::ActionsCase::kStopScreenRecording);
+Result<void> ServerLoopImpl::HandleStopScreenRecording() {
LOG(INFO) << "Sending the request to stop screen recording.";
CF_EXPECT(webrtc_recorder_.SendStopRecordingCommand(),
diff --git a/host/commands/run_cvd/server_loop_impl_snapshot.cpp b/host/commands/run_cvd/server_loop_impl_snapshot.cpp
index 7bf51a70e..26cbe0a97 100644
--- a/host/commands/run_cvd/server_loop_impl_snapshot.cpp
+++ b/host/commands/run_cvd/server_loop_impl_snapshot.cpp
@@ -142,13 +142,7 @@ Result<void> ServerLoopImpl::ResumeGuest() {
}
}
-Result<void> ServerLoopImpl::HandleSuspend(const std::string& serialized_data,
- ProcessMonitor& process_monitor) {
- run_cvd::ExtendedLauncherAction extended_action;
- CF_EXPECT(extended_action.ParseFromString(serialized_data),
- "Failed to load ExtendedLauncherAction proto.");
- CF_EXPECT_EQ(extended_action.actions_case(),
- run_cvd::ExtendedLauncherAction::ActionsCase::kSuspend);
+Result<void> ServerLoopImpl::HandleSuspend(ProcessMonitor& process_monitor) {
// right order: guest -> host
LOG(DEBUG) << "Suspending the guest..";
CF_EXPECT(SuspendGuest());
@@ -159,13 +153,7 @@ Result<void> ServerLoopImpl::HandleSuspend(const std::string& serialized_data,
return {};
}
-Result<void> ServerLoopImpl::HandleResume(const std::string& serialized_data,
- ProcessMonitor& process_monitor) {
- run_cvd::ExtendedLauncherAction extended_action;
- CF_EXPECT(extended_action.ParseFromString(serialized_data),
- "Failed to load ExtendedLauncherAction proto.");
- CF_EXPECT_EQ(extended_action.actions_case(),
- run_cvd::ExtendedLauncherAction::ActionsCase::kResume);
+Result<void> ServerLoopImpl::HandleResume(ProcessMonitor& process_monitor) {
// right order: host -> guest
CF_EXPECT(process_monitor.ResumeMonitoredProcesses(),
"Failed to resume host processes.");
@@ -246,15 +234,10 @@ Result<void> ServerLoopImpl::TakeGuestSnapshot(const std::string& vm_manager,
}
Result<void> ServerLoopImpl::HandleSnapshotTake(
- const std::string& serialized_data) {
- run_cvd::ExtendedLauncherAction extended_action;
- CF_EXPECT(extended_action.ParseFromString(serialized_data),
- "Failed to load ExtendedLauncherAction proto.");
- CF_EXPECT_EQ(extended_action.actions_case(),
- run_cvd::ExtendedLauncherAction::ActionsCase::kSnapshotTake);
+ const run_cvd::SnapshotTake& snapshot_take) {
// implement snapshot take
std::vector<std::string> path_to_snapshots;
- for (const auto& path : extended_action.snapshot_take().snapshot_path()) {
+ for (const auto& path : snapshot_take.snapshot_path()) {
path_to_snapshots.push_back(path);
}
CF_EXPECT_EQ(path_to_snapshots.size(), 1);
diff --git a/host/commands/secure_env/suspend_resume_handler.cpp b/host/commands/secure_env/suspend_resume_handler.cpp
index f1f126cea..cf689f729 100644
--- a/host/commands/secure_env/suspend_resume_handler.cpp
+++ b/host/commands/secure_env/suspend_resume_handler.cpp
@@ -72,25 +72,17 @@ SnapshotCommandHandler::SnapshotCommandHandler(SharedFD channel_to_run_cvd,
});
}
-Result<ExtendedActionType> SnapshotCommandHandler::ReadRunCvdSnapshotCmd()
- const {
- CF_EXPECT(channel_to_run_cvd_->IsOpen(), channel_to_run_cvd_->StrError());
+Result<void> SnapshotCommandHandler::SuspendResumeHandler() {
+ using ActionsCase =
+ ::cuttlefish::run_cvd::ExtendedLauncherAction::ActionsCase;
+
auto launcher_action =
CF_EXPECT(ReadLauncherActionFromFd(channel_to_run_cvd_),
"Failed to read LauncherAction from run_cvd");
CF_EXPECT(launcher_action.action == LauncherAction::kExtended);
- const auto action_type = launcher_action.type;
- CF_EXPECTF(action_type == ExtendedActionType::kSuspend ||
- action_type == ExtendedActionType::kResume,
- "Unsupported ExtendedActionType \"{}\"",
- fmt::underlying(action_type));
- return action_type;
-}
-Result<void> SnapshotCommandHandler::SuspendResumeHandler() {
- const auto snapshot_cmd = CF_EXPECT(ReadRunCvdSnapshotCmd());
- switch (snapshot_cmd) {
- case ExtendedActionType::kSuspend: {
+ switch (launcher_action.extended_action.actions_case()) {
+ case ActionsCase::kSuspend: {
LOG(DEBUG) << "Handling suspended...";
// Request all worker threads to suspend.
CF_EXPECT(WriteSuspendRequest(snapshot_sockets_.rust));
@@ -109,7 +101,7 @@ Result<void> SnapshotCommandHandler::SuspendResumeHandler() {
CF_EXPECT_EQ(sizeof(response), n_written);
return {};
};
- case ExtendedActionType::kResume: {
+ case ActionsCase::kResume: {
LOG(DEBUG) << "Handling resume...";
// Request all worker threads to resume.
CF_EXPECT(WriteResumeRequest(snapshot_sockets_.rust));
diff --git a/host/commands/secure_env/suspend_resume_handler.h b/host/commands/secure_env/suspend_resume_handler.h
index 3bbc3a7cd..cd542d7b8 100644
--- a/host/commands/secure_env/suspend_resume_handler.h
+++ b/host/commands/secure_env/suspend_resume_handler.h
@@ -67,7 +67,6 @@ class SnapshotCommandHandler {
private:
Result<void> SuspendResumeHandler();
- Result<ExtendedActionType> ReadRunCvdSnapshotCmd() const;
void Join();
SharedFD channel_to_run_cvd_;
diff --git a/host/libs/command_util/util.cc b/host/libs/command_util/util.cc
index 8b4f4534b..16bf03f76 100644
--- a/host/libs/command_util/util.cc
+++ b/host/libs/command_util/util.cc
@@ -97,8 +97,7 @@ Result<LauncherActionInfo> ReadLauncherActionFromFd(
if (IsShortAction(action)) {
return LauncherActionInfo{
.action = action,
- .type = ExtendedActionType::kUnused,
- .serialized_data = "",
+ .extended_action = {},
};
}
ExtendedActionType type;
@@ -110,8 +109,7 @@ Result<LauncherActionInfo> ReadLauncherActionFromFd(
if (length == 0) {
return LauncherActionInfo{
.action = action,
- .type = type,
- .serialized_data = "",
+ .extended_action = {},
};
}
std::string serialized_data(length, 0);
@@ -126,8 +124,7 @@ Result<LauncherActionInfo> ReadLauncherActionFromFd(
return LauncherActionInfo{
.action = action,
- .type = type,
- .serialized_data = std::move(serialized_data),
+ .extended_action = std::move(extended_action),
};
}
diff --git a/host/libs/command_util/util.h b/host/libs/command_util/util.h
index 1f0b59237..4798902a0 100644
--- a/host/libs/command_util/util.h
+++ b/host/libs/command_util/util.h
@@ -36,8 +36,7 @@ Result<SharedFD> GetLauncherMonitor(const CuttlefishConfig& config,
struct LauncherActionInfo {
LauncherAction action;
- ExtendedActionType type;
- std::string serialized_data;
+ run_cvd::ExtendedLauncherAction extended_action;
};
Result<LauncherActionInfo> ReadLauncherActionFromFd(
const SharedFD& monitor_socket);