diff options
| author | Andreas Brachold <vdr07@deltab.de> | 2008-12-07 16:28:12 +0000 |
|---|---|---|
| committer | Andreas Brachold <vdr07@deltab.de> | 2008-12-07 16:28:12 +0000 |
| commit | 7885d3624e79e2d5c5b1eddb7cd20af1b28113d7 (patch) | |
| tree | f9864693a0ec5570a1d193a1494e154dd87626ea /lib | |
| parent | f98ae2c03cd2ab4a47e7335e1adb5a97e4a1ccea (diff) | |
| download | xxv-7885d3624e79e2d5c5b1eddb7cd20af1b28113d7.tar.gz xxv-7885d3624e79e2d5c5b1eddb7cd20af1b28113d7.tar.bz2 | |
* SVDRP: after editing notify state of recorder to depends moduls
* RECORDS: dynamic add or remove watched video directory depends state of recorder
* Fix some typos
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/XXV/MODULES/MEDIALIB.pm | 2 | ||||
| -rw-r--r-- | lib/XXV/MODULES/MOVETIMER.pm | 2 | ||||
| -rw-r--r-- | lib/XXV/MODULES/RECORDS.pm | 137 | ||||
| -rw-r--r-- | lib/XXV/MODULES/SVDRP.pm | 48 |
4 files changed, 148 insertions, 41 deletions
diff --git a/lib/XXV/MODULES/MEDIALIB.pm b/lib/XXV/MODULES/MEDIALIB.pm index d219352..993fff0 100644 --- a/lib/XXV/MODULES/MEDIALIB.pm +++ b/lib/XXV/MODULES/MEDIALIB.pm @@ -713,7 +713,7 @@ sub saveMedia { $console->message(sprintf gettext('Media %s saved!'), $params->{id}); debug sprintf('%s media is saved%s', - ($id ? 'New' : 'Changed'), + ($id ? 'Changed' : 'New'), ( $console->{USER} && $console->{USER}->{Name} ? sprintf(' from user: %s', $console->{USER}->{Name}) : "" ) ); $console->redirect({url => '?cmd=mldisplay&data='. $params->{id}."&__range=". $range, wait => 2}) diff --git a/lib/XXV/MODULES/MOVETIMER.pm b/lib/XXV/MODULES/MOVETIMER.pm index 853ddb9..3ca9ba6 100644 --- a/lib/XXV/MODULES/MOVETIMER.pm +++ b/lib/XXV/MODULES/MOVETIMER.pm @@ -483,7 +483,7 @@ sub movetimeredit { $console->message(gettext('Rule to move timer saved!')); debug sprintf('%s rule to move timer is saved%s', - ($id ? 'New' : 'Changed'), + ($id ? 'Changed' : 'New'), ( $console->{USER} && $console->{USER}->{Name} ? sprintf(' from user: %s', $console->{USER}->{Name}) : "" ) ); diff --git a/lib/XXV/MODULES/RECORDS.pm b/lib/XXV/MODULES/RECORDS.pm index 45ca2be..05b3c5c 100644 --- a/lib/XXV/MODULES/RECORDS.pm +++ b/lib/XXV/MODULES/RECORDS.pm @@ -331,6 +331,10 @@ sub _init { unless($self->{svdrp}) { return 0; } + $self->{svdrp}->updated( sub{ + return $self->_watch_changerecorder(@_); + }); + $self->{timers} = main::getModule('TIMERS'); unless($self->{timers}) { return 0; @@ -340,7 +344,7 @@ sub _init { return 0; } - $self->_watch_updatefile(); + $self->_watch_recorder(); # Interval to read recordings and put to DB Event->timer( @@ -364,44 +368,104 @@ sub _init { 1; } -sub _watch_updatefile { +sub _watch_recorder { my $self = shift || return error('No object defined!'); - my $hostlist = $self->{svdrp}->list_unique_recording_hosts(); + my $hostlist = $self->{svdrp}->list_hosts(); # Query active hosts; foreach my $vid (@$hostlist) { + $self->_watch_addrecorder($vid); + } +} - next if(exists $self->{inotify} - && exists $self->{inotify}->{$vid}); +sub _watch_addrecorder { + my $self = shift || return error('No object defined!'); + my $vid = shift; - my $videodirectory = $self->{svdrp}->videodirectory($vid); - unless($videodirectory && -d $videodirectory) { - my $hostname = $self->{svdrp}->hostname($vid); - error(sprintf("Missing video directory on %s!",$hostname)); - next; + my $videodirectory = $self->{svdrp}->videodirectory($vid); + unless($videodirectory && -d $videodirectory) { + my $hostname = $self->{svdrp}->hostname($vid); + error(sprintf("Missing video directory on %s!",$hostname)); + return; + } + my $updatefile = sprintf("%s/.update",$videodirectory); + if( -r $updatefile) { + + if(exists $self->{inotify} + && exists $self->{inotify}->{$updatefile}) { + $self->{inotify}->{$updatefile}->{count} += 1; + return; } - my $updatefile = sprintf("%s/.update",$videodirectory); - if( -r $updatefile) { - $self->{inotify}->{$vid}->{handle} = new Linux::Inotify2 - or panic sprintf("Unable to create new inotify object: %s",$!); - - if($self->{inotify}->{$vid}->{handle}) { - # Bind watch to event::io - $self->{inotify}->{$vid}->{event} = Event->io( - fd => $self->{inotify}->{$vid}->{handle}->fileno, - poll => 'r', - cb => sub { $self->{inotify}->{$vid}->{handle}->poll } - ); - # watch update file - $self->{inotify}->{$vid}->{handle}->watch( - $updatefile, - IN_ALL_EVENTS, - sub { - my $e = shift; - $self->_notify_updatefile($e, $vid); - } - ); + $self->{inotify}->{$updatefile}->{handle} = new Linux::Inotify2 + or panic sprintf("Unable to create new inotify object %s: %s",$updatefile, $!); + + if($self->{inotify}->{$updatefile}->{handle}) { + $self->{inotify}->{$updatefile}->{count} = 1; + # Bind watch to event::io + $self->{inotify}->{$updatefile}->{event} = Event->io( + fd => $self->{inotify}->{$updatefile}->{handle}->fileno, + poll => 'r', + cb => sub { $self->{inotify}->{$updatefile}->{handle}->poll } + ); + # watch update file + $self->{inotify}->{$updatefile}->{watch} = + $self->{inotify}->{$updatefile}->{handle}->watch( + $updatefile, + IN_ALL_EVENTS, + sub { + my $e = shift; + $self->_notify_updatefile($e, $vid); + } + ); + lg(sprintf("Monitor file '%s'",$updatefile)); + } else { + delete $self->{inotify}->{$updatefile}; } - } + } +} + +sub _watch_removerecorder { + my $self = shift || return error('No object defined!'); + my $vid = shift; + my $force = shift; + + unless(exists $self->{inotify}) { + return; + } + + my $videodirectory = $self->{svdrp}->videodirectory($vid); + unless($videodirectory && -d $videodirectory) { + my $hostname = $self->{svdrp}->hostname($vid); + error(sprintf("Missing video directory on '%s'!",$hostname)); + return; + } + + my $updatefile = sprintf("%s/.update",$videodirectory); + if(exists $self->{inotify}->{$updatefile}) { + unless($force) { + if($self->{inotify}->{$updatefile}->{count} > 1) { + $self->{inotify}->{$updatefile}->{count} -= 1; + return; + } + } + lg(sprintf("Remove watching file '%s'",$updatefile)); + $self->{inotify}->{$updatefile}->{watch}->cancel() + if($self->{inotify}->{$updatefile}->{watch}); + + delete $self->{inotify}->{$updatefile}->{watch}; + delete $self->{inotify}->{$updatefile}->{event}; + delete $self->{inotify}->{$updatefile}->{handle}; + delete $self->{inotify}->{$updatefile}; + } +} + +sub _watch_changerecorder { + my $self = shift || return error('No object defined!'); + my $vid = shift; + my $state = shift; + if($state && $state eq 'y') { + $self->_watch_addrecorder($vid); + } else { + $self->_watch_removerecorder($vid); } } # ------------------ @@ -413,7 +477,14 @@ sub _notify_updatefile { my $e = shift; my $vid = shift; - lg sprintf "On recorder %d notify events for %s:%d received: %x", $vid, $e->fullname, $e->cookie, $e->mask; + if($e->{mask} & (IN_UNMOUNT|IN_Q_OVERFLOW|IN_IGNORED)) { + error(sprintf("Can't monitor events, '%s' is no longer mounted",$e->{w}{name})) if($e->{mask} & IN_UNMOUNT); + error(sprintf("Monitor events for '%s' have been lost",$e->{w}{name})) if($e->{mask} & IN_Q_OVERFLOW); + $self->_watch_removerecorder($vid,'force'); + $e->w->cancel; + } + + lg sprintf "On recorder %d notify events for %s received event: %x", $vid, $e->fullname, $e->mask; if((time - $self->{lastupdate}) > 3 # Only if last update prior 3 seconds (avoid callback chill) && $self->_readData()) { diff --git a/lib/XXV/MODULES/SVDRP.pm b/lib/XXV/MODULES/SVDRP.pm index f435597..99b3a90 100644 --- a/lib/XXV/MODULES/SVDRP.pm +++ b/lib/XXV/MODULES/SVDRP.pm @@ -159,9 +159,30 @@ sub _init { }); } + $self->{updated} = []; + return 1; } +# function to register callback for notify state of recorder +# ------------------ +sub updated { +# ------------------ + my $self = shift || return error('No object defined!'); + my $param = shift; + my $state = shift; + + if($param && ref $param eq 'CODE') { + push(@{$self->{updated}}, [$param]); + } else { + foreach my $CB (@{$self->{updated}}) { + next unless(ref $CB eq 'ARRAY'); + &{$CB->[0]}($param,$state) + if(ref $CB->[0] eq 'CODE'); + } + } +} + # ------------------ sub _insert { # ------------------ @@ -198,7 +219,7 @@ sub edit { my $data = shift || 0; my $default; - if($id and not ref $data) { + if($id) { my $sth = $self->{dbh}->prepare('SELECT SQL_CACHE * from RECORDER where id = ?'); $sth->execute($id) or return $console->err(sprintf(gettext("Definition of video disk recorder '%s' does not exist in the database!"),$id)); @@ -259,6 +280,8 @@ sub edit { if(ref $data eq 'HASH') { + $data->{'videodirectory'} =~ s/\/$//; + if($data->{'master'} eq 'y') { $self->{dbh}->do("UPDATE RECORDER SET master='n' WHERE master = 'y'"); } @@ -268,8 +291,12 @@ sub edit { delete $self->{Cache}; + # Update depends moduls + $self->updated($data->{'id'},$data->{'active'}) + if(!$default || $default->{'active'} ne $data->{'active'}); + debug sprintf('%s video disk recorder definition "%s" is saved%s', - ($id ? 'New' : 'Changed'), + ($id ? 'Changed' : 'New'), $data->{host}, ( $console->{USER} && $console->{USER}->{Name} ? sprintf(' from user: %s', $console->{USER}->{Name}) : "" ) ); @@ -292,6 +319,9 @@ sub delete { $sth->execute($id) or return $console->err(sprintf(gettext("Definition of video disk recorder '%s' does not exist in the database!"),$id)); + # Remove recorder from depends moduls + $self->updated($id,'n'); + $self->_deletevdrdata($id); delete $self->{Cache}; @@ -360,7 +390,7 @@ from sub _gethost { my $self = shift || return error('No object defined!'); my $vdrid = shift; - + unless(exists $self->{Cache}) { my $sth = $self->{dbh}->prepare("SELECT * from RECORDER where active = 'y'"); $sth->execute() @@ -491,9 +521,15 @@ sub list_unique_recording_hosts() { sub videodirectory { my $self = shift || return error('No object defined!'); my $vdrid = shift; - - my $vdr = $self->_gethost($vdrid); - return $vdr ? $vdr->{videodirectory} : undef; + + my $sql = qq| +SELECT SQL_CACHE videodirectory FROM RECORDER WHERE id = ? +|; + my $sth = $self->{dbh}->prepare($sql); + $sth->execute($vdrid) + or return error(sprintf("Video disk recorder '%s' does not exist in the database!",$vdrid)); + my $erg = $sth->fetchrow_hashref(); + return $erg ? $erg->{videodirectory} : undef; } # ------------------ |
