1 /* 2 * Copyright (C) 2023 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 #include "host/libs/config/cuttlefish_config.h" 18 19 #include "common/libs/utils/files.h" 20 21 const char* kEnvironments = "environments"; 22 23 namespace cuttlefish { 24 Dictionary()25Json::Value* CuttlefishConfig::EnvironmentSpecific::Dictionary() { 26 return &(*config_->dictionary_)[kEnvironments][envName_]; 27 } 28 Dictionary() const29const Json::Value* CuttlefishConfig::EnvironmentSpecific::Dictionary() const { 30 return &(*config_->dictionary_)[kEnvironments][envName_]; 31 } 32 Dictionary()33Json::Value* CuttlefishConfig::MutableEnvironmentSpecific::Dictionary() { 34 return &(*config_->dictionary_)[kEnvironments][envName_]; 35 } 36 environment_name() const37std::string CuttlefishConfig::EnvironmentSpecific::environment_name() const { 38 return envName_; 39 } 40 environment_uds_dir() const41std::string CuttlefishConfig::EnvironmentSpecific::environment_uds_dir() const { 42 return config_->EnvironmentsUdsPath(envName_); 43 } 44 PerEnvironmentUdsPath(const std::string & file_name) const45std::string CuttlefishConfig::EnvironmentSpecific::PerEnvironmentUdsPath( 46 const std::string& file_name) const { 47 return (environment_uds_dir() + "/") + file_name; 48 } 49 environment_dir() const50std::string CuttlefishConfig::EnvironmentSpecific::environment_dir() const { 51 return config_->EnvironmentsPath(envName_); 52 } 53 PerEnvironmentPath(const std::string & file_name) const54std::string CuttlefishConfig::EnvironmentSpecific::PerEnvironmentPath( 55 const std::string& file_name) const { 56 return (environment_dir() + "/") + file_name; 57 } 58 PerEnvironmentLogPath(const std::string & file_name) const59std::string CuttlefishConfig::EnvironmentSpecific::PerEnvironmentLogPath( 60 const std::string& file_name) const { 61 if (file_name.size() == 0) { 62 // Don't append a / if file_name is empty. 63 return PerEnvironmentPath(kLogDirName); 64 } 65 auto relative_path = (std::string(kLogDirName) + "/") + file_name; 66 return PerEnvironmentPath(relative_path.c_str()); 67 } 68 PerEnvironmentGrpcSocketPath(const std::string & file_name) const69std::string CuttlefishConfig::EnvironmentSpecific::PerEnvironmentGrpcSocketPath( 70 const std::string& file_name) const { 71 if (file_name.size() == 0) { 72 // Don't append a / if file_name is empty. 73 return PerEnvironmentPath(kGrpcSocketDirName); 74 } 75 auto relative_path = (std::string(kGrpcSocketDirName) + "/") + file_name; 76 return PerEnvironmentPath(relative_path.c_str()); 77 } 78 control_socket_path() const79std::string CuttlefishConfig::EnvironmentSpecific::control_socket_path() const { 80 return PerEnvironmentUdsPath("env_control.sock"); 81 } 82 launcher_log_path() const83std::string CuttlefishConfig::EnvironmentSpecific::launcher_log_path() const { 84 return AbsolutePath(PerEnvironmentLogPath("launcher.log")); 85 } 86 87 static constexpr char kEnableWifi[] = "enable_wifi"; set_enable_wifi(bool enable_wifi)88void CuttlefishConfig::MutableEnvironmentSpecific::set_enable_wifi( 89 bool enable_wifi) { 90 (*Dictionary())[kEnableWifi] = enable_wifi; 91 } enable_wifi() const92bool CuttlefishConfig::EnvironmentSpecific::enable_wifi() const { 93 return (*Dictionary())[kEnableWifi].asBool(); 94 } 95 96 static constexpr char kStartWmediumd[] = "start_wmediumd"; set_start_wmediumd(bool start)97void CuttlefishConfig::MutableEnvironmentSpecific::set_start_wmediumd( 98 bool start) { 99 (*Dictionary())[kStartWmediumd] = start; 100 } start_wmediumd() const101bool CuttlefishConfig::EnvironmentSpecific::start_wmediumd() const { 102 return (*Dictionary())[kStartWmediumd].asBool(); 103 } 104 105 static constexpr char kVhostUserMac80211Hwsim[] = "vhost_user_mac80211_hwsim"; 106 void CuttlefishConfig::MutableEnvironmentSpecific:: set_vhost_user_mac80211_hwsim(const std::string & path)107 set_vhost_user_mac80211_hwsim(const std::string& path) { 108 (*Dictionary())[kVhostUserMac80211Hwsim] = path; 109 } vhost_user_mac80211_hwsim() const110std::string CuttlefishConfig::EnvironmentSpecific::vhost_user_mac80211_hwsim() 111 const { 112 return (*Dictionary())[kVhostUserMac80211Hwsim].asString(); 113 } 114 115 static constexpr char kWmediumdApiServerSocket[] = "wmediumd_api_server_socket"; 116 void CuttlefishConfig::MutableEnvironmentSpecific:: set_wmediumd_api_server_socket(const std::string & path)117 set_wmediumd_api_server_socket(const std::string& path) { 118 (*Dictionary())[kWmediumdApiServerSocket] = path; 119 } wmediumd_api_server_socket() const120std::string CuttlefishConfig::EnvironmentSpecific::wmediumd_api_server_socket() 121 const { 122 return (*Dictionary())[kWmediumdApiServerSocket].asString(); 123 } 124 125 static constexpr char kWmediumdConfig[] = "wmediumd_config"; set_wmediumd_config(const std::string & config)126void CuttlefishConfig::MutableEnvironmentSpecific::set_wmediumd_config( 127 const std::string& config) { 128 (*Dictionary())[kWmediumdConfig] = config; 129 } wmediumd_config() const130std::string CuttlefishConfig::EnvironmentSpecific::wmediumd_config() const { 131 return (*Dictionary())[kWmediumdConfig].asString(); 132 } 133 134 static constexpr char kWmediumdMacPrefix[] = "wmediumd_mac_prefix"; set_wmediumd_mac_prefix(int mac_prefix)135void CuttlefishConfig::MutableEnvironmentSpecific::set_wmediumd_mac_prefix( 136 int mac_prefix) { 137 (*Dictionary())[kWmediumdMacPrefix] = mac_prefix; 138 } wmediumd_mac_prefix() const139int CuttlefishConfig::EnvironmentSpecific::wmediumd_mac_prefix() const { 140 return (*Dictionary())[kWmediumdMacPrefix].asInt(); 141 } 142 143 } // namespace cuttlefish 144