• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   bool Process(std::vector<std::string>& args) override {
37     bool proxy_fastboot = true;
38     Flag proxy_fastboot_flag = GflagsCompatFlag(kName, proxy_fastboot);
39     if (!ParseFlags({proxy_fastboot_flag}, args)) {
40       LOG(ERROR) << "Failed to parse proxy_fastboot config flags";
41       return false;
42     }
43     config_.SetProxyFastboot(proxy_fastboot);
44     return true;
45   }
46 
WriteGflagsCompatHelpXml(std::ostream & out) const47   bool WriteGflagsCompatHelpXml(std::ostream& out) const override {
48     bool proxy_fastboot = config_.ProxyFastboot();
49     Flag proxy_fastboot_flag = GflagsCompatFlag(kName, proxy_fastboot).Help(kHelp);
50     return WriteGflagsCompatXml({proxy_fastboot_flag}, out);
51   }
52 
53  private:
54   static constexpr char kName[] = "proxy_fastboot";
55   static constexpr char kHelp[] = "Enstablish fastboot TCP proxy";
56 
57   FastbootConfig& config_;
58   ConfigFlag& config_flag_;
59 };
60 
61 }  // namespace
62 
63 fruit::Component<fruit::Required<FastbootConfig, ConfigFlag>, FastbootConfigFlag>
FastbootConfigFlagComponent()64 FastbootConfigFlagComponent() {
65   return fruit::createComponent()
66       .bind<FastbootConfigFlag, FastbootConfigFlagImpl>()
67       .addMultibinding<FlagFeature, FastbootConfigFlag>();
68 }
69 
70 }  // namespace cuttlefish
71