diff options
author | Tzafrir Cohen <tzafrir.cohen@xorcom.com> | 2009-02-13 21:09:51 +0000 |
---|---|---|
committer | Tzafrir Cohen <tzafrir.cohen@xorcom.com> | 2009-02-13 21:09:51 +0000 |
commit | 66ca50e198ed2989b97293fac59de30f1be48bd3 (patch) | |
tree | a4a86ee84b1fbd840cc83500e73ff68e0bcf41c0 /xpp/perl_modules/Dahdi/Config/Gen/Unicall.pm | |
parent | 28afbbbb1753473ed1cf3bd073ff5aae5bbeadfe (diff) |
Rework dahdi_genconf to have separate configuration generation modules.
'dahdi_genconf foo bar' will use the modules Dahdi::Config::Gen::Foo and
Dahdi::Config::Gen::Bar to generate configuraion files. Extra formats
can thus be added without modifying dahdi_genconf and independently of
DAHDI.
git-svn-id: http://svn.asterisk.org/svn/dahdi/tools/trunk@6013 a0bf4364-ded3-4de4-8d8a-66a801d63aff
Diffstat (limited to 'xpp/perl_modules/Dahdi/Config/Gen/Unicall.pm')
-rw-r--r-- | xpp/perl_modules/Dahdi/Config/Gen/Unicall.pm | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/xpp/perl_modules/Dahdi/Config/Gen/Unicall.pm b/xpp/perl_modules/Dahdi/Config/Gen/Unicall.pm new file mode 100644 index 0000000..526b62b --- /dev/null +++ b/xpp/perl_modules/Dahdi/Config/Gen/Unicall.pm @@ -0,0 +1,70 @@ +package Dahdi::Config::Gen::Unicall; +use strict; + +use Dahdi::Config::Gen qw(is_true); + +sub new($$$) { + my $pack = shift || die; + my $gconfig = shift || die; + my $genopts = shift || die; + my $file = $ENV{UNICALL_CHANNELS_FILE} || "/etc/asterisk/unicall-channels.conf"; + my $self = { + FILE => $file, + GCONFIG => $gconfig, + GENOPTS => $genopts, + }; + bless $self, $pack; + return $self; +} + +sub generate($) { + my $self = shift || die; + my $file = $self->{FILE}; + my $gconfig = $self->{GCONFIG}; + my $genopts = $self->{GENOPTS}; + #Dahdi::Config::Gen::show_gconfig($gconfig); + my @spans = @_; + warn "Empty configuration -- no spans\n" unless @spans; + die "Only for R2" unless $gconfig->{'pri_connection_type'} eq 'R2'; + rename "$file", "$file.bak" + or $! == 2 # ENOENT (No dependency on Errno.pm) + or die "Failed to backup old config: $!\n"; + print "Generating $file\n" if $genopts->{verbose}; + open(F, ">$file") || die "$0: Failed to open $file: $!\n"; + my $old = select F; + printf "; Autogenerated by %s on %s -- do not hand edit\n", $0, scalar(localtime); + print "; This file should be #included in unicall.conf\n\n"; + foreach my $span (@spans) { + next unless $span->is_digital(); + printf "; Span %d: %s %s\n", $span->num, $span->name, $span->description; + my $idle_bits = $gconfig->{'r2_idle_bits'}; + printf "protocolend=%s\n", ($span->termtype() eq 'TE') ? 'cpe' : 'co'; + printf "channel=%s\n", Dahdi::Config::Gen::bchan_range($span); + print "\n"; + } + close F; + select $old; +} + +1; + +__END__ + +=head1 NAME + +unicall - Generate configuration for unicall channels. + +=head1 SYNOPSIS + + use Dahdi::Config::Gen::Unicall; + + my $cfg = new Dahdi::Config::Gen::Unicall(\%global_config, \%genopts); + $cfg->generate(@span_list); + +=head1 DESCRIPTION + +Generate the F</etc/asterisk/unicall-channels.conf> to be included in +F</etc/asterisk/unicall.conf> + +Its location may be overriden via the environment variable +C<UNICALL_CHANNELS_FILE>. |