ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Impl/Glib.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent/Impl/Glib.pm (file contents):
Revision 1.24 by root, Wed Jul 8 02:01:12 2009 UTC vs.
Revision 1.31 by root, Tue Mar 27 16:21:12 2012 UTC

32 32
33=cut 33=cut
34 34
35package AnyEvent::Impl::Glib; 35package AnyEvent::Impl::Glib;
36 36
37no warnings; 37use AnyEvent (); BEGIN { AnyEvent::common_sense }
38use strict; 38use Glib 1.210 (); # (stable 1.220 2009, also Glib 2.4+ required, 2004)
39
40use Glib ();
41 39
42our $mainloop = Glib::MainContext->default; 40our $mainloop = Glib::MainContext->default;
43 41
44my %io_cond = ( 42my %io_cond = (
45 r => ["in" , "hup"], 43 r => ["in" , "hup"],
65 my ($class, %arg) = @_; 63 my ($class, %arg) = @_;
66 64
67 my $cb = $arg{cb}; 65 my $cb = $arg{cb};
68 my $ival = $arg{interval} * 1000; 66 my $ival = $arg{interval} * 1000;
69 67
70 my $source; $source = add Glib::Timeout $arg{after} * 1000, 68 my $source; $source = add Glib::Timeout $arg{after} < 0 ? 0 : $arg{after} * 1000,
71 $ival ? sub { 69 $ival ? sub {
72 remove Glib::Source $source; 70 remove Glib::Source $source;
73 $source = add Glib::Timeout $ival, sub { &$cb; 1 }; 71 $source = add Glib::Timeout $ival, sub { &$cb; 1 };
74 &$cb; 72 &$cb;
75 0 73 0
82sub idle { 80sub idle {
83 my ($class, %arg) = @_; 81 my ($class, %arg) = @_;
84 82
85 my $cb = $arg{cb}; 83 my $cb = $arg{cb};
86 my $source = add Glib::Idle sub { &$cb; 1 }; 84 my $source = add Glib::Idle sub { &$cb; 1 };
85
87 bless \\$source, $class 86 bless \\$source, $class
88} 87}
89 88
90sub DESTROY { 89sub DESTROY {
91 remove Glib::Source $${$_[0]}; 90 remove Glib::Source $${$_[0]};
92} 91}
93 92
94sub one_event { 93our %pid_w;
94our %pid_cb;
95
96sub child {
97 my ($class, %arg) = @_;
98
99 $arg{pid} > 0
100 or Carp::croak "Glib does not support watching for all pids (pid == 0) as attempted";
101
102 my $pid = $arg{pid};
103 my $cb = $arg{cb};
104
105 $pid_cb{$pid}{$cb+0} = $cb;
106
107 $pid_w{$pid} ||= Glib::Child->watch_add ($pid, sub {
108 $_->($_[0], $_[1])
109 for values %{ $pid_cb{$pid} };
110
111 1
112 });
113
114 bless [$pid, $cb+0], "AnyEvent::Impl::Glib::child"
115}
116
117sub AnyEvent::Impl::Glib::child::DESTROY {
118 my ($pid, $icb) = @{ $_[0] };
119
120 delete $pid_cb{$pid}{$icb};
121 unless (%{ $pid_cb{$pid} }) {
122 delete $pid_cb{$pid};
123 remove Glib::Source delete $pid_w{$pid};
124 }
125}
126
127#sub loop {
128# # hackish, but we do not have a mainloop, just a maincontext
129# $mainloop->iteration (1) while 1;
130#}
131
132sub _poll {
95 $mainloop->iteration (1); 133 $mainloop->iteration (1);
96} 134}
97 135
98sub loop { 136sub AnyEvent::CondVar::Base::_wait {
99 # hackish, but we do not have a mainloop, just a maincontext 137 $mainloop->iteration (1) until exists $_[0]{_ae_sent};
100 $mainloop->iteration (1) while 1;
101} 138}
102
1031;
104 139
105=head1 SEE ALSO 140=head1 SEE ALSO
106 141
107L<AnyEvent>, L<Glib>. 142L<AnyEvent>, L<Glib>.
108 143
111 Marc Lehmann <schmorp@schmorp.de> 146 Marc Lehmann <schmorp@schmorp.de>
112 http://home.schmorp.de/ 147 http://home.schmorp.de/
113 148
114=cut 149=cut
115 150
1511
152

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines