1 |
package AnyEvent::Impl::Glib; |
2 |
|
3 |
no warnings; |
4 |
use strict; |
5 |
|
6 |
use Glib (); |
7 |
|
8 |
my $maincontext = Glib::MainContext->default; |
9 |
|
10 |
sub io { |
11 |
my ($class, %arg) = @_; |
12 |
|
13 |
my $self = bless \%arg, $class; |
14 |
my $rcb = \$self->{cb}; |
15 |
|
16 |
# some glibs need hup, others error with it, YMMV |
17 |
push @cond, "in", "hup" if $self->{poll} eq "r"; |
18 |
push @cond, "out", "hup" if $self->{poll} eq "w"; |
19 |
|
20 |
$self->{source} = add_watch Glib::IO fileno $self->{fh}, \@cond, sub { |
21 |
$$rcb->(); |
22 |
! ! $$rcb |
23 |
}; |
24 |
|
25 |
$self |
26 |
} |
27 |
|
28 |
sub timer { |
29 |
my ($class, %arg) = @_; |
30 |
|
31 |
my $self = bless \%arg, $class; |
32 |
my $cb = $self->{cb}; |
33 |
|
34 |
$self->{source} = add Glib::Timeout $self->{after} * 1000, sub { |
35 |
$cb->(); |
36 |
0 |
37 |
}; |
38 |
|
39 |
$self |
40 |
} |
41 |
|
42 |
sub DESTROY { |
43 |
my ($self) = @_; |
44 |
|
45 |
remove Glib::Source delete $self->{source} if $self->{source}; |
46 |
# need to undef $cb because we hold references to it |
47 |
$self->{cb} = undef; |
48 |
%$self = (); |
49 |
} |
50 |
|
51 |
sub one_event { |
52 |
$maincontext->iteration (1); |
53 |
} |
54 |
|
55 |
1 |
56 |
|