ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-DBus/DBus.pm
(Generate patch)

Comparing AnyEvent-DBus/DBus.pm (file contents):
Revision 1.1 by root, Sun Jun 20 23:52:13 2010 UTC vs.
Revision 1.2 by root, Mon Jun 21 00:11:17 2010 UTC

25module only implements the minimum API required to make Net::DBus work - 25module only implements the minimum API required to make Net::DBus work -
26Net::DBus unfortunately has no nice hooking API. 26Net::DBus unfortunately has no nice hooking API.
27 27
28However, unlike L<Net::DBus::Reactor>, this module should be fully 28However, unlike L<Net::DBus::Reactor>, this module should be fully
29non-blocking as long as you only use non-blocking APIs (Net::DBus::Reactor 29non-blocking as long as you only use non-blocking APIs (Net::DBus::Reactor
30blocks on writes). 30blocks on writes). It should also be faster, but Net::DBus is such a
31morass os unneeded method calls that speed won't matter much...
32
33=head2 EXAMPLE
34
35Here is a simple example. Both work with AnyEvent::DBus and do the same
36thing, but only the second is actually non-blocking.
37
38Example 1: list registered named, blocking version.
39
40 use AnyEvent::DBus;
41
42 my $conn = Net::DBus->find;
43 my $bus = $conn->get_bus_object;
44
45 for my $name (@{ $bus->ListNames }) {
46 print " $name\n";
47 }
48
49Example 1: list registered named, somewhat non-blocking version.
50
51 use AnyEvent;
52 use AnyEvent::DBus;
53 use Net::DBus::Annotation qw(:call);
54
55 my $conn = Net::DBus->find; # always blocks :/
56 my $bus = $conn->get_bus_object;
57
58 my $quit = AE::cv;
59
60 # the trick here is to prepend dbus_call_async to any method
61 # arguments and then to call the set_notify method on the
62 # returned Net::DBus::AsyncReply object
63
64 $bus->ListNames (dbus_call_async)->set_notify (sub {
65 for my $name (@{ $_[0]->get_result }) {
66 print " $name\n";
67 }
68 $quit->send;
69 });
70
71 $quit->recv;
31 72
32=cut 73=cut
33 74
34package AnyEvent::DBus; 75package AnyEvent::DBus;
35 76
59 100
60 my $id = $w->get_data; 101 my $id = $w->get_data;
61 my $f = $w->get_flags; 102 my $f = $w->get_flags;
62 my $fd = $w->get_fileno; 103 my $fd = $w->get_fileno;
63 my $on = $w->is_enabled; 104 my $on = $w->is_enabled;
64
65 warn "io $id $on?$f\n";
66 105
67 $f & Net::DBus::Binding::Watch::READABLE () 106 $f & Net::DBus::Binding::Watch::READABLE ()
68 and 107 and
69 $O{$id}[0] = $on && AE::io $fd, 0, sub { 108 $O{$id}[0] = $on && AE::io $fd, 0, sub {
70 $w->handle (Net::DBus::Binding::Watch::READABLE ()); 109 $w->handle (Net::DBus::Binding::Watch::READABLE ());
110 149
111 $con->set_watch_callbacks (\&io_on, \&watch_off, \&io_toggle); 150 $con->set_watch_callbacks (\&io_on, \&watch_off, \&io_toggle);
112 $con->set_timeout_callbacks (\&timeout_on, \&watch_off, \&timeout_toggle); 151 $con->set_timeout_callbacks (\&timeout_on, \&watch_off, \&timeout_toggle);
113} 152}
114 153
115use Net::DBus::Annotation qw(:call);
116my $bus = Net::DBus->find;
117my $ob = $bus->get_bus_object;
118#my $res = $ob->ListNames (dbus_call_async, "x" x 8192000);
119my $res = $ob->ListNames (dbus_call_async);
120#Net::DBus::Binding::PendingCall
121$res->set_notify (sub {
122 warn "<@_>\n";#d#
123 for my $name (sort @{$_[0]->get_result}) {
124 print " ", $name, "\n";
125 }
126});
127AE::cv->recv;
128warn $ob;
129
130=head1 SEE ALSO 154=head1 SEE ALSO
131 155
132L<AnyEvent>, L<Net::DBus>. 156L<AnyEvent>, L<Net::DBus>.
133 157
134=head1 AUTHOR 158=head1 AUTHOR

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines