• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #pragma once
18 
19 #include <sys/types.h>
20 
21 #include <string>
22 #include <unordered_map>
23 #include <vector>
24 
25 #include "common/libs/utils/result.h"
26 #include "host/commands/cvd/server_command/flags_collector.h"
27 
28 namespace cuttlefish {
29 
30 class HostToolTarget {
31  public:
32   using OperationToBinsMap =
33       std::unordered_map<std::string, std::vector<std::string>>;
34   struct FlagInfoRequest {
35     std::string operation_;
36     std::string flag_name_;
37   };
38   // artifacts_path: ANDROID_HOST_OUT, or so
39   static Result<HostToolTarget> Create(
40       const std::string& artifacts_path,
41       const OperationToBinsMap& supported_operations);
42 
43   bool IsDirty() const;
44   Result<FlagInfo> GetFlagInfo(const FlagInfoRequest& request) const;
HasField(const FlagInfoRequest & request)45   bool HasField(const FlagInfoRequest& request) const {
46     return GetFlagInfo(request).ok();
47   }
48   Result<std::string> GetBinName(const std::string& operation) const;
49 
50  private:
51   using SupportedFlagMap = std::unordered_map<std::string, FlagInfoPtr>;
52   struct OperationImplementation {
53     std::string bin_name_;
54     SupportedFlagMap supported_flags_;
55   };
56   HostToolTarget(const std::string& artifacts_path, const time_t dir_time_stamp,
57                  std::unordered_map<std::string, OperationImplementation>&&
58                      op_to_impl_map);
59 
60   // time stamp on creation
61   const std::string artifacts_path_;
62   const time_t dir_time_stamp_;
63   // map from "start", "stop", etc, to "cvd_internal_start", "stop_cvd", etc
64   // with the supported flags if those implementation offers --helpxml.
65   std::unordered_map<std::string, OperationImplementation> op_to_impl_map_;
66 };
67 
68 }  // namespace cuttlefish
69