… | |
… | |
25 | module only implements the minimum API required to make Net::DBus work - |
25 | module only implements the minimum API required to make Net::DBus work - |
26 | Net::DBus unfortunately has no nice hooking API. |
26 | Net::DBus unfortunately has no nice hooking API. |
27 | |
27 | |
28 | However, unlike L<Net::DBus::Reactor>, this module should be fully |
28 | However, unlike L<Net::DBus::Reactor>, this module should be fully |
29 | non-blocking as long as you only use non-blocking APIs (Net::DBus::Reactor |
29 | non-blocking as long as you only use non-blocking APIs (Net::DBus::Reactor |
30 | blocks on writes). |
30 | blocks on writes). It should also be faster, but Net::DBus is such a |
|
|
31 | morass os unneeded method calls that speed won't matter much... |
|
|
32 | |
|
|
33 | =head2 EXAMPLE |
|
|
34 | |
|
|
35 | Here is a simple example. Both work with AnyEvent::DBus and do the same |
|
|
36 | thing, but only the second is actually non-blocking. |
|
|
37 | |
|
|
38 | Example 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 | |
|
|
49 | Example 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 | |
34 | package AnyEvent::DBus; |
75 | package 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 | |
115 | use Net::DBus::Annotation qw(:call); |
|
|
116 | my $bus = Net::DBus->find; |
|
|
117 | my $ob = $bus->get_bus_object; |
|
|
118 | #my $res = $ob->ListNames (dbus_call_async, "x" x 8192000); |
|
|
119 | my $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 | }); |
|
|
127 | AE::cv->recv; |
|
|
128 | warn $ob; |
|
|
129 | |
|
|
130 | =head1 SEE ALSO |
154 | =head1 SEE ALSO |
131 | |
155 | |
132 | L<AnyEvent>, L<Net::DBus>. |
156 | L<AnyEvent>, L<Net::DBus>. |
133 | |
157 | |
134 | =head1 AUTHOR |
158 | =head1 AUTHOR |