thrasherbird.pl: Item disco target config was missing.
[thrasher.git] / perl / lib / Thrasher / EventLoop / Glib.pm
blob8966e783017a368e219854f37698692f64eee5c0
1 package Thrasher::EventLoop::Glib;
2 use strict;
3 use warnings;
5 =head1 NAME
7 Thrasher::EventLoop::Glib - implement the Thrasher event loop with
8 Glib's event loop
10 =head1 DESCRIPTION
12 As the NAME says. Glib's event loop is used to implement the necessary
13 event loop primitives.
15 Note that even if you don't need libpurple, Glib is a viable event
16 loop for you to use, if you have the necessary glib and modules
17 installed.
19 =cut
21 use Glib qw(FALSE G_PRIORITY_DEFAULT G_PRIORITY_HIGH);
23 use base 'Thrasher::EventLoop';
24 use Thrasher::Log qw(:all);
26 sub new {
27 my $class = shift;
29 my $self = $class->SUPER::new(@_);
31 $self->{mainloop_ref} = Glib::MainLoop->new(undef, FALSE);
33 return $self;
36 sub go {
37 my $self = shift;
39 $self->{mainloop_ref}->run();
41 delete $self->{mainloop_ref};
44 sub schedule {
45 my $self = shift;
46 my $closure = shift;
47 my $timeout = shift;
49 my ($package, $filename, $line) = caller;
50 my $name = "Task scheduled at $filename\:$line";
51 my $new_closure = Thrasher::error_wrap($name, $closure);
53 my $token = Glib::Timeout->add($timeout, $new_closure);
54 debug("added scheduled event: $package\:$line: $token");
55 return $token;
58 sub cancel_scheduled_event {
59 my $self = shift;
60 my $opaque_token = shift;
61 Glib::Source->remove($opaque_token);
64 sub add_fd_watch {
65 my $self = shift;
66 my $fd = shift;
67 my $directions = shift;
68 my $closure = shift;
70 my $condition = 0;
71 if ($directions & $Thrasher::EventLoop::IN) {
72 $condition = 'G_IO_IN';
73 } elsif ($directions & $Thrasher::EventLoop::OUT) {
74 $condition = 'G_IO_OUT';
77 debug("Adding watch: $fd, $condition, $closure\n");
79 my ($package, $filename, $line) = caller;
80 my $name = "FD watch created at $filename\:$line";
81 my $new_closure = Thrasher::error_wrap($name, $closure);
83 my $token = Glib::IO->add_watch($fd, $condition, $new_closure);
84 debug("added fd watch: ($package\:$line) $token\n");
85 return $token;
88 sub remove_fd_watch {
89 my $self = shift;
90 my $opaque_token = shift;
92 debug("Removing fd watch: $opaque_token\n");
94 Glib::Source->remove($opaque_token);
97 sub execute_on_idle {
98 my $self = shift;
99 my $closure = shift;
101 my ($package, $filename, $line) = caller;
102 my $name = "Idle execution created at $filename\:$line";
103 my $new_closure = Thrasher::error_wrap($name, $closure);
105 Glib::Idle->add($new_closure);
108 sub quit {
109 my $self = shift;
110 $self->{mainloop_ref}->quit;