1 /*
2 * Copyright (C) 2022 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 #include "host/libs/config/fastboot/fastboot.h"
17
18 #include "common/libs/utils/flag_parser.h"
19 #include "host/libs/config/config_flag.h"
20 #include "host/libs/config/feature.h"
21
22 namespace cuttlefish {
23 namespace {
24
25 class FastbootConfigFlagImpl : public FastbootConfigFlag {
26 public:
INJECT(FastbootConfigFlagImpl (FastbootConfig & config,ConfigFlag & config_flag))27 INJECT(FastbootConfigFlagImpl(FastbootConfig& config, ConfigFlag& config_flag))
28 : config_(config), config_flag_(config_flag) {}
29
Name() const30 std::string Name() const override { return "FastbootConfigFlagImpl"; }
31
Dependencies() const32 std::unordered_set<FlagFeature*> Dependencies() const override {
33 return {static_cast<FlagFeature*>(&config_flag_)};
34 }
35
Process(std::vector<std::string> & args)36 Result<void> Process(std::vector<std::string>& args) override {
37 bool proxy_fastboot = true;
38 Flag proxy_fastboot_flag = GflagsCompatFlag(kName, proxy_fastboot);
39 CF_EXPECT(ConsumeFlags({proxy_fastboot_flag}, args),
40 "Failed to parse proxy_fastboot config flags");
41 config_.SetProxyFastboot(proxy_fastboot);
42 return {};
43 }
44
WriteGflagsCompatHelpXml(std::ostream & out) const45 bool WriteGflagsCompatHelpXml(std::ostream& out) const override {
46 bool proxy_fastboot = config_.ProxyFastboot();
47 Flag proxy_fastboot_flag = GflagsCompatFlag(kName, proxy_fastboot).Help(kHelp);
48 return WriteGflagsCompatXml({proxy_fastboot_flag}, out);
49 }
50
51 private:
52 static constexpr char kName[] = "proxy_fastboot";
53 static constexpr char kHelp[] = "Enstablish fastboot TCP proxy";
54
55 FastbootConfig& config_;
56 ConfigFlag& config_flag_;
57 };
58
59 } // namespace
60
61 fruit::Component<fruit::Required<FastbootConfig, ConfigFlag>, FastbootConfigFlag>
FastbootConfigFlagComponent()62 FastbootConfigFlagComponent() {
63 return fruit::createComponent()
64 .bind<FastbootConfigFlag, FastbootConfigFlagImpl>()
65 .addMultibinding<FlagFeature, FastbootConfigFlag>();
66 }
67
68 } // namespace cuttlefish
69