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 our $event_file_all = "${event_datadir}changes.evt";
29 sub get_filename_event
($) {
30 my $class_device = "$_[0]";
31 my $filename = "${event_datadir}class_${class_device}.evt";
35 sub get_filename_bandwidth_info
($) {
36 my $class_device = "$_[0]";
37 my $filename = "${event_datadir}class_${class_device}_bandwidth.evt";
41 sub update_event_file
($$$) {
43 my $information = $_[1];
44 my $timestamp = $_[2];
46 if ("$information" ne "") {
48 open( OUTPUT
, ">>$filename")
49 or print "ERROR: Opening/updating event file $filename\n";
50 print OUTPUT
"$timestamp $information\n";
55 sub update_info_file
($$$) {
57 my $information = $_[1];
58 my $timestamp = $_[2];
60 open( OUTPUT
, ">$filename")
61 or print "ERROR: Opening/updating info event file $filename\n";
62 print OUTPUT
"$timestamp $information\n";
69 my @test = keys %classes_info;
71 print time, " [process_events] WARNING: classes_info empty!\n";
72 return "classes_info empty";
75 my @bandwidth_items = ( "type", "prio", "rate", "ceil" );
77 my $event_reduced = "";
80 # Find the class_device (keys) in %classes_info
81 for my $class_device ( sort keys %classes_info ) {
83 if ("$class_device" eq "last_update") {next}
86 my $bandwidth_info = "";
88 # Tests if something has changed
89 if ((not exists $classes_info{$class_device}{file_update
}) ||
90 ($classes_info{$class_device}{last_update
} >
91 $classes_info{$class_device}{file_update
})) {
93 $last_update = $classes_info{$class_device}{last_update
};
95 $event_class .= "($class_device)";
96 if ( "$event_reduced" eq "" ) {$event_reduced="Class changed:"}
97 $event_reduced .= " ($class_device)";
98 # The list of changed keys
100 shift @
{ $classes_info{$class_device}{changed
} })
102 my $value = $classes_info{$class_device}{$changed_key};
103 $event_class .= " $changed_key=$value";
106 # When something changed always update all the bandwidth info
107 foreach my $item (@bandwidth_items) {
108 if (exists $classes_info{$class_device}{$item}) {
109 my $value = $classes_info{$class_device}{$item};
110 if (defined $value) {
111 $bandwidth_info .= " $item:$value";
116 print time . "($class_device) changes... ($last_update) \"$bandwidth_info\" \n";
118 $classes_info{$class_device}{file_update
}=$last_update;
120 my $event_file = get_filename_event
($class_device);
121 update_event_file
($event_file , $event_class, $last_update);
123 my $info_file = get_filename_bandwidth_info
($class_device);
124 update_info_file
($info_file, $bandwidth_info, $last_update);
128 # Only one line per process_events call
129 # (notice $last_update is the latest timestamp assignment)
130 if (defined $last_update) {
131 update_event_file
($event_file_all, $event_reduced, $last_update);