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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
use crate::snapshot::Snapshot;
use crate::utility::macros::macros::{
get_function_result_bool, get_function_result_number, get_function_result_pointer,
get_function_result_pointer_vec, get_function_result_str, get_function_result_unit,
};
use crate::utility::string_to_c_u64_str;
use crate::{Machine, VboxError, VboxErrorType};
use vbox_raw::sys_lib::{IMachine, ISnapshot};
impl Snapshot {
/// UUID of the snapshot.
///
/// # Returns
///
/// Returns [&str] on success, or a [`VboxError`] on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::VirtualBox;
///
/// let vbox = VirtualBox::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// let snapshot = machine.get_current_snapshot().unwrap().unwrap();
///
/// let id = snapshot.get_id().unwrap();
///
pub fn get_id(&self) -> Result<&'static str, VboxError> {
get_function_result_str!(self.object, GetId)
}
/// Short name of the snapshot.
///
/// # Returns
///
/// Returns [&str] on success, or a [`VboxError`] on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::VirtualBox;
///
/// let vbox = VirtualBox::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// let snapshot = machine.get_current_snapshot().unwrap().unwrap();
///
/// let name = snapshot.get_name().unwrap();
///
pub fn get_name(&self) -> Result<&'static str, VboxError> {
get_function_result_str!(self.object, GetName)
}
/// Short name of the snapshot.
///
/// # Arguments
///
/// * `name` - &str. Short name of the snapshot.
///
/// # Returns
///
/// Returns () success, or a [`VboxError`] on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::VirtualBox;
///
/// let vbox = VirtualBox::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// let snapshot = machine.get_current_snapshot().unwrap().unwrap();
///
/// snapshot.set_name("Snapshot_1").unwrap();
pub fn set_name(&self, name: &str) -> Result<(), VboxError> {
let name_ptr = string_to_c_u64_str(name)?;
get_function_result_unit!(self.object, SetName, name_ptr)
}
/// Optional description of the snapshot.
///
/// # Returns
///
/// Returns [&str] on success, or a [`VboxError`] on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::VirtualBox;
///
/// let vbox = VirtualBox::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// let snapshot = machine.get_current_snapshot().unwrap().unwrap();
///
/// let description = snapshot.get_description().unwrap();
///
pub fn get_description(&self) -> Result<&'static str, VboxError> {
get_function_result_str!(self.object, GetDescription)
}
/// Optional description of the snapshot.
///
/// # Arguments
///
/// * `description` - &str. Optional description of the snapshot.
///
/// # Returns
///
/// Returns () success, or a [`VboxError`] on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::VirtualBox;
///
/// let vbox = VirtualBox::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// let snapshot = machine.get_current_snapshot().unwrap().unwrap();
///
/// snapshot.set_description("description").unwrap();
pub fn set_description(&self, name: &str) -> Result<(), VboxError> {
let description = string_to_c_u64_str(name)?;
get_function_result_unit!(self.object, SetDescription, description)
}
/// Timestamp of the snapshot, in milliseconds since 1970-01-01 UTC.
///
/// # Returns
///
/// Returns i64 success, or a [`VboxError`] on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::VirtualBox;
///
/// let vbox = VirtualBox::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// let snapshot = machine.get_current_snapshot().unwrap().unwrap();
///
/// let time_stamp = snapshot.get_time_stamp().unwrap();
pub fn get_time_stamp(&self) -> Result<i64, VboxError> {
get_function_result_number!(self.object, GetTimeStamp, i64)
}
/// true if this snapshot is an online snapshot and false otherwise.
///
/// When this attribute is true, the [`Machine::get_state_file_path`] attribute of the machine object associated with this snapshot will point to the saved state file. Otherwise, it will be an empty string.
///
/// # Returns
///
/// Returns bool success, or a [`VboxError`] on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::VirtualBox;
///
/// let vbox = VirtualBox::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// let snapshot = machine.get_current_snapshot().unwrap().unwrap();
///
/// let time_stamp = snapshot.get_time_stamp().unwrap();
pub fn get_online(&self) -> Result<bool, VboxError> {
get_function_result_bool!(self.object, GetOnline)
}
/// Virtual machine this snapshot is taken on.
///
/// This object stores all settings the machine had when taking this snapshot.
///
/// <div class="warning">
/// The returned machine object is immutable, i.e. no any settings can be changed.
/// </div>
///
/// # Returns
///
/// Returns [`Machine`] success, or a [`VboxError`] on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::VirtualBox;
///
/// let vbox = VirtualBox::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// let snapshot = machine.get_current_snapshot().unwrap().unwrap();
///
/// let machine = snapshot.get_machine().unwrap();
pub fn get_machine(&self) -> Result<Machine, VboxError> {
let machine = get_function_result_pointer!(self.object, GetMachine, *mut IMachine)?;
Ok(Machine::new(machine))
}
/// Parent snapshot (a snapshot this one is based on), or None if the snapshot has no parent (i.e. is the first snapshot).
///
/// # Returns
///
/// Returns [`Option<Snapshot>`] success, or a [`VboxError`] on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::VirtualBox;
///
/// let vbox = VirtualBox::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// let snapshot = machine.find_snapshot("Snapshot_2").unwrap();
///
/// let machine = snapshot.get_machine().unwrap();
pub fn get_parent(&self) -> Result<Option<Snapshot>, VboxError> {
let parent = get_function_result_pointer!(self.object, GetParent, *mut ISnapshot);
match parent {
Ok(parent) => Ok(Some(Snapshot::new(parent))),
Err(error) => {
if error.error_type == VboxErrorType::NullPointerError {
Ok(None)
} else {
Err(error)
}
}
}
}
/// Child snapshots (all snapshots having this one as a parent).
///
/// By inspecting this attribute starting with a machine's root snapshot (which can be obtained by calling [`Machine::find_snapshot`] with empty UUID), a machine's snapshots tree can be iterated over.
///
/// # Returns
///
/// Returns [`Vec<Snapshot>`] success, or a [`VboxError`] on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::VirtualBox;
///
/// let vbox = VirtualBox::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// let snapshot = machine.find_snapshot("Snapshot_2").unwrap();
///
/// let children = snapshot.get_children().unwrap();
pub fn get_children(&self) -> Result<Vec<Snapshot>, VboxError> {
let children = get_function_result_pointer_vec!(self.object, GetChildren, *mut ISnapshot)?;
Ok(children
.iter()
.map(|object| Snapshot::new(object.clone()))
.collect())
}
/// Returns the number of direct children of this snapshot.
///
/// # Returns
///
/// Returns [`Vec<Snapshot>`] success, or a [`VboxError`] on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::VirtualBox;
///
/// let vbox = VirtualBox::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// let snapshot = machine.find_snapshot("Snapshot_2").unwrap();
///
/// let count = snapshot.get_children_count().unwrap();
pub fn get_children_count(&self) -> Result<u32, VboxError> {
get_function_result_number!(self.object, GetChildrenCount, u32)
}
}