1 //
2 // Copyright (C) 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 <unordered_set>
19 #include <vector>
20 
21 #include "common/libs/utils/files.h"
22 #include "common/libs/utils/result.h"
23 #include "host/commands/run_cvd/launch/log_tee_creator.h"
24 #include "host/libs/config/cuttlefish_config.h"
25 #include "host/libs/config/known_paths.h"
26 
27 namespace cuttlefish {
28 
Pica(const CuttlefishConfig & config,const CuttlefishConfig::InstanceSpecific & instance,LogTeeCreator & log_tee)29 Result<std::vector<MonitorCommand>> Pica(
30     const CuttlefishConfig& config,
31     const CuttlefishConfig::InstanceSpecific& instance,
32     LogTeeCreator& log_tee) {
33   if (!instance.start_pica()) {
34     return {};
35   }
36   auto pcap_dir = instance.PerInstanceLogPath("/pica/");
37   CF_EXPECT(EnsureDirectoryExists(pcap_dir),
38             "Pica pcap directory cannot be created.");
39 
40   auto pica = Command(PicaBinary())
41                   .AddParameter("--uci-port=", config.pica_uci_port())
42                   .AddParameter("--pcapng-dir=", pcap_dir);
43 
44   std::vector<MonitorCommand> commands;
45   commands.emplace_back(CF_EXPECT(log_tee.CreateLogTee(pica, "pica")));
46   commands.emplace_back(std::move(pica));
47   return commands;
48 }
49 
50 }  // namespace cuttlefish
51