imgtools/buildrom/tools/featurefile.pm
changeset 0 044383f39525
child 590 360bd6b35136
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 #
       
     2 # Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of the License "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 #
       
    16 
       
    17 # This package contains common routines required for the creation of feature registry configuration/
       
    18 # features data file.
       
    19 package featurefile;
       
    20 
       
    21 # Include Module package
       
    22 use FileHandle;
       
    23 use WRITER;
       
    24 
       
    25 use strict;
       
    26 
       
    27 # Class constructor
       
    28 sub new 
       
    29 {
       
    30 	my ($class,$xmlDBHandle) = @_;
       
    31 
       
    32 	my $object = {};
       
    33 	$object->{_FEATUREFILENAME} = undef;
       
    34 	$object->{_FILEHANDLE} = undef;
       
    35 	$object->{_FILEVERSION} = undef;
       
    36 	$object->{_FEATCOUNT} = 0;
       
    37 	$object->{_DEFAULTRANGECOUNT} = 0;
       
    38 	$object->{_XMLDBHANDLE} = $xmlDBHandle;
       
    39 	
       
    40 	bless($object, $class);
       
    41 	return $object;
       
    42 }
       
    43 
       
    44 # Subroutine to create feature registry configuration/features data file
       
    45 # @param $object					- Object reference which is passed implicitly
       
    46 # @param _FEATUREFILENAME			- Feature registry configuration/features data filename
       
    47 # @param _FEATURELIST				- The complete List of features which are either to be included or excluded
       
    48 sub createFile
       
    49 {
       
    50 	my $object = shift;
       
    51 	$object->{_FEATUREFILENAME} = shift;
       
    52 	$object->{_FEATURELIST} = shift;
       
    53 		
       
    54 	# Open feature file for writing	
       
    55 	if (!$object->openFile())
       
    56 	{
       
    57 		return 0;
       
    58 	}
       
    59 
       
    60 	# Create feauture map
       
    61 	$object->createFeatureMap();
       
    62 	
       
    63 	# Set feature count
       
    64 	$object->setFeatureCount();
       
    65 
       
    66 	# Set Default Range Count
       
    67 	$object->setDefaultRangeCount();
       
    68 	
       
    69 	# Write feature file header
       
    70 	$object->writeHeader();	
       
    71 
       
    72 	# Create feature entry for the listed features
       
    73 	$object->writeFeatures();
       
    74 
       
    75 	# Write Default Supported Range 
       
    76 	$object->writeDefault();
       
    77 	
       
    78 	# Close feature file.
       
    79 	$object->closeFile();
       
    80 
       
    81 	return 1;
       
    82 }
       
    83 
       
    84 # Subroutine to open feature file 
       
    85 # @param $object					- Object reference which is passed implicitly
       
    86 sub openFile
       
    87 {
       
    88 	my $object = shift;	
       
    89 
       
    90 	open (CONFIG_FH, ">$object->{_FEATUREFILENAME}");
       
    91 	binmode(CONFIG_FH);
       
    92 	$object->{_FILEHANDLE} = *CONFIG_FH;
       
    93 
       
    94 	if(!defined $object->{_FILEHANDLE})
       
    95 	{
       
    96 		print "\nError in creating the $object->{_FEATUREFILENAME}, check for the accessability of File / Drive\n";
       
    97 		return 0;
       
    98 	}
       
    99 	return 1;
       
   100 }
       
   101 
       
   102 # Subroutine to write feature file header
       
   103 # @param $object					- Object reference which is passed implicitly
       
   104 sub writeHeader
       
   105 {
       
   106 	my $object = shift;
       
   107 
       
   108 	$object->write2File(0x74616566);
       
   109 	$object->write2File($object->{_FILEVERSION});
       
   110 	$object->write2File($object->{_FEATCOUNT});
       
   111 	$object->write2File($object->{_DEFAULTRANGECOUNT});
       
   112 }
       
   113 
       
   114 # Subroutine to check if the feature is present in feature databse XML file
       
   115 # @param $object					- Object reference which is passed implicitly
       
   116 sub isPresentInFeatureListXML
       
   117 {
       
   118 	my $object = shift;
       
   119 	my $fidMain= shift;	
       
   120 	
       
   121 	# If the feature is not found, generate an error message.
       
   122 	if(!defined $fidMain->{uid})
       
   123 	{
       
   124 		print "Error:Feature $fidMain->{name} not found in feature list XML \n";
       
   125 		return 0;
       
   126 	}	
       
   127 	return 1;
       
   128 }
       
   129 
       
   130 # Subroutine to set the count of listed features in feature file
       
   131 # @param $object					- Object reference which is passed implicitly
       
   132 sub setFeatureCount
       
   133 {
       
   134 	my $object = shift;
       
   135 
       
   136 	$object->{_FEATCOUNT} = scalar (keys %{$object->{_FEATUREHASHMAP}});	
       
   137 }
       
   138 
       
   139 # Subroutine to set the count of Default Support Range(D.S.R)
       
   140 # @param $object					- Object reference which is passed implicitly
       
   141 sub setDefaultRangeCount
       
   142 {
       
   143 	my $object = shift;
       
   144 	
       
   145 	$object->{_DEFAULTRANGECOUNT} = ($object->{_XMLDBHANDLE})->defaultIncludeCount();
       
   146 }
       
   147 
       
   148 # Write the default=present featureUID ranges (min/lowerruid,max/higheruid) to the feature file 
       
   149 # @param $object					- Object reference which is passed implicitly
       
   150 sub writeDefault
       
   151 {
       
   152 	my $object = shift;
       
   153 
       
   154 	if ($object->{_DEFAULTRANGECOUNT}) 
       
   155 	{
       
   156 		my @defaultFeatures = ($object->{_XMLDBHANDLE})->getDefaultIncludeInfo();
       
   157 		for my $i ( 0 .. $#defaultFeatures )
       
   158 		{
       
   159 			my $minuid = $defaultFeatures[$i][0];
       
   160 			my $maxuid = $defaultFeatures[$i][1];		
       
   161 			$object->write2File($minuid);
       
   162 			$object->write2File($maxuid);
       
   163 		}
       
   164 	}
       
   165 }
       
   166 
       
   167 # Subroutine to close feature file. 
       
   168 # @param $object					- Object reference which is passed implicitly
       
   169 sub closeFile
       
   170 {
       
   171 	my $object = shift;
       
   172 
       
   173 	close $object->{_FILEHANDLE};
       
   174 }
       
   175 
       
   176 # Subroutine to write the bytes to the binary file. 
       
   177 # @param $object					- Object reference which is passed implicitly
       
   178 # @param $bytes						- 32-bit value which is to be writen in binary file.
       
   179 sub write2File
       
   180 {
       
   181 	my $object = shift;
       
   182 	my $bytes = shift;
       
   183 
       
   184 	&WRITER::write32($object->{_FILEHANDLE}, $bytes);
       
   185 }
       
   186 
       
   187 1;