[dahdi-commits] tzafrir: tools/trunk r4764 - in /tools/trunk/xpp: ./ perl_modules/Dahdi/
SVN commits to the DAHDI project
dahdi-commits at lists.digium.com
Tue Aug 12 05:21:55 CDT 2008
Author: tzafrir
Date: Tue Aug 12 05:21:53 2008
New Revision: 4764
URL: http://svn.digium.com/view/dahdi?view=rev&rev=4764
Log:
Dahdi-perl: Add alarms() method for channels. Use it in lsdahdi.
* Better paring of the /proc/dahdi/N channel lines for alarms
* Provide it as a separate alarms() method.
Modified:
tools/trunk/xpp/lsdahdi
tools/trunk/xpp/perl_modules/Dahdi/Chans.pm
Modified: tools/trunk/xpp/lsdahdi
URL: http://svn.digium.com/view/dahdi/tools/trunk/xpp/lsdahdi?view=diff&rev=4764&r1=4763&r2=4764
==============================================================================
--- tools/trunk/xpp/lsdahdi (original)
+++ tools/trunk/xpp/lsdahdi Tue Aug 12 05:21:53 2008
@@ -36,8 +36,10 @@
my ($type) = map { $type_map{$_} or $_ } $chan->type || ("unknown");
my $batt = "";
$batt = "(battery)" if $chan->battery;
- printf "%3d %-10s %-10s %s %s\n",
- $chan->num, $type, $chan->signalling, $chan->info, $batt;
+ my @alarms = $chan->alarms;
+ my $alarm_str = join(" ", @alarms);
+ printf "%3d %-10s %-10s %s %s %s\n",
+ $chan->num, $type, $chan->signalling, $chan->info, $batt, $alarm_str;
$index++;
}
}
Modified: tools/trunk/xpp/perl_modules/Dahdi/Chans.pm
URL: http://svn.digium.com/view/dahdi/tools/trunk/xpp/perl_modules/Dahdi/Chans.pm?view=diff&rev=4764&r1=4763&r2=4764
==============================================================================
--- tools/trunk/xpp/perl_modules/Dahdi/Chans.pm (original)
+++ tools/trunk/xpp/perl_modules/Dahdi/Chans.pm Tue Aug 12 05:21:53 2008
@@ -17,6 +17,12 @@
This package allows access from perl to information about a Dahdi
channel. It is part of the Dahdi Perl package.
+=head1 alarms()
+
+In an array context returns a list of alarm strings (RED, BLUE, etc.)
+for this channel (an empty list == false if there are no alarms).
+In scalar context returns the number of alarms for a specific channel.
+
=head1 battery()
Returns 1 if channel reports to have battery (A remote PBX connected to
@@ -53,6 +59,8 @@
Returns the type of the channel: 'FXS', 'FXO', 'EMPTY', etc.
=cut
+
+my @alarm_types = qw(BLUE YELLOW RED LOOP RECOVERING NOTOPEN);
sub new($$$$$$) {
my $pack = shift or die "Wasn't called as a class method\n";
@@ -69,18 +77,29 @@
$num or die "Missing a channel number parameter\n";
$fqn or die "Missing a channel fqn parameter\n";
my $signalling = '';
+ my @alarms = ();
my $info = '';
if(defined $rest) {
+ # remarks in parenthesis (In use), (no pcm)
+ while($rest =~ s/(\([^)]+\))\s*//) {
+ $info .= " $1";
+ }
+ # Alarms
+ foreach my $alarm (@alarm_types) {
+ if($rest =~ s/\s*(\b${alarm}\b)\s*//) {
+ push(@alarms, $1);
+ }
+ }
if($rest =~ s/^\s*(\w+)\s*//) {
$signalling = $1;
}
- if($rest =~ s/(.*)//) {
- $info = $1;
- }
+ die "Unrecognized garbage '$rest' in $fqn\n"
+ if length($rest);
}
$self->{NUM} = $num;
$self->{FQN} = $fqn;
$self->{SIGNALLING} = $signalling;
+ $self->{ALARMS} = \@alarms;
$self->{INFO} = $info;
my $type;
if($fqn =~ m|\bXPP_(\w+)/.*$|) {
@@ -184,6 +203,13 @@
return $line->battery;
}
+sub alarms($) {
+ my $self = shift or die;
+ my @alarms = @{$self->{ALARMS}};
+
+ return @alarms;
+}
+
sub blink($$) {
my $self = shift or die;
my $on = shift;
More information about the dahdi-commits
mailing list