3 ##########################################
9 ## Which is part of the ADSL-optimizer.
21 ## Jesper Dangaard Brouer <hawk@diku.dk>, d.21/4-2004
24 ## 2004-04-21: Initial version.
26 ##########################################
28 sub update_event_file
($$$) {
30 my $information = $_[1];
31 my $timestamp = $_[2];
33 if ("$information" ne "") {
35 open( OUTPUT
, ">>$filename")
36 or print "ERROR: Opening/updating event file $filename\n";
37 print OUTPUT
"$timestamp $information\n";
42 sub update_info_file
($$$) {
44 my $information = $_[1];
45 my $timestamp = $_[2];
47 open( OUTPUT
, ">$filename")
48 or print "ERROR: Opening/updating info event file $filename\n";
49 print OUTPUT
"$timestamp $information\n";
56 my @test = keys %classes_info;
58 print time, " [process_events] WARNING: classes_info empty!\n";
59 return "classes_info empty";
62 my @bandwidth_items = ( "type", "prio", "rate", "ceil" );
64 my $event_reduced = "";
67 # Find the class_device (keys) in %classes_info
68 for my $class_device ( sort keys %classes_info ) {
70 if ("$class_device" eq "last_update") {next}
73 my $bandwidth_info = "";
75 # Tests if something has changed
76 if ((not exists $classes_info{$class_device}{file_update
}) ||
77 ($classes_info{$class_device}{last_update
} >
78 $classes_info{$class_device}{file_update
})) {
80 $last_update = $classes_info{$class_device}{last_update
};
82 $event_class .= "($class_device)";
83 if ( "$event_reduced" eq "" ) {$event_reduced="Class changed:"}
84 $event_reduced .= " ($class_device)";
85 # The list of changed keys
87 shift @
{ $classes_info{$class_device}{changed
} })
89 my $value = $classes_info{$class_device}{$changed_key};
90 $event_class .= " $changed_key=$value";
93 # When something changed always update all the bandwidth info
94 foreach my $item (@bandwidth_items) {
95 if (exists $classes_info{$class_device}{$item}) {
96 my $value = $classes_info{$class_device}{$item};
98 $bandwidth_info .= " $item:$value";
103 print time . "($class_device) changes... ($last_update) \"$bandwidth_info\" \n";
105 $classes_info{$class_device}{file_update
}=$last_update;
107 my $event_file = get_filename_event
($class_device);
108 update_event_file
($event_file , $event_class, $last_update);
110 my $info_file = get_filename_bandwidth_info
($class_device);
111 update_info_file
($info_file, $bandwidth_info, $last_update);
115 # Only one line per process_events call
116 # (notice $last_update is the latest timestamp assignment)
117 if (defined $last_update) {
118 update_event_file
($event_file_all, $event_reduced, $last_update);