GithubHelp home page GithubHelp logo

Comments (8)

c4milo avatar c4milo commented on August 25, 2024

I see. Unfortunately, I don't currently have extra bandwidth to work on that. Contributions are very welcome.

from node-libvirt.

atoy40 avatar atoy40 commented on August 25, 2024

I started working on the implementation, and it seems to work, but i've a problem, and may be you can help me to solve this one.

I registered a callback for a lifecycle event, and, if i started a vm, libvirt call the "C" handler you specified for this kind of event : domain_event_lifecycle_callback
But there is a problem with the opaque pointer you used to pass the node object containing the hypervisor and the JS callback : the opaque pointer address is the "same" (if i print the address of the opaque pointer where you define it, and if i print it in the domain_event_lifecycle_callback function, i got the same value) but it generate a segfault as soon as you used it :
Local hyp = obj->Get(domain_event_hypervisor_symbol)->ToObject();

it seems the Object has been freed between the callback registering and the callback call (when a lifecycle event occurs).

I tried to pass a simple integer pointer (allocated on the heap with a c++ new) instead of the Persistent, and i got it with the correct value in the domain_event_lifecycle_callback function.

Any idea ? i'm not very familar with node API and variable scopes...

from node-libvirt.

c4milo avatar c4milo commented on August 25, 2024

I see, you should be able to call hypervisor->Ref() before calling the JS callback and once it comes back you call hypervisor->Unref(). I'm doing a similar thing in https://github.com/c4milo/node-inotify/blob/master/src/bindings.cc#L154 and https://github.com/c4milo/node-inotify/blob/master/src/bindings.cc#L302

from node-libvirt.

c4milo avatar c4milo commented on August 25, 2024

it will increase the reference count and will avoid v8 GC to release that object.

from node-libvirt.

atoy40 avatar atoy40 commented on August 25, 2024

The released object is not the Hypervisor, but the Persistent v8 Object you set-up as "opaque" (the void* libvirt give you back in handler) :

Persistent<Object> opaque = Persistent<Object>::New(Object::New());
opaque->Set(domain_event_hypervisor_symbol, args.This());
opaque->Set(domain_event_callback_symbol, jscallback);

Hypervisor *hypervisor = ObjectWrap::Unwrap<Hypervisor>(args.This());
int ret = virConnectDomainEventRegisterAny( hypervisor->conn_,
                                                domain != NULL ? domain->domain() : NULL,
                                                evtype, callback,
                                                &opaque, domain_event_free);

from node-libvirt.

atoy40 avatar atoy40 commented on August 25, 2024

I found the fix for this issue. It comes from the way you pass the opaque object.
You use &opaque, which means "the address" of the persitent handle "opaque". But this variable is allocated on the stack, so only available in the function it is defined.
What you want to pass to the virConnectDomainEventRegisterAny is not the v8::Persistent address, but the v8::Object address. Handle (so Persistent) overload the * operator to get the embedded v8::Value pointer.
This is a bit strange at the syntax level, but you need to use *opaque (instead of &opaque) which return the address of the Object encapsulated in the Persistent.
There is nothing to change is the callback itself .. it works right.

I've some improvements to make, and i'll propose you a pull request for libvirt event management.

Anthony.

from node-libvirt.

c4milo avatar c4milo commented on August 25, 2024

hey @atoy40, great that you made it work! Thanks a lot for your help and apologies for my lack of timely and accurate responses. The truth is, It will take me a bit of time to wrap my head around this project again since I'm currently working on very different things.

from node-libvirt.

atoy40 avatar atoy40 commented on August 25, 2024

No problem :)

from node-libvirt.

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.