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 |
|
|
15 |
/ ); |
/ ); |
16 |
|
|
17 |
use CWMP::Session; |
use CWMP::Session; |
18 |
|
use CWMP::Queue; |
19 |
|
|
20 |
use Carp qw/confess/; |
use Carp qw/confess/; |
21 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
30 |
|
|
31 |
my $server = CWMP::Server->new({ |
my $server = CWMP::Server->new({ |
32 |
port => 3333, |
port => 3333, |
33 |
store => { |
session => { ... }, |
|
module => 'DBMDeep', |
|
|
path => 'var/', |
|
|
}, |
|
|
default_queue => [ qw/GetRPCMethods GetParameterNames/ ], |
|
34 |
background => 1, |
background => 1, |
35 |
debug => 1 |
debug => 1 |
36 |
}); |
}); |
43 |
|
|
44 |
port to listen on |
port to listen on |
45 |
|
|
46 |
=item store |
=item session |
47 |
|
|
48 |
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> |
49 |
is used. Other parametars are optional. |
is used. Other parametars are optional. |
50 |
|
|
|
=item default_queue |
|
|
|
|
|
commands which will be issued to every CPE on connect |
|
|
|
|
51 |
=back |
=back |
52 |
|
|
53 |
=cut |
=cut |
67 |
CWMP::Server::Helper->new({ |
CWMP::Server::Helper->new({ |
68 |
proto => 'tcp', |
proto => 'tcp', |
69 |
port => $self->port, |
port => $self->port, |
70 |
default_queue => $self->default_queue, |
session => $self->session, |
|
store => $self->store, |
|
71 |
debug => $self->debug, |
debug => $self->debug, |
72 |
background => $self->background, |
background => $self->background, |
73 |
}) |
}) |
104 |
$self->SUPER::options($template); |
$self->SUPER::options($template); |
105 |
|
|
106 |
# new single-value options |
# new single-value options |
107 |
foreach my $p ( qw/ store debug / ) { |
foreach my $p ( qw/ session debug / ) { |
108 |
$prop->{ $p } ||= undef; |
$prop->{ $p } ||= undef; |
109 |
$template->{ $p } = \$prop->{ $p }; |
$template->{ $p } = \$prop->{ $p }; |
110 |
} |
} |
111 |
|
|
112 |
# new multi-value options |
# new multi-value options |
113 |
foreach my $p ( qw/ default_queue / ) { |
# foreach my $p ( qw/ default_queue / ) { |
114 |
$prop->{ $p } ||= []; |
# $prop->{ $p } ||= []; |
115 |
$template->{ $p } = $prop->{ $p }; |
# $template->{ $p } = $prop->{ $p }; |
116 |
} |
# } |
117 |
} |
} |
118 |
|
|
119 |
|
|
129 |
my $sock = $prop->{client}; |
my $sock = $prop->{client}; |
130 |
confess "no sock in ", ref( $self ) unless $sock; |
confess "no sock in ", ref( $self ) unless $sock; |
131 |
|
|
132 |
warn "default CPE queue ", dump( $prop->{default_queue} ), "\n" if defined($prop->{default_queue}); |
my $sess = $prop->{session} || confess "no session"; |
133 |
|
|
134 |
eval { |
eval { |
135 |
my $session = CWMP::Session->new({ |
$sess->{sock} = $sock; |
136 |
sock => $sock, |
$sess->{debug} = $prop->{debug}; |
137 |
queue => $prop->{default_queue}, |
|
138 |
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"; |
|
139 |
|
|
140 |
while ( $session->process_request ) { |
while ( $session->process_request ) { |
141 |
warn "...waiting for next request from CPE...\n"; |
warn "...waiting for next request from CPE...\n" if $prop->{debug}; |
142 |
} |
} |
143 |
}; |
}; |
144 |
|
|
145 |
if ($@) { |
warn "ERROR: $@\n" if $@; |
|
warn $@; |
|
|
} |
|
146 |
|
|
147 |
warn "...returning to accepting new connections\n"; |
warn "...returning to accepting new connections\n" if $prop->{debug}; |
148 |
|
|
149 |
} |
} |
150 |
|
|