1 //
2 // Copyright (C) 2025 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 #include "host/libs/config/known_paths.h"
18
19 namespace cuttlefish {
20
SensorsSimulator(const CuttlefishConfig::InstanceSpecific & instance,AutoSensorsSocketPair::Type & sensors_socket_pair)21 Result<MonitorCommand> SensorsSimulator(
22 const CuttlefishConfig::InstanceSpecific& instance,
23 AutoSensorsSocketPair::Type& sensors_socket_pair) {
24 std::string to_guest_pipe_path =
25 instance.PerInstanceInternalPath("sensors_fifo_vm.in");
26 std::string from_guest_pipe_path =
27 instance.PerInstanceInternalPath("sensors_fifo_vm.out");
28 unlink(to_guest_pipe_path.c_str());
29 unlink(from_guest_pipe_path.c_str());
30 auto to_guest_fd = CF_EXPECT(SharedFD::Fifo(to_guest_pipe_path, 0660));
31 auto from_guest_fd = CF_EXPECT(SharedFD::Fifo(from_guest_pipe_path, 0660));
32 Command command(SensorsSimulatorBinary());
33 command.AddParameter("--sensors_in_fd=", from_guest_fd)
34 .AddParameter("--sensors_out_fd=", to_guest_fd)
35 .AddParameter("--webrtc_fd=", sensors_socket_pair->webrtc_socket);
36 return command;
37 }
38
39 } // namespace cuttlefish