]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/perlmods/OpenSRF/Transport/SlimJabber/Inbound.pm
making the router optional, and allowing multiple routers
[OpenSRF.git] / src / perlmods / OpenSRF / Transport / SlimJabber / Inbound.pm
1 package OpenSRF::Transport::SlimJabber::Inbound;
2 use strict;use warnings;
3 use base qw/OpenSRF::Transport::SlimJabber::Client/;
4 use OpenSRF::EX;
5 use OpenSRF::Utils::Config; 
6 use OpenSRF::Utils::Logger qw(:level);
7
8 my $logger = "OpenSRF::Utils::Logger";
9
10 =head1 Description
11
12 This is the jabber connection where all incoming client requests will be accepted.
13 This connection takes the data, passes it off to the system then returns to take
14 more data.  Connection params are all taken from the config file and the values
15 retreived are based on the $app name passed into new().
16
17 This service should be loaded at system startup.
18
19 =cut
20
21 # XXX This will be overhauled to connect as a component instead of as
22 # a user.  all in good time, though.
23
24 {
25         my $unix_sock;
26         sub unix_sock { return $unix_sock; }
27         my $instance;
28
29         sub new {
30                 my( $class, $app ) = @_;
31                 $class = ref( $class ) || $class;
32                 if( ! $instance ) {
33                         my $app_state = $app . "_inbound";
34                         my $config = OpenSRF::Utils::Config->current;
35
36                         if( ! $config ) {
37                                 throw OpenSRF::EX::Jabber( "No suitable config found" );
38                         }
39
40                         my $username    = $config->transport->users->$app;
41                         my $password    = $config->transport->auth->password;
42                         my $resource    = 'system';
43
44                         if (defined $config->system->router_target) {
45                                 $resource .= '_' . $config->env->hostname . "_$$";
46                         }
47
48                         my $self = __PACKAGE__->SUPER::new( 
49                                         username                => $username,
50                                         resource                => $resource,
51                                         password                => $password,
52                                         );
53
54                         $self->{app} = $app;
55                                         
56                                         
57                         my $f = $config->dirs->sock_dir;
58                         $unix_sock = join( "/", $f, $config->unix_sock->$app );
59                         bless( $self, $class );
60                         $instance = $self;
61                 }
62                 return $instance;
63         }
64
65 }
66         
67 sub listen {
68         my $self = shift;
69         
70         my $config = OpenSRF::Utils::Config->current;
71         my $routers = $config->system->router_target;
72         if (defined $routers) {
73                 for my $router (@$routers) P
74                         $self->send( to => $router, 
75                                         body => "registering", router_command => "register" , router_class => $self->{app} );
76                 }
77         }
78                         
79         while(1) {
80                 my $sock = $self->unix_sock();
81                 my $socket = IO::Socket::UNIX->new( Peer => $sock  );
82         
83                 throw OpenSRF::EX::Socket( "Unable to connect to UnixServer: socket-file: $sock \n :=> $! " )
84                         unless ($socket->connected);
85
86                 my $o = $self->process( -1 );
87
88                 if( ! defined( $o ) ) {
89                         throw OpenSRF::EX::Jabber( "Listen Loop failed at 'process()'" );
90                 }
91                 print $socket $o;
92
93                 $socket->close;
94
95         }
96
97         throw OpenSRF::EX::Socket( "How did we get here?!?!" );
98 }
99
100 1;
101