2 # module to manage channel lists & data
4 # This is the base class for all channel operations, which is everything to do
5 # with input and output really.
7 # The instance variable in the outside world will be generally be called $dxchann
9 # This class is 'inherited' (if that is the goobledegook for what I am doing)
10 # by various other modules. The point to understand is that the 'instance variable'
11 # is in fact what normal people would call the state vector and all useful info
12 # about a connection goes in there.
14 # Another point to note is that a vector may contain a list of other vectors.
15 # I have simply added another variable to the vector for 'simplicity' (or laziness
16 # as it is more commonly called)
18 # PLEASE NOTE - I am a C programmer using this as a method of learning perl
19 # firstly and OO about ninthly (if you don't like the design and you can't
20 # improve it with better OO by make it smaller and more efficient, then tough).
22 # Copyright (c) 1998 - Dirk Koopman G1TLH
39 conn => '9,Msg Conn ref',
40 user => '9,DXUser ref',
41 startt => '0,Start Time,atime',
43 pc50_t => '9,Last PC50 Time,atime',
44 priv => '9,Privilege',
45 state => '0,Current State',
46 oldstate => '5,Last State',
47 list => '9,Dep Chan List',
48 name => '0,User Name',
49 consort => '9,Connection Type',
50 sort => '9,Type of Channel',
51 wwv => '0,Want WWV,yesno',
52 talk => '0,Want Talk,yesno',
53 ann => '0,Want Announce,yesno',
54 here => '0,Here?,yesno',
55 confmode => '0,In Conference?,yesno',
56 dx => '0,DX Spots,yesno',
60 # create a new channel object [$obj = DXChannel->new($call, $msg_conn_obj, $user_obj)]
63 my ($pkg, $call, $conn, $user) = @_;
66 die "trying to create a duplicate channel for $call" if $channels{$call};
67 $self->{call} = $call;
68 $self->{conn} = $conn if defined $conn; # if this isn't defined then it must be a list
69 $self->{user} = $user if defined $user;
70 $self->{startt} = $self->{t} = time;
72 $self->{oldstate} = 0;
74 return $channels{$call} = $self;
77 # obtain a channel object by callsign [$obj = DXChannel->get($call)]
80 my ($pkg, $call) = @_;
81 return $channels{$call};
84 # obtain all the channel objects
88 return values(%channels);
91 # obtain a channel object by searching for its connection reference
94 my ($pkg, $conn) = @_;
97 foreach $self (values(%channels)) {
98 return $self if ($self->{conn} == $conn);
103 # get rid of a channel object [$obj->del()]
107 delete $channels{$self->{call}};
110 # is it an ak1a cluster ?
114 return $self->{sort} eq 'A';
121 return $self->{sort} eq 'U';
124 # handle out going messages, immediately without waiting for the select to drop
125 # this could, in theory, block
129 my $conn = $self->{conn};
131 my $call = $self->{call};
136 dbg('chan', "-> $sort $call $line\n");
137 $conn->send_now("$sort$call|$line");
143 # the normal output routine
145 sub send # this is always later and always data
148 my $conn = $self->{conn};
149 my $call = $self->{call};
154 dbg('chan', "-> D $call $line\n");
155 $conn->send_later("D$call|$line");
160 # send a file (always later)
163 my ($self, $fn) = @_;
164 my $call = $self->{call};
165 my $conn = $self->{conn};
168 open(F, $fn) or die "can't open $fn for sending file ($!)";
174 # just a shortcut for $dxchan->send(msg(...));
178 $self->send(DXM::msg(@_));
181 # change the state of the channel - lots of scope for debugging here :-)
185 $self->{oldstate} = $self->{state};
186 $self->{state} = shift;
187 dbg('state', "$self->{call} channel state $self->{oldstate} -> $self->{state}\n");
190 # various access routines
193 # return a list of valid elements
202 # return a prompt for a field
207 my ($self, $ele) = @_;
215 my $name = $AUTOLOAD;
216 return if $name =~ /::DESTROY$/;
219 die "Non-existant field '$AUTOLOAD'" if !$valid{$name};
220 @_ ? $self->{$name} = shift : $self->{$name} ;