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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
use crate::event_source::EventSource;
use crate::progress::Progress;
use crate::utility::macros::macros::{
get_function_result_bool, get_function_result_number, get_function_result_pointer,
get_function_result_str, get_function_result_unit,
};
use crate::virtualbox_error_info::VirtualBoxErrorInfo;
use crate::VboxError;
use vbox_raw::sys_lib::{IEventSource, IVirtualBoxErrorInfo};
impl Progress {
///
/// Waits until the task is done (including all sub-operations) with a given timeout in milliseconds; specify -1 for an indefinite wait.
///
/// # Arguments
///
/// * `timeout` - Maximum time in milliseconds to wait or -1 to wait indefinitely.
///
/// # Returns
///
/// Returns Ok(()) on success, or a `VboxError` on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::{Session, VirtualBox};
/// use virtualbox_rs::enums::SessionType;
///
/// let vbox = VirtualBox::init().unwrap();
/// let mut session = Session::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// machine.lock_machine(&mut session, SessionType::Shared).unwrap();
///
/// let machine_mut = session.get_machine().unwrap();
///
/// let progress = machine_mut.save_state().unwrap();
/// progress.wait_for_completion(-1).unwrap();
pub fn wait_for_completion(&self, timeout: i32) -> Result<(), VboxError> {
let timeout = if timeout < 0 { i32::MAX } else { timeout };
get_function_result_unit!(self.object, WaitForCompletion, timeout)
}
/// ID of the task.
///
/// # Returns
///
/// Returns &str on success, or a [`VboxError`] on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::{Session, VirtualBox};
/// use virtualbox_rs::enums::SessionType;
///
/// let vbox = VirtualBox::init().unwrap();
/// let mut session = Session::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// machine.lock_machine(&mut session, SessionType::Shared).unwrap();
///
/// let machine_mut = session.get_machine().unwrap();
///
/// let progress = machine_mut.save_state().unwrap();
/// progress.wait_for_completion(1).unwrap();
/// let id = progress.get_id().unwrap();
pub fn get_id(&self) -> Result<&'static str, VboxError> {
get_function_result_str!(self.object, GetId)
}
/// Description of the task.
///
/// # Returns
///
/// Returns &str on success, or a `VboxError` on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::{Session, VirtualBox};
/// use virtualbox_rs::enums::SessionType;
///
/// let vbox = VirtualBox::init().unwrap();
/// let mut session = Session::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// machine.lock_machine(&mut session, SessionType::Shared).unwrap();
///
/// let machine_mut = session.get_machine().unwrap();
///
/// let progress = machine_mut.save_state().unwrap();
/// progress.wait_for_completion(1).unwrap();
/// let description = progress.get_description().unwrap();
pub fn get_description(&self) -> Result<&'static str, VboxError> {
get_function_result_str!(self.object, GetDescription)
}
/// Whether the task can be interrupted.
///
/// # Returns
///
/// Returns bool on success, or a `VboxError` on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::{Session, VirtualBox};
/// use virtualbox_rs::enums::SessionType;
///
/// let vbox = VirtualBox::init().unwrap();
/// let mut session = Session::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// machine.lock_machine(&mut session, SessionType::Shared).unwrap();
///
/// let machine_mut = session.get_machine().unwrap();
///
/// let progress = machine_mut.save_state().unwrap();
/// progress.wait_for_completion(1).unwrap();
/// let cancelable = progress.get_cancelable().unwrap();
pub fn get_cancelable(&self) -> Result<bool, VboxError> {
get_function_result_bool!(self.object, GetCancelable)
}
/// Current progress value of the task as a whole, in percent.
///
/// # Returns
///
/// Returns u32 on success, or a `VboxError` on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::{Session, VirtualBox};
/// use virtualbox_rs::enums::SessionType;
///
/// let vbox = VirtualBox::init().unwrap();
/// let mut session = Session::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// machine.lock_machine(&mut session, SessionType::Shared).unwrap();
///
/// let machine_mut = session.get_machine().unwrap();
///
/// let progress = machine_mut.save_state().unwrap();
/// progress.wait_for_completion(1).unwrap();
/// let percent = progress.get_percent().unwrap();
pub fn get_percent(&self) -> Result<u32, VboxError> {
let percent = get_function_result_number!(self.object, GetPercent, u32)?;
Ok(percent)
}
/// Estimated remaining time until the task completes, in seconds.
///
/// # Returns
///
/// Returns i32 on success, or a `VboxError` on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::{Session, VirtualBox};
/// use virtualbox_rs::enums::SessionType;
///
/// let vbox = VirtualBox::init().unwrap();
/// let mut session = Session::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// machine.lock_machine(&mut session, SessionType::Shared).unwrap();
///
/// let machine_mut = session.get_machine().unwrap();
///
/// let progress = machine_mut.save_state().unwrap();
/// progress.wait_for_completion(1).unwrap();
/// let time_remaining = progress.get_time_remaining().unwrap();
pub fn get_time_remaining(&self) -> Result<i32, VboxError> {
let time_remaining = get_function_result_number!(self.object, GetTimeRemaining, i32)?;
Ok(time_remaining)
}
/// Whether the task has been completed.
///
/// # Returns
///
/// Returns bool on success, or a `VboxError` on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::{Session, VirtualBox};
/// use virtualbox_rs::enums::SessionType;
///
/// let vbox = VirtualBox::init().unwrap();
/// let mut session = Session::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// machine.lock_machine(&mut session, SessionType::Shared).unwrap();
///
/// let machine_mut = session.get_machine().unwrap();
///
/// let progress = machine_mut.save_state().unwrap();
/// progress.wait_for_completion(1).unwrap();
/// let completed = progress.get_completed().unwrap();
pub fn get_completed(&self) -> Result<bool, VboxError> {
get_function_result_bool!(self.object, GetCompleted)
}
/// Whether the task has been canceled.
///
/// # Returns
///
/// Returns bool on success, or a `VboxError` on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::{Session, VirtualBox};
/// use virtualbox_rs::enums::SessionType;
///
/// let vbox = VirtualBox::init().unwrap();
/// let mut session = Session::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// machine.lock_machine(&mut session, SessionType::Shared).unwrap();
///
/// let machine_mut = session.get_machine().unwrap();
///
/// let progress = machine_mut.save_state().unwrap();
/// progress.wait_for_completion(1).unwrap();
/// let canceled = progress.get_canceled().unwrap();
pub fn get_canceled(&self) -> Result<bool, VboxError> {
get_function_result_bool!(self.object, GetCanceled)
}
/// Result code of the progress task.
///
/// # Returns
///
/// Returns i32 on success, or a `VboxError` on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::{Session, VirtualBox};
/// use virtualbox_rs::enums::SessionType;
///
/// let vbox = VirtualBox::init().unwrap();
/// let mut session = Session::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// machine.lock_machine(&mut session, SessionType::Shared).unwrap();
///
/// let machine_mut = session.get_machine().unwrap();
///
/// let progress = machine_mut.save_state().unwrap();
/// progress.wait_for_completion(-1).unwrap();
/// let result_code = progress.get_result_code().unwrap();
pub fn get_result_code(&self) -> Result<i32, VboxError> {
let result_code = get_function_result_number!(self.object, GetResultCode, i32)?;
Ok(result_code)
}
/// Extended information about the unsuccessful result of the progress operation.
///
/// # Returns
///
/// Returns `VirtualBoxErrorInfo` on success, or a `VboxError` on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::{Session, VirtualBox};
/// use virtualbox_rs::enums::SessionType;
///
/// let vbox = VirtualBox::init().unwrap();
/// let mut session = Session::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// machine.lock_machine(&mut session, SessionType::Shared).unwrap();
///
/// let machine_mut = session.get_machine().unwrap();
///
/// let progress = machine_mut.save_state().unwrap();
/// progress.wait_for_completion(-1).unwrap();
/// let error_info = progress.get_error_info().unwrap();
pub fn get_error_info(&self) -> Result<VirtualBoxErrorInfo, VboxError> {
let virtual_box_error_info =
get_function_result_pointer!(self.object, GetErrorInfo, *mut IVirtualBoxErrorInfo)?;
Ok(VirtualBoxErrorInfo::new(virtual_box_error_info))
}
/// Number of sub-operations this task is divided into.
///
/// # Returns
///
/// Returns u32 on success, or a `VboxError` on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::{Session, VirtualBox};
/// use virtualbox_rs::enums::SessionType;
///
/// let vbox = VirtualBox::init().unwrap();
/// let mut session = Session::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// machine.lock_machine(&mut session, SessionType::Shared).unwrap();
///
/// let machine_mut = session.get_machine().unwrap();
///
/// let progress = machine_mut.save_state().unwrap();
/// progress.wait_for_completion(-1).unwrap();
/// let operation_count = progress.get_operation_count().unwrap();
pub fn get_operation_count(&self) -> Result<u32, VboxError> {
let operation_count = get_function_result_number!(self.object, GetOperationCount, u32)?;
Ok(operation_count)
}
/// Number of the sub-operation being currently executed.
///
/// # Returns
///
/// Returns u32 on success, or a `VboxError` on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::{Session, VirtualBox};
/// use virtualbox_rs::enums::SessionType;
///
/// let vbox = VirtualBox::init().unwrap();
/// let mut session = Session::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// machine.lock_machine(&mut session, SessionType::Shared).unwrap();
///
/// let machine_mut = session.get_machine().unwrap();
///
/// let progress = machine_mut.save_state().unwrap();
/// progress.wait_for_completion(-1).unwrap();
/// let operation = progress.get_operation().unwrap();
pub fn get_operation(&self) -> Result<u32, VboxError> {
let operation = get_function_result_number!(self.object, GetOperation, u32)?;
Ok(operation)
}
/// Description of the sub-operation being currently executed.
///
/// # Returns
///
/// Returns &str on success, or a `VboxError` on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::{Session, VirtualBox};
/// use virtualbox_rs::enums::SessionType;
///
/// let vbox = VirtualBox::init().unwrap();
/// let mut session = Session::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// machine.lock_machine(&mut session, SessionType::Shared).unwrap();
///
/// let machine_mut = session.get_machine().unwrap();
///
/// let progress = machine_mut.save_state().unwrap();
/// progress.wait_for_completion(-1).unwrap();
/// let operation_description = progress.get_operation_description().unwrap();
pub fn get_operation_description(&self) -> Result<&'static str, VboxError> {
get_function_result_str!(self.object, GetOperationDescription)
}
/// Progress value of the current sub-operation only, in percent.
///
/// # Returns
///
/// Returns u32 on success, or a `VboxError` on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::{Session, VirtualBox};
/// use virtualbox_rs::enums::SessionType;
///
/// let vbox = VirtualBox::init().unwrap();
/// let mut session = Session::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// machine.lock_machine(&mut session, SessionType::Shared).unwrap();
///
/// let machine_mut = session.get_machine().unwrap();
///
/// let progress = machine_mut.save_state().unwrap();
/// progress.wait_for_completion(-1).unwrap();
/// let operation_percent = progress.get_operation_percent().unwrap();
pub fn get_operation_percent(&self) -> Result<u32, VboxError> {
let operation_percent = get_function_result_number!(self.object, GetOperationPercent, u32)?;
Ok(operation_percent)
}
/// Weight value of the current sub-operation only.
///
/// # Returns
///
/// Returns u32 on success, or a `VboxError` on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::{Session, VirtualBox};
/// use virtualbox_rs::enums::SessionType;
///
/// let vbox = VirtualBox::init().unwrap();
/// let mut session = Session::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// machine.lock_machine(&mut session, SessionType::Shared).unwrap();
///
/// let machine_mut = session.get_machine().unwrap();
///
/// let progress = machine_mut.save_state().unwrap();
/// progress.wait_for_completion(-1).unwrap();
/// let operation_weight = progress.get_operation_weight().unwrap();
pub fn get_operation_weight(&self) -> Result<u32, VboxError> {
let operation_weight = get_function_result_number!(self.object, GetOperationWeight, u32)?;
Ok(operation_weight)
}
/// When non-zero, this specifies the number of milliseconds after which the operation will automatically be canceled.
///
/// # Returns
///
/// Returns u32 on success, or a `VboxError` on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::{Session, VirtualBox};
/// use virtualbox_rs::enums::SessionType;
///
/// let vbox = VirtualBox::init().unwrap();
/// let mut session = Session::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// machine.lock_machine(&mut session, SessionType::Shared).unwrap();
///
/// let machine_mut = session.get_machine().unwrap();
///
/// let progress = machine_mut.save_state().unwrap();
/// progress.wait_for_completion(-1).unwrap();
/// let timeout = progress.get_timeout().unwrap();
pub fn get_timeout(&self) -> Result<u32, VboxError> {
let timeout = get_function_result_number!(self.object, GetTimeout, u32)?;
Ok(timeout)
}
/// EventSource
///
/// # Returns
///
/// Returns `EventSource` on success, or a `VboxError` on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::{Session, VirtualBox};
/// use virtualbox_rs::enums::SessionType;
///
/// let vbox = VirtualBox::init().unwrap();
/// let mut session = Session::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// machine.lock_machine(&mut session, SessionType::Shared).unwrap();
///
/// let machine_mut = session.get_machine().unwrap();
///
/// let progress = machine_mut.save_state().unwrap();
/// progress.wait_for_completion(-1).unwrap();
/// let event_source = progress.get_event_source().unwrap();
pub fn get_event_source(&self) -> Result<EventSource, VboxError> {
let event_source =
get_function_result_pointer!(self.object, GetEventSource, *mut IEventSource)?;
Ok(EventSource::new(event_source))
}
///
/// Waits until the given operation is done with a given timeout in milliseconds; specify -1 for an indefinite wait.
///
/// # Arguments
///
/// * `timeout` - Maximum time in milliseconds to wait or -1 to wait indefinitely.
///
///
/// * `operation` - Number of the operation to wait for. Must be less than operationCount.
///
/// # Returns
///
/// Returns () on success, or a `VboxError` on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::{Session, VirtualBox};
/// use virtualbox_rs::enums::SessionType;
///
/// let vbox = VirtualBox::init().unwrap();
/// let mut session = Session::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// machine.lock_machine(&mut session, SessionType::Shared).unwrap();
///
/// let machine_mut = session.get_machine().unwrap();
///
/// let progress = machine_mut.save_state().unwrap();
/// progress.wait_for_operation_completion(-1, 1).unwrap();
pub fn wait_for_operation_completion(
&self,
timeout: i32,
operation: u32,
) -> Result<(), VboxError> {
let timeout = if timeout < 0 { i32::MAX } else { timeout };
get_function_result_unit!(self.object, WaitForOperationCompletion, operation, timeout)
}
///
/// Cancels the task.
///
/// # Returns
///
/// Returns u32 on success, or a `VboxError` on failure.
///
/// # Example
///
/// ```no_run
///
/// use virtualbox_rs::{Session, VirtualBox};
/// use virtualbox_rs::enums::SessionType;
///
/// let vbox = VirtualBox::init().unwrap();
/// let mut session = Session::init().unwrap();
/// let machine = vbox.
/// find_machines("Freebsd_14").unwrap();
/// machine.lock_machine(&mut session, SessionType::Shared).unwrap();
///
/// let machine_mut = session.get_machine().unwrap();
///
/// let progress = machine_mut.save_state().unwrap();
/// progress.cancel().unwrap();
pub fn cancel(&self) -> Result<(), VboxError> {
get_function_result_unit!(self.object, Cancel)
}
}