1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/featuremgmt/featuremgr/tools/datfilehelpers/FeatureFlag.pm Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,279 @@
1.4 +#!perl -w
1.5 +# Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +# All rights reserved.
1.7 +# This component and the accompanying materials are made available
1.8 +# under the terms of "Eclipse Public License v1.0"
1.9 +# which accompanies this distribution, and is available
1.10 +# at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +#
1.12 +# Initial Contributors:
1.13 +# Nokia Corporation - initial contribution.
1.14 +#
1.15 +# Contributors:
1.16 +#
1.17 +# Description:
1.18 +#
1.19 +
1.20 +use strict;
1.21 +
1.22 +#
1.23 +# A simple class to manage feature flags for a feature set data file.
1.24 +#
1.25 +package FeatureFlag;
1.26 +
1.27 +# Create a feature flag object.
1.28 +sub new
1.29 +{
1.30 + my $arg = shift;
1.31 + my $class = ref($arg) || $arg;
1.32 + my($uid, $sf, $ud) = @_;
1.33 + die "You must specify a UID when creating a FeatureFlag object"
1.34 + unless(defined($uid));
1.35 + $sf = 0 unless(defined($sf));
1.36 + $ud = 0 unless(defined($ud));
1.37 +
1.38 + my $self = {
1.39 + uid => $uid,
1.40 + statusflags => $sf,
1.41 + userdata => $ud,
1.42 + endian => "LE",
1.43 + };
1.44 + bless $self, $class;
1.45 + return $self;
1.46 +}
1.47 +
1.48 +sub Endian
1.49 +{
1.50 + my $self = shift;
1.51 + return undef unless(ref($self));
1.52 + my $arg = shift;
1.53 + return $self->{endian} unless(defined($arg) and $arg =~ m/(^BE$|^LE$)/i);
1.54 + $self->{endian} = lc($1);
1.55 + return $self->{endian};
1.56 +}
1.57 +
1.58 +# Return a twelve byte string 'feature flag' information.
1.59 +sub BinaryContent
1.60 +{
1.61 + my $self = shift;
1.62 + return undef unless(ref($self));
1.63 + my @arr = ( $self->UID(), $self->StatusFlags(), $self->UserData() );
1.64 +
1.65 + # Decide whether we want big or little endian output.
1.66 + # According to the documentation, 'V', 'N' are GUARANTEED to be 32-bit.
1.67 + my $packstring = "V3"; # Little endian.
1.68 + $packstring = "N3" if($self->Endian() eq "BE");
1.69 +
1.70 + my $string = pack $packstring, @arr;
1.71 + return $string;
1.72 +}
1.73 +
1.74 +# A single 32-bit number.
1.75 +sub UID
1.76 +{
1.77 + my $self = shift;
1.78 + return undef unless(ref($self));
1.79 + my $uid = shift;
1.80 + return $self->{uid} unless(defined($uid));
1.81 + $uid = int($uid);
1.82 + $self->{uid} = $uid;
1.83 + return $uid;
1.84 +}
1.85 +
1.86 +# A single 32-bit number.
1.87 +sub StatusFlags
1.88 +{
1.89 + my $self = shift;
1.90 + return undef unless(ref($self));
1.91 + my $sf = shift;
1.92 + return $self->{statusflags} unless(defined($sf));
1.93 + $sf = int($sf);
1.94 + $self->{statusflags} = $sf;
1.95 + return $sf;
1.96 +}
1.97 +
1.98 +# A single 32-bit number.
1.99 +sub UserData
1.100 +{
1.101 + my $self = shift;
1.102 + return undef unless(ref($self));
1.103 + my $ud = shift;
1.104 + return $self->{userdata} unless(defined($ud));
1.105 + $ud = int($ud);
1.106 + $self->{userdata} = $ud;
1.107 + return $ud;
1.108 +}
1.109 +
1.110 +# Display the content of the feature flag in english.
1.111 +sub Show
1.112 +{
1.113 + my $self = shift;
1.114 + return undef unless(ref($self));
1.115 + my $fd = shift;
1.116 + $fd = *STDOUT unless(defined($fd));
1.117 + printf $fd "UID 0x%08x\n", $self->UID();
1.118 + printf $fd "Status Flags 0x%08x\n", $self->StatusFlags();
1.119 +
1.120 + # Supported?
1.121 + print "\t";
1.122 + print "Not " unless($self->Supported);
1.123 + print "Supported\n";
1.124 +
1.125 + # Upgradable?
1.126 + print "\t";
1.127 + print "Not " unless($self->Upgradable);
1.128 + print "Upgradable\n";
1.129 +
1.130 + # Modifiable?
1.131 + print "\t";
1.132 + print "Not " unless($self->Modifiable);
1.133 + print "Modifiable\n";
1.134 +
1.135 + # BlackListed?
1.136 + print "\t";
1.137 + print "Not " unless($self->BlackListed);
1.138 + print "BlackListed\n";
1.139 +
1.140 + # Uninitialised?
1.141 + print "\t";
1.142 + print "Not " unless($self->Uninitialised); # Double negative.
1.143 + print "Uninitialised\n";
1.144 +
1.145 + # Persisted?
1.146 + print "\t";
1.147 + print "Not " unless($self->Persisted);
1.148 + print "Persisted\n";
1.149 +
1.150 + printf $fd "User Data 0x%08x\n\n", $self->UserData();
1.151 + return 1;
1.152 +}
1.153 +
1.154 +1;
1.155 +# ###########################################################################
1.156 +
1.157 +# The following methods operate on the 'StatusFlags' member, just setting
1.158 +# or clearing bits as required.
1.159 +#
1.160 +# Bits 6 through 31 are currently reserved, 23/7/07.
1.161 +#
1.162 +
1.163 +sub Supported
1.164 +{
1.165 + my $self = shift;
1.166 + return undef unless(ref($self));
1.167 + my $arg = shift;
1.168 + my $sp = $self->StatusFlags;
1.169 + if(defined($arg))
1.170 + {
1.171 + $arg = 0 if( $arg =~ m/EXCLUDE/i );
1.172 + $arg = 1 if( $arg =~ m/FEATURE/i );
1.173 + if($arg) { $sp |= 1; } else { $sp &= ~1; };
1.174 + $self->StatusFlags($sp);
1.175 + return $arg;
1.176 + }
1.177 + else
1.178 + {
1.179 + return ($sp & 1);
1.180 + }
1.181 +}
1.182 +
1.183 +sub Upgradable
1.184 +{
1.185 + my $self = shift;
1.186 + return undef unless(ref($self));
1.187 + my $arg = shift;
1.188 + my $sp = $self->StatusFlags;
1.189 + if(defined($arg))
1.190 + {
1.191 + if($arg) { $sp |= 2; } else { $sp &= ~2; };
1.192 + $self->StatusFlags($sp);
1.193 + return $arg;
1.194 + }
1.195 + else
1.196 + {
1.197 + return ($sp & 2);
1.198 + }
1.199 +}
1.200 +
1.201 +sub Modifiable
1.202 +{
1.203 + my $self = shift;
1.204 + return undef unless(ref($self));
1.205 + my $arg = shift;
1.206 + my $sp = $self->StatusFlags;
1.207 + if(defined($arg))
1.208 + {
1.209 + if($arg) { $sp |= 4; } else { $sp &= ~4; };
1.210 + $self->StatusFlags($sp);
1.211 + return $arg;
1.212 + }
1.213 + else
1.214 + {
1.215 + return ($sp & 4);
1.216 + }
1.217 +}
1.218 +
1.219 +sub BlackListed
1.220 +{
1.221 + my $self = shift;
1.222 + return undef unless(ref($self));
1.223 + my $arg = shift;
1.224 + my $sp = $self->StatusFlags;
1.225 + if(defined($arg))
1.226 + {
1.227 + if($arg) { $sp |= 8; } else { $sp &= ~8; };
1.228 + $self->StatusFlags($sp);
1.229 + return($arg);
1.230 + }
1.231 + else
1.232 + {
1.233 + return ($sp & 8);
1.234 + }
1.235 +}
1.236 +
1.237 +sub Uninitialised
1.238 +{
1.239 + my $self = shift;
1.240 + return undef unless(ref($self));
1.241 + my $arg = shift;
1.242 + my $sp = $self->StatusFlags;
1.243 + if(defined($arg))
1.244 + {
1.245 + if($arg) { $sp |= 16; } else { $sp &= ~16; };
1.246 + $self->StatusFlags($sp);
1.247 + return($arg);
1.248 + }
1.249 + else
1.250 + {
1.251 + return ($sp & 16);
1.252 + }
1.253 +}
1.254 +
1.255 +sub Uninitialized
1.256 +{
1.257 + return Uninitialised(@_);
1.258 +}
1.259 +
1.260 +sub Persisted
1.261 +{
1.262 + my $self = shift;
1.263 + return undef unless(ref($self));
1.264 + my $arg = shift;
1.265 + my $sp = $self->StatusFlags;
1.266 + if(defined($arg))
1.267 + {
1.268 + if($arg) { $sp |= 32; } else { $sp &= ~32; };
1.269 + $self->StatusFlags($sp);
1.270 + return($arg);
1.271 + }
1.272 + else
1.273 + {
1.274 + return ($sp & 32);
1.275 + }
1.276 +}
1.277 +
1.278 +
1.279 +# ###########################################################################
1.280 +
1.281 +1;
1.282 +