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/run_cvd/launch/launch.h"
17 
18 #include <unordered_set>
19 #include <vector>
20 
21 #include "host/commands/run_cvd/launch/log_tee_creator.h"
22 #include "host/libs/config/cuttlefish_config.h"
23 #include "host/libs/config/known_paths.h"
24 
25 namespace cuttlefish {
26 namespace {
27 
28 class Pica : public CommandSource {
29  public:
INJECT(Pica (const CuttlefishConfig & config,const CuttlefishConfig::InstanceSpecific & instance,LogTeeCreator & log_tee))30   INJECT(Pica(const CuttlefishConfig& config,
31                    const CuttlefishConfig::InstanceSpecific& instance,
32                    LogTeeCreator& log_tee))
33       : config_(config), instance_(instance), log_tee_(log_tee) {}
34 
35   // CommandSource
Commands()36   Result<std::vector<MonitorCommand>> Commands() override {
37     if (!Enabled()) {
38       return {};
39     }
40     Command command(PicaBinary());
41 
42     // UCI server port
43     command.AddParameter("--uci-port=", config_.pica_uci_port());
44 
45 
46     std::vector<MonitorCommand> commands;
47     commands.emplace_back(std::move(log_tee_.CreateLogTee(command, "pica")));
48     commands.emplace_back(std::move(command));
49     return commands;
50   }
51 
52   // SetupFeature
Name() const53   std::string Name() const override { return "Pica"; }
Enabled() const54   bool Enabled() const override {
55     return config_.enable_host_uwb_connector() && instance_.start_pica();
56   }
57 
58  private:
Dependencies() const59   std::unordered_set<SetupFeature*> Dependencies() const override { return {}; }
Setup()60   bool Setup() override { return true; }
61 
62   const CuttlefishConfig& config_;
63   const CuttlefishConfig::InstanceSpecific& instance_;
64   LogTeeCreator& log_tee_;
65 };
66 
67 }  // namespace
68 
69 fruit::Component<
70     fruit::Required<const CuttlefishConfig,
71                     const CuttlefishConfig::InstanceSpecific, LogTeeCreator>>
PicaComponent()72 PicaComponent() {
73   return fruit::createComponent()
74       .addMultibinding<CommandSource, Pica>()
75       .addMultibinding<SetupFeature, Pica>();
76 }
77 
78 }  // namespace cuttlefish
79