1 // 2 // Copyright (C) 2021 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 #pragma once 17 18 #include <optional> 19 #include <string> 20 21 #include <json/value.h> 22 23 #include "common/libs/utils/result.h" 24 #include "common/libs/utils/subprocess.h" 25 #include "host/libs/vm_manager/pci.h" 26 27 namespace cuttlefish { 28 29 class CrosvmBuilder { 30 public: 31 CrosvmBuilder(); 32 33 void ApplyProcessRestarter(const std::string& crosvm_binary, 34 const std::string& first_time_argument, 35 int exit_code); 36 void AddControlSocket(const std::string&, const std::string&); 37 38 Result<void> AddCpus(size_t cpus, const std::string& freq_domain_file); 39 Result<void> AddCpus(const Json::Value&); 40 void AddCpus(size_t cpus); 41 42 void AddHvcSink(); 43 void AddHvcReadOnly(const std::string& output, bool console = false); 44 void AddHvcReadWrite(const std::string& output, const std::string& input); 45 46 void AddReadOnlyDisk(const std::string& path); 47 void AddReadWriteDisk(const std::string& path); 48 49 void AddSerialSink(); 50 void AddSerialConsoleReadOnly(const std::string& output); 51 void AddSerialConsoleReadWrite(const std::string& output, 52 const std::string& input, bool earlycon); 53 // [[deprecated("do not add any more users")]] 54 void AddSerial(const std::string& output, const std::string& input); 55 56 #ifdef __linux__ 57 void AddTap(const std::string& tap_name, 58 std::optional<std::string_view> mac = std::nullopt, 59 const std::optional<pci::Address>& pci = std::nullopt); 60 #endif 61 62 int HvcNum(); 63 64 Command& Cmd(); 65 66 private: 67 Command command_; 68 int hvc_num_; 69 int serial_num_; 70 }; 71 72 } // namespace cuttlefish 73