-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatic reply from events on Drop #60
Comments
The default response sent in Also, I wonder if this will complicate implementation because we may need to add quite a few logic in the Moreover, I will think twice before adding a reference to |
A boolean would suffice #[repr(C)]
pub struct Event {
pub vcpu: u16,
pub kind: EventType,
driver: &dyn Introspectable, // pseudo code here, this might not be Rust compatible
reply_sent: bool,
}
impl Event {
// this API should be called to clearly define what event reply you want
fn reply(reply_type: ReplyEventType) -> Result<(), Box<dyn Error>> {
self.driver.reply_event(self, reply_type)?;
Ok(())
}
}
impl Drop for Event {
fn drop(&self) {
if !self.reply_sent {
self.reply(self, ReplyEventType::Continue);
self.reply_sent = true;
}
}
}
Yes, when I tried to implement it, I have issues with the lifetimes and such, so I gave up. |
You could use reference counting instead. I know this is very C++-ish, but this would allow you to store non-owning references aka weak pointers in your event. You need to upgrade weak pointers if you want to use them and this will fail if the object does not exist anymore. Might be worth a shot. |
I often use weak pointers in event callbacks for the vmi implementation in my company. Helps to alleviate segfaults. ;) |
Here is an idea: Why don't we have something like an event supervisor? The only way to listen for events is to register callbacks with the event supervisor. This would allow us to shape how events have to be handled. For example we could enforce an event reply by defining the reply as the return value of the callback. |
On feature that I would like on the API is when an
Event
is being Dropped from the scope, it would automatically send a default response, which would beEventReplyType::Continue
.tasks:
Introspectable
in theEvent
, so the event can call the driverimpl Drop for Event
Event
so that you can't reply twice to the same eventrelated: https://github.com/Wenzel/libmicrovmi/pull/49/files
thoughts @kylerky, @rageagainsthepc ?
The text was updated successfully, but these errors were encountered: