GithubHelp home page GithubHelp logo

Comments (5)

rageagainsthepc avatar rageagainsthepc commented on May 29, 2024 1

I often use weak pointers in event callbacks for the vmi implementation in my company. Helps to alleviate segfaults. ;)

from libmicrovmi.

kylerky avatar kylerky commented on May 29, 2024

The default response sent in drop does not make much sense to me. I would like more control of what I send.

Also, I wonder if this will complicate implementation because we may need to add quite a few logic in the drop function. The function may need to know whether a response by user has already been sent before it sends a default one.

Moreover, I will think twice before adding a reference to Introspectable, which may bring some troubles with the borrow checker.

from libmicrovmi.

Wenzel avatar Wenzel commented on May 29, 2024

Also, I wonder if this will complicate implementation because we may need to add quite a few logic in the drop function. The function may need to know whether a response by user has already been sent before it sends a default one.

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;
         }
    }
}

Moreover, I will think twice before adding a reference to Introspectable, which may bring some troubles with the borrow checker.

Yes, when I tried to implement it, I have issues with the lifetimes and such, so I gave up.

from libmicrovmi.

rageagainsthepc avatar rageagainsthepc commented on May 29, 2024

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.
https://doc.rust-lang.org/std/rc/struct.Weak.html

from libmicrovmi.

rageagainsthepc avatar rageagainsthepc commented on May 29, 2024

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.

from libmicrovmi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.