commands/hal/hal.cpp
changeset 0 7f656887cf89
child 63 ea6622dea85a
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // hal.cpp
       
     2 // 
       
     3 // Copyright (c) 2009 - 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 <fshell/ioutils.h>
       
    14 #include <hal.h>
       
    15 #include <fshell/common.mmh>
       
    16 #include <fshell/ltkhal.h>
       
    17 
       
    18 using namespace IoUtils;
       
    19 
       
    20 _LIT(KDefaultDumpFileName, "c:\\private\\102825B1\\HAL.DAT");
       
    21 
       
    22 class CCmdHal : public CCommandBase
       
    23 	{
       
    24 public:
       
    25 	static CCommandBase* NewLC();
       
    26 	~CCmdHal();
       
    27 private:
       
    28 	CCmdHal();
       
    29 private: // From CCommandBase.
       
    30 	virtual const TDesC& Name() const;
       
    31 	virtual void DoRunL();
       
    32 	virtual void ArgumentsL(RCommandArgumentList& aArguments);
       
    33 	virtual void OptionsL(RCommandOptionList& aOptions);
       
    34 private:
       
    35 	enum 
       
    36 		{
       
    37 		EList,
       
    38 		EGet,
       
    39 		ESet,
       
    40 		EDumpFile
       
    41 		} iOperation;
       
    42 	HAL::TAttribute iAttribute;
       
    43 	TInt iValue;
       
    44 	TInt iDeviceNumber;
       
    45 	TFileName2 iDumpFileName;
       
    46 	};
       
    47 
       
    48 
       
    49 CCommandBase* CCmdHal::NewLC()
       
    50 	{
       
    51 	CCmdHal* self = new(ELeave) CCmdHal();
       
    52 	CleanupStack::PushL(self);
       
    53 	self->BaseConstructL();
       
    54 	return self;
       
    55 	}
       
    56 
       
    57 CCmdHal::~CCmdHal()
       
    58 	{
       
    59 	}
       
    60 
       
    61 CCmdHal::CCmdHal() : iDumpFileName(KDefaultDumpFileName)
       
    62 	{
       
    63 	}
       
    64 
       
    65 const TDesC& CCmdHal::Name() const
       
    66 	{
       
    67 	_LIT(KName, "hal");	
       
    68 	return KName;
       
    69 	}
       
    70 
       
    71 void CCmdHal::DoRunL()
       
    72 	{
       
    73 	switch (iOperation)
       
    74 		{
       
    75 		case EGet:
       
    76 			{
       
    77 			if (!iArguments.IsPresent(1))
       
    78 				{
       
    79 				LeaveIfErr(KErrArgument, _L("Attribute to get not specified"));
       
    80 				}
       
    81 			LtkUtils::CHalAttribute* attrib = NULL;
       
    82 			if (iOptions.IsPresent(&iDeviceNumber))
       
    83 				{
       
    84 				TRAPL(attrib = LtkUtils::GetHalInfoL(iDeviceNumber, iAttribute), _L("Couldn't get attribute value"));
       
    85 				}
       
    86 			else
       
    87 				{
       
    88 				TRAPL(attrib = LtkUtils::GetHalInfoL(iAttribute), _L("Couldn't get attribute value"));
       
    89 				}
       
    90 			Printf(_L("%S: %S\r\n"), &attrib->iAttributeName, attrib->iDescription);
       
    91 			delete attrib;
       
    92 			}
       
    93 			break;
       
    94 		case ESet:
       
    95 			{
       
    96 			if (!iArguments.IsPresent(1))
       
    97 				{
       
    98 				LeaveIfErr(KErrArgument, _L("Attribute to set not specified"));
       
    99 				}
       
   100 			if (!iArguments.IsPresent(2))
       
   101 				{
       
   102 				LeaveIfErr(KErrArgument, _L("Attribute value to set not specified"));
       
   103 				}
       
   104 			if (iOptions.IsPresent(&iDeviceNumber))
       
   105 				{
       
   106 				LeaveIfErr(HAL::Set(iDeviceNumber, iAttribute, iValue), _L("Couldn't set attribute"));
       
   107 				}
       
   108 			else
       
   109 				{
       
   110 				LeaveIfErr(HAL::Set(iAttribute, iValue), _L("Couldn't set attribute"));
       
   111 				}
       
   112 			}
       
   113 			break;
       
   114 		case EList:
       
   115 			{
       
   116 			RPointerArray<LtkUtils::CHalAttribute> attribs;
       
   117 			LtkUtils::GetHalInfoL(attribs);
       
   118 			for (TInt i = 0; i < attribs.Count(); ++i)
       
   119 				{
       
   120 				LtkUtils::CHalAttribute& attrib = *attribs[i];
       
   121 				Printf(_L("%4d %S: %S\r\n"), attrib.iAttribute, &attrib.iAttributeName, attrib.iDescription);
       
   122 				}
       
   123 			attribs.ResetAndDestroy();
       
   124 			}
       
   125 			break;
       
   126 		case EDumpFile:
       
   127 			{
       
   128 			if (!iOptions.IsPresent(&iDumpFileName))
       
   129 				{
       
   130 #ifdef FSHELL_9_1_SUPPORT
       
   131 				TInt ch = 'c';
       
   132 				HAL::Get(HAL::ESystemDrive, ch);
       
   133 				iDumpFileName[0] = 'A' + ch;
       
   134 #else
       
   135 				iDumpFileName[0] = 'A' + static_cast<TInt>(RFs::GetSystemDrive());
       
   136 #endif
       
   137 				}
       
   138 			RFile file;
       
   139 			LeaveIfErr(file.Open(FsL(), iDumpFileName, EFileRead), _L("Couldn't open \"%S\" for reading"), &iDumpFileName);
       
   140 			CleanupClosePushL(file);
       
   141 
       
   142 			TInt fileSize;
       
   143 			LeaveIfErr(file.Size(fileSize), _L("Couldn't find the size of \"%S\""), &iDumpFileName);
       
   144 
       
   145 			RBuf8 buf;
       
   146 			buf.Create(fileSize);
       
   147 			buf.CleanupClosePushL();
       
   148 
       
   149 			LeaveIfErr(file.Read(buf), _L("Couldn't read \"%S\""), &iDumpFileName);
       
   150 
       
   151 			TInt32* p = (TInt32*)buf.Ptr();
       
   152 			TInt32* pE = p + (fileSize / sizeof(TInt32)) - 1;
       
   153 			Printf(_L("Machine UID: 0x%08x\r\n"), *p++);
       
   154 			Printf(_L("Type prefix: 0x%08x\r\n"), *p++);
       
   155 
       
   156 			while (p < pE)
       
   157 				{
       
   158 				TInt attribute = *p++;
       
   159 				TInt deviceNumber = (TUint)attribute >> 24;
       
   160 				attribute &= 0xFFFFFF;
       
   161 				TInt value = *p++;
       
   162 				LtkUtils::CHalAttribute* attrib = LtkUtils::GetHalInfoForValueL(deviceNumber, attribute, value);
       
   163 				Printf(_L("%4d %S[%d]: %S\r\n"), attrib->iAttribute, &attrib->iAttributeName, deviceNumber, attrib->iDescription);
       
   164 				delete attrib;
       
   165 				}
       
   166 
       
   167 			CleanupStack::PopAndDestroy(2, &file);
       
   168 			}
       
   169 			break;
       
   170 		}
       
   171 	}
       
   172 
       
   173 void CCmdHal::ArgumentsL(RCommandArgumentList& aArguments)
       
   174 	{
       
   175 	_LIT(KArgOperation, "operation");
       
   176 	aArguments.AppendEnumL((TInt&)iOperation, KArgOperation);
       
   177 
       
   178 	_LIT(KArgAttribute, "attribute");
       
   179 	aArguments.AppendUintL((TUint&)iAttribute, KArgAttribute);
       
   180 
       
   181 	_LIT(KArgValue, "value");
       
   182 	aArguments.AppendIntL(iValue, KArgValue);
       
   183 	}
       
   184 
       
   185 void CCmdHal::OptionsL(RCommandOptionList& aOptions)
       
   186 	{
       
   187 	_LIT(KOptDevice, "device");
       
   188 	aOptions.AppendIntL(iDeviceNumber, KOptDevice);
       
   189 
       
   190 	_LIT(KOptDumpFileName, "dump-file-name");
       
   191 	aOptions.AppendFileNameL(iDumpFileName, KOptDumpFileName);
       
   192 	}
       
   193 
       
   194 
       
   195 EXE_BOILER_PLATE(CCmdHal)
       
   196