| 1 | # $Id: Event.pm,v 1.3 2006/04/23 08:37:41 joern Exp $ | ||
| 2 | |||
| 3 | #----------------------------------------------------------------------- | ||
| 4 | # Copyright (C) 2002-2006 Jörn Reder <joern AT zyn.de>. | ||
| 5 | # All Rights Reserved. See file COPYRIGHT for details. | ||
| 6 | # | ||
| 7 | # This module is part of Event::RPC, which is free software; you can | ||
| 8 | # redistribute it and/or modify it under the same terms as Perl itself. | ||
| 9 | #----------------------------------------------------------------------- | ||
| 10 | |||
| 11 | package Event::RPC::Loop::Event; | ||
| 12 | |||
| 13 | use base qw( Event::RPC::Loop ); | ||
| 14 | |||
| 15 | use strict; | ||
| 16 | use Event; | ||
| 17 | |||
| 18 | sub add_io_watcher { | ||
| 19 | my $self = shift; | ||
| 20 | my %par = @_; | ||
| 21 | my ($fh, $cb, $desc, $poll) = @par{'fh','cb','desc','poll'}; | ||
| 22 | |||
| 23 | return Event->io ( | ||
| 24 | fd => $fh, | ||
| 25 | poll => $poll, | ||
| 26 | cb => $cb, | ||
| 27 | desc => $desc, | ||
| 28 | reentrant => 0, | ||
| 29 | ); | ||
| 30 | } | ||
| 31 | |||
| 32 | sub del_io_watcher { | ||
| 33 | my $self = shift; | ||
| 34 | my ($watcher) = @_; | ||
| 35 | |||
| 36 | $watcher->cancel; | ||
| 37 | |||
| 38 | 1; | ||
| 39 | } | ||
| 40 | |||
| 41 | sub add_timer { | ||
| 42 | my $self = shift; | ||
| 43 | my %par = @_; | ||
| 44 | my ($interval, $after, $cb, $desc) = | ||
| 45 | @par{'interval','after','cb','desc'}; | ||
| 46 | |||
| 47 | die "interval and after can't be used together" | ||
| 48 | if $interval && $after; | ||
| 49 | |||
| 50 | return Event->timer ( | ||
| 51 | interval => $interval, | ||
| 52 | after => $after, | ||
| 53 | cb => $cb, | ||
| 54 | desc => $desc, | ||
| 55 | ); | ||
| 56 | } | ||
| 57 | |||
| 58 | sub del_timer { | ||
| 59 | my $self = shift; | ||
| 60 | my ($timer) = @_; | ||
| 61 | |||
| 62 | $timer->cancel; | ||
| 63 | |||
| 64 | 1; | ||
| 65 | } | ||
| 66 | |||
| 67 | sub enter { | ||
| 68 | my $self = shift; | ||
| 69 | |||
| 70 | Event::loop(); | ||
| 71 | |||
| 72 | 1; | ||
| 73 | } | ||
| 74 | |||
| 75 | sub leave { | ||
| 76 | my $self = shift; | ||
| 77 | |||
| 78 | Event::unloop_all("ok"); | ||
| 79 | |||
| 80 | 1; | ||
| 81 | } | ||
| 82 | |||
| 83 | 1; | ||
| 84 | |||
| 85 | __END__ |