Expand description
VM state machine unit handling.
A state unit is a VM component (such as a device) that needs to react to changes in the VM state machine. It needs to start, stop, reset, and save/restore with the VM. (Save/restore is not really a state change but is modeled as such since it must be synchronized with actual state changes.)
This module contains types and functions for defining and manipulating state units. It does this in three parts:
-
It defines an RPC enum
StateRequest
which is used to request that a state unit change state (start, stop, etc.). Each state unit must handle incoming state requests on a mesh receiver. This is the foundational type of this model. -
It defines a type
StateUnits
, which is a collection of mesh senders for sendingStateRequest
s. This is used to initiate and wait for state changes across all the units in the VMM, handling any required dependency ordering. -
It defines a trait
StateUnit
that can be used to define handlers for each state request. This is an optional convenience; not all state units will have a type that implements this trait.
This model allows for asynchronous, highly concurrent state changes, and it
works across process boundaries thanks to mesh
.
Structs§
- Name
InUse - An error returned when a state unit name is already in use.
- Saved
State Unit - The saved state for an individual unit.
- Spawned
Unit - A handle to a spawned unit.
- State
Transition Error - An error from a state transition.
- State
Units - A set of state units.
- State
Units Inspector - An object returned by
StateUnits::inspector
to inspect state units while state transitions may be in flight. - Unit
Builder - A builder returned by
StateUnits::add
. - Unit
Handle - A handle returned by
StateUnits::add
, used to remove the state unit.
Enums§
- State
Request - A state change request.
Traits§
- State
Unit - Trait implemented by an object that can act as a state unit.
Functions§
- run_
async_ unit - Runs a state unit that can handle inspect requests while there is an active state transition.
- run_
unit - Runs a simple unit that only needs to respond to state requests.