pub struct DeviceBuilder<N> { /* private fields */ }
Expand description
Helper to process device messages and build a Device
The DeviceBuilder
provides a stateful interface and can assist with process the startup
messages for queue configuration that virtio devices need to undertake.
If a device needs full control of how messages are handled it can use the raw [add_queue
] and
[build
] methods to build a Device
, otherwise it is expected that
config_builder_from_stream
will typically be sufficient and automates the message loop.
Implementations§
Source§impl DeviceBuilder<()>
impl DeviceBuilder<()>
Sourcepub fn new(trap: Option<GuestBellTrap>, vmo: Option<Vmo>) -> DeviceBuilder<()>
pub fn new(trap: Option<GuestBellTrap>, vmo: Option<Vmo>) -> DeviceBuilder<()>
Construct a new DeviceBuilder
This provides complete flexibility on processing the StartInfo
, but typically it is
expected that from_start_info
is the more useful way to get a partially initialized
DeviceBuilder
.
If a GuestBellTrap
exists it can optionally be provided here. If not provided then the
final Device
will not have the trap, although users can always process the stream of
trap notifications themselves.
Source§impl<N> DeviceBuilder<N>
impl<N> DeviceBuilder<N>
Sourcepub fn map_notify<N2>(
self,
map: impl FnOnce(N) -> Result<N2, DeviceError>,
) -> Result<DeviceBuilder<N2>, DeviceError>
pub fn map_notify<N2>( self, map: impl FnOnce(N) -> Result<N2, DeviceError>, ) -> Result<DeviceBuilder<N2>, DeviceError>
Check if a trap has been configured.
Since it is an error to [set_trap
] if one already exists
Change the notify to a different type.
Passes the current notification object to the provided function, and stores any success result as the new notify.
When building the final Device
the internal notify will be given to each [Queue
] that
is constructed. Initially the notify type N
will always be NotifyEvent
and is created
from the [zx::Event] provided in the [
StartInfo`].
The normal reason to want to change the notify type is to interpose a [BufferedNotify
]
(virtio_device::util::BufferedNotify).
builder.map_notify(
|e| Result::<_, zx::Status>::Ok(virtio_device::util::BufferedNotify::new(e))
)
Sourcepub fn add_queue(self, config: QueueConfig) -> Result<Self, DeviceError>
pub fn add_queue(self, config: QueueConfig) -> Result<Self, DeviceError>
Add the specified QueueConfig
to the list of queues.
This just records the QueueConfig
and aside from ensuring config.queue
is not a
duplicate, no further validation is done. The [Queue
] itself will get build in the
[build
] step after all queues have been specified.
Sourcepub fn configured_queues(&self) -> impl Iterator<Item = u16> + '_
pub fn configured_queues(&self) -> impl Iterator<Item = u16> + '_
Query the queues configured so far.
Returns an iterator of the queue numbers that have been configured so far in the builder.