• 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 <map>
20 #include <mutex>
21 #include <optional>
22 #include <string>
23 
24 #include <fruit/fruit.h>
25 
26 #include "cvd_server.pb.h"
27 
28 #include "common/libs/fs/shared_fd.h"
29 #include "common/libs/utils/result.h"
30 #include "host/commands/cvd/instance_lock.h"
31 
32 namespace cuttlefish {
33 
34 constexpr char kStatusBin[] = "cvd_internal_status";
35 constexpr char kStopBin[] = "cvd_internal_stop";
36 
37 class InstanceManager {
38  public:
39   using InstanceGroupDir = std::string;
40   struct InstanceGroupInfo {
41     std::string host_binaries_dir;
42     std::set<int> instances;
43   };
44 
45   INJECT(InstanceManager(InstanceLockFileManager&));
46 
47   bool HasInstanceGroups() const;
48   void SetInstanceGroup(const InstanceGroupDir&, const InstanceGroupInfo&);
49   void RemoveInstanceGroup(const InstanceGroupDir&);
50   Result<InstanceGroupInfo> GetInstanceGroup(const InstanceGroupDir&) const;
51 
52   cvd::Status CvdClear(const SharedFD& out, const SharedFD& err);
53   cvd::Status CvdFleet(const SharedFD& out, const std::string& envconfig) const;
54 
55  private:
56   InstanceLockFileManager& lock_manager_;
57 
58   mutable std::mutex instance_groups_mutex_;
59   std::map<InstanceGroupDir, InstanceGroupInfo> instance_groups_;
60 };
61 
62 std::optional<std::string> GetCuttlefishConfigPath(
63     const std::string& assembly_dir);
64 
65 }  // namespace cuttlefish
66