summaryrefslogtreecommitdiff
path: root/kernel/xpp/utils/zconf/Zaptel/Config/Gen/Unicall.pm
blob: 6d9552fa897244053f42679e9cc9f4a0fc38c90d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package Zaptel::Config::Gen::Unicall;
use strict;

use Zaptel::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};
	#$gconfig->dump;
	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 $0 on %s\n", scalar(localtime);
	print  "; If you edit this file and execute $0 again,\n";
	print  "; your manual changes will be LOST.\n";
	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", Zaptel::Config::Gen::bchan_range($span);
		print "\n";
	}
	close F;
	select $old;
}

1;

__END__

=head1 NAME

unicall - Generate configuration for unicall channels.

=head1 SYNOPSIS

 use Zaptel::Config::Gen::Unicall;

 my $cfg = new Zaptel::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>.