summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTzafrir Cohen <tzafrir.cohen@xorcom.com>2012-03-15 20:32:27 +0000
committerTzafrir Cohen <tzafrir.cohen@xorcom.com>2012-03-15 20:32:27 +0000
commit906c7e3f92de6e3e0e2193ecdb0f232a40fd1d7e (patch)
treef6b1183639db85c81da55b3e97da8385d169bc1e
parentab44f81dde27cb645a2934e71956b40dc1eb581f (diff)
xpp: sysfs access cleanups
With /proc/xpp code removed, some cleanup can be done. * No need to search alternative attribute names, so xbus_attr_path() is redundant. * Don't compose xbus sysfs directory in multiple code locations. Do it once in Xbus->new() and use the result ($xbus->sysfs_dir) * Pass XPD directory strings directly to Xpd->new() - So we parse it for unit/subunit only in Xpd->new() * Don't parse xbus sysfs name: - Toplevel scan, pass it as is to Xbus->new() - Xbus->new() deduce the xbus->num from the naming of Xpd's inside (nn:m:k) -- this is a hack until we add xbus number as an xbus sysfs attribute Signed-off-by: Oron Peled <oron.peled@xorcom.com> Acked-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com> git-svn-id: http://svn.asterisk.org/svn/dahdi/tools/trunk@10494 a0bf4364-ded3-4de4-8d8a-66a801d63aff
-rw-r--r--xpp/perl_modules/Dahdi/Xpp.pm4
-rw-r--r--xpp/perl_modules/Dahdi/Xpp/Xbus.pm52
-rw-r--r--xpp/perl_modules/Dahdi/Xpp/Xpd.pm17
3 files changed, 35 insertions, 38 deletions
diff --git a/xpp/perl_modules/Dahdi/Xpp.pm b/xpp/perl_modules/Dahdi/Xpp.pm
index 765b59e..3acd2ef 100644
--- a/xpp/perl_modules/Dahdi/Xpp.pm
+++ b/xpp/perl_modules/Dahdi/Xpp.pm
@@ -50,8 +50,8 @@ sub scan($) {
opendir(D, $sysfs_astribanks) || return();
while(my $entry = readdir D) {
- next unless $entry =~ /xbus-(\d+)/;
- my $xbus = Dahdi::Xpp::Xbus->new($1);
+ next if $entry eq '.' or $entry eq '..';
+ my $xbus = Dahdi::Xpp::Xbus->new($sysfs_astribanks, $entry);
push(@xbuses, $xbus);
}
closedir D;
diff --git a/xpp/perl_modules/Dahdi/Xpp/Xbus.pm b/xpp/perl_modules/Dahdi/Xpp/Xbus.pm
index dbfab00..a6e07e5 100644
--- a/xpp/perl_modules/Dahdi/Xpp/Xbus.pm
+++ b/xpp/perl_modules/Dahdi/Xpp/Xbus.pm
@@ -45,23 +45,11 @@ sub get_xpd_by_number($$) {
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;
- next unless -f $file;
- return $file;
- }
- return undef;
-}
-
sub xbus_getattr($$) {
my $xbus = shift || die;
my $attr = shift || die;
$attr = lc($attr);
- my $file = xbus_attr_path($xbus->num, lc($attr));
+ my $file = sprintf "%s/%s", $xbus->sysfs_dir, $attr;
open(F, $file) || die "Failed opening '$file': $!";
my $val = <F>;
@@ -104,12 +92,11 @@ sub transport_type($$) {
}
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 $xbus_dir = shift or die;
+ my $pat = sprintf "%s/[0-9][0-9]:[0-9]:[0-9]", $xbus_dir;
my @xpdnames;
- #print STDERR "read_xpdnames($xbus_num): $pat\n";
+ #printf STDERR "read_xpdnames(%s): $pat\n", $xbus_dir;
foreach (glob $pat) {
die "Bad /sys entry: '$_'" unless m/^.*\/([0-9][0-9]):([0-9]):([0-9])$/;
my ($busnum, $unit, $subunit) = ($1, $2, $3);
@@ -120,19 +107,30 @@ sub read_xpdnames($) {
return @xpdnames;
}
+sub read_num($) {
+ my $self = shift or die;
+ my $xbus_dir = $self->sysfs_dir;
+ my @xpdnames = read_xpdnames($xbus_dir);
+ my $first = shift @xpdnames or die "No XPDs for '$xbus_dir'\n";
+ $first =~ /^(\d+\d+).*/;
+ return $1;
+}
+
sub new($$) {
my $pack = shift or die "Wasn't called as a class method\n";
- my $num = shift;
- my $xbus_dir = "$Dahdi::Xpp::sysfs_astribanks/xbus-$num";
- my $self = {
- NUM => $num,
- NAME => "XBUS-$num",
- SYSFS_DIR => $xbus_dir,
- };
+ my $parent_dir = shift or die;
+ my $entry_dir = shift or die;
+ my $xbus_dir = "$parent_dir/$entry_dir";
+ my $self = {};
bless $self, $pack;
+ $self->{SYSFS_DIR} = $xbus_dir;
+ my $num = $self->read_num;
+ $self->{NUM} = $num;
+ $self->{NAME} = "XBUS-$num";
$self->read_attrs;
# Get transport related info
my $transport = "$xbus_dir/transport";
+ die "OLD DRIVER: missing '$transport'\n" unless -e $transport;
my $transport_type = $self->transport_type($xbus_dir);
if(defined $transport_type) {
my $tt = "Dahdi::Hardware::$transport_type";
@@ -141,11 +139,9 @@ sub new($$) {
}
my @xpdnames;
my @xpds;
- die "OLD DRIVER: missing '$transport'\n" unless -e $transport;
- @xpdnames = read_xpdnames($num);
+ @xpdnames = read_xpdnames($self->sysfs_dir);
foreach my $xpdstr (@xpdnames) {
- my ($busnum, $unit, $subunit) = split(/:/, $xpdstr);
- my $xpd = Dahdi::Xpp::Xpd->new($self, $unit, $subunit, "$xbus_dir/$xpdstr");
+ my $xpd = Dahdi::Xpp::Xpd->new($self, $xpdstr);
push(@xpds, $xpd);
}
@{$self->{XPDS}} = sort { $a->id <=> $b->id } @xpds;
diff --git a/xpp/perl_modules/Dahdi/Xpp/Xpd.pm b/xpp/perl_modules/Dahdi/Xpp/Xpd.pm
index 7edfc58..810ad9e 100644
--- a/xpp/perl_modules/Dahdi/Xpp/Xpd.pm
+++ b/xpp/perl_modules/Dahdi/Xpp/Xpd.pm
@@ -99,14 +99,15 @@ my %file_warned; # Prevent duplicate warnings about same file.
sub xpd_attr_path($@) {
my $self = shift || die;
+ my $xbus = $self->xbus;
my ($busnum, $unitnum, $subunitnum, @attr) = (
- $self->xbus->num,
+ $xbus->num,
$self->unit,
$self->subunit,
@_);
foreach my $attr (@attr) {
- my $file = sprintf "$Dahdi::Xpp::sysfs_xpds/%02d:%1d:%1d/$attr",
- $busnum, $unitnum, $subunitnum;
+ my $file = sprintf "%s/%02d:%1d:%1d/$attr",
+ $xbus->sysfs_dir, $busnum, $unitnum, $subunitnum;
next unless -f $file;
return $file;
}
@@ -217,12 +218,12 @@ sub xpds_by_spanno() {
return @idx;
}
-sub new($$$$$) {
+sub new($$$) {
my $pack = shift or die "Wasn't called as a class method\n";
- my $xbus = shift || die;
- my $unit = shift; # May be zero
- my $subunit = shift; # May be zero
- my $sysfsdir = shift || die;
+ my $xbus = shift or die;
+ my $xpdstr = shift or die;
+ my $sysfsdir = sprintf "%s/%s", $xbus->sysfs_dir, $xpdstr;
+ my ($busnum, $unit, $subunit) = split(/:/, $xpdstr);
my $self = {
XBUS => $xbus,
ID => sprintf("%1d%1d", $unit, $subunit),