/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 171 - (hide annotations)
Sun Oct 28 15:00:19 2007 UTC (16 years, 6 months ago) by dpavlin
File size: 2823 byte(s)
dump queue structure correctly if it exists
1 dpavlin 83 # Dobrica Pavlinusic, <dpavlin@rot13.org> 06/22/07 14:35:38 CEST
2     package CWMP::Server;
3    
4     use strict;
5     use warnings;
6    
7     use base qw/Class::Accessor/;
8     __PACKAGE__->mk_accessors( qw/
9     port
10 dpavlin 150 store
11 dpavlin 83 default_queue
12 dpavlin 84 background
13 dpavlin 83 debug
14 dpavlin 84
15     server
16 dpavlin 83 / );
17    
18     use CWMP::Session;
19    
20     use Carp qw/confess/;
21     use Data::Dump qw/dump/;
22    
23     =head1 NAME
24    
25     CWMP::Server - description
26    
27     =head1 METHODS
28    
29     =head2 new
30    
31     my $server = CWMP::Server->new({
32     port => 3333,
33 dpavlin 158 store => {
34     module => 'DBMDeep',
35     path => 'var/',
36     },
37 dpavlin 83 default_queue => [ qw/GetRPCMethods GetParameterNames/ ],
38 dpavlin 84 background => 1,
39 dpavlin 83 debug => 1
40     });
41    
42     Options:
43    
44     =over 4
45    
46     =item port
47    
48     port to listen on
49    
50 dpavlin 150 =item store
51 dpavlin 83
52 dpavlin 150 hash with key C<module> with value C<DBMDeep> if L<CWMP::Store::DBMDeep>
53     is used. Other parametars are optional.
54 dpavlin 83
55     =item default_queue
56    
57     commands which will be issued to every CPE on connect
58    
59     =back
60    
61     =cut
62    
63     sub new {
64     my $class = shift;
65     my $self = $class->SUPER::new( @_ );
66    
67     warn "created ", __PACKAGE__, "(", dump( @_ ), ") object\n" if $self->debug;
68    
69 dpavlin 84 warn "ACS waiting for request on port ", $self->port, "\n";
70    
71     $self->debug( 0 ) unless $self->debug;
72     warn "## debug level: ", $self->debug, "\n" if $self->debug;
73    
74     $self->server(
75     CWMP::Server::Helper->new({
76     proto => 'tcp',
77     port => $self->port,
78     default_queue => $self->default_queue,
79 dpavlin 150 store => $self->store,
80 dpavlin 84 debug => $self->debug,
81     background => $self->background,
82     })
83     );
84    
85 dpavlin 83 return $self;
86     }
87    
88     =head2 run
89    
90     =cut
91    
92     sub run {
93     my $self = shift;
94    
95 dpavlin 84 $self->server->run;
96     }
97 dpavlin 83
98 dpavlin 84 package CWMP::Server::Helper;
99 dpavlin 83
100 dpavlin 84 use warnings;
101     use strict;
102 dpavlin 83
103 dpavlin 84 use base qw/Net::Server/;
104     use Carp qw/confess/;
105     use Data::Dump qw/dump/;
106 dpavlin 83
107 dpavlin 84 sub options {
108     my $self = shift;
109     my $prop = $self->{'server'};
110     my $template = shift;
111 dpavlin 83
112 dpavlin 84 ### setup options in the parent classes
113     $self->SUPER::options($template);
114 dpavlin 83
115 dpavlin 84 # new single-value options
116 dpavlin 150 foreach my $p ( qw/ store debug / ) {
117 dpavlin 84 $prop->{ $p } ||= undef;
118     $template->{ $p } = \$prop->{ $p };
119     }
120 dpavlin 83
121 dpavlin 84 # new multi-value options
122     foreach my $p ( qw/ default_queue / ) {
123     $prop->{ $p } ||= [];
124     $template->{ $p } = $prop->{ $p };
125 dpavlin 83 }
126     }
127    
128 dpavlin 84
129     =head2 process_request
130    
131     =cut
132    
133     sub process_request {
134     my $self = shift;
135    
136     my $prop = $self->{server};
137     confess "no server in ", ref( $self ) unless $prop;
138     my $sock = $prop->{client};
139     confess "no sock in ", ref( $self ) unless $sock;
140    
141 dpavlin 171 warn "default CPE queue ", dump( $prop->{default_queue} ), "\n" if defined($prop->{default_queue});
142 dpavlin 84
143 oleide 141 eval {
144     my $session = CWMP::Session->new({
145     sock => $sock,
146     queue => $prop->{default_queue},
147 dpavlin 150 store => $prop->{store},
148 oleide 141 debug => $prop->{debug},
149     }) || confess "can't create session";
150 dpavlin 84
151 oleide 141 while ( $session->process_request ) {
152     warn "...another one bites the dust...\n";
153     }
154     };
155    
156     if ($@) {
157     warn $@;
158 dpavlin 84 }
159    
160     warn "...returning to accepting new connections\n";
161    
162     }
163    
164 dpavlin 83 1;

  ViewVC Help
Powered by ViewVC 1.1.26