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 #include "host/commands/assemble_cvd/touchpad.h"
17
18 #include "common/libs/utils/flag_parser.h"
19 #include "host/libs/config/touchpad.h"
20
21 namespace cuttlefish {
22 namespace {
23
24 class TouchpadsConfigsImpl : public TouchpadsConfigs {
25 public:
INJECT(TouchpadsConfigsImpl ())26 INJECT(TouchpadsConfigsImpl()) {}
27
GetConfigs() const28 const std::vector<CuttlefishConfig::TouchpadConfig>& GetConfigs()
29 const override {
30 return touchpad_configs_;
31 }
32
SetConfigs(const std::vector<CuttlefishConfig::TouchpadConfig> & configs)33 void SetConfigs(
34 const std::vector<CuttlefishConfig::TouchpadConfig>& configs) {
35 touchpad_configs_ = configs;
36 }
37
Name() const38 std::string Name() const override { return "TouchpadsConfigsImpl"; }
39
40 private:
41 std::vector<CuttlefishConfig::TouchpadConfig> touchpad_configs_;
42 };
43
44 } // namespace
45
TouchpadsConfigsComponent()46 fruit::Component<TouchpadsConfigs> TouchpadsConfigsComponent() {
47 return fruit::createComponent()
48 .bind<TouchpadsConfigs, TouchpadsConfigsImpl>()
49 .addMultibinding<TouchpadsConfigs, TouchpadsConfigs>();
50 }
51
52 namespace {
53
54 class TouchpadsConfigsFlagImpl : public TouchpadsConfigsFlag {
55 public:
INJECT(TouchpadsConfigsFlagImpl (TouchpadsConfigs & configs,ConfigFlag & config_flag))56 INJECT(TouchpadsConfigsFlagImpl(TouchpadsConfigs& configs,
57 ConfigFlag& config_flag))
58 : touchpad_configs_(configs), config_flag_dependency_(config_flag) {}
59
Name() const60 std::string Name() const override { return "TouchpadsConfigsFlagImpl"; }
61
Dependencies() const62 std::unordered_set<FlagFeature*> Dependencies() const override {
63 return {static_cast<FlagFeature*>(&config_flag_dependency_)};
64 }
65
Process(std::vector<std::string> & args)66 Result<void> Process(std::vector<std::string>& args) override {
67 touchpad_configs_.SetConfigs(CF_EXPECT(ParseTouchpadConfigsFromArgs(args)));
68 return {};
69 }
70
WriteGflagsCompatHelpXml(std::ostream & out) const71 bool WriteGflagsCompatHelpXml(std::ostream& out) const override {
72 Flag touchpad_flag = GflagsCompatFlag(kTouchpadFlag).Help(kTouchpadHelp);
73 return WriteGflagsCompatXml({touchpad_flag}, out);
74 }
75
76 private:
77 TouchpadsConfigs& touchpad_configs_;
78 ConfigFlag& config_flag_dependency_;
79 };
80
81 } // namespace
82
83 fruit::Component<fruit::Required<TouchpadsConfigs, ConfigFlag>,
84 TouchpadsConfigsFlag>
TouchpadsConfigsFlagComponent()85 TouchpadsConfigsFlagComponent() {
86 return fruit::createComponent()
87 .bind<TouchpadsConfigsFlag, TouchpadsConfigsFlagImpl>()
88 .addMultibinding<FlagFeature, TouchpadsConfigsFlag>();
89 }
90
91 } // namespace cuttlefish
92