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