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 <vector>
20
21 #include <fruit/fruit.h>
22
23 #include "common/libs/fs/shared_fd.h"
24 #include "common/libs/utils/result.h"
25 #include "host/libs/config/command_source.h"
26 #include "host/libs/config/known_paths.h"
27
28 namespace cuttlefish {
29
GnssGrpcProxyServer(const CuttlefishConfig::InstanceSpecific & instance,GrpcSocketCreator & grpc_socket)30 Result<std::optional<MonitorCommand>> GnssGrpcProxyServer(
31 const CuttlefishConfig::InstanceSpecific& instance,
32 GrpcSocketCreator& grpc_socket) {
33 if (!instance.enable_gnss_grpc_proxy()) {
34 return {};
35 }
36 std::vector<SharedFD> fifos;
37 std::vector<std::string> fifo_paths = {
38 instance.PerInstanceInternalPath("gnsshvc_fifo_vm.in"),
39 instance.PerInstanceInternalPath("gnsshvc_fifo_vm.out"),
40 instance.PerInstanceInternalPath("locationhvc_fifo_vm.in"),
41 instance.PerInstanceInternalPath("locationhvc_fifo_vm.out"),
42 };
43 for (const auto& path : fifo_paths) {
44 fifos.emplace_back(CF_EXPECT(SharedFD::Fifo(path, 0660)));
45 }
46
47 auto gnss_grpc_proxy_cmd =
48 Command(GnssGrpcProxyBinary())
49 .AddParameter("--gnss_in_fd=", fifos[0])
50 .AddParameter("--gnss_out_fd=", fifos[1])
51 .AddParameter("--fixed_location_in_fd=", fifos[2])
52 .AddParameter("--fixed_location_out_fd=", fifos[3])
53 .AddParameter("--gnss_grpc_port=",
54 instance.gnss_grpc_proxy_server_port())
55 .AddParameter("--gnss_grpc_socket=",
56 grpc_socket.CreateGrpcSocket("GnssGrpcProxyServer"));
57 if (!instance.gnss_file_path().empty()) {
58 // If path is provided, proxy will start as local mode.
59 gnss_grpc_proxy_cmd.AddParameter("--gnss_file_path=",
60 instance.gnss_file_path());
61 }
62 if (!instance.fixed_location_file_path().empty()) {
63 gnss_grpc_proxy_cmd.AddParameter("--fixed_location_file_path=",
64 instance.fixed_location_file_path());
65 }
66 return gnss_grpc_proxy_cmd;
67 }
68
69 } // namespace cuttlefish
70