From cb99de4f46719f44da3f6c280adcd8e627d33424 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sun, 7 Mar 2010 14:11:56 +0000 Subject: [PATCH] fill ParameterInfo using GetParameterNames git-svn-id: https://perl-cwmp.googlecode.com/svn/trunk@257 836a5e1a-633d-0410-964b-294494ad4392 --- lib/CWMP/Session.pm | 22 +++++++++++++++++++--- lib/CWMP/Store.pm | 13 +++++++++++++ lib/CWMP/Store/HASH.pm | 14 ++++++++++++++ t/05-store.t | 6 +++--- 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/lib/CWMP/Session.pm b/lib/CWMP/Session.pm index ce43cb3..442a434 100644 --- a/lib/CWMP/Session.pm +++ b/lib/CWMP/Session.pm @@ -137,9 +137,25 @@ sub process_request { $xml = $self->dispatch( $job->dispatch ); $job->finish; } else { - warn ">>> empty response $to_uid"; - $state->{NoMoreRequests} = 1; - $xml = ''; + my $stored = $self->store->get_state( $uid ); + if ( ! defined $stored->{ParameterInfo} ) { + $xml = $self->dispatch( 'GetParameterNames', [ 'InternetGatewayDevice.', 1 ] ); + } else { + my @params = grep { m/\.$/ } keys %{ $stored->{ParameterInfo} }; + if ( @params ) { + warn "# GetParameterNames ", dump( @params ); + $xml = $self->dispatch( 'GetParameterNames', [ shift @params, 1 ] ); + foreach ( @params ) { + $queue->enqueue( 'GetParameterNames', [ $_, 1 ] ); + delete( $stored->{ParameterInfo}->{ $_ } ); + } + $self->store->set_state( $uid, $stored ); + } else { + warn ">>> empty response $to_uid"; + $state->{NoMoreRequests} = 1; + $xml = ''; + } + } } my $status = length($xml) ? 200 : 204; diff --git a/lib/CWMP/Store.pm b/lib/CWMP/Store.pm index c5b5da9..da8164e 100644 --- a/lib/CWMP/Store.pm +++ b/lib/CWMP/Store.pm @@ -109,6 +109,19 @@ sub get_state { } + +=head2 set_state + + $store->set_state( $uid, $state ); + +=cut + +sub set_state { + my $self = shift; + return $self->current_store->set_state( @_ ); +} + + =head2 all_uids my @cpe = $store->all_uids; diff --git a/lib/CWMP/Store/HASH.pm b/lib/CWMP/Store/HASH.pm index 3624e4f..5b15fcc 100644 --- a/lib/CWMP/Store/HASH.pm +++ b/lib/CWMP/Store/HASH.pm @@ -101,6 +101,20 @@ sub get_state { return; } + +=head2 set_state + + $store->set_state( $uid, $state ); + +=cut + +sub set_state { + my ( $self, $uid, $state ) = @_; + my $file = $self->file( $uid ); + return $self->save_hash( $file, $state ); +} + + =head2 all_uids my @uids = $store->all_uids; diff --git a/t/05-store.t b/t/05-store.t index 6748641..0cac16f 100755 --- a/t/05-store.t +++ b/t/05-store.t @@ -61,14 +61,14 @@ sub test_store { is_deeply( $state, $store_state, 'state ID same as uid' ); - ok( $store->update_state( { + $state = { DeviceID => { SerialNumber => 123456, }, baz => 12345 - } ), 'update_state existing' ); + }; - $state->{baz} = 12345; + ok( $store->set_state( 123456, $state ), 'set_state' ); is_deeply( $store->get_state( 123456 ), $state, 'get_state' ); -- 2.20.1