libmicrovmi
libmicrovmi copied to clipboard
API design: events interfaces and traits
Following https://github.com/Wenzel/libmicrovmi/pull/49 I'm opening this issue to start the discussion on how the event API should be implemented.
I'm reposting an idea from @kylerky, where each driver event (KVMEvent, XenEvent...) should implement a set of traits, and Event should contain generic type:
pub struct Event {
common: EventCommon,
extra: EventExtra,
}
pub enum EventExtra<CR>
where CR: CREvent
{
CR(CR),
Pause,
}
pub trait CREvent {
fn get_old() -> u64;
fn get_new() -> u64;
}
pub struct KVMCrEvent {
pub fn construct_reply(...) -> KVMCrReply {
}
}
impl CREvent for KVMCrEvent {...}
struct KVMCrReply {...}
impl Reply for KVMCrReply {...}
fn main() {
let kvm_cr_event = ...;
let reply = kvm_cr_event.construct_reply(Continue, new);
dom.send(reply);
}
fn send<T: Reply>(reply: T) { ... }