mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vm-virtio: Modify VirtioInterrupt callback into a trait
Callbacks are not the most Rust idiomatic way of programming. The right way is to use a Trait to provide multiple implementation of the same interface. Additionally, a Trait will allow for multiple functions to be defined while using callbacks means that a new callback must be introduced for each new function we want to add. For these two reasons, the current commit modifies the existing VirtioInterrupt callback into a Trait of the same name. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
committed by
Samuel Ortiz
parent
ef7d889a79
commit
c396baca46
@@ -17,11 +17,13 @@ pub enum VirtioInterruptType {
|
||||
Queue,
|
||||
}
|
||||
|
||||
pub type VirtioInterrupt = Box<
|
||||
dyn Fn(&VirtioInterruptType, Option<&Queue>) -> std::result::Result<(), std::io::Error>
|
||||
+ Send
|
||||
+ Sync,
|
||||
>;
|
||||
pub trait VirtioInterrupt: Send + Sync {
|
||||
fn trigger(
|
||||
&self,
|
||||
int_type: &VirtioInterruptType,
|
||||
queue: Option<&Queue>,
|
||||
) -> std::result::Result<(), std::io::Error>;
|
||||
}
|
||||
|
||||
pub type VirtioIommuRemapping =
|
||||
Box<dyn Fn(u64) -> std::result::Result<u64, std::io::Error> + Send + Sync>;
|
||||
@@ -72,14 +74,14 @@ pub trait VirtioDevice: Send {
|
||||
fn activate(
|
||||
&mut self,
|
||||
mem: Arc<ArcSwap<GuestMemoryMmap>>,
|
||||
interrupt_evt: Arc<VirtioInterrupt>,
|
||||
interrupt_evt: Arc<dyn VirtioInterrupt>,
|
||||
queues: Vec<Queue>,
|
||||
queue_evts: Vec<EventFd>,
|
||||
) -> ActivateResult;
|
||||
|
||||
/// Optionally deactivates this device and returns ownership of the guest memory map, interrupt
|
||||
/// event, and queue events.
|
||||
fn reset(&mut self) -> Option<(Arc<VirtioInterrupt>, Vec<EventFd>)> {
|
||||
fn reset(&mut self) -> Option<(Arc<dyn VirtioInterrupt>, Vec<EventFd>)> {
|
||||
None
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user