added Ids and changed the name of DXConnect to DXChannel
[spider.git] / perl / DXChannel.pm
1 #
2 # module to manage channel lists & data
3 #
4 # Copyright (c) 1998 - Dirk Koopman G1TLH
5 #
6 # $Id$
7 #
8 package DXChannel;
9
10 require Exporter;
11 @ISA = qw(Exporter);
12
13 %connects = undef;
14
15 # create a new connection object [$obj = Connect->new($call, $msg_conn_obj, $user_obj)]
16 sub new
17 {
18   my ($pkg, $call, $conn, $user) = @_;
19   my $self = {};
20   
21   die "trying to create a duplicate Connect for call $call\n" if $connects{$call};
22   $self->{call} = $call;
23   $self->{conn} = $conn;
24   $self->{user} = $user;
25   $self->{t} = time;
26   $self->{state} = 0;
27   bless $self, $pkg; 
28   return $connects{$call} = $self;
29 }
30
31 # obtain a connection object by callsign [$obj = Connect->get($call)]
32 sub get
33 {
34   my ($pkg, $call) = @_;
35   return $connect{$call};
36 }
37
38 # obtain all the connection objects
39 sub get_all
40 {
41   my ($pkg) = @_;
42   return values(%connects);
43 }
44
45 # obtain a connection object by searching for its connection reference
46 sub get_by_cnum
47 {
48   my ($pkg, $conn) = @_;
49   my $self;
50   
51   foreach $self (values(%connects)) {
52     return $self if ($self->{conn} == $conn);
53   }
54   return undef;
55 }
56
57 # get rid of a connection object [$obj->del()]
58 sub del
59 {
60   my $self = shift;
61   delete $connects{$self->{call}};
62 }
63
64 1;
65 __END__;