commands/variant/variant.cpp
changeset 0 7f656887cf89
child 41 4a2ffd3562a3
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // variant.cpp
       
     2 // 
       
     3 // Copyright (c) 2008 - 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "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 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 #include <hal.h>
       
    14 #include "variant.h"
       
    15 #include <fshell/descriptorutils.h>
       
    16 
       
    17 //
       
    18 // CCmdVariant
       
    19 //
       
    20 CCommandBase* CCmdVariant::NewLC()
       
    21 	{
       
    22 	CCmdVariant* self = new (ELeave) CCmdVariant();
       
    23 	CleanupStack::PushL(self);
       
    24 	self->BaseConstructL();
       
    25 	return self;
       
    26 	}
       
    27 
       
    28 CCmdVariant::~CCmdVariant()
       
    29 	{
       
    30 	iVariant.ResetAndDestroy();
       
    31 	}
       
    32 
       
    33 CCmdVariant::CCmdVariant() : 
       
    34 CCommandBase(CCommandBase::EManualComplete)
       
    35 	{
       
    36 	}
       
    37 
       
    38 const TDesC& CCmdVariant::Name() const
       
    39 	{
       
    40 	_LIT(KName, "variant");	
       
    41 	return KName;
       
    42 	}
       
    43 
       
    44 //
       
    45 // CCmdVariant::DoRunL
       
    46 // looks for a match between the variant uids specified via the command line and the
       
    47 // actual variant uid of the device
       
    48 //
       
    49 
       
    50 struct TVariant
       
    51 	{
       
    52 	TInt iUid;
       
    53 	LtkUtils::SLitC iName;
       
    54 	};
       
    55 
       
    56 // Only shipping products or established reference hardware platforms in here please.
       
    57 // Unannounced protos should have their platform build its own variant.exe to identify their hardware,
       
    58 // alternatively people have to rely on doing a "variant --uid xyz" whichever is preferred by the platform
       
    59 const TVariant KMachineIdVariants[] = {
       
    60 	{ 0x102734E3, DESC("h4") },
       
    61 	{ 0x10286564, DESC("h6") },
       
    62 	{ 0x102864F7, DESC("naviengine") },
       
    63 	{ 0x20002D82, DESC("n96") },
       
    64 	{ 0x20002496, DESC("e90") },
       
    65 	{ 0x20002D7E, DESC("6120") },
       
    66 	{ 0x20002D83, DESC("n81") },
       
    67 	{ 0x2000DA56, DESC("5800") },
       
    68 	{ 0x2001F0A1, DESC("satio") }, // I assume this is what it shipped with...
       
    69 	{ 0x20029a73, DESC("n8") }, // Likewise...
       
    70 	};
       
    71 const TInt KMachineIdVariantCount = sizeof(KMachineIdVariants) / sizeof(TVariant);
       
    72 
       
    73 void CCmdVariant::DoRunL()
       
    74 	{
       
    75 	if (iMachineId.Count() == 0 && iVariant.Count() == 0)
       
    76 		{
       
    77 		LeaveIfErr(KErrArgument, _L("You must specify at least one <variantname> argument or --uid option"));
       
    78 		}
       
    79 
       
    80 	TInt localMachineUid = GetMachineUidL();
       
    81 	TBool match = EFalse;
       
    82 	if (iMachineId.Count())
       
    83 		{
       
    84 		for (TInt i = 0; i < iMachineId.Count(); i++)
       
    85 			{
       
    86 			if (iMachineId[i] == (TUint)localMachineUid)
       
    87 				{
       
    88 				match = ETrue;
       
    89 				break;
       
    90 				}
       
    91 			}
       
    92 		}
       
    93 
       
    94 	if (iVariant.Count())
       
    95 		{
       
    96 		for (TInt i = 0; match == EFalse && i < iVariant.Count(); i++)
       
    97 			{
       
    98 			for (TInt j = 0; match == EFalse && j < KMachineIdVariantCount; j++)
       
    99 				{
       
   100 				if (iVariant[i]->CompareF(KMachineIdVariants[j].iName) == 0 && localMachineUid == KMachineIdVariants[j].iUid)
       
   101 					{
       
   102 					match = ETrue;
       
   103 					}
       
   104 				}
       
   105 #ifdef __WINS__
       
   106 			if (iVariant[i]->CompareF(_L("wins")) == 0) match = ETrue;
       
   107 #else
       
   108 			if (iVariant[i]->CompareF(_L("target")) == 0) match = ETrue;
       
   109 #endif
       
   110 			}
       
   111 		}
       
   112 
       
   113 	if (iVerbose)
       
   114 		{
       
   115 		if (match)
       
   116 			{
       
   117 			Printf(_L("Specified variant supported\r\n"));
       
   118 			}
       
   119 		else
       
   120 			{
       
   121 			PrintError(KErrNotSupported, _L("Specified variant not supported"));
       
   122 			}
       
   123 		}
       
   124 
       
   125 	SetErrorReported(ETrue); // Don't show the error
       
   126 	Complete(match ? KErrNone : KErrNotSupported);
       
   127 	}
       
   128 
       
   129 void CCmdVariant::ArgumentsL(RCommandArgumentList& aArguments)
       
   130 	{
       
   131 	aArguments.AppendStringL(iVariant, _L("variantname"));
       
   132 	}
       
   133 
       
   134 void CCmdVariant::OptionsL(RCommandOptionList& aOptions)
       
   135 	{
       
   136 	_LIT(KCmdOptUid, "uid");
       
   137 	aOptions.AppendUintL(iMachineId, KCmdOptUid);
       
   138 	_LIT(KOptVerbose, "verbose");
       
   139 	aOptions.AppendBoolL(iVerbose, KOptVerbose);
       
   140 	}
       
   141 
       
   142 //
       
   143 // CCmdVariant::GetMachineUidL
       
   144 // retrieve the variant's machine uid
       
   145 //
       
   146 TInt CCmdVariant::GetMachineUidL()
       
   147 	{
       
   148 	TInt value = KErrNotSupported;
       
   149 	User::LeaveIfError(HAL::Get(HALData::EMachineUid, value));
       
   150 	return value;
       
   151 	}
       
   152 	
       
   153 EXE_BOILER_PLATE(CCmdVariant)