line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#================================ List.pm =================================== |
2
|
|
|
|
|
|
|
# Filename: List |
3
|
|
|
|
|
|
|
# Description: Internal class for managing a list of delegates. |
4
|
|
|
|
|
|
|
# Original Author: Dale M. Amon |
5
|
|
|
|
|
|
|
# Revised by: $Author: amon $ |
6
|
|
|
|
|
|
|
# Date: $Date: 2008-08-28 23:20:19 $ |
7
|
|
|
|
|
|
|
# Version: $Revision: 1.5 $ |
8
|
|
|
|
|
|
|
# License: LGPL 2.1, Perl Artistic or BSD |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
#============================================================================= |
11
|
1
|
|
|
1
|
|
620
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
12
|
1
|
|
|
1
|
|
6
|
use Fault::ErrorHandler; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package Fault::Delegate::List; |
15
|
1
|
|
|
1
|
|
5
|
use vars qw{@ISA}; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1945
|
|
16
|
|
|
|
|
|
|
@ISA = qw( UNIVERSAL ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#============================================================================= |
19
|
|
|
|
|
|
|
# CLASS METHODS |
20
|
|
|
|
|
|
|
#============================================================================= |
21
|
|
|
|
|
|
|
my %fault = (); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new { |
24
|
0
|
|
|
0
|
1
|
|
my ($class,@list) = @_; |
25
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
%fault = (); |
28
|
0
|
|
|
|
|
|
$self->{'list'} = {}; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
$self->add (@list); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# If we had no good delegates, default to command line. |
33
|
0
|
0
|
|
|
|
|
scalar keys %{$self->{'list'}} or $self->add (Fault::Delegate::Stdout->new); |
|
0
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
return $self; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
#============================================================================= |
39
|
|
|
|
|
|
|
# INSTANCE METHODS |
40
|
|
|
|
|
|
|
#============================================================================= |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub add ($@) { |
43
|
0
|
|
|
0
|
1
|
|
my ($self, @list) = @_; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
foreach my $d (@list) { |
46
|
0
|
0
|
|
|
|
|
next if (!defined $d); |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
0
|
|
|
|
if (! ((ref $d) && |
|
|
|
0
|
|
|
|
|
49
|
|
|
|
|
|
|
((ref $d) ne "HASH") && |
50
|
|
|
|
|
|
|
$d->can("log"))) { |
51
|
0
|
|
|
|
|
|
Fault::ErrorHandler->warn |
52
|
|
|
|
|
|
|
("Fault::Logger->new: Ignoring an invalid logger delegate " . |
53
|
|
|
|
|
|
|
"object. A delegate must at the very least support a 'log' " . |
54
|
|
|
|
|
|
|
"method. Read the docs and fix your code."); |
55
|
0
|
|
|
|
|
|
next;} |
56
|
0
|
|
|
|
|
|
my $list = $self->{'list'}; |
57
|
0
|
|
|
|
|
|
$list->{$d} = $d; |
58
|
0
|
0
|
|
|
|
|
if ($d->can ("initfaults")) { |
59
|
0
|
|
|
|
|
|
foreach my $m (eval{$d->initfaults}) {$fault{$m}=1;} |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
0
|
|
|
|
|
|
return 1; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
0
|
1
|
|
sub delegates ($) {values %{shift->{'list'}};} |
|
0
|
|
|
|
|
|
|
68
|
0
|
0
|
|
0
|
0
|
|
sub fault_exists ($$) {my ($s,$m)=@_; return ($fault{$m->msg}) ? 1 : 0;} |
|
0
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
71
|
|
|
|
|
|
|
# Apply a Delegate Protocol Methdo to each Delegate |
72
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub log ($$@) { |
75
|
0
|
|
|
0
|
1
|
|
my ($s,$msg,@rest) = @_; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
foreach my $l ($s->delegates) { |
78
|
0
|
0
|
|
|
|
|
(eval ($l->log ($msg,@rest))) || |
79
|
|
|
|
|
|
|
(Fault::ErrorHandler->warn("Failed to report: \"" . |
80
|
|
|
|
|
|
|
$msg->msg . |
81
|
|
|
|
|
|
|
"\" due to Delegate error \"$@\"!"), |
82
|
|
|
|
|
|
|
return 0); |
83
|
|
|
|
|
|
|
} |
84
|
0
|
|
|
|
|
|
return 1; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
88
|
|
|
|
|
|
|
# Log on condition still low. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub trans00 ($$@) { |
91
|
0
|
|
|
0
|
1
|
|
my ($s,$msg,@rest) = @_; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
foreach my $l ($s->delegates) { |
94
|
0
|
0
|
|
|
|
|
($l->can ("trans00")) && eval($l->trans00($msg,@rest)); |
95
|
|
|
|
|
|
|
} |
96
|
0
|
|
|
|
|
|
return 0; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
100
|
|
|
|
|
|
|
# Log on condition rising edge. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub trans01 ($$@) { |
103
|
0
|
|
|
0
|
1
|
|
my ($s,$msg,@rest) = @_; |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
$fault{$msg->msg} = 1; |
106
|
0
|
|
|
|
|
|
foreach my $l ($s->delegates) { |
107
|
0
|
0
|
|
|
|
|
($l->can ("trans01")) && eval($l->trans01($msg,@rest)); |
108
|
|
|
|
|
|
|
} |
109
|
0
|
|
|
|
|
|
return 0; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
113
|
|
|
|
|
|
|
# Log on condition falling edge. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub trans10 ($$@) { |
116
|
0
|
|
|
0
|
1
|
|
my ($s,$msg,@rest) = @_; |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
foreach my $l ($s->delegates) { |
119
|
0
|
0
|
|
|
|
|
($l->can ("trans10")) && eval($l->trans10($msg,@rest)); |
120
|
|
|
|
|
|
|
} |
121
|
0
|
|
|
|
|
|
return 0; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
125
|
|
|
|
|
|
|
# Log on condition still high. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub trans11 ($$@) { |
128
|
0
|
|
|
0
|
1
|
|
my ($s,$msg,@rest) = @_; |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
delete $fault{$msg->msg}; |
131
|
0
|
|
|
|
|
|
foreach my $l ($s->delegates) { |
132
|
0
|
0
|
|
|
|
|
($l->can ("trans11")) && eval($l->trans11($msg,@rest)); |
133
|
|
|
|
|
|
|
} |
134
|
0
|
|
|
|
|
|
return 0; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
#============================================================================= |
138
|
|
|
|
|
|
|
# POD DOCUMENTATION |
139
|
|
|
|
|
|
|
#============================================================================= |
140
|
|
|
|
|
|
|
# You may extract and format the documention section with the 'perldoc' cmd. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 NAME |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Fault::Delegate::List - Internal class for managing a list of delegates. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 SYNOPSIS |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
use Fault::Delegate::List; |
149
|
|
|
|
|
|
|
$self = Fault::Delegate::List->new (@delegates); |
150
|
|
|
|
|
|
|
$bool = $self->add (@delegates); |
151
|
|
|
|
|
|
|
@delegates = $self->delegates; |
152
|
|
|
|
|
|
|
$bool = $self->log ($msg,@rest); |
153
|
|
|
|
|
|
|
$bool = $self->trans00 ($msg,@rest); |
154
|
|
|
|
|
|
|
$bool = $self->trans01 ($msg,@rest); |
155
|
|
|
|
|
|
|
$bool = $self->trans10 ($msg,@rest); |
156
|
|
|
|
|
|
|
$bool = $self->trans11 ($msg,@rest); |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 Inheritance |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
UNIVERSAL |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 Description |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Internal class for managing a list of delegates. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 Examples |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
None. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 Class Variables |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
None. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 Instance Variables |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
list Contains a pointer to a hash of delegate pointers. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 Class Methods |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=over 4 |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item B<$self = Fault::Delegate::List-Enew(@delegates)> |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Create an instance of Fault::Delegate::List and initialize it with the |
185
|
|
|
|
|
|
|
contents of @delegates. The list may be null. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
If a delegate has an initfaults method, it is executed and the results |
188
|
|
|
|
|
|
|
merged into the current list of active faults. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 Instance Methods |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=over 4 |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item B<$bool = $self-Eadd (@delegates)> |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Add each member of a list of delegates, that is not already present, to the |
197
|
|
|
|
|
|
|
internal list of delegates. The list may be empty. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
A member of the list is included only if it is a pointer to an object that |
200
|
|
|
|
|
|
|
has a log method. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
If a delegate has an initfaults method, it is executed and the results |
203
|
|
|
|
|
|
|
merged into the current list of active faults. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=item B<@delegates = $self-Edelegates> |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Returns a list of delegate objects suitable for iteration. The list may be |
208
|
|
|
|
|
|
|
empty. |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=item B<$bool = $self-Elog ($msg,@rest)> |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Send a message to each delegate for logging. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item B<$bool = $self-Etrans00 ($msg,@rest)> |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Send a message to each delegate for 4 state fault monitoring in the case |
217
|
|
|
|
|
|
|
that $msg was in a Fault Clear state previously and still is. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=item B<$bool = $self-Etrans01 ($msg,@rest)> |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Send a message to each delegate for 4 state fault monitoring in the case |
222
|
|
|
|
|
|
|
that $msg was in a Fault Clear state previously and is now in a Fault |
223
|
|
|
|
|
|
|
Raised state. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=item B<$bool = $self-Etrans10 ($msg,@rest)> |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Send a message to each delegate for 4 state fault monitoring in the case |
228
|
|
|
|
|
|
|
that $msg was in a Fault Raised state previously but is now in a Fault |
229
|
|
|
|
|
|
|
Clear state. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=item B<$bool = $self-Etrans11 ($msg,@rest)> |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Send a message to each delegate for 4 state fault monitoring in the case |
234
|
|
|
|
|
|
|
that $msg was in a Fault Raised state previously and still is. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=item B<@faults = $self-Einitfaults> |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
Ask each delegate to return a current list of faults for this process from |
239
|
|
|
|
|
|
|
its persistant storage. Returns an empty list if there are none or the |
240
|
|
|
|
|
|
|
delegate class has no such memory or if it does and is unable to retrieve |
241
|
|
|
|
|
|
|
data from it. |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=back 4 |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head1 Private Class Method |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
None. |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=head1 Private Instance Methods |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
None. |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=head1 Errors and Warnings |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
None. |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=head1 KNOWN BUGS |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
See TODO. |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=head1 SEE ALSO |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
None. |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=head1 AUTHOR |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
Dale Amon |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=cut |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
#============================================================================= |
272
|
|
|
|
|
|
|
# CVS HISTORY |
273
|
|
|
|
|
|
|
#============================================================================= |
274
|
|
|
|
|
|
|
# $Log: List.pm,v $ |
275
|
|
|
|
|
|
|
# Revision 1.5 2008-08-28 23:20:19 amon |
276
|
|
|
|
|
|
|
# perldoc section regularization. |
277
|
|
|
|
|
|
|
# |
278
|
|
|
|
|
|
|
# Revision 1.4 2008-08-17 21:56:37 amon |
279
|
|
|
|
|
|
|
# Make all titles fit CPAN standard. |
280
|
|
|
|
|
|
|
# |
281
|
|
|
|
|
|
|
# Revision 1.3 2008-05-09 18:24:55 amon |
282
|
|
|
|
|
|
|
# Bugs and changes due to pre-release testing |
283
|
|
|
|
|
|
|
# |
284
|
|
|
|
|
|
|
# Revision 1.2 2008-05-08 20:22:50 amon |
285
|
|
|
|
|
|
|
# Minor bug fixes; shifted fault table and initfault from Logger to List |
286
|
|
|
|
|
|
|
# |
287
|
|
|
|
|
|
|
# Revision 1.1 2008-05-07 18:16:12 amon |
288
|
|
|
|
|
|
|
# A class to manage a list of logger delegates |
289
|
|
|
|
|
|
|
# |
290
|
|
|
|
|
|
|
# $DATE Dale Amon |
291
|
|
|
|
|
|
|
# Created. |
292
|
|
|
|
|
|
|
1; |