forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
concierge_client.h
267 lines (222 loc) · 10.4 KB
/
concierge_client.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_DBUS_CONCIERGE_CLIENT_H_
#define CHROMEOS_DBUS_CONCIERGE_CLIENT_H_
#include <memory>
#include "base/component_export.h"
#include "base/files/scoped_file.h"
#include "base/observer_list.h"
#include "chromeos/dbus/concierge/concierge_service.pb.h"
#include "chromeos/dbus/dbus_client.h"
#include "chromeos/dbus/dbus_method_call_status.h"
#include "dbus/object_proxy.h"
namespace chromeos {
// ConciergeClient is used to communicate with Concierge, which is used to
// start and stop VMs, as well as for disk image management.
class COMPONENT_EXPORT(CHROMEOS_DBUS) ConciergeClient : public DBusClient {
public:
// Used for observing Concierge service itself.
class Observer : public base::CheckedObserver {
public:
// Called when Concierge service exits.
virtual void ConciergeServiceStopped() = 0;
// Called when Concierge service is either started or restarted.
virtual void ConciergeServiceStarted() = 0;
};
// Used for observing VMs starting and stopping.
class VmObserver {
public:
// OnVmStarted is signaled by Concierge when a VM starts.
virtual void OnVmStarted(
const vm_tools::concierge::VmStartedSignal& signal) = 0;
// OnVmStopped is signaled by Concierge when a VM stops.
virtual void OnVmStopped(
const vm_tools::concierge::VmStoppedSignal& signal) = 0;
protected:
virtual ~VmObserver() = default;
};
// Used for observing all concierge signals related to running
// containers (e.g. startup).
class ContainerObserver {
public:
// OnContainerStartupFailed is signaled by Concierge after the long-running
// container startup process's failure is detected. Note the signal protocol
// buffer type is the same as in OnContainerStarted.
virtual void OnContainerStartupFailed(
const vm_tools::concierge::ContainerStartedSignal& signal) = 0;
protected:
virtual ~ContainerObserver() = default;
};
// Used for observing all concierge signals related to VM disk image
// operations, e.g. importing.
class DiskImageObserver {
public:
// OnDiskImageProgress is signaled by Concierge after an ImportDiskImage
// call has been made and an update about the status of the import
// is available.
virtual void OnDiskImageProgress(
const vm_tools::concierge::DiskImageStatusResponse& signal) = 0;
protected:
virtual ~DiskImageObserver() = default;
};
// Adds an observer for monitoring Concierge service.
virtual void AddObserver(Observer* observer) = 0;
// Removes an observer if added.
virtual void RemoveObserver(Observer* observer) = 0;
// Adds an observer for VM start and stop.
virtual void AddVmObserver(VmObserver* observer) = 0;
// Removes an observer if added.
virtual void RemoveVmObserver(VmObserver* observer) = 0;
// Adds an observer for container startup.
virtual void AddContainerObserver(ContainerObserver* observer) = 0;
// Removes an observer if added.
virtual void RemoveContainerObserver(ContainerObserver* observer) = 0;
// Adds an observer for disk image operations.
virtual void AddDiskImageObserver(DiskImageObserver* observer) = 0;
// Adds an observer for disk image operations.
virtual void RemoveDiskImageObserver(DiskImageObserver* observer) = 0;
// IsVmSartedSignalConnected and IsVmStoppedSignalConnected must return true
// before RestartCrostini is called.
virtual bool IsVmStartedSignalConnected() = 0;
virtual bool IsVmStoppedSignalConnected() = 0;
// IsContainerStartupFailedSignalConnected must return true before
// StartContainer is called.
virtual bool IsContainerStartupFailedSignalConnected() = 0;
// IsDiskImageProgressSignalConnected must return true before
// ImportDiskImage is called.
virtual bool IsDiskImageProgressSignalConnected() = 0;
// Creates a disk image for the Termina VM.
// |callback| is called after the method call finishes.
virtual void CreateDiskImage(
const vm_tools::concierge::CreateDiskImageRequest& request,
DBusMethodCallback<vm_tools::concierge::CreateDiskImageResponse>
callback) = 0;
// Creates a disk image for a VM.
// |fd| references the source media (ISO).
// |callback| is called after the method call finishes.
virtual void CreateDiskImageWithFd(
base::ScopedFD fd,
const vm_tools::concierge::CreateDiskImageRequest& request,
DBusMethodCallback<vm_tools::concierge::CreateDiskImageResponse>
callback) = 0;
// Destroys a VM and removes its disk image.
// |callback| is called after the method call finishes.
virtual void DestroyDiskImage(
const vm_tools::concierge::DestroyDiskImageRequest& request,
DBusMethodCallback<vm_tools::concierge::DestroyDiskImageResponse>
callback) = 0;
// Imports a VM disk image.
// |callback| is called after the method call finishes.
virtual void ImportDiskImage(
base::ScopedFD fd,
const vm_tools::concierge::ImportDiskImageRequest& request,
DBusMethodCallback<vm_tools::concierge::ImportDiskImageResponse>
callback) = 0;
// Cancels a VM disk image operation (import or export) that is being
// executed.
// |callback| is called after the method call finishes.
virtual void CancelDiskImageOperation(
const vm_tools::concierge::CancelDiskImageRequest& request,
DBusMethodCallback<vm_tools::concierge::CancelDiskImageResponse>
callback) = 0;
// Retrieves the status of a disk image operation
// |callback| is called after the method call finishes.
virtual void DiskImageStatus(
const vm_tools::concierge::DiskImageStatusRequest& request,
DBusMethodCallback<vm_tools::concierge::DiskImageStatusResponse>
callback) = 0;
// Lists the Termina VMs.
// |callback| is called after the method call finishes.
virtual void ListVmDisks(
const vm_tools::concierge::ListVmDisksRequest& request,
DBusMethodCallback<vm_tools::concierge::ListVmDisksResponse>
callback) = 0;
// Starts a Termina VM if there is not alread one running.
// |callback| is called after the method call finishes.
virtual void StartTerminaVm(
const vm_tools::concierge::StartVmRequest& request,
DBusMethodCallback<vm_tools::concierge::StartVmResponse> callback) = 0;
// Stops the named Termina VM if it is running.
// |callback| is called after the method call finishes.
virtual void StopVm(
const vm_tools::concierge::StopVmRequest& request,
DBusMethodCallback<vm_tools::concierge::StopVmResponse> callback) = 0;
// Suspends the named Termina VM if it is running.
// |callback| is called after the method call finishes.
virtual void SuspendVm(
const vm_tools::concierge::SuspendVmRequest& request,
DBusMethodCallback<vm_tools::concierge::SuspendVmResponse> callback) = 0;
// Resumes the named Termina VM if it is running.
// |callback| is called after the method call finishes.
virtual void ResumeVm(
const vm_tools::concierge::ResumeVmRequest& request,
DBusMethodCallback<vm_tools::concierge::ResumeVmResponse> callback) = 0;
// Get VM Info.
// |callback| is called after the method call finishes.
virtual void GetVmInfo(
const vm_tools::concierge::GetVmInfoRequest& request,
DBusMethodCallback<vm_tools::concierge::GetVmInfoResponse> callback) = 0;
// Get enterprise-reporting specific VM info.
// |callback| is called after the method call finishes.
virtual void GetVmEnterpriseReportingInfo(
const vm_tools::concierge::GetVmEnterpriseReportingInfoRequest& request,
DBusMethodCallback<
vm_tools::concierge::GetVmEnterpriseReportingInfoResponse>
callback) = 0;
// Set VM's CPU restriction state.
// |callback| is called after the method call finishes.
virtual void SetVmCpuRestriction(
const vm_tools::concierge::SetVmCpuRestrictionRequest& request,
DBusMethodCallback<vm_tools::concierge::SetVmCpuRestrictionResponse>
callback) = 0;
// Registers |callback| to run when the Concierge service becomes available.
// If the service is already available, or if connecting to the name-owner-
// changed signal fails, |callback| will be run once asynchronously.
// Otherwise, |callback| will be run once in the future after the service
// becomes available.
virtual void WaitForServiceToBeAvailable(
dbus::ObjectProxy::WaitForServiceToBeAvailableCallback callback) = 0;
// Gets SSH server public key of container and trusted SSH client private key
// which can be used to connect to the container.
// |callback| is called after the method call finishes.
virtual void GetContainerSshKeys(
const vm_tools::concierge::ContainerSshKeysRequest& request,
DBusMethodCallback<vm_tools::concierge::ContainerSshKeysResponse>
callback) = 0;
// Attaches a USB device to a VM.
// |callback| is called once the method call has finished.
virtual void AttachUsbDevice(
base::ScopedFD fd,
const vm_tools::concierge::AttachUsbDeviceRequest& request,
DBusMethodCallback<vm_tools::concierge::AttachUsbDeviceResponse>
callback) = 0;
// Removes a USB device from a VM it's been attached to.
// |callback| is called once the method call has finished.
virtual void DetachUsbDevice(
const vm_tools::concierge::DetachUsbDeviceRequest& request,
DBusMethodCallback<vm_tools::concierge::DetachUsbDeviceResponse>
callback) = 0;
// Starts ARCVM if there is not already one running.
// |callback| is called after the method call finishes.
virtual void StartArcVm(
const vm_tools::concierge::StartArcVmRequest& request,
DBusMethodCallback<vm_tools::concierge::StartVmResponse> callback) = 0;
// Launches a resize operation for the specified disk image.
// |callback| is called after the method call finishes, then you must use
// |DiskImageStatus| to poll for task completion.
virtual void ResizeDiskImage(
const vm_tools::concierge::ResizeDiskImageRequest& request,
DBusMethodCallback<vm_tools::concierge::ResizeDiskImageResponse>
callback) = 0;
// Creates an instance of ConciergeClient.
static std::unique_ptr<ConciergeClient> Create();
~ConciergeClient() override;
protected:
// Create() should be used instead.
ConciergeClient();
private:
DISALLOW_COPY_AND_ASSIGN(ConciergeClient);
};
} // namespace chromeos
#endif // CHROMEOS_DBUS_CONCIERGE_CLIENT_H_