1 package Thrasher
::EventLoop
::Glib
;
7 Thrasher::EventLoop::Glib - implement the Thrasher event loop with
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
21 use Glib
qw(FALSE G_PRIORITY_DEFAULT G_PRIORITY_HIGH);
23 use base
'Thrasher::EventLoop';
24 use Thrasher
::Log
qw(:all);
29 my $self = $class->SUPER::new
(@_);
31 $self->{mainloop_ref
} = Glib
::MainLoop
->new(undef, FALSE
);
39 $self->{mainloop_ref
}->run();
41 delete $self->{mainloop_ref
};
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");
58 sub cancel_scheduled_event
{
60 my $opaque_token = shift;
61 Glib
::Source
->remove($opaque_token);
67 my $directions = shift;
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");
90 my $opaque_token = shift;
92 debug
("Removing fd watch: $opaque_token\n");
94 Glib
::Source
->remove($opaque_token);
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);
110 $self->{mainloop_ref
}->quit;