• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <string>
19 #include <unordered_set>
20 #include <utility>
21 #include <vector>
22 
23 #include <fruit/fruit.h>
24 
25 #include "common/libs/utils/files.h"
26 #include "common/libs/utils/result.h"
27 #include "host/commands/run_cvd/launch/grpc_socket_creator.h"
28 #include "host/libs/config/command_source.h"
29 #include "host/libs/config/known_paths.h"
30 
31 namespace cuttlefish {
32 namespace {
33 
34 class OpenwrtControlServer : public CommandSource {
35  public:
INJECT(OpenwrtControlServer (const CuttlefishConfig::InstanceSpecific & instance,GrpcSocketCreator & grpc_socket))36   INJECT(
37       OpenwrtControlServer(const CuttlefishConfig::InstanceSpecific& instance,
38                            GrpcSocketCreator& grpc_socket))
39       : instance_(instance), grpc_socket_(grpc_socket) {}
40 
41   // CommandSource
Commands()42   Result<std::vector<MonitorCommand>> Commands() override {
43     Command openwrt_control_server_cmd(OpenwrtControlServerBinary());
44     openwrt_control_server_cmd.AddParameter(
45         "--grpc_uds_path=", grpc_socket_.CreateGrpcSocket(Name()));
46     openwrt_control_server_cmd.AddParameter(
47         "--bridged_wifi_tap=",
48         std::to_string(instance_.use_bridged_wifi_tap()));
49     openwrt_control_server_cmd.AddParameter("--launcher_log_path=",
50                                             instance_.launcher_log_path());
51     openwrt_control_server_cmd.AddParameter(
52         "--openwrt_log_path=",
53         AbsolutePath(instance_.PerInstanceLogPath("crosvm_openwrt.log")));
54 
55     std::vector<MonitorCommand> commands;
56     commands.emplace_back(std::move(openwrt_control_server_cmd));
57     return commands;
58   }
59 
60   // SetupFeature
Name() const61   std::string Name() const override { return "OpenwrtControlServer"; }
Enabled() const62   bool Enabled() const override { return true; }
63 
64  private:
Dependencies() const65   std::unordered_set<SetupFeature*> Dependencies() const override { return {}; }
Setup()66   bool Setup() override { return true; }
67 
68   const CuttlefishConfig::InstanceSpecific& instance_;
69   GrpcSocketCreator& grpc_socket_;
70 };
71 
72 }  // namespace
73 
74 fruit::Component<fruit::Required<const CuttlefishConfig::InstanceSpecific,
75                                  GrpcSocketCreator>>
OpenwrtControlServerComponent()76 OpenwrtControlServerComponent() {
77   return fruit::createComponent()
78       .addMultibinding<CommandSource, OpenwrtControlServer>()
79       .addMultibinding<SetupFeature, OpenwrtControlServer>();
80 }
81 
82 }  // namespace cuttlefish
83