imgtools/buildrom/tools/featuremanager.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 routines to read the information from the Feature manager XML file.
       
    18 package featuremanager; # Derived class for the feature manager xml parser
       
    19 
       
    20 BEGIN {
       
    21 	@ISA = qw(featureparser); # Derived from featuerParser
       
    22 	require featureparser;
       
    23 };
       
    24 
       
    25 use constant STRICTCASE=>1; # To suppress the case conversion in genericparser routine
       
    26 
       
    27 # Parse the featuredatabase XML file and generate the maps and counts
       
    28 #
       
    29 #featureset:
       
    30 # {namespace}<namespace> - optional
       
    31 # {ibyname}<ibyname> - optional
       
    32 # {hfilename}<hfilename> - optional
       
    33 # {hfileheader}<fileheader> - optional
       
    34 # {interfacestatus}<interfacestatus> -optional
       
    35 # {interfacevisibility}<interfacevisibility> - optional
       
    36 # {feature_list}<nameuidmap>
       
    37 # {feature} {<uid1>}{statusflags}<statusflag>
       
    38 #					{name}<name>
       
    39 #					{userdata}<userdata> - optional
       
    40 #					{includemacro}<macro>
       
    41 #					{excludemacro}<macro>
       
    42 #					{infeaturesetiby}<yes/no> - optional
       
    43 #					{comment}<comment> - optional
       
    44 #			{<uid2>}{statusflags}<statusflag>
       
    45 #					{name}<name>
       
    46 #					{userdata}<userdata> - optional
       
    47 #					{includemacro}<macro>
       
    48 #					{excludemacro}<macro>
       
    49 #					{infeaturesetiby}<yes/no> - optional
       
    50 #					{comment}<comment>
       
    51 #
       
    52 
       
    53 #
       
    54 # Class constructor
       
    55 #
       
    56 sub new
       
    57 {
       
    58 	my $class = shift;
       
    59 	my $object = $class->SUPER::new();
       
    60 	
       
    61 	# Class members
       
    62 	$object->{_OBJNAME} = "FeatureManager"; # Name of the object
       
    63 	$object->{_FEAT_SET_LIST} = [];  # Array of <featureset> hash maps
       
    64 	$object->{_FEAT_LIST} = {};      # Hash map of all feature name with uid
       
    65 	$object->{_ALIAS_FEAT_LIST} = {}; # Hash map of all alias feature name with uid
       
    66 	return $object;
       
    67 }
       
    68 
       
    69 #
       
    70 # Private methods
       
    71 #
       
    72 
       
    73 # Private method to Get/Set the _FEAT_SET_LIST member value of this class
       
    74 # @param : reference to the array of <featureset> hash maps (optional for GET)
       
    75 #
       
    76 my $featuresetList = sub 
       
    77 {
       
    78 	my $object = shift; 
       
    79 	return 0 if(!&featureparser::ISREF($object,"featuresetList"));
       
    80 	
       
    81 	if (@_) 
       
    82 	{ 
       
    83 		$object->{_FEAT_SET_LIST} = shift; 
       
    84 	}
       
    85 	return $object->{_FEAT_SET_LIST};
       
    86 };
       
    87 
       
    88 # Private method to Get/Set the _FEAT_LIST member value of this class
       
    89 # @param : reference to the fash map of feature name with uid (optional for GET)
       
    90 #
       
    91 my $featureList = sub 
       
    92 {
       
    93 	my $object = shift; 
       
    94 	return 0 if(!&featureparser::ISREF($object,"featureList"));
       
    95 	
       
    96 	if (@_) 
       
    97 	{ 
       
    98 		$object->{_FEAT_LIST} = shift; 
       
    99 	}
       
   100 	return $object->{_FEAT_LIST};
       
   101 };
       
   102 # Private method ot Get/Set the _ALIAS_FEAT_LIST member value of this class
       
   103 # @param: reference to the hash map of alias feature name with uid
       
   104 my $aliasfeatureList = sub
       
   105 {
       
   106 	my $object = shift;
       
   107 	return 0 if(!&featureparser::ISREF($object, "aliasfeatureList"));
       
   108 
       
   109 	if(@_)
       
   110 	{
       
   111 		$object->{_ALIAS_FEAT_LIST} = shift;
       
   112 	}
       
   113 	return $object->{_ALIAS_FEAT_LIST};
       
   114 };
       
   115 
       
   116 # Read the attributes of <featureset> element
       
   117 # @param : reference to the featureset
       
   118 # @param : reference to the attributemap
       
   119 #
       
   120 my $fillFeatureSetAttributes = sub 
       
   121 {
       
   122 	my  $node = shift;
       
   123 	my  $map = shift;
       
   124 	$map->{ibyname} = &featureparser::getattrValue($node, "ibyname", STRICTCASE);
       
   125 	$map->{hfilename} = &featureparser::getattrValue($node, "hfilename", STRICTCASE);
       
   126 	$map->{namespace} = &featureparser::getattrValue($node, "namespace", STRICTCASE);
       
   127 };
       
   128 
       
   129 # Read the attributes of <hfileheader> element
       
   130 # @param : reference to the featureset
       
   131 # @param : reference to the attributemap
       
   132 #
       
   133 my $fillFileHeaderAttributes = sub 
       
   134 {
       
   135 	my $node = shift;
       
   136 	my $map = shift;
       
   137 	my @attribSet =  &featureparser::getnodefromTree($node, "hfileheader");
       
   138 	
       
   139 	foreach my $att_node (@attribSet) 
       
   140 	{
       
   141 		$map->{interfacestatus} = &featureparser::getattrValue($att_node, "interfacestatus",STRICTCASE);
       
   142 		$map->{interfacevisibility} = &featureparser::getattrValue($att_node, "interfacevisibility",STRICTCASE);
       
   143 		$map->{hfileheader} = &featureparser::getelementValue($att_node,STRICTCASE);
       
   144 	}
       
   145 };
       
   146 
       
   147 # Read the attributes of <feature> element
       
   148 # @param : reference to the featureset
       
   149 # @param : reference to the attributemap
       
   150 #
       
   151 my $fillFeatureAttributes = sub 
       
   152 {
       
   153 	my $node = shift; my $map = shift;
       
   154 	
       
   155 	my @attribSet =  &featureparser::getnodefromTree($node, "feature");
       
   156 	
       
   157 	my %nameUidMap = ();
       
   158 	foreach my $att_node (@attribSet)
       
   159 	{
       
   160 		my ($uid_value, $feat_name, $attval);
       
   161 		my (@macroSet, @commentSet);
       
   162 		my %featureHash = ();
       
   163 		
       
   164 		#Read the feature name and its other attributes
       
   165 		$feat_name = &featureparser::getattrValue($att_node, "name",STRICTCASE);
       
   166 		
       
   167 		# Validate Name
       
   168 		if(!$feat_name) {
       
   169 			&featureparser::ERROR("Feature name attribute is empty");
       
   170 			return 0;
       
   171 		}
       
   172 		if(exists $nameUidMap{lc($feat_name)}) {
       
   173 			&featureparser::ERROR("Feature entry \"".$feat_name."\" already exists");
       
   174 			return 0;
       
   175 		}
       
   176 		
       
   177 		#Read the uid value
       
   178 		$uid_value = &featureparser::getattrValue($att_node, "uid");
       
   179 		if(!&featureparser::IsValidNum($uid_value)) {
       
   180 			&featureparser::ERROR("Valid hexadecimal or decimal value expected in UID entry for \"$feat_name\"");
       
   181 			return 0;
       
   182 		}
       
   183 		$uid_value = &featureparser::ConvertHexToDecimal($uid_value);
       
   184 		if((defined $map->{feature}) && (exists $map->{feature}{$uid_value})) {
       
   185 			&featureparser::ERROR("UID entry for \"".$feat_name."\" already exists");
       
   186 			return 0;
       
   187 		}
       
   188 		
       
   189 		$attval = &featureparser::getattrValue($att_node, "statusflags");
       
   190 		if(!&featureparser::IsValidNum($attval)) {
       
   191 			&featureparser::ERROR("Valid hexadecimal or decimal value expected in STATUS_FLAGS entry for \"$feat_name\"");
       
   192 			return 0;
       
   193 		}
       
   194 		$featureHash{statusflags} = $attval;
       
   195 		
       
   196 		$attval = &featureparser::getattrValue($att_node, "userdata");
       
   197 		if(defined $attval) {
       
   198 			if(!&featureparser::IsValidNum($attval)) {
       
   199 				&featureparser::ERROR("Valid hexadecimal or decimal value expected in USER_DATA entry for \"$feat_name\"");
       
   200 				return 0;
       
   201 			}
       
   202 		}
       
   203 		$featureHash{name} = $feat_name;
       
   204 		$featureHash{userdata} = $attval;
       
   205 		
       
   206 		#Read the attributes of <hrhmacro> element
       
   207 		@macroSet = &featureparser::getnodefromTree($att_node, "hrhmacro");
       
   208 		foreach my $nodeMac (@macroSet) {
       
   209 			$featureHash{includemacro} = &featureparser::getattrValue($nodeMac,"include",STRICTCASE);
       
   210 			$featureHash{excludemacro} = &featureparser::getattrValue($nodeMac,"exclude",STRICTCASE);
       
   211 			
       
   212 			#Read the attribute infeaturesetiby
       
   213 			$attval = &featureparser::getattrValue($nodeMac,"infeaturesetiby");
       
   214 			if(($attval eq undef) or (lc($attval) eq "yes")) {
       
   215 				$featureHash{infeaturesetiby} = 1;
       
   216 			}
       
   217 			elsif(lc($attval) eq "no") {
       
   218 				$featureHash{infeaturesetiby} = 0;
       
   219 			}
       
   220 			else {
       
   221 				&featureparser::ERROR("(yes|no) value expected in infeaturesetiby attribute for \"$feat_name\"");
       
   222 				return 0;
       
   223 			}
       
   224 		}
       
   225 		
       
   226 		#Read the <comment> element value
       
   227 		@commentSet = &featureparser::getnodefromTree($att_node, "comment");
       
   228 		foreach my $nodeCmt (@commentSet) {
       
   229 			$featureHash{comment} =  &featureparser::getelementValue($nodeCmt,STRICTCASE);
       
   230 		}
       
   231 		
       
   232 		#Add an entry to name->uid map for this feature
       
   233 		$nameUidMap{lc($feat_name)} = $uid_value;
       
   234 		#Add an entry to the global hash map with all the attributes of this feature
       
   235 		$map->{feature}{$uid_value} = \%featureHash;
       
   236 	}
       
   237 	
       
   238 	$map->{feature_list} = \%nameUidMap;
       
   239 	
       
   240 	return 1;
       
   241 };
       
   242 my $fillAliasAttributes = sub
       
   243 {
       
   244 	my $node = shift;
       
   245 	my $map = shift;
       
   246 	my %aliasnameUidMap = ();
       
   247 	my $featureList = $map->{feature_list};
       
   248 	my @attribSet = &featureparser::getnodefromTree($node, "featureoverride");
       
   249 	foreach my $att_node (@attribSet)
       
   250 	{
       
   251 		my ($uid_value, $alias_name, $feat_name, $attval);
       
   252 		my (@macroSet, @commentSet);
       
   253 		my %featureHash = ();
       
   254 		#read the alias name 
       
   255 		$alias_name = &featureparser::getattrValue($att_node, "name", STRICTCASE);
       
   256 		if(!$alias_name)
       
   257 		{
       
   258 			&featureparser::ERROR("Featureoverride name attribute is empty");
       
   259 			return 0;
       
   260 		}
       
   261 		if(exists $featureList->{lc($alias_name)})
       
   262 		{
       
   263 			&featureparser::ERROR("Can't override <feature> \"".sprintf("0x%08x", $featureList->{lc($alias_name)})."\" in the same <featureset>");
       
   264 			return 0;
       
   265 		}
       
   266 		if(exists $aliasnameUidMap{lc($alias_name)})
       
   267 		{
       
   268 			&featureparser::ERROR("Can't override <featureoverride> \"".sprintf("0x%08x", $aliasnameUidMap{lc($alias_name)})."\" in the same <featureset>");
       
   269 			return 0;
       
   270 		}
       
   271 		$uid_value = &featureparser::getattrValue($att_node, "uid");
       
   272 		if(!&featureparser::IsValidNum($uid_value))
       
   273 		{
       
   274 			&featureparser::ERROR("Valid hexadecimal or decimal value expected in UID entry for \"$alias_name\"");
       
   275 			return 0;
       
   276 		}
       
   277 		$uid_value = &featureparser::ConvertHexToDecimal($uid_value);
       
   278 		if((defined $map->{alias_feature}) && (exists $map->{alias_feature}{$uid_value}))
       
   279 		{
       
   280 			&featureparser::ERROR("Can't override <featureoverride> \"".sprintf("0x%08x", $uid_value)."\" in the same <featureset>");
       
   281 			return 0;
       
   282 		}
       
   283 		if((defined $map->{feature}) && (exists $map->{feature}{$uid_value}))
       
   284 		{
       
   285 			&featureparser::ERROR("Can't override <feature> \"".sprintf("0x%08x", $uid_value)."\" in the same <featureset>");
       
   286 			return 0;
       
   287 		}
       
   288 		$attval = &featureparser::getattrValue($att_node, "statusflags");
       
   289 		if(defined $attval)
       
   290 		{
       
   291 			if(!&featureparser::IsValidNum($attval))
       
   292 			{
       
   293 				&featureparser::ERROR("Valid hexadecimal or decimal value expected in STATUS_FLAGS entry for \"$alias_name\"");
       
   294 				return 0;
       
   295 			}
       
   296 		}
       
   297 		$featureHash{statusflags} = $attval;
       
   298 
       
   299 		$attval = &featureparser::getattrValue($att_node, "userdata");
       
   300 		if(defined $attval)
       
   301 		{
       
   302 			if(!&featureparser::IsValidNum($attval))
       
   303 			{
       
   304 				&featureparser::ERROR("Valid hexadecimal or decimal value expected in USER_DATA entry for \"$alias_name\"");
       
   305 				return 0;
       
   306 			}
       
   307 		}
       
   308 
       
   309 		$featureHash{uid} = $uid_value;
       
   310 		$featureHash{name} = $alias_name;
       
   311 		$featureHash{userdata} = $attval;
       
   312 		#read the attributes of <hrhmacro> element
       
   313 		@macroSet = &featureparser::getnodefromTree($att_node,"hrhmacro");
       
   314 		foreach my $nodeMac (@macroSet) 
       
   315 		{
       
   316 			$featureHash{includemacro} = &featureparser::getattrValue($nodeMac, "include", STRICTCASE);
       
   317 			$featureHash{excludemacro} = &featureparser::getattrValue($nodeMac, "exclude", STRICTCASE);
       
   318 			#read the attribute infeaturesetiby
       
   319 			$attval = &featureparser::getattrValue($nodeMac, "infeaturesetiby");
       
   320 			if(($attval eq undef) or (lc($attval) eq "yes"))
       
   321 			{
       
   322 				$featureHash{infeaturesetiby} = 1;
       
   323 			}
       
   324 			elsif(lc($attval) eq "no")
       
   325 			{
       
   326 				$featureHash{infeaturesetiby} = 0;
       
   327 			}
       
   328 			else
       
   329 			{
       
   330 				&featureparser::ERROR("(yes|no) value expected in infeaturesetiby attribute for \"$feat_name\"");
       
   331 				return 0;
       
   332 			}
       
   333 		}
       
   334 		#read the <comment> element value
       
   335 		@commentSet = &featureparser::getnodefromTree($att_node, "comment");
       
   336 		foreach my $nodeCmt (@commentSet)
       
   337 		{
       
   338 			$featureHash{comment} = &featureparser::getelementValue($nodeCmt, STRICTCASE);
       
   339 		}
       
   340 		#add an entry to alias->uid map for this feature
       
   341 		$aliasnameUidMap{lc($alias_name)} = $uid_value;
       
   342 		#add an entry to the global hash map with all the attributes of this alias feature
       
   343 		$map->{alias_feature}{$uid_value} = \%featureHash;
       
   344 	}
       
   345 	$map->{alias_feature_list} = \%aliasnameUidMap;
       
   346 
       
   347 	return 1;
       
   348 };
       
   349 
       
   350 #
       
   351 # Public methods
       
   352 #
       
   353 
       
   354 sub getAliasFeatureList
       
   355 {
       
   356 	my $object = shift; 
       
   357 	return 0 if(!&featureparser::ISREF($object,"getAliasFeatureList"));
       
   358 	
       
   359 	my $aliasfeatlist = $object->$aliasfeatureList();
       
   360 	return $aliasfeatlist;
       
   361 }
       
   362 # To get the status flag attribute value of the given feature
       
   363 # @param : feature name
       
   364 #
       
   365 sub getStatusFlag
       
   366 {
       
   367 	my $object = shift; 
       
   368 	return 0 if(!&featureparser::ISREF($object,"getStausFlag"));
       
   369 	
       
   370 	my $name = shift;
       
   371 	my $namespace = shift;
       
   372 	my $uid = $object->getFeatureUID($name, $namespace);
       
   373 	if($uid)
       
   374 	{
       
   375 		my $feature = $object->getFeatureInfo($uid, $namespace);
       
   376 		
       
   377 		return ($feature->{statusflags}) if(exists $feature->{statusflags});
       
   378 	}
       
   379 	
       
   380 	return undef;
       
   381 }
       
   382 
       
   383 # To get the user data attribute value of the given feature
       
   384 # @param : feature name
       
   385 #
       
   386 sub getUserData
       
   387 {
       
   388 	my $object = shift; 
       
   389 	return 0 if(!&featureparser::ISREF($object,"getUserData"));
       
   390 	
       
   391 	my $name = shift;
       
   392 	my $namespace = shift;
       
   393 	my $uid = $object->getFeatureUID($name, $namespace);
       
   394 	if($uid)
       
   395 	{
       
   396 		my $feature = $object->getFeatureInfo($uid, $namespace);
       
   397 		
       
   398 		return ($feature->{userdata}) if(exists $feature->{userdata});
       
   399 	}
       
   400 	
       
   401 	return undef;
       
   402 }
       
   403 
       
   404 # To get the include macro attribute value of the given feature
       
   405 # @param : feature name
       
   406 #
       
   407 sub getIncludeMacro
       
   408 {
       
   409 	my $object = shift; 
       
   410 	return 0 if(!&featureparser::ISREF($object,"getIncludeMacro"));
       
   411 	
       
   412 	my $name = shift;
       
   413 	my $uid = $object->getfeatureUID($name);
       
   414 	if($uid)
       
   415 	{
       
   416 		my $feature = $object->getfeatureInfo($uid);
       
   417 		return $feature->{includemacro};
       
   418 	}
       
   419 	
       
   420 	return undef;
       
   421 }
       
   422 
       
   423 # To get the exclude macro attribute value of the given feature
       
   424 # @param : feature name
       
   425 #
       
   426 sub getExcludeMacro
       
   427 {
       
   428 	my $object = shift; 
       
   429 	return 0 if(!&featureparser::ISREF($object,"getExcludeMacro"));
       
   430 	
       
   431 	my $name = shift;
       
   432 	my $uid = $object->getfeatureUID($name);
       
   433 	if($uid)
       
   434 	{
       
   435 		my $feature = $object->getfeatureInfo($uid);
       
   436 		return $feature->{excludemacro};
       
   437 	}
       
   438 	
       
   439 	return undef;
       
   440 }
       
   441 
       
   442 # Return the feature uid for the given feature name.
       
   443 # @param : Feature Name
       
   444 # @param : namespace of the featureset (optional)
       
   445 #
       
   446 sub getFeatureUID
       
   447 {
       
   448 	my $object = shift; 
       
   449 	return 0 if(!&featureparser::ISREF($object,"getFeatureUID"));
       
   450 	
       
   451 	my $feature = shift;
       
   452 	my $namespace = shift;
       
   453 	my $featuresetList = $object->$featuresetList;
       
   454 	
       
   455 	$feature = lc($feature);
       
   456 	if($namespace eq undef)	{
       
   457 		if(exists $$featuresetList[0]->{feature_list}{$feature}) {
       
   458 			return $$featuresetList[0]->{feature_list}{$feature};
       
   459 		}
       
   460 		if(exists $$featuresetList[0]->{alias_feature_list}{$feature}) {
       
   461 			return $$featuresetList[0]->{alias_feature_list}{$feature};
       
   462 		}
       
   463 	}
       
   464 	else {
       
   465 		foreach my $node (@$featuresetList)
       
   466 		{
       
   467 			if((lc($node->{namespace}) eq lc($namespace)) && ((exists $node->{feature_list}{$feature})||(exists $node->{alias_feature_list}{$feature}))) {
       
   468 				return $node->{feature_list}{$feature} if (exists $node->{feature_list}{$feature});
       
   469 				return $node->{alias_feature_list}{$feature} if (exists $node->{alias_feature_list}{$feature});
       
   470 			}
       
   471 		}
       
   472 	}
       
   473 	foreach my $node (@$featuresetList) {
       
   474 		return $node->{feature_list}{$feature} if(exists $node->{feature_list}{$feature});
       
   475 		return $node->{alias_feature_list}{$feature} if(exists $node->{alias_feature_list}{$feature});
       
   476 	}
       
   477 	return undef;
       
   478 }
       
   479 
       
   480 # Get the details of feature with given featureuid and other parameters
       
   481 # This function only consider the feature UID only and that UID should be in decimal
       
   482 # @param : Feature UID
       
   483 # @param : namespace of the featureset (optional)
       
   484 #
       
   485 sub getFeatureInfo
       
   486 {
       
   487 	my $object = shift; 
       
   488 	return 0 if(!&featureparser::ISREF($object,"getFeatureInfo"));
       
   489 	
       
   490 	my $uid = shift;
       
   491 	my $namespace = shift;
       
   492 	my $featuresetList = $object->$featuresetList;
       
   493 
       
   494 	if($namespace eq undef)	{
       
   495 		foreach my $node (@$featuresetList) {
       
   496 			return $node->{alias_feature}{$uid} if(exists $node->{alias_feature}{$uid});
       
   497 		}
       
   498 		if(exists $$featuresetList[0]->{feature}{$uid}) {
       
   499 			return $$featuresetList[0]->{feature}{$uid};
       
   500 		}
       
   501 		if(exists $$featuresetList[0]->{alias_feature}{$uid}) {
       
   502 			return $$featuresetList[0]->{alias_feature}{$uid};
       
   503 		}
       
   504 	}
       
   505 	else {
       
   506 		foreach my $node (@$featuresetList)
       
   507 		{
       
   508 			if((lc($node->{namespace}) eq lc($namespace)) && ((exists $node->{feature}{$uid})||(exists $node->{alias_feature}{$uid}))) {
       
   509 				return $node->{feature}{$uid} if (exists $node->{feature}{$uid});
       
   510 				return $node->{alias_feature}{$uid} if (exists $node->{alias_feature}{$uid});
       
   511 			}
       
   512 		}
       
   513 	}
       
   514 	foreach my $node (@$featuresetList) {
       
   515 		return $node->{feature}{$uid} if(exists $node->{feature}{$uid});
       
   516 	}
       
   517 	return undef;
       
   518 }
       
   519 
       
   520 
       
   521 # Get the Feature set info as a hash
       
   522 # @param: namespace of the featureset
       
   523 #
       
   524 sub getFeaturesetInfo 
       
   525 {
       
   526 	my $object = shift; 
       
   527 	return 0 if(!&featureparser::ISREF($object,"getFeaturesetInfo"));
       
   528 	
       
   529 	my $namespace = shift;
       
   530 	
       
   531 	my $featuresetList = $object->$featuresetList;
       
   532 	if($namespace eq undef)	{
       
   533 		if(exists $$featuresetList[0]) {
       
   534 			return $$featuresetList[0];
       
   535 		}
       
   536 	}
       
   537 	else {
       
   538 		foreach my $node (@$featuresetList)
       
   539 		{
       
   540 			if((lc($node->{namespace}) eq lc($namespace))) {
       
   541 				return $node;
       
   542 			}
       
   543 		}
       
   544 	}
       
   545 	return undef;
       
   546 }
       
   547 
       
   548 # Get the Featureset namespaces as an array
       
   549 #
       
   550 sub getFeatureset
       
   551 {
       
   552 	my $object = shift; 
       
   553 	return 0 if(!&featureparser::ISREF($object,"getFeatureset"));
       
   554 	
       
   555 	my @featureSet=();
       
   556 	
       
   557 	my $featuresetList = $object->$featuresetList;
       
   558 	foreach my $node (@$featuresetList) {
       
   559 		push @featureSet, $node;
       
   560 	}
       
   561 	return \@featureSet;
       
   562 }
       
   563 
       
   564 # Add feature registry object contents to feature manager object
       
   565 # @param : feature registry object
       
   566 #
       
   567 sub addFeatureRegistry
       
   568 {
       
   569 	my $object = shift; 
       
   570 	return 0 if(!&featureparser::ISREF($object,"addFeatureRegistry"));
       
   571 	
       
   572 	my $registryobj = shift;
       
   573 	my %attribHash = ();
       
   574 	my $nameuidmap;
       
   575 	my $newRangeList;
       
   576 	my $rangeList;
       
   577 	
       
   578 	# Adding default range list
       
   579 	$newRangeList = $registryobj->defaultRangeList();
       
   580 	$rangeList = $object->defaultRangeList();
       
   581 
       
   582 	foreach my $newnode (@$newRangeList) {
       
   583 		my $include = 1;
       
   584 		foreach my $node (@$rangeList) { #Check if the range is already exists
       
   585 			if(($node->{min} == $newnode->{min}) && ($node->{max} == $newnode->{max}) 
       
   586 				&& ($node->{support} eq $newnode->{support})) {
       
   587 				$include = 0;
       
   588 			}
       
   589 		}
       
   590 		
       
   591 		if($include) { # Add it if it is new range
       
   592 			push @$rangeList, $newnode;
       
   593 			$object->defaultIncludeCount($object->defaultIncludeCount()+1) if(lc($newnode->{support}) eq "include");
       
   594 			$object->defaultExcludeCount($object->defaultExcludeCount()+1) if(lc($newnode->{support}) eq "exclude");
       
   595 		}
       
   596 	}
       
   597 	
       
   598 	# Adding feature list
       
   599 	$nameuidmap = $registryobj->featureNameUidMap();
       
   600 	$attribHash{namespace} = undef;
       
   601 	$attribHash{feature_list} = $nameuidmap;
       
   602 	
       
   603 	foreach my $name (keys %$nameuidmap) {
       
   604 		my $uid = $nameuidmap->{$name};
       
   605 		my %featureinfo = ();
       
   606 		
       
   607 		$featureinfo{name} = $name;
       
   608 		# Default values for statusflags and userdata
       
   609 		$featureinfo{statusflags} = "0x00000001";
       
   610 		$featureinfo{userdata} = "0x00000000";
       
   611 		
       
   612 		$attribHash{feature}{$uid} = \%featureinfo;
       
   613 	}
       
   614 	
       
   615 	# add the featureset into the feature manager object
       
   616 	return 0 if(! &addFeatureSet($object, \%attribHash));
       
   617 
       
   618 	return 1;
       
   619 }
       
   620 
       
   621 #
       
   622 # Utility functions
       
   623 #
       
   624 # Add the featureset into the hash map
       
   625 # @param : reference to the atrribute hash map of featureset
       
   626 #
       
   627 sub addFeatureSet
       
   628 {
       
   629 	my $object = shift; 
       
   630 	return 0 if(!&featureparser::ISREF($object,"addFeatureSet"));
       
   631 	
       
   632 	my $newSet = shift;
       
   633 	my $featSetList = $object->$featuresetList();
       
   634 	my $newfeatList = $newSet->{feature_list};
       
   635 	my $newaliasfeatList = $newSet->{alias_feature_list};
       
   636 
       
   637 	# Check for the duplicate featue names in the existing list
       
   638 	foreach my $name (keys %$newfeatList)
       
   639 	{
       
   640 		if(exists $object->$featureList()->{$name})
       
   641 		{
       
   642 			&featureparser::ERROR("\(".$object->fileName()."\) Feature \"".uc($name)."\" already exists");
       
   643 			return 0;
       
   644 		}
       
   645 		else
       
   646 		{
       
   647 			my $uid = $newfeatList->{$name};
       
   648 			$object->$featureList()->{$name} = $uid; #Add it to global featue name list
       
   649 		}
       
   650 	}
       
   651 	
       
   652 	# Check for the duplicate UIDs in the existing list
       
   653 	if(@$featSetList) 
       
   654 	{	
       
   655 		foreach my $set (@$featSetList)
       
   656 		{
       
   657 			foreach my $name (keys %$newfeatList)
       
   658 			{
       
   659 				my $uid = $newfeatList->{$name};
       
   660 				if(exists $set->{feature}{$uid})
       
   661 				{
       
   662 					&featureparser::ERROR("\(".$object->fileName()."\) UID \"".sprintf("0x%08x",$uid)."\" for the feature \"".uc($name)."\" already exists");
       
   663 					return 0;
       
   664 				}
       
   665 			}
       
   666 		}
       
   667 	}
       
   668 	#check for the duplicate alias feature names in the existing list
       
   669 	foreach my $alias_name (keys %$newaliasfeatList)
       
   670 	{
       
   671 		if(exists $object->$featureList()->{$alias_name})
       
   672 		{
       
   673 			&featureparser::ERROR("\(".$object->fileName."\) Can't override <feature> \"".sprintf("0x%08x", $newaliasfeatList->{$alias_name})."\" with the same feature name ".$alias_name);
       
   674 			return 0;
       
   675 
       
   676 		}
       
   677 		if(exists $object->$aliasfeatureList()->{$alias_name})
       
   678 		{
       
   679 			&featureparser::ERROR("\(".$object->fileName."\) Can't override <featureoverride> \"".sprintf("0x%08x", $newaliasfeatList->{$alias_name})."\" with the same feature name ".$alias_name);
       
   680 			return 0;
       
   681 		}
       
   682 		else
       
   683 		{
       
   684 			my $uid = $newaliasfeatList->{$alias_name};
       
   685 			# add it to global alias feature name list
       
   686 			$object->$aliasfeatureList()->{$alias_name} = $uid;
       
   687 		}
       
   688 	}
       
   689 	#check if the original feature has existed in other feature set.
       
   690 	foreach my $alias_name (keys %$newaliasfeatList)
       
   691 	{
       
   692 		my $featHash;
       
   693 		my $uid = $newaliasfeatList->{$alias_name};
       
   694 		foreach my $set (@$featSetList)
       
   695 		{
       
   696 			if(exists $set->{feature}{$uid})
       
   697 			{
       
   698 				$featHash = $set->{feature}{$uid};
       
   699 				last;
       
   700 			}
       
   701 			if(exists $set->{alias_feature}{$uid})
       
   702 			{
       
   703 				$featHash = $set->{alias_feature}{$uid};
       
   704 				last;
       
   705 			}
       
   706 		}
       
   707 		if(!$featHash)
       
   708 		{
       
   709 			&featureparser::ERROR("original feature definition does not exist.");
       
   710 			return 0;
       
   711 		}
       
   712 
       
   713 		my $aliasfeatHash = $newSet->{alias_feature}{$uid};
       
   714 
       
   715 		if(($aliasfeatHash->{includemacro}) || ($aliasfeatHash->{excludemacro}))
       
   716 		{
       
   717 			if(($featHash->{includemacro}) || ($featHash->{excludemacro}))
       
   718 			{
       
   719 				&featureparser::WARN("the value of attribute hrhmacro has been overrided in ogrinal feature ".sprintf("0x%08x", $uid));
       
   720 				undef $featHash->{includemacro};
       
   721 				undef $featHash->{excludemacro};
       
   722 			}
       
   723 		}
       
   724 		elsif($featHash->{includemacro} || $featHash->{excludemacro})
       
   725 		{
       
   726 			&featureparser::WARN("the original value of attribute hrhmacro will be used for featureoverride ".sprintf("0x%08x", $uid));
       
   727 			$aliasfeatHash->{includemacro} = $featHash->{includemacro};
       
   728 			$aliasfeatHash->{excludemacro} = $featHash->{excludemacro};
       
   729 		}
       
   730 		if($aliasfeatHash->{statusflags})
       
   731 		{
       
   732 			if(($featHash->{statusflags}) && !($aliasfeatHash->{statusflags} eq $featHash->{statusflags}))
       
   733 			{
       
   734 				&featureparser::WARN("the value of attribute statusflags has been overrided in ogrinal feature ".sprintf("0x%08x", $uid));
       
   735 			}
       
   736 		}
       
   737 		elsif($featHash->{statusflags})
       
   738 		{
       
   739 			$aliasfeatHash->{statusflags} = $featHash->{statusflags};
       
   740 			&featureparser::WARN("the original value of attribute statusflags will be used for featureoverride ".sprintf("0x%08x", $uid));
       
   741 		}
       
   742 		if($aliasfeatHash->{userdata})
       
   743 		{
       
   744 			if(($featHash->{userdata}) && !($aliasfeatHash->{userdata} eq $featHash->{userdata}))
       
   745 			{
       
   746 				&featureparser::WARN("the value of attribute userdata has been overrided in ogrinal feature ".sprintf("0x%08x", $uid));
       
   747 			}
       
   748 		}
       
   749 		elsif($featHash->{userdata})
       
   750 		{
       
   751 			$aliasfeatHash->{userdata} = $featHash->{userdata};
       
   752 			&featureparser::WARN("the original value of attribute userdata will be used for featureoverride ".sprintf("0x%08x", $uid));
       
   753 		}
       
   754 		if($aliasfeatHash->{infeaturesetiby})
       
   755 		{
       
   756 			if(($featHash->{infeaturesetiby}) && ($aliasfeatHash->{infeaturesetiby} != $featHash->{infeaturesetiby}))
       
   757 			{
       
   758 				&featureparser::WARN("the value of attribute infeautresetiby has been overrided in ogrinal feature ".sprintf("0x%08x", $uid));
       
   759 			}
       
   760 		}
       
   761 		elsif(defined($featHash->{infeaturesetiby}))
       
   762 		{
       
   763 			$aliasfeatHash->{infeaturesetiby} = $featHash->{infeaturesetiby};
       
   764 			&featureparser::WARN("the original value of attribute infewaturesetiby will be used for featureoverride ".sprintf("0x%08x", $uid));
       
   765 		}
       
   766 	}
       
   767 	# Add the unique featureset into the list
       
   768 	push @$featSetList, $newSet;
       
   769 	return 1;
       
   770 }
       
   771 
       
   772 # Read the <featureset> element
       
   773 # 
       
   774 sub createFeatureMap
       
   775 {
       
   776 	my $object = shift; 
       
   777 	return 0 if(!&featureparser::ISREF($object,"createFeatureMap"));
       
   778 	
       
   779 	# Return error if the rootelement reference is NULL
       
   780 	return 0 if($object->rootElement() < 0);
       
   781 	
       
   782 	# Get all the <featureset> elements
       
   783 	my @attrSet =  &featureparser::getnodefromTree($object->rootElement(), "featureset");
       
   784 	
       
   785 	if(@attrSet)
       
   786 	{
       
   787 		foreach my $currNode (@attrSet)
       
   788 		{
       
   789 			my %attrHashMap = ();
       
   790 			
       
   791 			# Get the <featureset> attributes
       
   792 			$fillFeatureSetAttributes->($currNode,\%attrHashMap);
       
   793 			# Get the <hfileheader> attributes
       
   794 			$fillFileHeaderAttributes->($currNode,\%attrHashMap);
       
   795 			
       
   796 			# Get the <feature> attributes
       
   797 			return 0 if( !($fillFeatureAttributes->($currNode,\%attrHashMap)) );
       
   798 			# Get the <alias> attributes
       
   799 			return 0 if( !($fillAliasAttributes->($currNode, \%attrHashMap)) );
       
   800 			
       
   801 			# Add the featureset into the object
       
   802 			if(! &addFeatureSet($object,\%attrHashMap))
       
   803 			{
       
   804 				return 0;
       
   805 			}
       
   806 		}
       
   807 		return 1;
       
   808 	}
       
   809 	return 0;
       
   810 }
       
   811 
       
   812 # Read the <defaultfeaturerange> element
       
   813 #
       
   814 sub createDefaultRangeMap
       
   815 {
       
   816 	my $object = shift; 
       
   817 	return 0 if(!&featureparser::ISREF($object,"createDefaultRangeMap"));
       
   818 	
       
   819 	# Return error if the rootelement reference is NULL
       
   820 	return 0 if($object->rootElement() < 0);
       
   821 	
       
   822 	# Get all the <defaultfeaturerange> elements
       
   823 	my @attrSet =  &featureparser::getnodefromTree($object->rootElement(), "defaultfeaturerange");
       
   824 	
       
   825 	# Add the defaultfeaturerange elements into the object
       
   826 	return &featureparser::createDefaultRangeMap($object,@attrSet);
       
   827 }
       
   828 
       
   829 # Read the attributes of the <defaultfeaturerange> element
       
   830 # @param - <defaultfeaturerange> node reference
       
   831 # @param - reference to the range attributes
       
   832 #
       
   833 sub readRangeAttributes
       
   834 {
       
   835 	my ($object, $currNode, $range) = @_; 
       
   836 	my @commentSet;
       
   837 	return 0 if(!&featureparser::ISREF($object,"readRangeAttributes"));	
       
   838 	
       
   839 	#Get the lower and higher uids
       
   840 	$range->{min} = &featureparser::getattrValue($currNode, "loweruid");
       
   841 	$range->{max} = &featureparser::getattrValue($currNode, "higheruid");
       
   842 
       
   843  	#Always supported/included for FM. Keep this value for compatible with FR
       
   844  	$range->{support} = "include";
       
   845 	#Read the <comment> element
       
   846 	@commentSet = &featureparser::getnodefromTree($currNode, "comment");
       
   847 	foreach my $node (@commentSet) {
       
   848 		$range->{comment} =  &featureparser::getelementValue($node,STRICTCASE);
       
   849 	}
       
   850 }
       
   851 
       
   852 1;