// // Copyright (C) 2019 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include "host/commands/run_cvd/launch/launch.h" #include #include #include #include #include #include "common/libs/utils/files.h" #include "common/libs/utils/result.h" #include "host/libs/config/command_source.h" #include "host/libs/config/known_paths.h" namespace cuttlefish { namespace { class GnssGrpcProxyServer : public CommandSource { public: INJECT(GnssGrpcProxyServer(const CuttlefishConfig::InstanceSpecific& instance, GrpcSocketCreator& grpc_socket)) : instance_(instance), grpc_socket_(grpc_socket) {} // CommandSource Result> Commands() override { Command gnss_grpc_proxy_cmd(GnssGrpcProxyBinary()); const unsigned gnss_grpc_proxy_server_port = instance_.gnss_grpc_proxy_server_port(); gnss_grpc_proxy_cmd.AddParameter("--gnss_in_fd=", gnss_grpc_proxy_in_wr_); gnss_grpc_proxy_cmd.AddParameter("--gnss_out_fd=", gnss_grpc_proxy_out_rd_); gnss_grpc_proxy_cmd.AddParameter("--fixed_location_in_fd=", fixed_location_grpc_proxy_in_wr_); gnss_grpc_proxy_cmd.AddParameter("--fixed_location_out_fd=", fixed_location_grpc_proxy_out_rd_); gnss_grpc_proxy_cmd.AddParameter("--gnss_grpc_port=", gnss_grpc_proxy_server_port); gnss_grpc_proxy_cmd.AddParameter("--gnss_grpc_socket=", grpc_socket_.CreateGrpcSocket(Name())); if (!instance_.gnss_file_path().empty()) { // If path is provided, proxy will start as local mode. gnss_grpc_proxy_cmd.AddParameter("--gnss_file_path=", instance_.gnss_file_path()); } if (!instance_.fixed_location_file_path().empty()) { gnss_grpc_proxy_cmd.AddParameter("--fixed_location_file_path=", instance_.fixed_location_file_path()); } std::vector commands; commands.emplace_back(std::move(gnss_grpc_proxy_cmd)); return commands; } // SetupFeature std::string Name() const override { return "GnssGrpcProxyServer"; } bool Enabled() const override { return instance_.enable_gnss_grpc_proxy() && FileExists(GnssGrpcProxyBinary()); } private: std::unordered_set Dependencies() const override { return {}; } Result ResultSetup() override { std::vector fifos; std::vector fifo_paths = { instance_.PerInstanceInternalPath("gnsshvc_fifo_vm.in"), instance_.PerInstanceInternalPath("gnsshvc_fifo_vm.out"), instance_.PerInstanceInternalPath("locationhvc_fifo_vm.in"), instance_.PerInstanceInternalPath("locationhvc_fifo_vm.out"), }; for (const auto& path : fifo_paths) { unlink(path.c_str()); CF_EXPECT(mkfifo(path.c_str(), 0660) == 0, "Could not create " << path); auto fd = SharedFD::Open(path, O_RDWR); CF_EXPECT(fd->IsOpen(), "Could not open " << path << ": " << fd->StrError()); fifos.push_back(fd); } gnss_grpc_proxy_in_wr_ = fifos[0]; gnss_grpc_proxy_out_rd_ = fifos[1]; fixed_location_grpc_proxy_in_wr_ = fifos[2]; fixed_location_grpc_proxy_out_rd_ = fifos[3]; return {}; } private: const CuttlefishConfig::InstanceSpecific& instance_; SharedFD gnss_grpc_proxy_in_wr_; SharedFD gnss_grpc_proxy_out_rd_; SharedFD fixed_location_grpc_proxy_in_wr_; SharedFD fixed_location_grpc_proxy_out_rd_; GrpcSocketCreator& grpc_socket_; }; } // namespace fruit::Component> GnssGrpcProxyServerComponent() { return fruit::createComponent() .addMultibinding() .addMultibinding(); } } // namespace cuttlefish