7 |
use base qw/Class::Accessor/; |
use base qw/Class::Accessor/; |
8 |
__PACKAGE__->mk_accessors( qw/ |
__PACKAGE__->mk_accessors( qw/ |
9 |
debug |
debug |
10 |
store_path |
store |
11 |
|
|
12 |
sock |
sock |
13 |
state |
state |
34 |
|
|
35 |
my $server = CWMP::Session->new({ |
my $server = CWMP::Session->new({ |
36 |
sock => $io_socket_object, |
sock => $io_socket_object, |
37 |
store_path => 'state.db', |
store => 'state.db', |
38 |
queue => [ qw/GetRPCMethods GetParameterNames/ ], |
queue => [ qw/GetRPCMethods GetParameterNames/ ], |
39 |
debug => 1, |
debug => 1, |
40 |
}); |
}); |
51 |
|
|
52 |
warn "created ", __PACKAGE__, "(", dump( @_ ), ") for ", $self->sock->peerhost, "\n" if $self->debug; |
warn "created ", __PACKAGE__, "(", dump( @_ ), ") for ", $self->sock->peerhost, "\n" if $self->debug; |
53 |
|
|
54 |
$self->store( CWMP::Store->new({ |
my $store_obj = CWMP::Store->new({ |
55 |
debug => $self->debug, |
debug => $self->debug, |
56 |
path => $self->store_path, |
%{ $self->store }, |
57 |
}) ); |
}); |
58 |
|
|
59 |
|
croak "can't open ", dump( $self->store ), ": $!" unless $store_obj; |
60 |
|
|
61 |
croak "can't open ", $self->store_path, ": $!" unless $self->store; |
# FIXME looks ugly. Should we have separate accessor for this? |
62 |
|
$self->store( $store_obj ); |
63 |
|
|
64 |
return $self; |
return $self; |
65 |
} |
} |
125 |
|
|
126 |
} else { |
} else { |
127 |
|
|
128 |
warn "## empty request\n"; |
warn "## empty request, using last request state\n"; |
129 |
|
|
130 |
$state = $self->state; |
$state = $self->state; |
131 |
delete( $state->{_dispatch} ); |
delete( $state->{_dispatch} ); |
132 |
warn "last request state = ", dump( $state ), "\n" if $self->debug > 1; |
#warn "last request state = ", dump( $state ), "\n" if $self->debug > 1; |
133 |
} |
} |
134 |
|
|
135 |
|
|
149 |
} elsif ( $dispatch = shift @{ $self->queue } ) { |
} elsif ( $dispatch = shift @{ $self->queue } ) { |
150 |
$xml = $self->dispatch( $dispatch ); |
$xml = $self->dispatch( $dispatch ); |
151 |
} elsif ( $size == 0 ) { |
} elsif ( $size == 0 ) { |
152 |
warn ">>> closing connection\n"; |
warn ">>> no more queued commands, closing connection\n"; |
153 |
return 0; |
return 0; |
154 |
} else { |
} else { |
155 |
warn ">>> empty response\n"; |
warn ">>> empty response\n"; |