[dahdi-commits] tzafrir: tools/trunk r10494 - in /tools/trunk/xpp/perl_modules/Dahdi: ./ Xpp/

SVN commits to the DAHDI project dahdi-commits at lists.digium.com
Thu Mar 15 15:32:31 CDT 2012


Author: tzafrir
Date: Thu Mar 15 15:32:27 2012
New Revision: 10494

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=10494
Log:
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 at xorcom.com>
Acked-by: Tzafrir Cohen <tzafrir.cohen at xorcom.com>

Modified:
    tools/trunk/xpp/perl_modules/Dahdi/Xpp.pm
    tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xbus.pm
    tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xpd.pm

Modified: tools/trunk/xpp/perl_modules/Dahdi/Xpp.pm
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/xpp/perl_modules/Dahdi/Xpp.pm?view=diff&rev=10494&r1=10493&r2=10494
==============================================================================
--- tools/trunk/xpp/perl_modules/Dahdi/Xpp.pm (original)
+++ tools/trunk/xpp/perl_modules/Dahdi/Xpp.pm Thu Mar 15 15:32:27 2012
@@ -50,8 +50,8 @@
 
 	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;

Modified: tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xbus.pm
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xbus.pm?view=diff&rev=10494&r1=10493&r2=10494
==============================================================================
--- tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xbus.pm (original)
+++ tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xbus.pm Thu Mar 15 15:32:27 2012
@@ -45,23 +45,11 @@
 	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 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 @@
 	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 @@
 	}
 	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;

Modified: tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xpd.pm
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xpd.pm?view=diff&rev=10494&r1=10493&r2=10494
==============================================================================
--- tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xpd.pm (original)
+++ tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xpd.pm Thu Mar 15 15:32:27 2012
@@ -99,14 +99,15 @@
 
 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 @@
 	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),




More information about the dahdi-commits mailing list