1 //
2 // Copyright 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/libs/config/command_source.h"
27 #include "host/libs/config/cuttlefish_config.h"
28 #include "host/libs/config/known_paths.h"
29 
30 constexpr const size_t kBufferSize = 1024;
31 
32 namespace cuttlefish {
33 
NfcConnector(const CuttlefishConfig::EnvironmentSpecific & environment,const CuttlefishConfig::InstanceSpecific & instance)34 Result<MonitorCommand> NfcConnector(
35     const CuttlefishConfig::EnvironmentSpecific& environment,
36     const CuttlefishConfig::InstanceSpecific& instance) {
37   std::vector<std::string> fifo_paths = {
38       instance.PerInstanceInternalPath("nfc_fifo_vm.in"),
39       instance.PerInstanceInternalPath("nfc_fifo_vm.out"),
40   };
41   std::vector<SharedFD> fifos;
42   for (const auto& path : fifo_paths) {
43     fifos.emplace_back(CF_EXPECT(SharedFD::Fifo(path, 0660)));
44   }
45   return Command(TcpConnectorBinary())
46       .AddParameter("-fifo_out=", fifos[0])
47       .AddParameter("-fifo_in=", fifos[1])
48       .AddParameter("-data_path=", environment.casimir_nci_socket_path())
49       .AddParameter("-buffer_size=", kBufferSize);
50 }
51 
52 }  // namespace cuttlefish
53