ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Impl/Glib.pm
Revision: 1.7
Committed: Fri Nov 24 14:40:13 2006 UTC (17 years, 6 months ago) by root
Branch: MAIN
Changes since 1.6: +4 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 package AnyEvent::Impl::Glib;
2    
3     use Glib ();
4    
5     my $maincontext = Glib::MainContext->default;
6    
7 root 1.2 sub io {
8     my ($class, %arg) = @_;
9    
10 root 1.3 my $self = bless \%arg, $class;
11 root 1.2 my $rcb = \$self->{cb};
12    
13 root 1.4 # some glibs need hup, others error with it, YMMV
14 root 1.6 push @cond, "in", "hup" if $self->{poll} eq "r";
15     push @cond, "out", "hup" if $self->{poll} eq "w";
16 root 1.2
17     $self->{source} = add_watch Glib::IO fileno $self->{fh}, \@cond, sub {
18 root 1.6 $$rcb->();
19 root 1.2 ! ! $$rcb
20     };
21 root 1.1
22 root 1.2 $self
23 root 1.1 }
24    
25 root 1.2 sub timer {
26     my ($class, %arg) = @_;
27 root 1.1
28 root 1.3 my $self = bless \%arg, $class;
29 root 1.2 my $cb = $self->{cb};
30 root 1.1
31 root 1.2 $self->{source} = add Glib::Timeout $self->{after} * 1000, sub {
32     $cb->();
33     0
34 root 1.1 };
35    
36 root 1.2 $self
37 root 1.1 }
38    
39 root 1.6 sub DESTROY {
40 root 1.1 my ($self) = @_;
41    
42     remove Glib::Source delete $self->{source} if $self->{source};
43 root 1.6 # need to undef $cb because we hold references to it
44 root 1.2 $self->{cb} = undef;
45 root 1.6 %$self = ();
46 root 1.2 }
47    
48     sub condvar {
49 root 1.1 my $class = shift;
50    
51 root 1.6 bless \my $flag, $class
52 root 1.1 }
53    
54 root 1.6 sub broadcast {
55 root 1.3 ${$_[0]}++;
56 root 1.1 }
57    
58 root 1.6 sub wait {
59 root 1.1 $maincontext->iteration (1) while !${$_[0]};
60     }
61    
62 root 1.7 sub one_event {
63     $maincontext->iteration (1);
64     }
65    
66 root 1.4 1
67 root 1.1