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/commands/run_cvd/launch/log_tee_creator.h"
27 #include "host/libs/config/command_source.h"
28 #include "host/libs/config/cuttlefish_config.h"
29 #include "host/libs/config/known_paths.h"
30 
31 namespace cuttlefish {
32 
Casimir(const CuttlefishConfig & config,const CuttlefishConfig::InstanceSpecific & instance,LogTeeCreator & log_tee)33 Result<std::vector<MonitorCommand>> Casimir(
34     const CuttlefishConfig& config,
35     const CuttlefishConfig::InstanceSpecific& instance,
36     LogTeeCreator& log_tee) {
37   if (!(config.enable_host_nfc() && instance.start_casimir())) {
38     return {};
39   }
40 
41   Command command(ProcessRestarterBinary());
42   command.AddParameter("-when_killed");
43   command.AddParameter("-when_dumped");
44   command.AddParameter("-when_exited_with_failure");
45   command.AddParameter("--");
46 
47   command.AddParameter(CasimirBinary());
48   command.AddParameter("--nci-port");
49   command.AddParameter(config.casimir_nci_port());
50   command.AddParameter("--rf-port");
51   command.AddParameter(config.casimir_rf_port());
52   for (auto const& arg : config.casimir_args()) {
53     command.AddParameter(arg);
54   }
55 
56   std::vector<MonitorCommand> commands;
57   commands.emplace_back(CF_EXPECT(log_tee.CreateLogTee(command, "casimir")));
58   commands.emplace_back(std::move(command));
59   return commands;
60 }
61 
62 }  // namespace cuttlefish
63