--- AnyEvent-DBus/DBus.pm 2010/06/20 23:52:13 1.1 +++ AnyEvent-DBus/DBus.pm 2010/06/21 00:11:17 1.2 @@ -27,7 +27,48 @@ However, unlike L, this module should be fully non-blocking as long as you only use non-blocking APIs (Net::DBus::Reactor -blocks on writes). +blocks on writes). It should also be faster, but Net::DBus is such a +morass os unneeded method calls that speed won't matter much... + +=head2 EXAMPLE + +Here is a simple example. Both work with AnyEvent::DBus and do the same +thing, but only the second is actually non-blocking. + +Example 1: list registered named, blocking version. + + use AnyEvent::DBus; + + my $conn = Net::DBus->find; + my $bus = $conn->get_bus_object; + + for my $name (@{ $bus->ListNames }) { + print " $name\n"; + } + +Example 1: list registered named, somewhat non-blocking version. + + use AnyEvent; + use AnyEvent::DBus; + use Net::DBus::Annotation qw(:call); + + my $conn = Net::DBus->find; # always blocks :/ + my $bus = $conn->get_bus_object; + + my $quit = AE::cv; + + # the trick here is to prepend dbus_call_async to any method + # arguments and then to call the set_notify method on the + # returned Net::DBus::AsyncReply object + + $bus->ListNames (dbus_call_async)->set_notify (sub { + for my $name (@{ $_[0]->get_result }) { + print " $name\n"; + } + $quit->send; + }); + + $quit->recv; =cut @@ -62,8 +103,6 @@ my $fd = $w->get_fileno; my $on = $w->is_enabled; - warn "io $id $on?$f\n"; - $f & Net::DBus::Binding::Watch::READABLE () and $O{$id}[0] = $on && AE::io $fd, 0, sub { @@ -112,21 +151,6 @@ $con->set_timeout_callbacks (\&timeout_on, \&watch_off, \&timeout_toggle); } -use Net::DBus::Annotation qw(:call); -my $bus = Net::DBus->find; -my $ob = $bus->get_bus_object; -#my $res = $ob->ListNames (dbus_call_async, "x" x 8192000); -my $res = $ob->ListNames (dbus_call_async); -#Net::DBus::Binding::PendingCall -$res->set_notify (sub { - warn "<@_>\n";#d# - for my $name (sort @{$_[0]->get_result}) { - print " ", $name, "\n"; - } -}); -AE::cv->recv; -warn $ob; - =head1 SEE ALSO L, L.