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<()>

source

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>

source

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))
)
source

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.

source

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.

source

pub fn take_vmo(&mut self) -> Option<Vmo>

Allow virtio devices to take the guest zx::Vmo. If the zx::Vmo is not taken it will be dropped as part of the DeviceBuilder::build call

Returns an option to guest vmo

source§

impl<N: Clone> DeviceBuilder<N>

source

pub fn build<'a, M: DriverMem>( self, negotiated_features: u32, mem: &'a M ) -> Result<Device<'a, N>, DeviceError>

Build a Device from the current builder state.

This builds all of the queues the were configured and constructs the final Device. The negotiated features and a [DriverMem] need to given here for queue building.

Trait Implementations§

source§

impl<N: Debug> Debug for DeviceBuilder<N>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<N> Freeze for DeviceBuilder<N>
where N: Freeze,

§

impl<N> !RefUnwindSafe for DeviceBuilder<N>

§

impl<N> Send for DeviceBuilder<N>
where N: Send,

§

impl<N> Sync for DeviceBuilder<N>
where N: Sync,

§

impl<N> Unpin for DeviceBuilder<N>
where N: Unpin,

§

impl<N> !UnwindSafe for DeviceBuilder<N>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> Encode<Ambiguous1> for T

source§

unsafe fn encode( self, _encoder: &mut Encoder<'_>, _offset: usize, _depth: Depth ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
source§

impl<T> Encode<Ambiguous2> for T

source§

unsafe fn encode( self, _encoder: &mut Encoder<'_>, _offset: usize, _depth: Depth ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more