[svn-commits] tzafrir: tools/trunk r6057 - in /tools/trunk/xpp: ./ perl_modules/Dahdi/Confi...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Sun Mar 1 08:29:06 CST 2009
Author: tzafrir
Date: Sun Mar 1 08:29:03 2009
New Revision: 6057
URL: http://svn.digium.com/svn-view/dahdi?view=rev&rev=6057
Log:
xpp-dahdi: freepbx code generation; better procfs compatibility
* dahdi_genconf -F will generate chan_dahdi.conf for freepbx
(like genzaptelconf -F)
* Better procfs compatibility for xpp modules.
Modified:
tools/trunk/xpp/dahdi_genconf
tools/trunk/xpp/perl_modules/Dahdi/Config/Gen/Chandahdi.pm
tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xbus.pm
tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xpd.pm
Modified: tools/trunk/xpp/dahdi_genconf
URL: http://svn.digium.com/svn-view/dahdi/tools/trunk/xpp/dahdi_genconf?view=diff&rev=6057&r1=6056&r2=6057
==============================================================================
--- tools/trunk/xpp/dahdi_genconf (original)
+++ tools/trunk/xpp/dahdi_genconf Sun Mar 1 08:29:03 2009
@@ -15,6 +15,9 @@
use Dahdi;
use Dahdi::Xpp;
use Dahdi::Config::GenconfDefaults;
+
+my $version = '1'; # Functionality version (integer)
+my $revision = '$Revision$';
my %opts;
my $genconf_defaults;
@@ -72,6 +75,7 @@
my %global_config = (
'genconf_file' => 'HARD-CODED-DEFAULT', # GenconfDefaults override
'base_exten' => 4000,
+ 'freepbx' => 'no', # Better via -F command line
'fxs_immediate' => 'no',
'loadzone' => $lc_country,
'defaultzone' => $lc_country,
@@ -80,7 +84,7 @@
'bri_hardhdlc' => 'no',
'bri_sig_style' => 'bri_ptmp',
'r2_idle_bits' => '1101',
- 'bri_overlapdial' => 'no',
+ 'brint_overlap' => 'no',
'pri_connection_type' => 'PRI', # PRI or R2
'dahdi_signalling' => \%default_dahdi_signalling,
'chan_dahdi_signalling' => \%default_chan_dahdi_signalling,
@@ -89,6 +93,7 @@
my %dahdi_default_vars = (
GENCONF_FILE => \$global_config{'genconf_file'},
base_exten => \$global_config{'base_exten'},
+ freepbx => \$global_config{'freepbx'},
fxs_immediate => \$global_config{'fxs_immediate'},
fxs_default_start => \$fxs_default_start,
lc_country => [
@@ -106,7 +111,7 @@
],
group_lines => \$default_group{FXO},
bri_sig_style => \$global_config{'bri_sig_style'},
- bri_overlapdial => \$global_config{'bri_overlapdial'},
+ brint_overlap => \$global_config{'brint_overlap'},
pri_termtype => \$pri_termtype,
pri_connection_type => \$global_config{'pri_connection_type'},
r2_idle_bits => \$global_config{'r2_idle_bits'},
@@ -147,7 +152,6 @@
if($opts{v}) {
print "Default parameters from ", $genconf_defaults->{GENCONF_FILE}, "\n";
}
- #$genconf_defaults->dump;
map_dahdi_defaults(%$genconf_defaults);
foreach my $span (@spans) {
if($span->is_pri) {
@@ -158,12 +162,12 @@
foreach my $val (values %default_dahdi_signalling, values %default_chan_dahdi_signalling) {
$val =~ s/{fxs_default_start}/$fxs_default_start/g;
}
+ #$genconf_defaults->dump;
}
sub parse_args {
my @default_generators;
- getopts('v', \%opts);
if (@ARGV) {
for my $gen (@ARGV) {
push @default_generators, $gen;
@@ -214,8 +218,18 @@
die "Illegal name '$name'\n" unless $name =~ /^\w+$/;
$name =~ s/(.)(.*)/\u$1\L$2/;
my %genopts = parse_genopts($optstr);
+ $genopts{'freepbx'} = 'yes' if $opts{'F'};
run_generator($name, \%genopts);
}
+}
+
+getopts('vVF', \%opts) || die "$0: Bad option\n";
+if($opts{'V'}) {
+ my $revstr = $revision;
+ $revstr =~ s/[^$]*\$[^:]+:\s*//;
+ $revstr =~ s/\s*\$.*//;
+ print "$0: version=$version revision=$revstr\n";
+ exit 0;
}
my @default_generators = parse_args;
@@ -269,8 +283,18 @@
=over 4
+=item -V
+
+Version -- print version string and exit.
+
=item -v
-Verbose -- also sets the C<'verbose'> option for all generators.
+Verbose -- sets the C<'verbose'> option for all generators.
+
+=item -F
+
+Freepbx -- sets the C<'freepbx'> option for all generators.
+Currently, chandahdi is affected.
+
=back
Modified: tools/trunk/xpp/perl_modules/Dahdi/Config/Gen/Chandahdi.pm
URL: http://svn.digium.com/svn-view/dahdi/tools/trunk/xpp/perl_modules/Dahdi/Config/Gen/Chandahdi.pm?view=diff&rev=6057&r1=6056&r2=6057
==============================================================================
--- tools/trunk/xpp/perl_modules/Dahdi/Config/Gen/Chandahdi.pm (original)
+++ tools/trunk/xpp/perl_modules/Dahdi/Config/Gen/Chandahdi.pm Sun Mar 1 08:29:03 2009
@@ -155,7 +155,7 @@
$self->gen_digital($span);
} else {
foreach my $chan ($span->chans()) {
- if($genopts->{'freepbx'}) {
+ if(is_true($genopts->{'freepbx'}) || is_true($gconfig->{'freepbx'})) {
# Freepbx has its own idea about channels
my $type = $chan->type;
if($type eq 'FXS' || $type eq 'OUT' || $type eq 'IN') {
@@ -208,3 +208,6 @@
generated and inserted into I<freepbx> database anyway.
=back
+
+The I<freepbx> option may be activated also by adding a C<freepbx yes> line
+to the C<genconf_parameters> file.
Modified: tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xbus.pm
URL: http://svn.digium.com/svn-view/dahdi/tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xbus.pm?view=diff&rev=6057&r1=6056&r2=6057
==============================================================================
--- tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xbus.pm (original)
+++ tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xbus.pm Sun Mar 1 08:29:03 2009
@@ -46,13 +46,16 @@
return $wanted;
}
+my %file_warned; # Prevent duplicate warnings about same file.
+
sub xbus_attr_path($$) {
my ($busnum, @attr) = @_;
foreach my $attr (@attr) {
my $file = sprintf "$Dahdi::Xpp::sysfs_astribanks/xbus-%02d/$attr", $busnum;
unless(-f $file) {
my $procfile = sprintf "/proc/xpp/XBUS-%02d/$attr", $busnum;
- warn "$0: OLD DRIVER: missing '$file'. Fall back to '$procfile'\n";
+ warn "$0: warning - OLD DRIVER: missing '$file'. Fall back to '$procfile'\n"
+ unless $file_warned{$attr}++;
$file = $procfile;
}
next unless -f $file;
@@ -91,6 +94,40 @@
$xbus->{$attr} = $val;
}
}
+
+sub read_xpdnames_old($) {
+ my $xbus_num = shift || die;
+ my $pat = sprintf "/proc/xpp/XBUS-%02d/XPD-[0-9][0-9]", $xbus_num;
+ my @xpdnames;
+
+ #print STDERR "read_xpdnames_old($xbus_num): $pat\n";
+ foreach (glob $pat) {
+ die "Bad /proc entry: '$_'" unless /^.*XPD-([0-9])([0-9])$/;
+ my $name = sprintf("%02d:%1d:%1d", $xbus_num, $1, $2);
+ #print STDERR "\t> $_ ($name)\n";
+ push(@xpdnames, $name);
+ }
+ return @xpdnames;
+}
+
+sub read_xpdnames($) {
+ my $xbus_num = shift || die;
+ my $xbus_dir = "$Dahdi::Xpp::sysfs_astribanks/xbus-$xbus_num";
+ my $pat = sprintf "%s/xbus-%02d/[0-9][0-9]:[0-9]:[0-9]", $Dahdi::Xpp::sysfs_astribanks, $xbus_num;
+ my @xpdnames;
+
+ #print STDERR "read_xpdnames($xbus_num): $pat\n";
+ foreach (glob $pat) {
+ die "Bad /sys entry: '$_'" unless m/^.*\/([0-9][0-9]):([0-9]):([0-9])$/;
+ my ($busnum, $unit, $subunit) = ($1, $2, $3);
+ my $name = sprintf("%02d:%1d:%1d", $1, $2, $3);
+ #print STDERR "\t> $_ ($name)\n";
+ push(@xpdnames, $name);
+ }
+ return @xpdnames;
+}
+
+my $warned_notransport = 0;
sub new($$) {
my $pack = shift or die "Wasn't called as a class method\n";
@@ -116,18 +153,22 @@
warn "Bad USB transport='$transport' usbdev='$usbdev'\n";
}
}
- @{$self->{XPDS}} = ();
- opendir(D, $xbus_dir) || die "Failed opendir($xbus_dir): $!";
- while(my $entry = readdir D) {
- $entry =~ /^([0-9]+):([0-9]+):([0-9]+)$/ or next;
- my ($busnum, $unit, $subunit) = ($1, $2, $3);
+ my @xpdnames;
+ my @xpds;
+ if(-e $transport) {
+ @xpdnames = read_xpdnames($num);
+ } else {
+ @xpdnames = read_xpdnames_old($num);
+ warn "$0: warning - OLD DRIVER: missing '$transport'. Fall back to /proc\n"
+ unless $warned_notransport++;
+ }
+ foreach my $xpdstr (@xpdnames) {
+ my ($busnum, $unit, $subunit) = split(/:/, $xpdstr);
my $procdir = "/proc/xpp/XBUS-$busnum/XPD-$unit$subunit";
- #print STDERR "busnum=$busnum, unit=$unit, subunit=$subunit procdir=$procdir\n";
- my $xpd = Dahdi::Xpp::Xpd->new($self, $unit, $subunit, $procdir, "$xbus_dir/$entry");
- push(@{$self->{XPDS}}, $xpd);
- }
- closedir D;
- @{$self->{XPDS}} = sort { $a->id <=> $b->id } @{$self->{XPDS}};
+ my $xpd = Dahdi::Xpp::Xpd->new($self, $unit, $subunit, $procdir, "$xbus_dir/$xpdstr");
+ push(@xpds, $xpd);
+ }
+ @{$self->{XPDS}} = sort { $a->id <=> $b->id } @xpds;
return $self;
}
Modified: tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xpd.pm
URL: http://svn.digium.com/svn-view/dahdi/tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xpd.pm?view=diff&rev=6057&r1=6056&r2=6057
==============================================================================
--- tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xpd.pm (original)
+++ tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xpd.pm Sun Mar 1 08:29:03 2009
@@ -12,6 +12,8 @@
use Dahdi::Xpp;
use Dahdi::Xpp::Line;
+my %file_warned; # Prevent duplicate warnings about same file.
+
sub xpd_attr_path($@) {
my $self = shift || die;
my ($busnum, $unitnum, $subunitnum, @attr) = (
@@ -25,7 +27,8 @@
unless(-f $file) {
my $procfile = sprintf "/proc/xpp/XBUS-%02d/XPD-%1d%1d/$attr",
$busnum, $unitnum, $subunitnum;
- warn "$0: OLD DRIVER: missing '$file'. Fall back to /proc\n";
+ warn "$0: warning - OLD DRIVER: missing '$file'. Fall back to /proc\n"
+ unless $file_warned{$attr}++;
$file = $procfile;
}
next unless -f $file;
@@ -47,13 +50,56 @@
return $head;
}
+sub xpd_old_getspan($) {
+ my $xpd = shift || die;
+ my $dahdi_registration = "/proc/xpp/" . $xpd->fqn . "/dahdi_registration";
+ open(F, $dahdi_registration) or die "Failed to open '$dahdi_registration': $!";
+ my $head = <F>;
+ close F;
+ chomp $head;
+ return $head;
+}
+
+sub xpd_old_getoffhook($) {
+ my $xpd = shift || die;
+ my $summary = "/proc/xpp/" . $xpd->fqn . "/summary";
+ my $channels;
+
+ local $/ = "\n";
+ open(F, "$summary") || die "Failed opening $summary: $!\n";
+ my $head = <F>;
+ chomp $head; # "XPD-00 (BRI_TE ,card present, span 3)"
+ my $offhook;
+ while(<F>) {
+ chomp;
+ if(s/^\s*offhook\s*:\s*//) {
+ s/\s*$//;
+ $offhook = $_;
+ $offhook || die "No channels in '$summary'";
+ last;
+ }
+ }
+ close F;
+ return $offhook;
+}
+
+my %attr_missing_warned; # Prevent duplicate warnings
+
sub xpd_getattr($$) {
my $xpd = shift || die;
my $attr = shift || die;
$attr = lc($attr);
- my $file = xpd_attr_path($xpd, lc($attr));
-
+ my $file = $xpd->xpd_attr_path(lc($attr));
+
+ # Handle special cases for backward compat
return xpd_old_gettype($xpd) if $attr eq 'type' and !defined $file;
+ return xpd_old_getspan($xpd) if $attr eq 'span' and !defined $file;
+ return xpd_old_getoffhook($xpd) if $attr eq 'offhook' and !defined $file;
+ if(!defined($file)) {
+ warn "$0: xpd_getattr($attr) -- Missing attribute.\n" if
+ $attr_missing_warned{$attr};
+ return undef;
+ }
open(F, $file) || return undef;
my $val = <F>;
close F;
@@ -136,29 +182,15 @@
my $self = {
XBUS => $xbus,
ID => "$unit$subunit",
+ FQN => $xbus->name . "/" . "XPD-$unit$subunit",
UNIT => $unit,
SUBUNIT => $subunit,
DIR => $procdir,
SYSFS_DIR => $sysfsdir,
};
bless $self, $pack;
- local $/ = "\n";
- open(F, "$procdir/summary") || die "Missing summary file in $procdir";
- my $head = <F>;
- chomp $head; # "XPD-00 (BRI_TE ,card present, span 3)"
- # The driver does not export the number of channels...
- # Let's find it indirectly
- while(<F>) {
- chomp;
- if(s/^\s*offhook\s*:\s*//) {
- my @offhook = split;
- @offhook || die "No channels in '$procdir/summary'";
- $self->{CHANNELS} = @offhook;
- last;
- }
- }
- close F;
- $self->{FQN} = $xbus->name . "/" . "XPD-$unit$subunit";
+ my @offhook = split / /, ($self->xpd_getattr('offhook'));
+ $self->{CHANNELS} = @offhook;
my $type = $self->xpd_getattr('type');
my $span = $self->xpd_getattr('span');
$self->{SPANNO} = $span;
More information about the svn-commits
mailing list