• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2019 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/result.h"
26 #include "host/libs/config/command_source.h"
27 #include "host/libs/config/known_paths.h"
28 
29 namespace cuttlefish {
30 namespace {
31 
32 class ConfigServer : public CommandSource {
33  public:
INJECT(ConfigServer (const CuttlefishConfig::InstanceSpecific & instance))34   INJECT(ConfigServer(const CuttlefishConfig::InstanceSpecific& instance))
35       : instance_(instance) {}
36 
37   // CommandSource
Commands()38   Result<std::vector<MonitorCommand>> Commands() override {
39     Command command(ConfigServerBinary());
40     command.AddParameter("-server_fd=", socket_);
41     std::vector<MonitorCommand> commands;
42     commands.emplace_back(std::move(command));
43     return commands;
44   }
45 
46   // SetupFeature
Name() const47   std::string Name() const override { return "ConfigServer"; }
Enabled() const48   bool Enabled() const override { return true; }
49 
50  private:
Dependencies() const51   std::unordered_set<SetupFeature*> Dependencies() const override { return {}; }
ResultSetup()52   Result<void> ResultSetup() override {
53     auto port = instance_.config_server_port();
54     socket_ = SharedFD::VsockServer(port, SOCK_STREAM);
55     CF_EXPECT(socket_->IsOpen(),
56               "Unable to create configuration server socket: "
57                   << socket_->StrError());
58     return {};
59   }
60 
61  private:
62   const CuttlefishConfig::InstanceSpecific& instance_;
63   SharedFD socket_;
64 };
65 
66 }  // namespace
67 
68 fruit::Component<fruit::Required<const CuttlefishConfig::InstanceSpecific>>
ConfigServerComponent()69 ConfigServerComponent() {
70   return fruit::createComponent()
71       .addMultibinding<CommandSource, ConfigServer>()
72       .addMultibinding<SetupFeature, ConfigServer>();
73 }
74 
75 }  // namespace cuttlefish
76