ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Impl/Glib.pm
Revision: 1.3
Committed: Thu Dec 1 22:04:50 2005 UTC (18 years, 6 months ago) by root
Branch: MAIN
CVS Tags: rel-0_3, rel-0_2
Changes since 1.2: +6 -8 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 package AnyEvent::Impl::Glib;
2
3 use Glib ();
4
5 my $maincontext = Glib::MainContext->default;
6
7 my %RWE = (
8 in => 'r',
9 out => 'w',
10 pri => 'e',
11 );
12
13 sub io {
14 my ($class, %arg) = @_;
15
16 my $self = bless \%arg, $class;
17 my $rcb = \$self->{cb};
18
19 my @cond;
20 push @cond, "in" if $self->{poll} =~ /r/i;
21 push @cond, "out" if $self->{poll} =~ /w/i;
22 push @cond, "pri" if $self->{poll} =~ /e/i;
23
24 $self->{source} = add_watch Glib::IO fileno $self->{fh}, \@cond, sub {
25 $$rcb->(join "", map $RWE{$_}, @{ $_[1] });
26 ! ! $$rcb
27 };
28
29 $self
30 }
31
32 sub timer {
33 my ($class, %arg) = @_;
34
35 my $self = bless \%arg, $class;
36 my $cb = $self->{cb};
37
38 $self->{source} = add Glib::Timeout $self->{after} * 1000, sub {
39 $cb->();
40 0
41 };
42
43 $self
44 }
45
46 sub cancel {
47 my ($self) = @_;
48
49 remove Glib::Source delete $self->{source} if $self->{source};
50 $self->{cb} = undef;
51 delete $self->{cb};
52 }
53
54 sub DESTROY {
55 my ($self) = @_;
56
57 $self->cancel;
58 }
59
60 sub condvar {
61 my $class = shift;
62
63 bless \my $x, AnyEvent::Impl::Glib::CondVar::
64 }
65
66 sub AnyEvent::Impl::Glib::CondVar::broadcast {
67 ${$_[0]}++;
68 }
69
70 sub AnyEvent::Impl::Glib::CondVar::wait {
71 $maincontext->iteration (1) while !${$_[0]};
72 }
73
74 $AnyEvent::MODEL = __PACKAGE__;
75
76 1;
77