/[cwmp]/google/trunk/lib/CWMP/Server.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /google/trunk/lib/CWMP/Server.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 150 by dpavlin, Sat Oct 27 22:53:14 2007 UTC revision 220 by dpavlin, Fri Nov 23 00:42:50 2007 UTC
# Line 7  use warnings; Line 7  use warnings;
7  use base qw/Class::Accessor/;  use base qw/Class::Accessor/;
8  __PACKAGE__->mk_accessors( qw/  __PACKAGE__->mk_accessors( qw/
9  port  port
10  store  session
 default_queue  
11  background  background
12  debug  debug
13    
# Line 16  server Line 15  server
15  / );  / );
16    
17  use CWMP::Session;  use CWMP::Session;
18    use CWMP::Queue;
19    use CWMP::MemLeak;
20    
21  use Carp qw/confess/;  use Carp qw/confess/;
22  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
# Line 30  CWMP::Server - description Line 31  CWMP::Server - description
31    
32    my $server = CWMP::Server->new({    my $server = CWMP::Server->new({
33          port => 3333,          port => 3333,
34          store => 'state.db',          session => { ... },
         default_queue => [ qw/GetRPCMethods GetParameterNames/ ],                                                            
35          background => 1,          background => 1,
36          debug => 1          debug => 1
37    });    });
# Line 44  Options: Line 44  Options:
44    
45  port to listen on  port to listen on
46    
47  =item store  =item session
48    
49  hash with key C<module> with value C<DBMDeep> if L<CWMP::Store::DBMDeep>  hash with key C<module> with value C<DBMDeep> if L<CWMP::Store::DBMDeep>
50  is used. Other parametars are optional.  is used. Other parametars are optional.
51    
 =item default_queue  
   
 commands which will be issued to every CPE on connect  
   
52  =back  =back
53    
54  =cut  =cut
# Line 72  sub new { Line 68  sub new {
68                  CWMP::Server::Helper->new({                  CWMP::Server::Helper->new({
69                          proto => 'tcp',                          proto => 'tcp',
70                          port => $self->port,                          port => $self->port,
71                          default_queue => $self->default_queue,                          session => $self->session,
                         store => $self->store,  
72                          debug => $self->debug,                          debug => $self->debug,
73                          background => $self->background,                          background => $self->background,
74                  })                  })
# Line 110  sub options { Line 105  sub options {
105          $self->SUPER::options($template);          $self->SUPER::options($template);
106    
107          # new single-value options          # new single-value options
108          foreach my $p ( qw/ store debug / ) {          foreach my $p ( qw/ session debug / ) {
109                  $prop->{ $p } ||= undef;                  $prop->{ $p } ||= undef;
110                  $template->{ $p } = \$prop->{ $p };                  $template->{ $p } = \$prop->{ $p };
111          }          }
112    
113          # new multi-value options          # new multi-value options
114          foreach my $p ( qw/ default_queue / ) {  #       foreach my $p ( qw/ default_queue / ) {
115                  $prop->{ $p } ||= [];  #               $prop->{ $p } ||= [];
116                  $template->{ $p } = $prop->{ $p };  #               $template->{ $p } = $prop->{ $p };
117          }  #       }
118  }  }
119    
120    
# Line 130  sub options { Line 125  sub options {
125  sub process_request {  sub process_request {
126          my $self = shift;          my $self = shift;
127    
128            my $leak = CWMP::MemLeak->new;
129    
130          my $prop = $self->{server};          my $prop = $self->{server};
131          confess "no server in ", ref( $self ) unless $prop;          confess "no server in ", ref( $self ) unless $prop;
132          my $sock = $prop->{client};          my $sock = $prop->{client};
133          confess "no sock in ", ref( $self ) unless $sock;          confess "no sock in ", ref( $self ) unless $sock;
134    
135          warn "default CPE queue ( " . join(",",@{$prop->{default_queue}}) . " )\n" if defined($prop->{default_queue});          my $sess = $prop->{session} || confess "no session";
136    
137          eval  {          eval  {
138                  my $session = CWMP::Session->new({                  $sess->{sock} = $sock;
139                          sock => $sock,                  $sess->{debug} = $prop->{debug};
140                          queue => $prop->{default_queue},  
141                          store => $prop->{store},                  my $session = CWMP::Session->new( $sess ) || confess "can't create session from ",dump( $sess );
                         debug => $prop->{debug},  
                 }) || confess "can't create session";  
142    
143                  while ( $session->process_request ) {                  while ( $session->process_request ) {
144                          warn "...another one bites the dust...\n";                          warn "...waiting for next request from CPE...\n" if $prop->{debug};
145                  }                  }
146          };          };
147    
148          if ($@) {          warn "ERROR: $@\n" if $@;
149                  warn $@;  
150          }          warn "...returning to accepting new connections\n" if $prop->{debug};
151    
152          warn "...returning to accepting new connections\n";          $leak->report;
153    
154  }  }
155    

Legend:
Removed from v.150  
changed lines
  Added in v.220

  ViewVC Help
Powered by ViewVC 1.1.26