aboutsummaryrefslogtreecommitdiff
path: root/host/libs/config/cuttlefish_config_environment.cpp
blob: aa798827af00796b3f03b10006510dbf1efcb03c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 * Copyright (C) 2023 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.
 */

#include "host/libs/config/cuttlefish_config.h"

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

const char* kEnvironments = "environments";

namespace cuttlefish {

Json::Value* CuttlefishConfig::EnvironmentSpecific::Dictionary() {
  return &(*config_->dictionary_)[kEnvironments][envName_];
}

const Json::Value* CuttlefishConfig::EnvironmentSpecific::Dictionary() const {
  return &(*config_->dictionary_)[kEnvironments][envName_];
}

Json::Value* CuttlefishConfig::MutableEnvironmentSpecific::Dictionary() {
  return &(*config_->dictionary_)[kEnvironments][envName_];
}

std::string CuttlefishConfig::EnvironmentSpecific::environment_name() const {
  return envName_;
}

std::string CuttlefishConfig::EnvironmentSpecific::environment_uds_dir() const {
  return config_->EnvironmentsUdsPath(envName_);
}

std::string CuttlefishConfig::EnvironmentSpecific::PerEnvironmentUdsPath(
    const std::string& file_name) const {
  return (environment_uds_dir() + "/") + file_name;
}

std::string CuttlefishConfig::EnvironmentSpecific::environment_dir() const {
  return config_->EnvironmentsPath(envName_);
}

std::string CuttlefishConfig::EnvironmentSpecific::PerEnvironmentPath(
    const std::string& file_name) const {
  return (environment_dir() + "/") + file_name;
}

std::string CuttlefishConfig::EnvironmentSpecific::PerEnvironmentLogPath(
    const std::string& file_name) const {
  if (file_name.size() == 0) {
    // Don't append a / if file_name is empty.
    return PerEnvironmentPath(kLogDirName);
  }
  auto relative_path = (std::string(kLogDirName) + "/") + file_name;
  return PerEnvironmentPath(relative_path.c_str());
}

std::string CuttlefishConfig::EnvironmentSpecific::PerEnvironmentGrpcSocketPath(
    const std::string& file_name) const {
  if (file_name.size() == 0) {
    // Don't append a / if file_name is empty.
    return PerEnvironmentPath(kGrpcSocketDirName);
  }
  auto relative_path = (std::string(kGrpcSocketDirName) + "/") + file_name;
  return PerEnvironmentPath(relative_path.c_str());
}

std::string CuttlefishConfig::EnvironmentSpecific::control_socket_path() const {
  return PerEnvironmentUdsPath("env_control.sock");
}

std::string CuttlefishConfig::EnvironmentSpecific::launcher_log_path() const {
  return AbsolutePath(PerEnvironmentLogPath("launcher.log"));
}

static constexpr char kEnableWifi[] = "enable_wifi";
void CuttlefishConfig::MutableEnvironmentSpecific::set_enable_wifi(
    bool enable_wifi) {
  (*Dictionary())[kEnableWifi] = enable_wifi;
}
bool CuttlefishConfig::EnvironmentSpecific::enable_wifi() const {
  return (*Dictionary())[kEnableWifi].asBool();
}

static constexpr char kStartWmediumd[] = "start_wmediumd";
void CuttlefishConfig::MutableEnvironmentSpecific::set_start_wmediumd(
    bool start) {
  (*Dictionary())[kStartWmediumd] = start;
}
bool CuttlefishConfig::EnvironmentSpecific::start_wmediumd() const {
  return (*Dictionary())[kStartWmediumd].asBool();
}

static constexpr char kVhostUserMac80211Hwsim[] = "vhost_user_mac80211_hwsim";
void CuttlefishConfig::MutableEnvironmentSpecific::
    set_vhost_user_mac80211_hwsim(const std::string& path) {
  (*Dictionary())[kVhostUserMac80211Hwsim] = path;
}
std::string CuttlefishConfig::EnvironmentSpecific::vhost_user_mac80211_hwsim()
    const {
  return (*Dictionary())[kVhostUserMac80211Hwsim].asString();
}

static constexpr char kWmediumdApiServerSocket[] = "wmediumd_api_server_socket";
void CuttlefishConfig::MutableEnvironmentSpecific::
    set_wmediumd_api_server_socket(const std::string& path) {
  (*Dictionary())[kWmediumdApiServerSocket] = path;
}
std::string CuttlefishConfig::EnvironmentSpecific::wmediumd_api_server_socket()
    const {
  return (*Dictionary())[kWmediumdApiServerSocket].asString();
}

static constexpr char kWmediumdConfig[] = "wmediumd_config";
void CuttlefishConfig::MutableEnvironmentSpecific::set_wmediumd_config(
    const std::string& config) {
  (*Dictionary())[kWmediumdConfig] = config;
}
std::string CuttlefishConfig::EnvironmentSpecific::wmediumd_config() const {
  return (*Dictionary())[kWmediumdConfig].asString();
}

static constexpr char kWmediumdMacPrefix[] = "wmediumd_mac_prefix";
void CuttlefishConfig::MutableEnvironmentSpecific::set_wmediumd_mac_prefix(
    int mac_prefix) {
  (*Dictionary())[kWmediumdMacPrefix] = mac_prefix;
}
int CuttlefishConfig::EnvironmentSpecific::wmediumd_mac_prefix() const {
  return (*Dictionary())[kWmediumdMacPrefix].asInt();
}

}  // namespace cuttlefish