~ubuntu-branches/ubuntu/saucy/dahdi-tools/saucy

« back to all changes in this revision

Viewing changes to xpp/perl_modules/Dahdi/Xpp/Xpd.pm

  • Committer: Stefan Lesicnik
  • Date: 2011-05-08 12:22:46 UTC
  • mfrom: (2.1.4 sid)
  • Revision ID: stefan@lsd.co.za-20110508122246-lh6k2x1uy8pl3vdi
Tags: 1:2.4.1-1ubuntu1
* Merge from Debian. Remaining changes:
  - Bug Fix: If linux-headers are not installed, don't block, and print
    information for the user.
  - added debian/dahdi.postinst
  - added --error-handler=init_failed to debian/rules
  - Changes from Debian:
    - debian/control: Change Maintainer
    - debian/control: Removed Uploaders field.
    - debian/control: Removed Debian Vcs-Svn entry and replaced with
      ubuntu-voip Vcs-Bzr, to reflect divergence in packages.
    - debian/control: Package dahdi Depends on dahdi-dkms | dahdi-source
* debian/control: Added gawk as dependency for dkms build (LP: #493304)
* New upstream release (Closes: #581076, #582094).
* Patches hardware_rescan, perl_fix_noserial, perl_fix_transportdir,
  astribank_allow_ignoreend, init_unload_modules and wcb4xxp_extra_trunk
  dropped: merged upstream.
* dahdi-linux 2.3.0 is required (extra config options for dahdi_cfg).
* Convert to dpkg v.3 format.
* Standards version: 3.9.1.0 (No change needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
# This program is free software; you can redistribute and/or
6
6
# modify it under the same terms as Perl itself.
7
7
#
8
 
# $Id: Xpd.pm 7492 2009-11-05 09:41:22Z tzafrir $
 
8
# $Id: Xpd.pm 7256 2009-09-29 19:20:32Z tzafrir $
9
9
#
10
10
use strict;
11
11
use Dahdi::Utils;
327
327
# static xpd related helper functions
328
328
#------------------------------------
329
329
 
 
330
sub format_rank($$) {
 
331
        my ($rank, $prio) = @_;
 
332
        my $width = 2;
 
333
        # 0 is replaced with a character that is sorted *AFTER* numbers.
 
334
        $prio = '_' x $width unless defined $prio && $prio;
 
335
        return sprintf "%${width}s-%s", $prio, $rank;
 
336
}
 
337
 
330
338
sub sync_priority_rank($) {
331
339
        my $xpd = shift || die;
 
340
        my $prio = $xpd->timing_priority;
332
341
        # The @rank array is ordered by priority of sync (good to bad)
 
342
        # It is used when timing_priority is not defined (analog) or
 
343
        # is 0 (NT).
333
344
        my @rank = (
334
345
                ($xpd->is_pri and defined($xpd->termtype) and $xpd->termtype eq 'TE'),
335
346
                ($xpd->is_bri and defined($xpd->termtype) and $xpd->termtype eq 'TE'),
 
347
                ($xpd->type eq 'FXO'),
336
348
                ($xpd->is_pri),
337
 
                ($xpd->type eq 'FXO'),
338
349
                ($xpd->is_bri),
339
350
                ($xpd->type eq 'FXS'),
340
351
                );
341
 
        for(my $i = 0; $i < @rank; $i++) {
342
 
                return $i if $rank[$i];
 
352
        my $i;
 
353
        for($i = 0; $i < @rank; $i++) {
 
354
                last if $rank[$i];
343
355
        }
344
 
        return @rank + 1;
 
356
        return format_rank($i, $prio);
345
357
}
346
358
 
347
359
# An XPD sync priority comparator for sort()
348
360
sub sync_priority_compare() {
349
361
        my $rank_a = sync_priority_rank($a);
350
362
        my $rank_b = sync_priority_rank($b);
351
 
        #print STDERR "DEBUG: $rank_a (", $a->fqn, ") $rank_b (", $b->fqn, ")\n";
352
 
        return $a->fqn cmp $b->fqn if $rank_a == $rank_b;
353
 
        return $rank_a <=> $rank_b;
 
363
        #print STDERR "DEBUG(rank): $rank_a (", $a->fqn, ") $rank_b (", $b->fqn, ")\n";
 
364
        return $rank_a cmp $rank_b;     # The easy case
354
365
}
355
366
 
356
367
# For debugging: show a list of XPD's with relevant sync info.
358
369
        print STDERR "XPD's by rank\n";
359
370
        foreach my $xpd (@_) {
360
371
                my $type = $xpd->type;
 
372
                my $extra = "";
361
373
                my $rank = sync_priority_rank($xpd);
362
374
                if($xpd->is_digital) {
363
 
                        $type .= " (TERMTYPE " . ($xpd->termtype || "UNKNOWN") . ")";
 
375
                        $extra .= " termtype " . ($xpd->termtype || "UNKNOWN");
364
376
                }
365
 
                printf STDERR "%3d %-15s %s\n", $rank, $xpd->fqn, $type;
 
377
                printf STDERR "%3s %-15s %s\n", $rank, $xpd->fqn, $extra;
366
378
        }
367
379
}
368
380