Android-cuttlefish cvd tool
instance_group_record.h
Go to the documentation of this file.
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 <memory>
20#include <string>
21#include <vector>
22
23#include <json/json.h>
24
26#include "cuttlefish/host/commands/cvd/instances/cvd_persistent_data.pb.h"
29
30namespace cuttlefish {
31
33 public:
35 const cvd::InstanceGroup& group_proto);
36
40
41 static Result<LocalInstanceGroup> Deserialize(const Json::Value& group_json);
42
43 const std::string& GroupName() const { return group_proto_->name(); }
44 const std::string& HomeDir() const { return group_proto_->home_directory(); }
45 void SetHomeDir(const std::string& home_dir);
46 const std::string& HostArtifactsPath() const {
47 return group_proto_->host_artifacts_path();
48 }
49 void SetHostArtifactsPath(const std::string& host_artifacts_path);
50 const std::string& ProductOutPath() const {
51 return group_proto_->product_out_path();
52 }
53 void SetProductOutPath(const std::string& product_out_path);
54 TimeStamp StartTime() const;
55 void SetStartTime(TimeStamp time);
56 const std::vector<LocalInstance>& Instances() const { return instances_; }
57 std::vector<LocalInstance>& Instances() { return instances_; }
58 bool HasActiveInstances() const;
59 const cvd::InstanceGroup& Proto() const { return *group_proto_; }
60 void SetAllStates(cvd::InstanceState state);
61
62 std::string AssemblyDir() const;
63
64 Result<LocalInstance> FindInstanceById(unsigned id) const;
72 std::vector<LocalInstance> FindByInstanceName(
73 const std::string& instance_name) const;
74 // Fetches status from all instances in the group. Waits for run_cvd to
75 // respond for at most timeout seconds for each instance.
77 std::chrono::seconds timeout = std::chrono::seconds(5));
78
79 private:
80 LocalInstanceGroup(const cvd::InstanceGroup& group_proto);
81
82 // Ownership of the proto is shared between the LocalInstanceGroup and
83 // LocalInstance classes to ensure the references the latter maintains remain
84 // valid if the LocalInstanceGroup is destroyed before it.
85 std::shared_ptr<cvd::InstanceGroup> group_proto_;
86 std::vector<LocalInstance> instances_;
87};
88
89} // namespace cuttlefish
Definition: expected.h:86
Definition: instance_group_record.h:32
const std::vector< LocalInstance > & Instances() const
Definition: instance_group_record.h:56
void SetStartTime(TimeStamp time)
Definition: instance_group_record.cpp:118
Result< LocalInstance > FindInstanceById(unsigned id) const
Definition: instance_group_record.cpp:129
std::vector< LocalInstance > FindByInstanceName(const std::string &instance_name) const
Definition: instance_group_record.cpp:139
void SetAllStates(cvd::InstanceState state)
Definition: instance_group_record.cpp:108
void SetProductOutPath(const std::string &product_out_path)
Definition: instance_group_record.cpp:92
const std::string & ProductOutPath() const
Definition: instance_group_record.h:50
const cvd::InstanceGroup & Proto() const
Definition: instance_group_record.h:59
bool HasActiveInstances() const
Definition: instance_group_record.cpp:99
std::vector< LocalInstance > instances_
Definition: instance_group_record.h:86
LocalInstanceGroup & operator=(const LocalInstanceGroup &)=default
Result< Json::Value > FetchStatus(std::chrono::seconds timeout=std::chrono::seconds(5))
Definition: instance_group_record.cpp:207
void SetHostArtifactsPath(const std::string &host_artifacts_path)
Definition: instance_group_record.cpp:85
LocalInstanceGroup(const LocalInstanceGroup &)=default
const std::string & HostArtifactsPath() const
Definition: instance_group_record.h:46
std::vector< LocalInstance > & Instances()
Definition: instance_group_record.h:57
const std::string & HomeDir() const
Definition: instance_group_record.h:44
const std::string & GroupName() const
Definition: instance_group_record.h:43
static Result< LocalInstanceGroup > Create(const cvd::InstanceGroup &group_proto)
Definition: instance_group_record.cpp:57
void SetHomeDir(const std::string &home_dir)
Definition: instance_group_record.cpp:79
static Result< LocalInstanceGroup > Deserialize(const Json::Value &group_json)
Definition: instance_group_record.cpp:150
std::string AssemblyDir() const
Definition: instance_group_record.cpp:146
std::shared_ptr< cvd::InstanceGroup > group_proto_
Definition: instance_group_record.h:85
LocalInstanceGroup(LocalInstanceGroup &&)=default
TimeStamp StartTime() const
Definition: instance_group_record.cpp:114
Definition: alloc_utils.cpp:23
std::chrono::time_point< CvdServerClock > TimeStamp
Definition: instance_database_types.h:29