/* * Copyright (C) 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include #include #include #include #include #include "common/libs/fs/shared_fd.h" #include "common/libs/utils/json.h" #include "common/libs/utils/result.h" #include "common/libs/utils/unix_sockets.h" #include "cvd_server.pb.h" #include "host/commands/cvd/types.h" namespace cuttlefish { struct OverrideFd { std::optional stdin_override_fd; std::optional stdout_override_fd; std::optional stderr_override_fd; }; class CvdClient { public: Result ValidateServerVersion(const int num_retries = 1); Result StopCvdServer(bool clear); Result HandleAcloud( const std::vector& args, const std::unordered_map& env); Result HandleCommand( const std::vector& args, const std::unordered_map& env, const std::vector& selector_args, const OverrideFd& control_fds); Result HandleCommand( const std::vector& args, const std::unordered_map& env, const std::vector& selector_args) { auto response = CF_EXPECT( HandleCommand(args, env, selector_args, OverrideFd{std::nullopt, std::nullopt, std::nullopt})); return response; } Result HandleVersion(); Result ValidSubcmdsList(const cvd_common::Envs& envs); private: std::optional server_; Result SetServer(const SharedFD& server); Result SendRequest(const cvd::Request& request, const OverrideFd& new_control_fds = {}, std::optional extra_fd = {}); Result StartCvdServer(); Result CheckStatus(const cvd::Status& status, const std::string& rpc); Result GetServerVersion(); Result ListSubcommands(const cvd_common::Envs& envs); static cvd::Version GetClientVersion(); }; } // end of namespace cuttlefish