sl@0
|
1 |
#!perl -w
|
sl@0
|
2 |
# Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
# All rights reserved.
|
sl@0
|
4 |
# This component and the accompanying materials are made available
|
sl@0
|
5 |
# under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
# which accompanies this distribution, and is available
|
sl@0
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
#
|
sl@0
|
9 |
# Initial Contributors:
|
sl@0
|
10 |
# Nokia Corporation - initial contribution.
|
sl@0
|
11 |
#
|
sl@0
|
12 |
# Contributors:
|
sl@0
|
13 |
#
|
sl@0
|
14 |
# Description:
|
sl@0
|
15 |
#
|
sl@0
|
16 |
|
sl@0
|
17 |
use strict;
|
sl@0
|
18 |
|
sl@0
|
19 |
#
|
sl@0
|
20 |
# A simple class to manage feature flags for a feature set data file.
|
sl@0
|
21 |
#
|
sl@0
|
22 |
package FeatureFlag;
|
sl@0
|
23 |
|
sl@0
|
24 |
# Create a feature flag object.
|
sl@0
|
25 |
sub new
|
sl@0
|
26 |
{
|
sl@0
|
27 |
my $arg = shift;
|
sl@0
|
28 |
my $class = ref($arg) || $arg;
|
sl@0
|
29 |
my($uid, $sf, $ud) = @_;
|
sl@0
|
30 |
die "You must specify a UID when creating a FeatureFlag object"
|
sl@0
|
31 |
unless(defined($uid));
|
sl@0
|
32 |
$sf = 0 unless(defined($sf));
|
sl@0
|
33 |
$ud = 0 unless(defined($ud));
|
sl@0
|
34 |
|
sl@0
|
35 |
my $self = {
|
sl@0
|
36 |
uid => $uid,
|
sl@0
|
37 |
statusflags => $sf,
|
sl@0
|
38 |
userdata => $ud,
|
sl@0
|
39 |
endian => "LE",
|
sl@0
|
40 |
};
|
sl@0
|
41 |
bless $self, $class;
|
sl@0
|
42 |
return $self;
|
sl@0
|
43 |
}
|
sl@0
|
44 |
|
sl@0
|
45 |
sub Endian
|
sl@0
|
46 |
{
|
sl@0
|
47 |
my $self = shift;
|
sl@0
|
48 |
return undef unless(ref($self));
|
sl@0
|
49 |
my $arg = shift;
|
sl@0
|
50 |
return $self->{endian} unless(defined($arg) and $arg =~ m/(^BE$|^LE$)/i);
|
sl@0
|
51 |
$self->{endian} = lc($1);
|
sl@0
|
52 |
return $self->{endian};
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
# Return a twelve byte string 'feature flag' information.
|
sl@0
|
56 |
sub BinaryContent
|
sl@0
|
57 |
{
|
sl@0
|
58 |
my $self = shift;
|
sl@0
|
59 |
return undef unless(ref($self));
|
sl@0
|
60 |
my @arr = ( $self->UID(), $self->StatusFlags(), $self->UserData() );
|
sl@0
|
61 |
|
sl@0
|
62 |
# Decide whether we want big or little endian output.
|
sl@0
|
63 |
# According to the documentation, 'V', 'N' are GUARANTEED to be 32-bit.
|
sl@0
|
64 |
my $packstring = "V3"; # Little endian.
|
sl@0
|
65 |
$packstring = "N3" if($self->Endian() eq "BE");
|
sl@0
|
66 |
|
sl@0
|
67 |
my $string = pack $packstring, @arr;
|
sl@0
|
68 |
return $string;
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
# A single 32-bit number.
|
sl@0
|
72 |
sub UID
|
sl@0
|
73 |
{
|
sl@0
|
74 |
my $self = shift;
|
sl@0
|
75 |
return undef unless(ref($self));
|
sl@0
|
76 |
my $uid = shift;
|
sl@0
|
77 |
return $self->{uid} unless(defined($uid));
|
sl@0
|
78 |
$uid = int($uid);
|
sl@0
|
79 |
$self->{uid} = $uid;
|
sl@0
|
80 |
return $uid;
|
sl@0
|
81 |
}
|
sl@0
|
82 |
|
sl@0
|
83 |
# A single 32-bit number.
|
sl@0
|
84 |
sub StatusFlags
|
sl@0
|
85 |
{
|
sl@0
|
86 |
my $self = shift;
|
sl@0
|
87 |
return undef unless(ref($self));
|
sl@0
|
88 |
my $sf = shift;
|
sl@0
|
89 |
return $self->{statusflags} unless(defined($sf));
|
sl@0
|
90 |
$sf = int($sf);
|
sl@0
|
91 |
$self->{statusflags} = $sf;
|
sl@0
|
92 |
return $sf;
|
sl@0
|
93 |
}
|
sl@0
|
94 |
|
sl@0
|
95 |
# A single 32-bit number.
|
sl@0
|
96 |
sub UserData
|
sl@0
|
97 |
{
|
sl@0
|
98 |
my $self = shift;
|
sl@0
|
99 |
return undef unless(ref($self));
|
sl@0
|
100 |
my $ud = shift;
|
sl@0
|
101 |
return $self->{userdata} unless(defined($ud));
|
sl@0
|
102 |
$ud = int($ud);
|
sl@0
|
103 |
$self->{userdata} = $ud;
|
sl@0
|
104 |
return $ud;
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
# Display the content of the feature flag in english.
|
sl@0
|
108 |
sub Show
|
sl@0
|
109 |
{
|
sl@0
|
110 |
my $self = shift;
|
sl@0
|
111 |
return undef unless(ref($self));
|
sl@0
|
112 |
my $fd = shift;
|
sl@0
|
113 |
$fd = *STDOUT unless(defined($fd));
|
sl@0
|
114 |
printf $fd "UID 0x%08x\n", $self->UID();
|
sl@0
|
115 |
printf $fd "Status Flags 0x%08x\n", $self->StatusFlags();
|
sl@0
|
116 |
|
sl@0
|
117 |
# Supported?
|
sl@0
|
118 |
print "\t";
|
sl@0
|
119 |
print "Not " unless($self->Supported);
|
sl@0
|
120 |
print "Supported\n";
|
sl@0
|
121 |
|
sl@0
|
122 |
# Upgradable?
|
sl@0
|
123 |
print "\t";
|
sl@0
|
124 |
print "Not " unless($self->Upgradable);
|
sl@0
|
125 |
print "Upgradable\n";
|
sl@0
|
126 |
|
sl@0
|
127 |
# Modifiable?
|
sl@0
|
128 |
print "\t";
|
sl@0
|
129 |
print "Not " unless($self->Modifiable);
|
sl@0
|
130 |
print "Modifiable\n";
|
sl@0
|
131 |
|
sl@0
|
132 |
# BlackListed?
|
sl@0
|
133 |
print "\t";
|
sl@0
|
134 |
print "Not " unless($self->BlackListed);
|
sl@0
|
135 |
print "BlackListed\n";
|
sl@0
|
136 |
|
sl@0
|
137 |
# Uninitialised?
|
sl@0
|
138 |
print "\t";
|
sl@0
|
139 |
print "Not " unless($self->Uninitialised); # Double negative.
|
sl@0
|
140 |
print "Uninitialised\n";
|
sl@0
|
141 |
|
sl@0
|
142 |
# Persisted?
|
sl@0
|
143 |
print "\t";
|
sl@0
|
144 |
print "Not " unless($self->Persisted);
|
sl@0
|
145 |
print "Persisted\n";
|
sl@0
|
146 |
|
sl@0
|
147 |
printf $fd "User Data 0x%08x\n\n", $self->UserData();
|
sl@0
|
148 |
return 1;
|
sl@0
|
149 |
}
|
sl@0
|
150 |
|
sl@0
|
151 |
1;
|
sl@0
|
152 |
# ###########################################################################
|
sl@0
|
153 |
|
sl@0
|
154 |
# The following methods operate on the 'StatusFlags' member, just setting
|
sl@0
|
155 |
# or clearing bits as required.
|
sl@0
|
156 |
#
|
sl@0
|
157 |
# Bits 6 through 31 are currently reserved, 23/7/07.
|
sl@0
|
158 |
#
|
sl@0
|
159 |
|
sl@0
|
160 |
sub Supported
|
sl@0
|
161 |
{
|
sl@0
|
162 |
my $self = shift;
|
sl@0
|
163 |
return undef unless(ref($self));
|
sl@0
|
164 |
my $arg = shift;
|
sl@0
|
165 |
my $sp = $self->StatusFlags;
|
sl@0
|
166 |
if(defined($arg))
|
sl@0
|
167 |
{
|
sl@0
|
168 |
$arg = 0 if( $arg =~ m/EXCLUDE/i );
|
sl@0
|
169 |
$arg = 1 if( $arg =~ m/FEATURE/i );
|
sl@0
|
170 |
if($arg) { $sp |= 1; } else { $sp &= ~1; };
|
sl@0
|
171 |
$self->StatusFlags($sp);
|
sl@0
|
172 |
return $arg;
|
sl@0
|
173 |
}
|
sl@0
|
174 |
else
|
sl@0
|
175 |
{
|
sl@0
|
176 |
return ($sp & 1);
|
sl@0
|
177 |
}
|
sl@0
|
178 |
}
|
sl@0
|
179 |
|
sl@0
|
180 |
sub Upgradable
|
sl@0
|
181 |
{
|
sl@0
|
182 |
my $self = shift;
|
sl@0
|
183 |
return undef unless(ref($self));
|
sl@0
|
184 |
my $arg = shift;
|
sl@0
|
185 |
my $sp = $self->StatusFlags;
|
sl@0
|
186 |
if(defined($arg))
|
sl@0
|
187 |
{
|
sl@0
|
188 |
if($arg) { $sp |= 2; } else { $sp &= ~2; };
|
sl@0
|
189 |
$self->StatusFlags($sp);
|
sl@0
|
190 |
return $arg;
|
sl@0
|
191 |
}
|
sl@0
|
192 |
else
|
sl@0
|
193 |
{
|
sl@0
|
194 |
return ($sp & 2);
|
sl@0
|
195 |
}
|
sl@0
|
196 |
}
|
sl@0
|
197 |
|
sl@0
|
198 |
sub Modifiable
|
sl@0
|
199 |
{
|
sl@0
|
200 |
my $self = shift;
|
sl@0
|
201 |
return undef unless(ref($self));
|
sl@0
|
202 |
my $arg = shift;
|
sl@0
|
203 |
my $sp = $self->StatusFlags;
|
sl@0
|
204 |
if(defined($arg))
|
sl@0
|
205 |
{
|
sl@0
|
206 |
if($arg) { $sp |= 4; } else { $sp &= ~4; };
|
sl@0
|
207 |
$self->StatusFlags($sp);
|
sl@0
|
208 |
return $arg;
|
sl@0
|
209 |
}
|
sl@0
|
210 |
else
|
sl@0
|
211 |
{
|
sl@0
|
212 |
return ($sp & 4);
|
sl@0
|
213 |
}
|
sl@0
|
214 |
}
|
sl@0
|
215 |
|
sl@0
|
216 |
sub BlackListed
|
sl@0
|
217 |
{
|
sl@0
|
218 |
my $self = shift;
|
sl@0
|
219 |
return undef unless(ref($self));
|
sl@0
|
220 |
my $arg = shift;
|
sl@0
|
221 |
my $sp = $self->StatusFlags;
|
sl@0
|
222 |
if(defined($arg))
|
sl@0
|
223 |
{
|
sl@0
|
224 |
if($arg) { $sp |= 8; } else { $sp &= ~8; };
|
sl@0
|
225 |
$self->StatusFlags($sp);
|
sl@0
|
226 |
return($arg);
|
sl@0
|
227 |
}
|
sl@0
|
228 |
else
|
sl@0
|
229 |
{
|
sl@0
|
230 |
return ($sp & 8);
|
sl@0
|
231 |
}
|
sl@0
|
232 |
}
|
sl@0
|
233 |
|
sl@0
|
234 |
sub Uninitialised
|
sl@0
|
235 |
{
|
sl@0
|
236 |
my $self = shift;
|
sl@0
|
237 |
return undef unless(ref($self));
|
sl@0
|
238 |
my $arg = shift;
|
sl@0
|
239 |
my $sp = $self->StatusFlags;
|
sl@0
|
240 |
if(defined($arg))
|
sl@0
|
241 |
{
|
sl@0
|
242 |
if($arg) { $sp |= 16; } else { $sp &= ~16; };
|
sl@0
|
243 |
$self->StatusFlags($sp);
|
sl@0
|
244 |
return($arg);
|
sl@0
|
245 |
}
|
sl@0
|
246 |
else
|
sl@0
|
247 |
{
|
sl@0
|
248 |
return ($sp & 16);
|
sl@0
|
249 |
}
|
sl@0
|
250 |
}
|
sl@0
|
251 |
|
sl@0
|
252 |
sub Uninitialized
|
sl@0
|
253 |
{
|
sl@0
|
254 |
return Uninitialised(@_);
|
sl@0
|
255 |
}
|
sl@0
|
256 |
|
sl@0
|
257 |
sub Persisted
|
sl@0
|
258 |
{
|
sl@0
|
259 |
my $self = shift;
|
sl@0
|
260 |
return undef unless(ref($self));
|
sl@0
|
261 |
my $arg = shift;
|
sl@0
|
262 |
my $sp = $self->StatusFlags;
|
sl@0
|
263 |
if(defined($arg))
|
sl@0
|
264 |
{
|
sl@0
|
265 |
if($arg) { $sp |= 32; } else { $sp &= ~32; };
|
sl@0
|
266 |
$self->StatusFlags($sp);
|
sl@0
|
267 |
return($arg);
|
sl@0
|
268 |
}
|
sl@0
|
269 |
else
|
sl@0
|
270 |
{
|
sl@0
|
271 |
return ($sp & 32);
|
sl@0
|
272 |
}
|
sl@0
|
273 |
}
|
sl@0
|
274 |
|
sl@0
|
275 |
|
sl@0
|
276 |
# ###########################################################################
|
sl@0
|
277 |
|
sl@0
|
278 |
1;
|
sl@0
|
279 |
|