/[cwmp]/google/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/lib/CWMP/Server.pm

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

revision 83 by dpavlin, Fri Jun 22 15:54:43 2007 UTC revision 84 by dpavlin, Fri Jun 22 18:25:24 2007 UTC
# Line 4  package CWMP::Server; Line 4  package CWMP::Server;
4  use strict;  use strict;
5  use warnings;  use warnings;
6    
   
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_path  store_path
11  default_queue  default_queue
12    background
13  debug  debug
14    
15    server
16  / );  / );
17    
18  use CWMP::Session;  use CWMP::Session;
# Line 30  CWMP::Server - description Line 32  CWMP::Server - description
32          port => 3333,          port => 3333,
33          store_path => 'state.db',          store_path => 'state.db',
34          default_queue => [ qw/GetRPCMethods GetParameterNames/ ],                                                                    default_queue => [ qw/GetRPCMethods GetParameterNames/ ],                                                          
35            background => 1,
36          debug => 1          debug => 1
37    });    });
38    
# Line 59  sub new { Line 62  sub new {
62    
63          warn "created ", __PACKAGE__, "(", dump( @_ ), ") object\n" if $self->debug;          warn "created ", __PACKAGE__, "(", dump( @_ ), ") object\n" if $self->debug;
64    
65            warn "ACS waiting for request on port ", $self->port, "\n";
66    
67            $self->debug( 0 ) unless $self->debug;
68            warn "## debug level: ", $self->debug, "\n" if $self->debug;
69    
70            $self->server(
71                    CWMP::Server::Helper->new({
72                            proto => 'tcp',
73                            port => $self->port,
74                            default_queue => $self->default_queue,
75                            store_path => $self->store_path,
76                            debug => $self->debug,
77                            background => $self->background,
78                    })
79            );
80    
81          return $self;          return $self;
82  }  }
83    
84  =head2 run  =head2 run
85    
   $server->run();  
   
86  =cut  =cut
87    
88  sub run {  sub run {
89          my $self = shift;          my $self = shift;
90    
91          my $listen = IO::Socket::INET->new(          $self->server->run;
92                  Listen    => 5,  }
 #               LocalAddr => 'localhost',  
                 LocalPort => $self->port,  
                 Proto     => 'tcp',  
                 Blocking  => 1,  
                 ReuseAddr => 1,  
         );  
93    
94          warn "ACS waiting for request on port ", $self->port;  package CWMP::Server::Helper;
95    
96          $self->debug( 0 ) unless $self->debug;  use warnings;
97          warn "## debug level: ", $self->debug, "\n" if $self->debug;  use strict;
98    
99          warn $self->default_queue ? " queue ( " . join(",",@{$self->default_queue}) . " )" : "",  use base qw/Net::Server/;
100                  "\n";  use Carp qw/confess/;
101    use Data::Dump qw/dump/;
102    
103          while ( my $sock = $listen->accept ) {  sub options {
104                  $sock->autoflush(1);          my $self     = shift;
105            my $prop     = $self->{'server'};
106            my $template = shift;
107    
108            ### setup options in the parent classes
109            $self->SUPER::options($template);
110    
111            # new single-value options
112            foreach my $p ( qw/ store_path debug / ) {
113                    $prop->{ $p } ||= undef;
114                    $template->{ $p } = \$prop->{ $p };
115            }
116    
117                  my $session = CWMP::Session->new({          # new multi-value options
118                          sock => $sock,          foreach my $p ( qw/ default_queue / ) {
119                          queue => $self->default_queue,                  $prop->{ $p } ||= [];
120                          store_path => $self->store_path,                  $template->{ $p } = $prop->{ $p };
121                          debug => $self->debug,          }
122                  }) || confess "can't create session";  
123            warn dump( $prop );
124    }
125    
                 while ( $session->process_request ) {  
                         warn "...another one bites the dust...\n";  
                 }  
126    
127                  warn "...returning to accepting new connections\n";  =head2 process_request
128    
129    =cut
130    
131    sub process_request {
132            my $self = shift;
133    
134            my $prop = $self->{server};
135            confess "no server in ", ref( $self ) unless $prop;
136            my $sock = $prop->{client};
137            confess "no sock in ", ref( $self ) unless $sock;
138    
139            warn "default CPE queue ( " . join(",",@{$prop->{default_queue}}) . " )" if defined($prop->{default_queue});
140    
141            warn "sock = ",dump( $sock );
142    
143            my $session = CWMP::Session->new({
144                    sock => $sock,
145                    queue => $prop->{default_queue},
146                    store_path => $prop->{store_path},
147                    debug => $prop->{debug},
148            }) || confess "can't create session";
149    
150            while ( $session->process_request ) {
151                    warn "...another one bites the dust...\n";
152          }          }
153    
154            warn "...returning to accepting new connections\n";
155    
156  }  }
157    
158  1;  1;

Legend:
Removed from v.83  
changed lines
  Added in v.84

  ViewVC Help
Powered by ViewVC 1.1.26