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

File Contents

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