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/result.h" 26 #include "host/commands/run_cvd/launch/grpc_socket_creator.h" 27 #include "host/libs/config/command_source.h" 28 #include "host/libs/config/known_paths.h" 29 30 namespace cuttlefish { 31 namespace { 32 33 class EchoServer : public CommandSource { 34 public: INJECT(EchoServer (GrpcSocketCreator & grpc_socket))35 INJECT(EchoServer(GrpcSocketCreator& grpc_socket)) 36 : grpc_socket_(grpc_socket) {} 37 38 // CommandSource Commands()39 Result<std::vector<MonitorCommand>> Commands() override { 40 Command command(EchoServerBinary()); 41 command.AddParameter("--grpc_uds_path=", 42 grpc_socket_.CreateGrpcSocket(Name())); 43 std::vector<MonitorCommand> commands; 44 commands.emplace_back(std::move(command)); 45 return commands; 46 } 47 48 // SetupFeature Name() const49 std::string Name() const override { return "EchoServer"; } Enabled() const50 bool Enabled() const override { return true; } 51 52 private: Dependencies() const53 std::unordered_set<SetupFeature*> Dependencies() const override { return {}; } Setup()54 bool Setup() override { return true; } 55 56 GrpcSocketCreator& grpc_socket_; 57 }; 58 59 } // namespace 60 EchoServerComponent()61fruit::Component<fruit::Required<GrpcSocketCreator>> EchoServerComponent() { 62 return fruit::createComponent() 63 .addMultibinding<CommandSource, EchoServer>() 64 .addMultibinding<SetupFeature, EchoServer>(); 65 } 66 67 } // namespace cuttlefish 68