• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 
17 #pragma once
18 
19 #include <sys/types.h>
20 
21 #include <optional>
22 #include <string>
23 #include <unordered_map>
24 #include <vector>
25 
26 #include "cvd_server.pb.h"
27 
28 #include "common/libs/utils/result.h"
29 #include "common/libs/utils/subprocess.h"
30 #include "host/commands/cvd/server_client.h"
31 #include "host/commands/cvd/types.h"
32 
33 namespace cuttlefish {
34 
35 struct CommandInvocation {
36   std::string command;
37   std::vector<std::string> arguments;
38 };
39 
40 CommandInvocation ParseInvocation(const cvd::Request& request);
41 
42 cuttlefish::cvd::Response ResponseFromSiginfo(siginfo_t infop);
43 
44 Result<void> VerifyPrecondition(const RequestWithStdio& request);
45 
46 struct ConstructCommandParam {
47   const std::string& bin_path;
48   const std::string& home;
49   const std::vector<std::string>& args;
50   const cvd_common::Envs& envs;
51   const std::string& working_dir;
52   const std::string& command_name;
53   SharedFD in;
54   SharedFD out;
55   SharedFD err;
56 };
57 Result<Command> ConstructCommand(const ConstructCommandParam& cmd_param);
58 
59 // Constructs a command for cvd whatever --help or --help-related-option
60 Result<Command> ConstructCvdHelpCommand(const std::string& bin_file,
61                                         cvd_common::Envs envs,
62                                         const cvd_common::Args& _args,
63                                         const RequestWithStdio& request);
64 
65 // Constructs a command for cvd non-start-op
66 struct ConstructNonHelpForm {
67   std::string bin_file;
68   cvd_common::Envs envs;
69   cvd_common::Args cmd_args;
70   std::string android_host_out;
71   std::string home;
72   bool verbose;
73 };
74 Result<Command> ConstructCvdGenericNonHelpCommand(
75     const ConstructNonHelpForm& request_form, const RequestWithStdio& request);
76 
77 // e.g. cvd start --help, cvd stop --help
78 bool IsHelpSubcmd(const std::vector<std::string>& args);
79 
80 }  // namespace cuttlefish
81