- Register and run your own event loop impl by calling the method
Sys::Virt::Event::register(), passing in a custom subclass of
the Sys::Virt::Event class. This is what you should do to integrate
with existing event loop impls like AnyEvent.
If you're set on using AnyEvent, then you want todo option 2 here. There's
no particularly good docs or example code here, but you can see how todo
this by looking at the Perl test suite. eg the t/800-events.t file.
This test suite does a pure perl event loop based on select(). You'd
probably want to adapt that and call into AnyEvent, instead of select().
The add_handle/remove_handle/update_handle/add_timeout/update_timeout/
remove_timeout methods should all call into appropriate AnyEvent APIs.
Then you just need to run AnyEvent as normal.
package Sys::Virt::AnyEvent;use parent 'Sys::Virt::Event';sub new {my $proto = shift;my $class = ref($proto) || $proto;my $self = {};bless $self, $class;$self->register;return $self;}sub add_handle {my $self = shift;my $fd = shift;my $events = shift;my $cb = shift;my $opaque = shift;my $ff = shift;AnyEvent->io(fh => $fd,poll => 'r',cb => $cb );}
use EV;use AnyEvent;use Sys::Virt;use Sys::Virt::Domain;my $ev = Sys::Virt::AnyEvent->new();my $c = Sys::Virt->new(uri => "remote:///system", readonly => 1);my $w = AnyEvent->timer(after => 1, interval => 1, cb => sub { say scalar localtime } );my $cv; $cv = AnyEvent->condvar(cb => sub { say "cv fired: " . $_[0]->recv;$cv = AnyEvent->condvar(cb => __SUB__) });$c->domain_event_register_any(undef,Sys::Virt::Domain::EVENT_ID_LIFECYCLE,sub { my ($sv, $dom, $evt, $detail) = @_;$cv->send($dom->get_name);say STDERR "Domain: " . $dom->get_name;say STDERR Dumper($evt) . $detail });EV::run;
Not a subroutine reference at local/lib/perl5/x86_64-linux-thread-multi/AnyEvent/Impl/EV.pm line 55.
cb: $VAR1 = \'222528336192';