[Pkg-voip-commits] [dahdi-tools] 194/285: xpp: better dahdi_registration

tzafrir at debian.org tzafrir at debian.org
Thu Jul 7 19:18:55 UTC 2016


This is an automated email from the git hooks/post-receive script.

tzafrir pushed a commit to branch master
in repository dahdi-tools.

commit ca09f327edaf0c462f1ff5b92720de85dee3dd5c
Author: Oron Peled <oron.peled at xorcom.com>
Date:   Sun Apr 6 14:33:12 2014 -0400

    xpp: better dahdi_registration
    
    Improvements to the xpp tool dahdi_registration:
    
    * Use the new xpp driver with support for dahdi_registration sysfs
      attribute in each device.
    
    * Wait for UDEV to finish handling span assignments (via
      dahdi_waitfor_span_assignments).
    
    * Still supports legacy drivers without this, by falling back
      to old style iterative "registration" on each xpd.
    
    Signed-off-by: Tzafrir Cohen <tzafrir.cohen at xorcom.com>
---
 xpp/dahdi_registration             | 61 +++++++++++++++++++-------------------
 xpp/perl_modules/Dahdi/Xpp/Xbus.pm | 34 +++++++++++++++++++++
 2 files changed, 65 insertions(+), 30 deletions(-)

diff --git a/xpp/dahdi_registration b/xpp/dahdi_registration
index 7202e76..2772e00 100755
--- a/xpp/dahdi_registration
+++ b/xpp/dahdi_registration
@@ -74,8 +74,6 @@ if(defined($on)) {	# Translate to booleans
 	$should_output = 0 unless $verbose;
 }
 
-undef $on if $dahdi_autoreg and not $opts{'R'};
-
 sub state2str($) {
 	return (shift)?"on":"off";
 }
@@ -84,38 +82,41 @@ sub myprintf {
 	printf @_ if $should_output;
 }
 
-my @spans = Dahdi::spans;
-
 foreach my $xbus (Dahdi::Xpp::xbuses($sorter)) {
-	myprintf "%-10s\t%3s-%s\t%s\n",
-		$xbus->name, $xbus->xpporder, $xbus->label, $xbus->connector;
+	my $prev = $xbus->dahdi_registration($on);
+	if(!defined($prev)) {			# Failure
+		printf STDERR "%s: Failed %s\n", $xbus->name, $!;
+		next;
+	}
+	my $reg_str;
+	if (defined $on) {
+		$reg_str = ($on) ? "registering" : "unregistering";
+	} else {
+		$reg_str = ($prev) ? "registered" : "unregistered";
+	}
+	myprintf "%-10s\t%3s-%s\t%s (%s)\n",
+		$xbus->name, $xbus->xpporder, $xbus->label, $xbus->connector,
+		$reg_str;
 	next unless $xbus->status eq 'CONNECTED';
-	foreach my $xpd (Dahdi::Xpp::Xpd::telephony_devs($xbus->xpds())) {
-		my $prev = $xpd->dahdi_registration($on);
-		if(!defined($prev)) {			# Failure
-			printf "%s: Failed %s\n", $xpd->fqn, $!;
-			next;
-		}
-		myprintf "\t%-10s: ", $xpd->fqn;
-		if(!defined($on)) {			# Query only
-			my ($span) = grep { $_->name eq $xpd->fqn } @spans;
-			my $spanstr = ($span) ? ("Span " . $span->num) : "";
-			myprintf "%s %s\n", state2str($prev), $spanstr ;
-			next;
+	# Only assign if no default assignment, or forced by '-R' option
+	if (defined($on) && $on) {
+		if ($opts{'R'} || ! $default_auto_assign) {
+			# Emulate /etc/dahdi/assigned-spans.conf:
+			#   - We iterate over $xbus according to /etc/dahdi/xpp_order
+			#   - We "auto" assign all spans of current $xbus
+			my $devpath = sprintf "/sys/bus/dahdi_devices/devices/astribanks:xbus-%02d", $xbus->num;
+			my @cmd = ('dahdi_span_assignments', 'auto', $devpath);
+			system @cmd;
+			warn "Failed '@cmd' (status=$?)\n" if $?;
 		}
-		myprintf "%3s ==> %3s\n", state2str($prev), state2str($on);
+		# wait for UDEV to do its stuff
+		system "dahdi_waitfor_span_assignments assigned";
 	}
-	next unless defined($on) && $on;
-	# Only assign if no default assignment, or forced by '-R' option
-	if ($opts{'R'} || ! $default_auto_assign) {
-		# Emulate /etc/dahdi/assigned-spans.conf:
-		#   - We iterate over $xbus according to /etc/dahdi/xpp_order
-		#   - We "auto" assign all spans of current $xbus
-		my $devpath = sprintf "/sys/bus/dahdi_devices/devices/astribanks:xbus-%02d", $xbus->num;
-		myprintf "auto-assign $devpath\n";
-		my @cmd = ('dahdi_span_assignments', 'auto', $devpath);
-		system @cmd;
-		warn "Failed '@cmd' (status=$?)\n" if $?;
+	foreach my $xpd (Dahdi::Xpp::Xpd::telephony_devs($xbus->xpds())) {
+		my $spanno = $xpd->xpd_getattr('span');
+		myprintf "\t%-10s: ", $xpd->fqn;
+		my $spanstr = ($spanno) ? ("Span " . $spanno) : "unassigned";
+		myprintf "%s\n", $spanstr ;
 	}
 }
 myprintf "# Sorted: $sort_order\n" if defined $sort_order;
diff --git a/xpp/perl_modules/Dahdi/Xpp/Xbus.pm b/xpp/perl_modules/Dahdi/Xpp/Xbus.pm
index d916066..e1973b1 100644
--- a/xpp/perl_modules/Dahdi/Xpp/Xbus.pm
+++ b/xpp/perl_modules/Dahdi/Xpp/Xbus.pm
@@ -146,6 +146,40 @@ sub new($$) {
 	return $self;
 }
 
+sub dahdi_registration($$) {
+	my $xbus = shift;
+	my $on = shift;
+	my $result;
+	my $file = sprintf("%s/dahdi_registration", $xbus->sysfs_dir);
+	# Handle old drivers without dahdi_registration xbus attribute
+	if (! -f $file) {
+		warn "Old xpp driver without dahdi_registration support. Emulating it using xpd/span support\n";
+		my @xpds = sort { $a->id <=> $b->id } $xbus->xpds();
+		my $prev;
+		foreach my $xpd (@xpds) {
+			$prev = $xpd->dahdi_registration($on);
+		}
+		return $prev;
+	}
+	# First query
+	open(F, "$file") or die "Failed to open $file for reading: $!";
+	$result = <F>;
+	chomp $result;
+	close F;
+	if(defined($on) and $on ne $result) {		# Now change
+		open(F, ">$file") or die "Failed to open $file for writing: $!";
+		print F ($on)?"1":"0";
+		if(!close(F)) {
+			if($! == 17) {	# EEXISTS
+				# good
+			} else {
+				undef $result;
+			}
+		}
+	}
+	return $result;
+}
+
 sub pretty_xpds($) {
 		my $xbus = shift;
 		my @xpds = sort { $a->id <=> $b->id } $xbus->xpds();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/dahdi-tools.git



More information about the Pkg-voip-commits mailing list