<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">On Mar 14, 2014, at 9:32 AM, Daniel P. Berrange <<a href="mailto:berrange@redhat.com">berrange@redhat.com</a>> wrote:<br><div><blockquote type="cite"><div style="font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">- Register and run your own event loop impl by calling the method<br>  Sys::Virt::Event::register(), passing in a custom subclass of<br>  the Sys::Virt::Event class. This is what you should do to integrate<br>  with existing event loop impls like AnyEvent.<br><br>If you're set on using AnyEvent, then you want todo option 2 here. There's<br>no particularly good docs or example code here, but you can see how todo<br>this by looking at the Perl test suite. eg the t/800-events.t file.<br>This test suite does a pure perl event loop based on select(). You'd<br>probably want to adapt that and call into AnyEvent, instead of select().<br>The add_handle/remove_handle/update_handle/add_timeout/update_timeout/<br>remove_timeout methods should all call into appropriate AnyEvent APIs.<br>Then you just need to run AnyEvent as normal.<br></div></blockquote><div><br></div><div>I’ve borrowed a little bit from t/800-events.t and have the following package:</div><div><br></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><div>package Sys::Virt::AnyEvent;</div></div></div><div><div><div><br></div></div></div><div><div><div>use parent 'Sys::Virt::Event';</div></div></div><div><div><div><br></div></div></div><div><div><div>sub new {</div></div></div><div><div><div>    my $proto = shift;</div></div></div><div><div><div>    my $class = ref($proto) || $proto;</div></div></div><div><div><div>    my $self = {};</div></div></div><div><div><div>    bless $self, $class;</div></div></div><div><div><div>    $self->register;</div></div></div><div><div><div>    return $self;</div></div></div><div><div><div>}</div></div></div><div><div><div><br></div></div></div><div><div><div>sub add_handle {</div></div></div><div><div><div>    my $self = shift;</div></div></div><div><div><div>    my $fd = shift;</div></div></div><div><div><div>    my $events = shift;</div></div></div><div><div><div>    my $cb = shift;</div></div></div><div><div><div>    my $opaque = shift;</div></div></div><div><div><div>    my $ff = shift;</div></div></div><div><div><div><br></div></div></div><div><div><div>    AnyEvent->io(</div></div></div><div><div><div>        fh   => $fd,</div></div></div><div><div><div>        poll => 'r',</div></div></div><div><div><div>        cb   => $cb );</div></div></div><div><div><div>}</div></div></div><div><div><div><br></div></div></div></blockquote><div><div><div><div>When I try to use this package (since it’s in the same lexical scope, so I don’t use() it):</div><div><br></div></div></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><div><div><div>use EV;</div></div></div></div></div><div><div><div><div><div>use AnyEvent;</div></div></div></div></div><div><div><div><div><div>use Sys::Virt;</div></div></div></div></div><div><div><div><div><div>use Sys::Virt::Domain;</div></div></div></div></div><div><div><div><div><div><br></div></div></div></div></div><div><div><div><div><div>my $ev = Sys::Virt::AnyEvent->new();</div></div></div></div></div><div><div><div><div><div>my $c = Sys::Virt->new(uri => "<a href="remote:///system">remote:///system</a>", readonly => 1);</div></div></div></div></div><div><div><div><div><div><br></div></div></div></div></div><div><div><div><div><div>my $w = AnyEvent->timer(after => 1, interval => 1, cb => sub { say scalar localtime } );</div></div></div></div></div><div><div><div><div><div>my $cv; $cv = AnyEvent->condvar(cb => sub { say "cv fired: " . $_[0]->recv;</div></div></div></div></div><div><div><div><div><div>                                            $cv = AnyEvent->condvar(cb => __SUB__) });</div></div></div></div></div><div><div><div><div><div><br></div></div></div></div></div><div><div><div><div><div>$c->domain_event_register_any(undef,</div></div></div></div></div><div><div><div><div><div>                              Sys::Virt::Domain::EVENT_ID_LIFECYCLE,</div></div></div></div></div><div><div><div><div><div>                              sub { my ($sv, $dom, $evt, $detail) = @_;</div></div></div></div></div><div><div><div><div><div>                                    $cv->send($dom->get_name);</div></div></div></div></div><div><div><div><div><div>                                    say STDERR "Domain: " . $dom->get_name;</div></div></div></div></div><div><div><div><div><div>                                    say STDERR Dumper($evt) . $detail });</div></div></div></div></div><div><div><div><div><div><br></div></div></div></div></div><div><div><div><div><div>EV::run;</div></div></div></div></div></blockquote><div><div><div><div><div><br></div><div>I get this:</div><div><br></div></div></div></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><div><div><div>Not a subroutine reference at local/lib/perl5/x86_64-linux-thread-multi/AnyEvent/Impl/EV.pm line 55.</div></div></div></div></div></blockquote><div><div><div><div><div><br></div><div>EV.pm line 55 is this:</div><div><br></div><div><div>     52 sub io {</div><div>     53    my ($class, %arg) = @_;</div><div>     54</div><div>     55    EV::io</div><div>     56       $arg{fh},</div><div>     57       $arg{poll} eq "r" ? EV::READ : EV::WRITE,</div><div>     58       $arg{cb}</div><div>     59 }</div><div><br></div><div>If I dump $arg{cb} it looks like this:</div><div><br></div></div></div></div></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><div><div><div><div>cb:     $VAR1 = \'222528336192';</div></div></div></div></div></div></blockquote><div><div><div><div><div><div><br></div><div>Definitely not a subroutine reference. I know there’s a lot more going on here than I’m understanding, but I’m out of ideas of how to get Sys::Virt to play well in an AnyEvent environment.</div><div><br></div><div>I see that add_handle() in t/800-events.t returns a unique watch id, but AnyEvent doesn’t have that same notion. What should I be doing instead of returning an AnyEvent::io object?</div><div><br></div><div>Scott</div><div><br></div></div></div></div></div></div></body></html>