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.4 by root, Mon Jun 21 00:12:52 2010 UTC vs.
Revision 1.6 by root, Mon Jun 21 19:43:42 2010 UTC

1=head1 NAME 1=head1 NAME
2 2
3AnyEvent::AIO - truly asynchronous file and directory I/O 3AnyEvent::DBus - adapt Net::DBus to AnyEvent
4 4
5=head1 SYNOPSIS 5=head1 SYNOPSIS
6 6
7 use AnyEvent::DBus; 7 use AnyEvent::DBus;
8 8
9 # now use the Net::DBus API, preferably the non-blocking variants 9 # now use the Net::DBus API, preferably the non-blocking variants:
10
11 use Net::DBus::Annotation qw(:call);
12
13 $bus->get_object (...)
14 ->Method (dbus_call_async, $arg1, ...)
15 ->set_notify (sub {
16 my @data = $_[0]->get_result
17 ...
18 });
19
20 $bus->get_connection->send (...);
10 21
11=head1 DESCRIPTION 22=head1 DESCRIPTION
12 23
13This module is an L<AnyEvent> user, you need to make sure that you use and 24This module is an L<AnyEvent> user, you need to make sure that you use and
14run a supported event loop. 25run a supported event loop.
78 89
79use AnyEvent (); 90use AnyEvent ();
80use Net::DBus (); 91use Net::DBus ();
81use Net::DBus::Binding::Watch (); 92use Net::DBus::Binding::Watch ();
82 93
83our $VERSION = '0.1'; 94our $VERSION = '0.3';
84 95
85# yup, Net::DBus checks by using exists on %INC... 96# yup, Net::DBus checks by using exists on %INC...
86$INC{'Net/DBus/Reactor.pm'} = undef; 97$INC{'Net/DBus/Reactor.pm'} = undef;
87 98
88# claim we are the main reactor mainloop 99# claim we are the main reactor mainloop
105 116
106 $f & Net::DBus::Binding::Watch::READABLE () 117 $f & Net::DBus::Binding::Watch::READABLE ()
107 and 118 and
108 $O{$id}[0] = $on && AE::io $fd, 0, sub { 119 $O{$id}[0] = $on && AE::io $fd, 0, sub {
109 $w->handle (Net::DBus::Binding::Watch::READABLE ()); 120 $w->handle (Net::DBus::Binding::Watch::READABLE ());
110 $con->dispatch; # wtf., we tell it data is ready, but have to call dispatch ourselves??? 121 $con->dispatch;
111 }; 122 };
112 123
113 $f & Net::DBus::Binding::Watch::WRITABLE () 124 $f & Net::DBus::Binding::Watch::WRITABLE ()
114 and 125 and
115 $O{$id}[1] = $on && AE::io $fd, 1, sub { 126 $O{$id}[1] = $on && AE::io $fd, 1, sub {
116 $w->handle (Net::DBus::Binding::Watch::WRITABLE ()); 127 $w->handle (Net::DBus::Binding::Watch::WRITABLE ());
117 # calling flush, as NEt::DBus::Reactor does, is blocking :/ 128 $con->dispatch;
118 }; 129 };
119} 130}
120 131
121sub io_on { 132sub io_on {
122 my ($con, $w) = @_; 133 my ($con, $w) = @_;
131 my ($con, $w) = @_; 142 my ($con, $w) = @_;
132 143
133 my $id = $w->get_data; 144 my $id = $w->get_data;
134 my $i = $w->get_interval * 0.001; 145 my $i = $w->get_interval * 0.001;
135 146
136 $O{$id} = $w->is_enabled && AE::timer $i, $i, sub { $w->handle }; 147 $O{$id} = $w->is_enabled && AE::timer $i, $i, sub {
148 $w->handle;
149 $con->dispatch;
150 };
137} 151}
138 152
139sub timeout_on { 153sub timeout_on {
140 my ($con, $w) = @_; 154 my ($con, $w) = @_;
141 my $id = ++$I; 155 my $id = ++$I;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines