Skip to content

Commit

Permalink
Rename RequestWithStdio as CommandRequest
Browse files Browse the repository at this point in the history
Also rename the server_client.* files as there are no servers and
clients anymore.
jemoreira committed Oct 10, 2024
1 parent 3058ca1 commit 1559550
Showing 47 changed files with 215 additions and 215 deletions.
6 changes: 3 additions & 3 deletions base/cvd/cuttlefish/host/commands/cvd/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -168,8 +168,8 @@ cc_library(
"selector/selector_option_parser_utils.h",
"selector/start_selector_parser.cpp",
"selector/start_selector_parser.h",
"server_client.cpp",
"server_client.h",
"command_request.cpp",
"command_request.h",
"server_command/acloud_command.cpp",
"server_command/acloud_command.h",
"server_command/acloud_common.cpp",
@@ -299,7 +299,7 @@ cc_library(
"selector/selector_constants.h",
"selector/selector_option_parser_utils.h",
"selector/start_selector_parser.h",
"server_client.h",
"command_request.h",
"server_command/acloud_command.h",
"server_command/acloud_common.h",
"server_command/acloud_mixsuperimage.h",
16 changes: 8 additions & 8 deletions base/cvd/cuttlefish/host/commands/cvd/acloud/converter.cpp
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@
#include "host/commands/cvd/lock_file.h"
#include "host/commands/cvd/selector/instance_database_utils.h"
#include "host/commands/cvd/selector/selector_constants.h"
#include "host/commands/cvd/server_client.h"
#include "host/commands/cvd/command_request.h"
#include "host/commands/cvd/server_command/utils.h"
#include "host/commands/cvd/types.h"
#include "host/libs/config/config_constants.h"
@@ -146,7 +146,7 @@ Result<std::vector<std::string>> BashTokenize(const std::string& str) {
namespace acloud_impl {

Result<ConvertedAcloudCreateCommand> ConvertAcloudCreate(
const RequestWithStdio& request) {
const CommandRequest& request) {
auto arguments = ParseInvocation(request).arguments;
CF_EXPECT(arguments.size() > 0);
CF_EXPECT(arguments[0] == "create");
@@ -329,7 +329,7 @@ Result<ConvertedAcloudCreateCommand> ConvertAcloudCreate(
auto host_artifacts_path =
CF_EXPECT(AndroidHostPath(request.Env()), "Missing host artifacts path");

std::vector<RequestWithStdio> inner_requests;
std::vector<CommandRequest> inner_requests;
const std::string user_config_path =
parsed_flags.config_file.value_or(CF_EXPECT(GetDefaultConfigFile()));

@@ -373,8 +373,8 @@ Result<ConvertedAcloudCreateCommand> ConvertAcloudCreate(
// the same method by using Android build api to get build ID,
// but it is not easy in C++.

RequestWithStdio& fetch_request =
inner_requests.emplace_back(RequestWithStdio())
CommandRequest& fetch_request =
inner_requests.emplace_back(CommandRequest())
.AddArguments(
{"cvd", "fetch", "--directory", host_dir, "--default_build"});
fetch_command_str += "--default_build=";
@@ -476,8 +476,8 @@ Result<ConvertedAcloudCreateCommand> ConvertAcloudCreate(
required_paths = super_image_path;
required_paths += ("," + parsed_flags.local_system_image.value());

RequestWithStdio& mixsuperimage_request =
inner_requests.emplace_back(RequestWithStdio())
CommandRequest& mixsuperimage_request =
inner_requests.emplace_back(CommandRequest())
.AddArguments(
{"cvd", "acloud", "mix-super-image", "--super_image"});

@@ -500,7 +500,7 @@ Result<ConvertedAcloudCreateCommand> ConvertAcloudCreate(
mixsuperimage_request.AddArguments({required_paths});
}

RequestWithStdio start_request = RequestWithStdio();
CommandRequest start_request = CommandRequest();
start_request.AddArguments({"cvd", "create", "--daemon", "--undefok",
"report_anonymous_usage_stats",
"--report_anonymous_usage_stats", "y"});
8 changes: 4 additions & 4 deletions base/cvd/cuttlefish/host/commands/cvd/acloud/converter.h
Original file line number Diff line number Diff line change
@@ -19,15 +19,15 @@
#include <string>
#include <vector>

#include "host/commands/cvd/server_client.h"
#include "host/commands/cvd/command_request.h"

#include "common/libs/utils/result.h"

namespace cuttlefish {

struct ConvertedAcloudCreateCommand {
std::vector<RequestWithStdio> prep_requests;
RequestWithStdio start_request;
std::vector<CommandRequest> prep_requests;
CommandRequest start_request;
std::string fetch_command_str;
std::string fetch_cvd_args_file;
bool verbose;
@@ -36,7 +36,7 @@ struct ConvertedAcloudCreateCommand {
namespace acloud_impl {

Result<ConvertedAcloudCreateCommand> ConvertAcloudCreate(
const RequestWithStdio& request);
const CommandRequest& request);

} // namespace acloud_impl
} // namespace cuttlefish
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
* limitations under the License.
*/

#include "host/commands/cvd/server_client.h"
#include "host/commands/cvd/command_request.h"

#include <string>

@@ -23,7 +23,7 @@
#include "common/libs/fs/shared_fd.h"
#include "common/libs/utils/result.h"
#include "common/libs/utils/unix_sockets.h"
#include "host/commands/cvd/server_client.h"
#include "host/commands/cvd/command_request.h"

namespace cuttlefish {

@@ -48,42 +48,42 @@ Result<void> SendResponse(const SharedFD& client,
return {};
}

const cvd_common::Args& RequestWithStdio::Args() const { return args_; }
const cvd_common::Args& CommandRequest::Args() const { return args_; }

RequestWithStdio& RequestWithStdio::AddArguments(
CommandRequest& CommandRequest::AddArguments(
std::initializer_list<std::string_view> args) & {
return AddArguments(std::vector<std::string_view>(args));
}

RequestWithStdio RequestWithStdio::AddArguments(
CommandRequest CommandRequest::AddArguments(
std::initializer_list<std::string_view> args) && {
return AddArguments(std::vector<std::string_view>(args));
}

const cvd_common::Args& RequestWithStdio::SelectorArgs() const {
const cvd_common::Args& CommandRequest::SelectorArgs() const {
return selector_args_;
}

RequestWithStdio& RequestWithStdio::AddSelectorArguments(
CommandRequest& CommandRequest::AddSelectorArguments(
std::initializer_list<std::string_view> args) & {
return AddSelectorArguments(std::vector<std::string_view>(args));
}

RequestWithStdio RequestWithStdio::AddSelectorArguments(
CommandRequest CommandRequest::AddSelectorArguments(
std::initializer_list<std::string_view> args) && {
return AddSelectorArguments(std::vector<std::string_view>(args));
}

const cvd_common::Envs& RequestWithStdio::Env() const { return env_; }
const cvd_common::Envs& CommandRequest::Env() const { return env_; }

cvd_common::Envs& RequestWithStdio::Env() { return env_; }
cvd_common::Envs& CommandRequest::Env() { return env_; }

RequestWithStdio& RequestWithStdio::SetEnv(cvd_common::Envs env) & {
CommandRequest& CommandRequest::SetEnv(cvd_common::Envs env) & {
env_ = std::move(env);
return *this;
}

RequestWithStdio RequestWithStdio::SetEnv(cvd_common::Envs env) && {
CommandRequest CommandRequest::SetEnv(cvd_common::Envs env) && {
env_ = std::move(env);
return *this;
}
Original file line number Diff line number Diff line change
@@ -32,59 +32,59 @@

namespace cuttlefish {

class RequestWithStdio {
class CommandRequest {
public:
RequestWithStdio() = default;
CommandRequest() = default;

template <typename T>
RequestWithStdio& AddArguments(T&& args) & {
CommandRequest& AddArguments(T&& args) & {
for (auto&& arg : args) {
args_.emplace_back(arg);
}
return *this;
}

template <typename T>
RequestWithStdio AddArguments(T&& args) && {
CommandRequest AddArguments(T&& args) && {
for (auto&& arg : args) {
args_.emplace_back(arg);
}
return *this;
}

RequestWithStdio& AddArguments(std::initializer_list<std::string_view>) &;
RequestWithStdio AddArguments(std::initializer_list<std::string_view>) &&;
CommandRequest& AddArguments(std::initializer_list<std::string_view>) &;
CommandRequest AddArguments(std::initializer_list<std::string_view>) &&;

const cvd_common::Args& Args() const;

template <typename T>
RequestWithStdio& AddSelectorArguments(T&& args) & {
CommandRequest& AddSelectorArguments(T&& args) & {
for (auto&& arg : args) {
selector_args_.emplace_back(arg);
}
return *this;
}

template <typename T>
RequestWithStdio AddSelectorArguments(T&& args) && {
CommandRequest AddSelectorArguments(T&& args) && {
for (auto&& arg : args) {
selector_args_.emplace_back(arg);
}
return *this;
}

RequestWithStdio& AddSelectorArguments(
CommandRequest& AddSelectorArguments(
std::initializer_list<std::string_view>) &;
RequestWithStdio AddSelectorArguments(
CommandRequest AddSelectorArguments(
std::initializer_list<std::string_view>) &&;

const cvd_common::Args& SelectorArgs() const;

const cvd_common::Envs& Env() const;
cvd_common::Envs& Env();

RequestWithStdio& SetEnv(cvd_common::Envs) &;
RequestWithStdio SetEnv(cvd_common::Envs) &&;
CommandRequest& SetEnv(cvd_common::Envs) &;
CommandRequest SetEnv(cvd_common::Envs) &&;

private:
cvd_common::Args args_;
10 changes: 5 additions & 5 deletions base/cvd/cuttlefish/host/commands/cvd/command_sequence.cpp
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@

#include "common/libs/fs/shared_buf.h"
#include "host/commands/cvd/request_context.h"
#include "host/commands/cvd/server_client.h"
#include "host/commands/cvd/command_request.h"
#include "host/commands/cvd/types.h"

namespace cuttlefish {
@@ -48,7 +48,7 @@ std::string BashEscape(const std::string& input) {
return safe ? input : "'" + StringReplace(input, "'", "\\'", true) + "'";
}

std::string FormattedCommand(const RequestWithStdio& command) {
std::string FormattedCommand(const CommandRequest& command) {
std::stringstream effective_command;
effective_command << "*******************************************************"
"*************************\n";
@@ -82,7 +82,7 @@ CommandSequenceExecutor::CommandSequenceExecutor(
: server_handlers_(server_handlers) {}

Result<std::vector<cvd::Response>> CommandSequenceExecutor::Execute(
const std::vector<RequestWithStdio>& requests, std::ostream& report) {
const std::vector<CommandRequest>& requests, std::ostream& report) {
std::vector<cvd::Response> responses;
for (const auto& request : requests) {
report << FormattedCommand(request);
@@ -101,7 +101,7 @@ Result<std::vector<cvd::Response>> CommandSequenceExecutor::Execute(
}

Result<cvd::Response> CommandSequenceExecutor::ExecuteOne(
const RequestWithStdio& request, std::ostream& report) {
const CommandRequest& request, std::ostream& report) {
auto response_in_vector = CF_EXPECT(Execute({request}, report));
CF_EXPECT_EQ(response_in_vector.size(), 1ul);
return response_in_vector.front();
@@ -120,7 +120,7 @@ std::vector<std::string> CommandSequenceExecutor::CmdList() const {
}

Result<CvdServerHandler*> CommandSequenceExecutor::GetHandler(
const RequestWithStdio& request) {
const CommandRequest& request) {
return CF_EXPECT(RequestHandler(request, server_handlers_));
}

8 changes: 4 additions & 4 deletions base/cvd/cuttlefish/host/commands/cvd/command_sequence.h
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@
#include <vector>

#include "cuttlefish/host/commands/cvd/cvd_server.pb.h"
#include "host/commands/cvd/server_client.h"
#include "host/commands/cvd/command_request.h"
#include "host/commands/cvd/server_command/server_handler.h"

namespace cuttlefish {
@@ -31,12 +31,12 @@ class CommandSequenceExecutor {
const std::vector<std::unique_ptr<CvdServerHandler>>& server_handlers);

Result<std::vector<cvd::Response>> Execute(
const std::vector<RequestWithStdio>&, std::ostream& report);
Result<cvd::Response> ExecuteOne(const RequestWithStdio&,
const std::vector<CommandRequest>&, std::ostream& report);
Result<cvd::Response> ExecuteOne(const CommandRequest&,
std::ostream& report);

std::vector<std::string> CmdList() const;
Result<CvdServerHandler*> GetHandler(const RequestWithStdio& request);
Result<CvdServerHandler*> GetHandler(const CommandRequest& request);

private:
const std::vector<std::unique_ptr<CvdServerHandler>>& server_handlers_;
2 changes: 1 addition & 1 deletion base/cvd/cuttlefish/host/commands/cvd/common_utils.cpp
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
#include "common/libs/utils/contains.h"
#include "common/libs/utils/files.h"
#include "common/libs/utils/result.h"
#include "host/commands/cvd/server_client.h"
#include "host/commands/cvd/command_request.h"

namespace cuttlefish {

4 changes: 2 additions & 2 deletions base/cvd/cuttlefish/host/commands/cvd/cvd.cpp
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
#include "host/commands/cvd/instance_lock.h"
#include "host/commands/cvd/instance_manager.h"
#include "host/commands/cvd/request_context.h"
#include "host/commands/cvd/server_client.h"
#include "host/commands/cvd/command_request.h"

namespace cuttlefish {

@@ -63,7 +63,7 @@ Result<cvd::Response> Cvd::HandleCommand(
const std::vector<std::string>& cvd_process_args,
const std::unordered_map<std::string, std::string>& env,
const std::vector<std::string>& selector_args) {
RequestWithStdio request = RequestWithStdio()
CommandRequest request = CommandRequest()
.AddArguments(cvd_process_args)
.SetEnv(env)
.AddSelectorArguments(selector_args);
4 changes: 2 additions & 2 deletions base/cvd/cuttlefish/host/commands/cvd/group_selector.cpp
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ std::string SelectionMenu(
}

Result<selector::LocalInstanceGroup> PromptUserForGroup(
InstanceManager& instance_manager, const RequestWithStdio& request,
InstanceManager& instance_manager, const CommandRequest& request,
const cvd_common::Envs& envs, const cvd_common::Args& selector_args) {
// show the menu and let the user choose
std::vector<selector::LocalInstanceGroup> groups =
@@ -98,7 +98,7 @@ Result<selector::LocalInstanceGroup> PromptUserForGroup(
} // namespace

Result<selector::LocalInstanceGroup> SelectGroup(
InstanceManager& instance_manager, const RequestWithStdio& request) {
InstanceManager& instance_manager, const CommandRequest& request) {
auto has_groups = CF_EXPECT(instance_manager.HasInstanceGroups());
CF_EXPECT(std::move(has_groups), "No instance groups available");
const cvd_common::Envs& env = request.Env();
4 changes: 2 additions & 2 deletions base/cvd/cuttlefish/host/commands/cvd/group_selector.h
Original file line number Diff line number Diff line change
@@ -19,10 +19,10 @@
#include "common/libs/utils/result.h"
#include "host/commands/cvd/selector/instance_group_record.h"
#include "host/commands/cvd/instance_manager.h"
#include "host/commands/cvd/server_client.h"
#include "host/commands/cvd/command_request.h"

namespace cuttlefish {
Result<selector::LocalInstanceGroup> SelectGroup(InstanceManager&,
const RequestWithStdio&);
const CommandRequest&);

} // namespace cuttlefish
4 changes: 2 additions & 2 deletions base/cvd/cuttlefish/host/commands/cvd/instance_manager.cpp
Original file line number Diff line number Diff line change
@@ -179,7 +179,7 @@ Result<void> InstanceManager::UpdateInstance(const LocalInstanceGroup& group,
}

Result<void> InstanceManager::IssueStopCommand(
const RequestWithStdio& request, const std::string& config_file_path,
const CommandRequest& request, const std::string& config_file_path,
selector::LocalInstanceGroup& group) {

const auto stop_bin = CF_EXPECT(StopBin(group.HostArtifactsPath()));
@@ -221,7 +221,7 @@ Result<void> InstanceManager::IssueStopCommand(
return {};
}

cvd::Status InstanceManager::CvdClear(const RequestWithStdio& request) {
cvd::Status InstanceManager::CvdClear(const CommandRequest& request) {
cvd::Status status;
const std::string config_json_name = cpp_basename(GetGlobalConfigFileLink());
auto instance_groups_res = instance_db_.Clear();
Loading

0 comments on commit 1559550

Please sign in to comment.