Debian Codegraph @

xpp/perl_modules/Dahdi/Xpp/Line.pm

raw
1 package Dahdi::Xpp::Line;
2 #
3 # Written by Oron Peled <[email protected]>
4 # Copyright (C) 2008, Xorcom
5 # This program is free software; you can redistribute and/or
6 # modify it under the same terms as Perl itself.
7 #
8 # $Id$
9 #
10 use strict;
11 use Dahdi::Utils;
12
13 sub new($$$) {
14 my $pack = shift or die "Wasn't called as a class method\n";
15 my $xpd = shift or die;
16 my $index = shift;
17 defined $index or die;
18 my $self = {};
19 bless $self, $pack;
20 $self->{XPD} = $xpd;
21 $self->{INDEX} = $index;
22 return $self;
23 }
24
25 sub blink($$) {
26 my $self = shift;
27 my $on = shift;
28 my $xpd = $self->xpd;
29 my $result = $xpd->xpd_getattr("blink");
30 $result = hex($result);
31 if(defined($on)) { # Now change
32 my $onbitmask = 1 << $self->index;
33 my $offbitmask = $result & ~$onbitmask;
34
35 $result = $offbitmask;
36 $result |= $onbitmask if $on;
37 $result = $xpd->xpd_setattr("blink", $result);
38 }
39 return $result;
40 }
41
42 sub create_all($$) {
43 my $pack = shift or die "Wasn't called as a class method\n";
44 my $xpd = shift || die;
45 local $/ = "\n";
46 my @lines;
47 for(my $i = 0; $i < $xpd->{CHANNELS}; $i++) {
48 my $line = Dahdi::Xpp::Line->new($xpd, $i);
49 push(@lines, $line);
50 }
51 $xpd->{LINES} = \@lines;
52 if($xpd->type eq 'FXO') {
53 my $battery = $xpd->xpd_getattr("fxo_battery");
54 die "Missing '$battery' attribute\n" unless defined $battery;
55 my @batt = split(/\s+/, $battery);
56 foreach my $l (@lines) {
57 die unless @batt;
58 my $state = shift @batt;
59 $l->{BATTERY} = ($state eq '+') ? 1 : 0;
60 }
61 }
62 }
63
64
65 1;