Debian Codegraph @

xpp/perl_modules/Dahdi/Config/Gen/Unicall.pm

raw
1 package Dahdi::Config::Gen::Unicall;
2 use strict;
3
4 use Dahdi::Config::Gen qw(is_true);
5
6 sub new($$$) {
7 my $pack = shift || die;
8 my $gconfig = shift || die;
9 my $genopts = shift || die;
10 my $file = $ENV{UNICALL_CHANNELS_FILE} || "/etc/asterisk/unicall-channels.conf";
11 my $self = {
12 FILE => $file,
13 GCONFIG => $gconfig,
14 GENOPTS => $genopts,
15 };
16 bless $self, $pack;
17 return $self;
18 }
19
20 sub generate($) {
21 my $self = shift || die;
22 my $file = $self->{FILE};
23 my $gconfig = $self->{GCONFIG};
24 my $genopts = $self->{GENOPTS};
25 #$gconfig->dump;
26 my @spans = @_;
27 warn "Empty configuration -- no spans\n" unless @spans;
28 die "Only for R2" unless $gconfig->{'pri_connection_type'} eq 'R2';
29 rename "$file", "$file.bak"
30 or $! == 2 # ENOENT (No dependency on Errno.pm)
31 or die "Failed to backup old config: $!\n";
32 print "Generating $file\n" if $genopts->{verbose};
33 open(F, ">$file") || die "$0: Failed to open $file: $!\n";
34 my $old = select F;
35 printf "; Autogenerated by $0 on %s\n", scalar(localtime);
36 print "; If you edit this file and execute $0 again,\n";
37 print "; your manual changes will be LOST.\n";
38 print "; This file should be #included in unicall.conf\n\n";
39 foreach my $span (@spans) {
40 next unless $span->is_digital();
41 printf "; Span %d: %s %s\n", $span->num, $span->name, $span->description;
42 my $idle_bits = $gconfig->{'r2_idle_bits'};
43 printf "protocolend=%s\n", ($span->termtype() eq 'TE') ? 'cpe' : 'co';
44 printf "channel=%s\n", Dahdi::Config::Gen::bchan_range($span);
45 print "\n";
46 }
47 close F;
48 select $old;
49 }
50
51 1;
52
53 __END__
54
55 =head1 NAME
56
57 unicall - Generate configuration for unicall channels.
58
59 =head1 SYNOPSIS
60
61 use Dahdi::Config::Gen::Unicall;
62
63 my $cfg = new Dahdi::Config::Gen::Unicall(\%global_config, \%genopts);
64 $cfg->generate(@span_list);
65
66 =head1 DESCRIPTION
67
68 Generate the F</etc/asterisk/unicall-channels.conf> to be included in
69 F</etc/asterisk/unicall.conf>
70
71 Its location may be overriden via the environment variable
72 C<UNICALL_CHANNELS_FILE>.