libmicrovmi icon indicating copy to clipboard operation
libmicrovmi copied to clipboard

API design: events interfaces and traits

Open Wenzel opened this issue 5 years ago • 0 comments

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) { ... }

Wenzel avatar Feb 15 '20 16:02 Wenzel