vmi_core/
handler.rs

1use crate::{VmiContext, VmiDriver, VmiEventResponse, VmiOs, VmiSession};
2
3/// A trait for handling VMI events.
4///
5/// A factory that creates a handler implementing this trait is passed to
6/// the [`VmiSession::handle`] method to handle VMI events.
7///
8/// [`VmiSession::handle`]: crate::VmiSession::handle
9pub trait VmiHandler<Driver, Os>
10where
11    Driver: VmiDriver,
12    Os: VmiOs<Driver>,
13{
14    /// The output type of the handler.
15    type Output;
16
17    /// Handles a VMI event.
18    fn handle_event(
19        &mut self,
20        event: VmiContext<Driver, Os>,
21    ) -> VmiEventResponse<Driver::Architecture>;
22
23    /// Handles a timeout event.
24    fn handle_timeout(&mut self, _session: &VmiSession<Driver, Os>) {}
25
26    /// Handles an interrupted event.
27    fn handle_interrupted(&mut self, _session: &VmiSession<Driver, Os>) {}
28
29    /// Checks if the handler has completed.
30    ///
31    /// This method is called after each event is handled. If the handler
32    /// has completed, this method should return the output of the handler.
33    /// Otherwise, it should return `None`.
34    fn check_completion(&self) -> Option<Self::Output> {
35        None
36    }
37}