/[cwmp]/google/trunk/lib/CWMP/Store.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /google/trunk/lib/CWMP/Store.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 208 - (hide annotations)
Sun Nov 18 12:58:40 2007 UTC (16 years, 7 months ago) by dpavlin
File size: 2707 byte(s)
 r228@brr:  dpavlin | 2007-11-18 13:58:05 +0100
 - version bump [0.11]
 - rewrote CPE state management to actually work for multiple devices and
   simplify code in the process
 - CWMP::Store::DBMDeep don't return blessed objects any more

1 dpavlin 77 # Dobrica Pavlinusic, <dpavlin@rot13.org> 06/22/07 14:35:38 CEST
2     package CWMP::Store;
3    
4     use strict;
5     use warnings;
6    
7    
8     use base qw/Class::Accessor/;
9     __PACKAGE__->mk_accessors( qw/
10 dpavlin 150 module
11     path
12 dpavlin 77 debug
13     / );
14    
15 dpavlin 79 use Carp qw/confess/;
16 dpavlin 77 use Data::Dump qw/dump/;
17 dpavlin 150 use Module::Pluggable search_path => 'CWMP::Store', sub_name => 'possible_stores', require => 1;
18 dpavlin 77
19     =head1 NAME
20    
21     CWMP::Store - parsist CPE state on disk
22    
23     =head1 METHODS
24    
25     =head2 new
26    
27     my $store = CWMP::Store->new({
28 dpavlin 150 module => 'DBMDeep',
29 dpavlin 77 path => '/path/to/state.db',
30 dpavlin 162 clean => 1,
31 dpavlin 77 debug => 1,
32     });
33    
34     =cut
35    
36     sub new {
37     my $class = shift;
38     my $self = $class->SUPER::new( @_ );
39    
40 dpavlin 150 confess "requed parametar module is missing" unless $self->module;
41    
42 dpavlin 162 # XXX it's important to call possible_stores once, because current_store won't work
43     my @plugins = $self->possible_stores();
44 dpavlin 77
45 dpavlin 162 warn "Found store plugins: ", join(", ", @plugins ), "\n" if $self->debug;
46 dpavlin 84
47 dpavlin 150 $self->current_store->open( @_ );
48 dpavlin 77
49 dpavlin 170 # so that we don't have to check if it's defined
50     $self->debug( 0 ) unless $self->debug;
51    
52 dpavlin 77 return $self;
53     }
54    
55 dpavlin 150 =head2 current_store
56    
57     Returns currnet store plugin object
58    
59     =cut
60    
61     sub current_store {
62     my $self = shift;
63    
64     my $module = $self->module;
65     my $s = $self->only( ref($self).'::'.$module );
66    
67     confess "unknown store module $module not one of ", dump( $self->possible_stores ) unless $s;
68    
69 dpavlin 172 # warn "#### current store = $s\n" if $self->debug > 4;
70 dpavlin 150
71     return $s;
72     }
73    
74 dpavlin 79 =head2 update_state
75 dpavlin 77
76 dpavlin 208 $store->update_state( $state );
77 dpavlin 79
78     =cut
79    
80     sub update_state {
81     my $self = shift;
82    
83 dpavlin 208 my ( $state ) = @_;
84 dpavlin 79
85     confess "need state" unless $state;
86    
87 dpavlin 208 my $uid = $self->state_to_uid( $state );
88 dpavlin 100
89 dpavlin 208 warn "#### update_state( ", dump( $state ), " ) for $uid\n" if $self->debug > 2;
90 dpavlin 150 $self->current_store->update_uid_state( $uid, $state );
91 dpavlin 79 }
92 dpavlin 85
93 dpavlin 162 =head2 get_state
94 dpavlin 85
95 dpavlin 208 my $state = $store->get_state( $uid );
96 dpavlin 85
97     Returns normal unblessed hash (actually, in-memory copy of state in database).
98    
99     =cut
100    
101 dpavlin 162 sub get_state {
102 dpavlin 85 my $self = shift;
103 dpavlin 208 my ( $uid ) = @_;
104     confess "need uid" unless $uid;
105 dpavlin 100
106 dpavlin 208 warn "#### get_state( $uid )\n" if $self->debug > 4;
107 dpavlin 100
108 dpavlin 150 return $self->current_store->get_state( $uid );
109 dpavlin 100
110 dpavlin 85 }
111    
112 dpavlin 162 =head2 all_uids
113 dpavlin 95
114 dpavlin 162 my @cpe = $store->all_uids;
115 dpavlin 95
116     =cut
117    
118 dpavlin 162 sub all_uids {
119 dpavlin 95 my $self = shift;
120 dpavlin 150 my @cpes = $self->current_store->all_uids;
121 dpavlin 162 warn "## all_uids = ", dump( @cpes ), "\n" if $self->debug;
122 dpavlin 95 return @cpes;
123     }
124    
125 dpavlin 208 =head2 state_to_uid
126 dpavlin 95
127 dpavlin 208 my $CPE_uid = $store->ID_to_uid( $state );
128 dpavlin 95
129     It uses C<< DeviceID.SerialNumber >> from C<Inform> message as unique ID
130     for each CPE.
131    
132     =cut
133    
134 dpavlin 208 sub state_to_uid {
135 dpavlin 95 my $self = shift;
136 dpavlin 208 my ( $state ) = @_;
137 dpavlin 95
138 dpavlin 208 warn "#### state_to_uid",dump( $state ),$/ if $self->debug > 4;
139 dpavlin 95
140 dpavlin 208 my $uid = $state->{DeviceID}->{SerialNumber} ||
141     confess "no DeviceID.SerialNumber in ",dump( $state );
142 dpavlin 95
143 dpavlin 208 return $uid;
144 dpavlin 95 }
145    
146 dpavlin 77 1;

  ViewVC Help
Powered by ViewVC 1.1.26