Fixed extraneous reloads and broken pending tasks.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@224 e3e1d417-86f3-4887-817a-d78f3d33393f
pull/27/merge
stan 2003-01-02 12:55:09 +00:00
parent faf094abcd
commit e89cd6118e
1 changed files with 9 additions and 6 deletions

View File

@ -179,6 +179,8 @@ sub runServer
my $timeout = 0.2; my $timeout = 0.2;
#print( "F:".fileno(SERVER)."\n" ); #print( "F:".fileno(SERVER)."\n" );
my $reload = undef; my $reload = undef;
my $reload_count = 0;
my $reload_limit = main::DB_RELOAD_INTERVAL/$timeout;
while( 1 ) while( 1 )
{ {
my $nfound = select( my $rout = $rin, undef, undef, $timeout ); my $nfound = select( my $rout = $rin, undef, undef, $timeout );
@ -324,14 +326,15 @@ sub runServer
my $pending_list = $pending_tasks{$activation_time}; my $pending_list = $pending_tasks{$activation_time};
foreach my $task ( @$pending_list ) foreach my $task ( @$pending_list )
{ {
processTask( $task ); processTask( $task );
} }
delete( $pending_tasks{$activation_time} ); delete( $pending_tasks{$activation_time} );
} }
if ( $reload || !($now%main::DB_RELOAD_INTERVAL) ) if ( $reload || $reload_count >= $reload_limit )
{ {
loadTasks(); loadTasks();
$reload = undef; $reload = undef;
$reload_count = 0;
} }
} }
} }
@ -388,7 +391,7 @@ sub addToMonitorList
my $task = { type=>"monitor", device=>$device, function=>$function }; my $task = { type=>"monitor", device=>$device, function=>$function };
if ( $limit ) if ( $limit )
{ {
$task->{limit} = $limit $task->{limit} = $limit;
} }
my $task_list = $monitor->{$event."_list"}; my $task_list = $monitor->{$event."_list"};
@ -518,7 +521,7 @@ sub addPendingTask
} }
elsif ( $task->{type} eq "monitor" ) elsif ( $task->{type} eq "monitor" )
{ {
if (( $task->{device}->unit_code() != $pending_task->{device}->unit_code() ) if (( $task->{device}->{appliance}->unit_code() != $pending_task->{device}->{appliance}->unit_code() )
|| ( $task->{function} != $pending_task->{function} )) || ( $task->{function} != $pending_task->{function} ))
{ {
push( @$new_pending_list, $pending_task ) push( @$new_pending_list, $pending_task )
@ -544,12 +547,12 @@ sub addPendingTask
my $pending_task; my $pending_task;
if ( $task->{type} eq "device" ) if ( $task->{type} eq "device" )
{ {
$pending_task = { monitor=>$task->{monitor}, function=>$task->{function} }; $pending_task = { type=>$task->{type}, monitor=>$task->{monitor}, function=>$task->{function} };
$pending_task->{function} =~ s/start/stop/; $pending_task->{function} =~ s/start/stop/;
} }
elsif ( $task->{type} eq "monitor" ) elsif ( $task->{type} eq "monitor" )
{ {
$pending_task = { device=>$task->{device}, function=>$task->{function} }; $pending_task = { type=>$task->{type}, device=>$task->{device}, function=>$task->{function} };
$pending_task->{function} =~ s/on/off/; $pending_task->{function} =~ s/on/off/;
} }
push( @$pending_list, $pending_task ); push( @$pending_list, $pending_task );