1 # Dobrica Pavlinusic, <dpavlin@rot13.org> 06/22/07 14:35:38 CEST
8 use base qw/Class::Accessor/;
9 __PACKAGE__->mk_accessors( qw/
16 use Data::Dump qw/dump/;
17 use Module::Pluggable search_path => 'CWMP::Store', sub_name => 'possible_stores', require => 1;
21 CWMP::Store - parsist CPE state on disk
27 my $store = CWMP::Store->new({
29 path => '/path/to/state.db',
38 my $self = $class->SUPER::new( @_ );
40 confess "requed parametar module is missing" unless $self->module;
42 # XXX it's important to call possible_stores once, because current_store won't work
43 my @plugins = $self->possible_stores();
45 warn "Found store plugins: ", join(", ", @plugins ), "\n" if $self->debug;
47 $self->current_store->open( @_ );
49 # so that we don't have to check if it's defined
50 $self->debug( 0 ) unless $self->debug;
57 Returns currnet store plugin object
64 my $module = $self->module;
65 my $s = $self->only( ref($self).'::'.$module );
67 confess "unknown store module $module not one of ", dump( $self->possible_stores ) unless $s;
69 # warn "#### current store = $s\n" if $self->debug > 4;
76 $store->update_state( $state );
85 confess "need state" unless $state;
87 my $uid = $self->state_to_uid( $state );
89 warn "#### update_state( ", dump( $state ), " ) for $uid\n" if $self->debug > 2;
90 $self->current_store->update_uid_state( $uid, $state );
95 my $state = $store->get_state( $uid );
97 Returns normal unblessed hash (actually, in-memory copy of state in database).
104 confess "need uid" unless $uid;
106 warn "#### get_state( $uid )\n" if $self->debug > 4;
108 return $self->current_store->get_state( $uid );
114 my @cpe = $store->all_uids;
120 my @cpes = $self->current_store->all_uids;
121 warn "## all_uids = ", dump( @cpes ), "\n" if $self->debug;
127 my $CPE_uid = $store->ID_to_uid( $state );
129 It uses C<< DeviceID.SerialNumber >> from C<Inform> message as unique ID
138 warn "#### state_to_uid",dump( $state ),$/ if $self->debug > 4;
140 my $uid = $state->{DeviceID}->{SerialNumber} ||
141 confess "no DeviceID.SerialNumber in ",dump( $state );