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

Contents of /google/lib/CWMP/Server.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 84 - (show annotations)
Fri Jun 22 18:25:24 2007 UTC (16 years, 10 months ago) by dpavlin
File size: 2783 byte(s)
use Net::Server instead of low-level IO::Socket::INET (that will hopefully
bring us free of charge forking server, background and various other stuff
:-)
1 # 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 store_path
11 default_queue
12 background
13 debug
14
15 server
16 / );
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 store_path => 'state.db',
34 default_queue => [ qw/GetRPCMethods GetParameterNames/ ],
35 background => 1,
36 debug => 1
37 });
38
39 Options:
40
41 =over 4
42
43 =item port
44
45 port to listen on
46
47 =item store_path
48
49 path to L<DBM::Deep> database file to preserve state
50
51 =item default_queue
52
53 commands which will be issued to every CPE on connect
54
55 =back
56
57 =cut
58
59 sub new {
60 my $class = shift;
61 my $self = $class->SUPER::new( @_ );
62
63 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;
82 }
83
84 =head2 run
85
86 =cut
87
88 sub run {
89 my $self = shift;
90
91 $self->server->run;
92 }
93
94 package CWMP::Server::Helper;
95
96 use warnings;
97 use strict;
98
99 use base qw/Net::Server/;
100 use Carp qw/confess/;
101 use Data::Dump qw/dump/;
102
103 sub options {
104 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 # new multi-value options
118 foreach my $p ( qw/ default_queue / ) {
119 $prop->{ $p } ||= [];
120 $template->{ $p } = $prop->{ $p };
121 }
122
123 warn dump( $prop );
124 }
125
126
127 =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;

  ViewVC Help
Powered by ViewVC 1.1.26