featuremgmt/featuremgr/tools/datfilehelpers/CreateFeatExample.pl
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 #!perl -w
       
     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 "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 # This simple script shows how simple it is to create a feature set data file
       
    16 # using the 'FMCreate', 'FeatureFlag' and 'FeatureDSR' classes.
       
    17 # 
       
    18 #
       
    19 
       
    20 use strict;
       
    21 use fmcreate;
       
    22 use featureflag;
       
    23 use featuredsr;
       
    24 
       
    25 #
       
    26 # First create a 'FMCreate' object. Note that the typefield defaults to "feat",
       
    27 # the fileversion defaults to '1', fileflags to '0'. Initially it contains no
       
    28 # feature flags or default supported ranges.
       
    29 #
       
    30 my $fmc = FMCreate->new();
       
    31 die "Couldn't create an 'FMCreate' object" unless(ref($fmc));
       
    32 
       
    33 #
       
    34 # Now we can do all sorts of things with this object - for example populating
       
    35 # it from an existing file (using the LoadUp method). But let's populate it
       
    36 # manually..
       
    37 #
       
    38 
       
    39 #
       
    40 # Create a feature flag object. The arguments are UID, status flag (defaults
       
    41 # to zero) and user data word. 
       
    42 #
       
    43 my $ff = FeatureFlag->new(0xabcd1234, undef, 0xf00df00d);
       
    44 die "Couldn't create a 'FeatureFlag' object" unless(ref($ff));
       
    45 
       
    46 #
       
    47 # Change some bits in the status flags.
       
    48 #
       
    49 $ff->Modifiable(1);
       
    50 $ff->BlackListed(0);
       
    51 $ff->Uninitialized(1);
       
    52 
       
    53 # Hey, I've decided I don't like the user data word (0xf00df00d) we defined
       
    54 # when we created $ff, so lets change it..
       
    55 $ff->UserData(0x12344331);
       
    56 
       
    57 # We need to add the feature flag to the 'FMCreate' object - they aren't tied
       
    58 # in any way yet. 
       
    59 $fmc->AddFeatureFlag($ff);
       
    60 
       
    61 # Create another FeatureFlag. We can't re-use the '$ff' object (without doing
       
    62 # another 'new') because '$fmc' owns it now and holds a reference to it.
       
    63 # This line creates a totally separate FeatureFlag object which we can set up
       
    64 # in any way we like - but we must remember to add it to '$fmc'.
       
    65 
       
    66 $ff = FeatureFlag->new(0xfedcba98);
       
    67 $fmc->AddFeatureFlag($ff);
       
    68 
       
    69 # Modify $ff - this is already in '$fmc' but that's ok - perhaps we want to
       
    70 # modify one that's already in.
       
    71 $ff->UserData(0x42);
       
    72 $ff->BlackListed(1);
       
    73 
       
    74 
       
    75 
       
    76 # Ok now create a couple of 'default supported range' objects. Again we
       
    77 # have to add these to the '$fmc' FMCreate object.
       
    78 my $dsr1 = FeatureDSR->new(0x10000000, 0x10000005);
       
    79 my $dsr2 = FeatureDSR->new(0x10000050, 0x10000055);
       
    80 die "Failed to create 'FeatureDSR' object"  unless(ref($dsr1) and ref($dsr2));
       
    81 
       
    82 # Add them in the wrong order to '$fmc'. Note that 'FMCreate' does not check
       
    83 # for duplicate default supported range objects (or FeatureFlag objects for
       
    84 # that matter).
       
    85 $fmc->AddFeatureDSR($dsr2);
       
    86 $fmc->AddFeatureDSR($dsr1);
       
    87 
       
    88 
       
    89 # OK, the FMCreate object '$fmc' is fairly well populated now. Lets display
       
    90 # the content.. There also are methods to just show the header information, the
       
    91 # FeatureFlag information and FeatureDSR information.
       
    92 $fmc->ShowALL();
       
    93 
       
    94 
       
    95 # Let's write the features to a binary file..
       
    96 print "\n\n\nWriting feature set data to 'featureset.dat'\n";
       
    97 $fmc->WriteToFile("featureset.dat")
       
    98 	   	or die "Couldn't write to feature set data file 'featureset.dat'\n";