fill ParameterInfo using GetParameterNames
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 7 Mar 2010 14:11:56 +0000 (14:11 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 7 Mar 2010 14:11:56 +0000 (14:11 +0000)
git-svn-id: https://perl-cwmp.googlecode.com/svn/trunk@257 836a5e1a-633d-0410-964b-294494ad4392

lib/CWMP/Session.pm
lib/CWMP/Store.pm
lib/CWMP/Store/HASH.pm
t/05-store.t

index ce43cb3..442a434 100644 (file)
@@ -137,9 +137,25 @@ sub process_request {
                $xml = $self->dispatch( $job->dispatch );
                $job->finish;
        } else {
                $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;
        }
 
        my $status = length($xml) ? 200 : 204;
index c5b5da9..da8164e 100644 (file)
@@ -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;
 =head2 all_uids
 
   my @cpe = $store->all_uids;
index 3624e4f..5b15fcc 100644 (file)
@@ -101,6 +101,20 @@ sub get_state {
        return;
 }
 
        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;
 =head2 all_uids
 
   my @uids = $store->all_uids;
index 6748641..0cac16f 100755 (executable)
@@ -61,14 +61,14 @@ sub test_store {
 
        is_deeply( $state, $store_state, 'state ID same as uid' );
 
 
        is_deeply( $state, $store_state, 'state ID same as uid' );
 
-       ok( $store->update_state( {
+       $state = {
                DeviceID => {
                        SerialNumber => 123456,
                },
                baz => 12345 
                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' );
 
 
        is_deeply( $store->get_state( 123456 ), $state, 'get_state' );