source: perl/modules/Jabber/lib/BarnOwl/Module/Jabber/ConnectionManager.pm @ 2cedb7a

barnowl_perlaimdebianrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 2cedb7a was 2cedb7a, checked in by Nelson Elhage <nelhage@mit.edu>, 17 years ago
Adding the new M::Iified jabber module. There isn't a target to build the PAR yet.
  • Property mode set to 100644
File size: 2.1 KB
Line 
1use warnings;
2use strict;
3
4=head1 NAME
5
6BarnOwl::Module::Jabber::ConnectionManager
7
8=head1 DESCRIPTION
9
10A class to keep track of all the active connection in the barnowl
11jabber module
12
13=cut
14
15package BarnOwl::Module::Jabber::ConnectionManager;
16
17sub new {
18    my $class = shift;
19    return bless { }, $class;
20}
21
22sub addConnection {
23    my $self = shift;
24    my $jidStr = shift;
25
26    my $client = BarnOwl::Module::Jabber::Connection->new;
27
28    $self->{$jidStr}->{Client} = $client;
29    $self->{$jidStr}->{Roster} = $client->Roster();
30    $self->{$jidStr}->{Status} = "available";
31    return $client;
32}
33
34sub removeConnection {
35    my $self = shift;
36    my $jidStr = shift;
37    return 0 unless exists $self->{$jidStr};
38
39    $self->{$jidStr}->{Client}->Disconnect()
40      if $self->{$jidStr}->{Client};
41    delete $self->{$jidStr};
42
43    return 1;
44}
45
46sub connected {
47    my $self = shift;
48    return scalar keys %{ $self };
49}
50
51sub getJIDs {
52    my $self = shift;
53    return keys %{ $self };
54}
55
56sub jidExists {
57    my $self = shift;
58    my $jidStr = shift;
59    return exists $self->{$jidStr};
60}
61
62sub sidExists {
63    my $self = shift;
64    my $sid = shift || "";
65    foreach my $c ( values %{ $self } ) {
66        return 1 if ($c->{Client}->{SESSION}->{id} eq $sid);
67    }
68    return 0;
69}
70
71sub getConnectionFromSid {
72    my $self = shift;
73    my $sid = shift;
74    foreach my $c (values %{ $self }) {
75        return $c->{Client} if $c->{Client}->{SESSION}->{id} eq $sid;
76    }
77    return undef;
78}
79
80sub getConnectionFromJID {
81    my $self = shift;
82    my $jid = shift;
83    $jid = $jid->GetJID('full') if UNIVERSAL::isa($jid, 'Net::XMPP::JID');
84    return $self->{$jid}->{Client} if exists $self->{$jid};
85}
86
87sub getRosterFromSid {
88    my $self = shift;
89    my $sid = shift;
90    foreach my $c (values %{ $self }) {
91        return $c->{Roster}
92          if $c->{Client}->{SESSION}->{id} eq $sid;
93    }
94    return undef;
95}
96
97sub getRosterFromJID {
98    my $self = shift;
99    my $jid = shift;
100    $jid = $jid->GetJID('full') if UNIVERSAL::isa($jid, 'Net::XMPP::JID');
101    return $self->{$jid}->{Roster} if exists $self->{$jid};
102}
103
104
1051;
Note: See TracBrowser for help on using the repository browser.