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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
use std::future::Future;
/// Trait for transitioning device state.
pub trait ChangeDeviceState {
/// Starts a device, allowing it to interact with the guest asynchronously.
///
/// For example, a device might process work queues that reside in guest
/// memory on a separate thread.
///
/// Callers must ensure that the device is in a stopped state before calling
/// this method.
///
/// This is a synchronous method instead of an asynchronous one because it
/// is a notification only--callers do not need to wait for the device to
/// finish starting to consider the VM started. Devices should kick off any
/// tasks that need to run any return, without waiting.
///
// FUTURE: make this asynchronous if any device has a good reason to need
// it. This may also require changing state units to wait for device start
// to finish, which may require a bunch of other changes.
fn start(&mut self);
/// Stops a device's asynchronous work.
///
/// After this returns, the device must not process any additional work. It
/// should be in a stable state where it can be saved without losing data
/// (if it implements the appropriate trait).
///
/// Callers must ensure that the device is in a started state before calling
/// this method.
fn stop(&mut self) -> impl Send + Future<Output = ()>;
/// Resets the device state to its initial state, for a fresh boot.
///
/// Callers must ensure that the device is in a stopped state before calling
/// this method.
fn reset(&mut self) -> impl Send + Future<Output = ()>;
}