testapps/rschandler/Common/src/ResourceHandler_ResourceDetails.cpp
branchRCL_3
changeset 20 493058e57c8c
parent 0 9736f095102e
equal deleted inserted replaced
19:4ca382093dae 20:493058e57c8c
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 #include "ResourceHandler.h"
       
    18 
       
    19 /**
       
    20 Gets process details for a process with the given name - assumed to be a valid process
       
    21 name.
       
    22 */
       
    23 void TResourceDetails::GetProcessData(TDesC& aProcessName)
       
    24 	{
       
    25 		RProcess process;
       
    26 		process.Open(aProcessName);
       
    27 
       
    28 		// ID
       
    29 		iProcessData.iIdString.Format(KFormatDec,process.Id().Id());
       
    30 
       
    31 		// Store Process Name
       
    32 		iProcessData.iProcessName.Copy(aProcessName);
       
    33 		//to increase readability of resource table
       
    34 		AppendDotsToResourceName(iProcessData.iProcessName);
       
    35 		
       
    36 		// Priority
       
    37 		iProcessData.iPriorityString.Format(KFormatDec,process.Priority());
       
    38 		
       
    39 		// Protected
       
    40 
       
    41 		// System
       
    42 
       
    43 		// Owner
       
    44 		RProcess owner;
       
    45 		TInt err = KErrNotSupported;
       
    46 		if (err == KErrNone)
       
    47 			{
       
    48 			iProcessData.iOwnerIdString.Format(KFormatHex,owner.Id().Id());
       
    49 			}
       
    50 		else
       
    51 			{
       
    52 			iProcessData.iOwnerIdString.Format(KFormatHex,0);
       
    53 			}
       
    54 				
       
    55 		// Exit Type
       
    56 		TExitType et = process.ExitType();
       
    57 		switch(et)
       
    58 			{
       
    59 			case(0): iProcessData.iExitTypeString.Copy((_L("Kill"))); break;
       
    60 			case(1): iProcessData.iExitTypeString.Copy((_L("Terminate"))); break;
       
    61 			case(2): iProcessData.iExitTypeString.Copy((_L("Panic"))); break;
       
    62 			case(3): iProcessData.iExitTypeString.Copy((_L("Pending"))); break;
       
    63 			default: iProcessData.iExitTypeString.Copy((_L("Error!"))); break;
       
    64 			};
       
    65 		
       
    66 		// Exit Reason
       
    67 		TInt er = process.ExitReason();
       
    68 		if (er==0) iProcessData.iExitReasonString.Copy(_L("n/a"));
       
    69 		else
       
    70 			{
       
    71 			iProcessData.iExitReasonString.Format(KFormatHex,(TInt)er);
       
    72 			}
       
    73 
       
    74 		// Exit Category
       
    75 		TExitCategoryName ec;
       
    76 		ec = process.ExitCategory();
       
    77 		if (ec.Length() == 0) iProcessData.iExitCategoryName.Copy(_L("n/a"));
       
    78 		else iProcessData.iExitCategoryName.Copy(ec);
       
    79 
       
    80 		// UIDs
       
    81 		TUidType uids = process.Type();
       
    82 		iProcessData.iUidType0String.Format(KFormatHex, uids[0].iUid);
       
    83 		iProcessData.iUidType1String.Format(KFormatHex, uids[1].iUid);
       
    84 		iProcessData.iUidType2String.Format(KFormatHex, uids[2].iUid);
       
    85 				
       
    86 		// File
       
    87 		iProcessData.iFileName = process.FileName();
       
    88 
       
    89 		process.Close();	
       
    90 	}
       
    91 	
       
    92 /**
       
    93 Gets process details for a drive with the properties. These properties are assumed 
       
    94 to be a valid.
       
    95 */
       
    96 void TResourceDetails::GetDriveData(TInt aValidDriveNum, TDriveUnit aDriveUnit, TVolumeInfo aVolumeInfo)
       
    97 	{
       
    98 	iDriveData.iDriveName.Copy(aDriveUnit.Name());
       
    99 	iDriveData.iVolumeName.Copy(aVolumeInfo.iName);
       
   100 	iDriveData.iDriveNumberString.Format(KFormatDec, aValidDriveNum);
       
   101 
       
   102 	TBufC<20> mediaInfo;
       
   103 	switch (aVolumeInfo.iDrive.iType)
       
   104 		{
       
   105 		case EMediaNotPresent:mediaInfo=_L("EMediaNotPresent");break;
       
   106 		case EMediaUnknown:mediaInfo=_L("EMediaUnknown");break;
       
   107 		case EMediaFloppy:mediaInfo=_L("EMediaFloppy");break;
       
   108 		case EMediaHardDisk:mediaInfo=_L("EMediaHardDisk");break;
       
   109 		case EMediaCdRom:mediaInfo=_L("EMediaCdRom");break;
       
   110 		case EMediaRam:mediaInfo=_L("EMediaRam");break;
       
   111 		case EMediaFlash:mediaInfo=_L("EMediaFlash");break;
       
   112 		case EMediaRom:mediaInfo=_L("EMediaRom");break;
       
   113 		case EMediaRemote:mediaInfo=_L("EMediaRemote");break;
       
   114 		default:mediaInfo=_L("Other");break;
       
   115 		}
       
   116 
       
   117 	iDriveData.iMediaString.Copy(mediaInfo);
       
   118 	iDriveData.iAttributesString.Format(KFormatHex,aVolumeInfo.iDrive.iDriveAtt);
       
   119 	iDriveData.iSpaceString.Format(KFormatDec64,aVolumeInfo.iSize);
       
   120 	#if defined(WINS)
       
   121 		iDriveData.iFreeSpaceString.Copy(_L("Unavail."));
       
   122 	#else
       
   123 	if (aVolumeInfo.iFree.GetTInt() > aVolumeInfo.iSize.GetTInt()) // this value is odd on wins
       
   124 		{
       
   125 		iDriveData.iFreeSpaceString.Format(KFormatDec,aVolumeInfo.iSize.GetTInt());
       
   126 		}
       
   127 	else if (aVolumeInfo.iFree.GetTInt() < 0)
       
   128 		{
       
   129 		iDriveData.iFreeSpaceString.Copy(_L("InvalidVal"));
       
   130 		}
       
   131 	else
       
   132 		{
       
   133 		iDriveData.iFreeSpaceString.Format(KFormatDec,aVolumeInfo.iFree.GetTInt());
       
   134 		}
       
   135 	#endif
       
   136 	}
       
   137 	
       
   138 /**
       
   139 Gets thread details for a thread with the given name - assumed to be a valid name.
       
   140 */
       
   141 void TResourceDetails::GetThreadData(TDesC& aThreadName)
       
   142 	{
       
   143 	RThread thread;
       
   144 	TInt err = thread.Open(aThreadName);
       
   145 	if (err == KErrNone)
       
   146 		{
       
   147 		// ID
       
   148 		iThreadData.iIdString.Format(KFormatDec,thread.Id().Id());
       
   149 
       
   150 		// Name
       
   151 		iThreadData.iThreadName.Copy(aThreadName);
       
   152 		
       
   153 		//to increase readability of resource table
       
   154 		AppendDotsToResourceName(iThreadData.iThreadName);
       
   155 
       
   156 		// Priority
       
   157 		iThreadData.iPriorityString.Format(KFormatDec,thread.Priority());
       
   158 
       
   159 		// Owner Process
       
   160 		RProcess owner;
       
   161 		thread.Process(owner);
       
   162 		iThreadData.iOwnerIdString.Format(KFormatDec,owner.Id().Id());
       
   163 
       
   164 		owner.Close();
       
   165 				
       
   166 		// Stack Size
       
   167 
       
   168 		TInt aHeapSize = 0, aStackSize = 0;
       
   169 		iThreadData.iStackSizeString.Format(KFormatHex,aStackSize);
       
   170 		iThreadData.iHeapSizeString.Format(KFormatHex,aHeapSize);
       
   171 		
       
   172 		// Protected
       
   173 
       
   174 		// System
       
   175 		
       
   176 		// Exit Type
       
   177 		TExitType et = thread.ExitType();
       
   178 		switch(et)
       
   179 			{
       
   180 			case(0): iThreadData.iExitTypeString.Copy((_L("Kill"))); break;
       
   181 			case(1): iThreadData.iExitTypeString.Copy((_L("Terminate"))); break;
       
   182 			case(2): iThreadData.iExitTypeString.Copy((_L("Panic"))); break;
       
   183 			case(3): iThreadData.iExitTypeString.Copy((_L("Pending"))); break;
       
   184 			default: iThreadData.iExitTypeString.Copy((_L("Error!"))); break;
       
   185 			};
       
   186 
       
   187 		// Exit Reason
       
   188 		
       
   189 		TInt er = thread.ExitReason();
       
   190 		if (er==0) iThreadData.iExitReasonString.Copy(_L("n/a"));
       
   191 		else iThreadData.iExitReasonString.Format(KFormatHex,(TInt)er);
       
   192 
       
   193 		// Exit Category
       
   194 
       
   195 		TExitCategoryName ec;
       
   196 		ec = thread.ExitCategory();
       
   197 		if (ec.Length() == 0) iThreadData.iExitCategoryName.Copy(_L("n/a"));
       
   198 		else iThreadData.iExitCategoryName.Copy(ec);
       
   199 
       
   200 		thread.Close();
       
   201 		}
       
   202 	}
       
   203 	
       
   204 /**
       
   205 Gets details for a chunk using the given TFindChunk and name.
       
   206 */
       
   207 void TResourceDetails::GetChunkData(TFindChunk findHb, TDesC& aChunkName)
       
   208 	{	
       
   209 	RChunk chunk;
       
   210 	chunk.Open(findHb);
       
   211 
       
   212 	// Name
       
   213 	iChunkData.iChunkName.Copy(aChunkName);
       
   214 	
       
   215 	//to increase readability of resource table
       
   216 	AppendDotsToResourceName(iChunkData.iChunkName);
       
   217 
       
   218 	// Size
       
   219 	TInt chunkSize = 0;
       
   220 	iChunkData.iSizeString.Format(KFormatHex,chunkSize);
       
   221 
       
   222 	// Max Size
       
   223 
       
   224 	TInt chunkMaxSize = 0;
       
   225 	iChunkData.iMaxSizeString.Format(KFormatHex,chunkMaxSize);
       
   226 		
       
   227 	// Readable
       
   228 	if (chunk.IsReadable()) iChunkData.iReadableIndicator.Copy(_L("R"));
       
   229 	else iChunkData.iReadableIndicator.Copy(_L("-"));
       
   230 
       
   231 	// Writeable
       
   232 	if (chunk.IsWritable()) iChunkData.iWritableIndicator.Copy(_L("W"));
       
   233 	else iChunkData.iWritableIndicator.Copy(_L("-"));
       
   234 			
       
   235 	chunk.Close();
       
   236 	}
       
   237 
       
   238 /**
       
   239 Gets details for a mutex using the given TFindMutex and name.
       
   240 */
       
   241 void TResourceDetails::GetMutexData(TFindMutex& findHb, TDesC& aMutexName)
       
   242 	{	
       
   243 	RMutex mutex;
       
   244 	
       
   245 	// Name
       
   246 	iMutexData.iMutexName.Copy(aMutexName);	
       
   247 	
       
   248 	//to increase readability of resource table
       
   249 	AppendDotsToResourceName(iMutexData.iMutexName);
       
   250 		
       
   251 	// Count
       
   252 	mutex.Open(findHb);
       
   253 	TInt count = 0;
       
   254 	iMutexData.iHexCountString.Format(KFormatHex, count);
       
   255 	iMutexData.iDecCountString.Format(KFormatDec, count);
       
   256 	mutex.Close();
       
   257 	}
       
   258 	
       
   259 /**
       
   260 Gets details for a mutex using the given TFindSemaphore and name.
       
   261 */
       
   262 void TResourceDetails::GetSemaphoreData(TFindSemaphore& findHb, TDesC& aSemaphoreName)
       
   263 	{			
       
   264 		RSemaphore sem;
       
   265 		// Name
       
   266 		iSemaphoreData.iSemaphoreName.Copy(aSemaphoreName);
       
   267 		//to increase readability of resource table
       
   268 		AppendDotsToResourceName(iSemaphoreData.iSemaphoreName);
       
   269 		iSemaphoreData.iSemaphoreName.AppendFill('.', KMaxFullName - iSemaphoreData.iSemaphoreName.Length());
       
   270 		
       
   271 		// Count
       
   272 		sem.Open(findHb);
       
   273 		TInt count = 0;
       
   274 		iSemaphoreData.iHexCountString.Format(KFormatHex,count);
       
   275 	
       
   276 		iSemaphoreData.iDecCountString.Format(KFormatDec,count);
       
   277 		
       
   278 		sem.Close();
       
   279 		}
       
   280 
       
   281 /**
       
   282 Gets details for a HAL entry. Assumes that the parameters are valid.
       
   283 */
       
   284 void TResourceDetails::GetHalData(TInt aValidEntryNum, HAL::SEntry* aSEntry)
       
   285 	{
       
   286 	iHalData.iNumberString.Format(KFormatDec,aValidEntryNum);
       
   287 
       
   288 	TBuf<100> halName;
       
   289 	switch (aValidEntryNum)
       
   290 		{
       
   291 		case HALData::EManufacturer:	halName=_L("EManufacturer");break;
       
   292 		case HALData::EManufacturerHardwareRev:	halName=_L("EManufacturerHardwareRev");break;
       
   293 		case HALData::EManufacturerSoftwareRev:	halName=_L("EManufacturerSoftwareRev");break;
       
   294 		case HALData::EManufacturerSoftwareBuild:	halName=_L("EManufacturerSoftwareBuild");break;
       
   295 		case HALData::EModel:	halName=_L("EModel");break;
       
   296 		case HALData::EMachineUid:	halName=_L("EMachineUid");break;
       
   297 		case HALData::EDeviceFamily:	halName=_L("EDeviceFamily");break;
       
   298 		case HALData::EDeviceFamilyRev:	halName=_L("EDeviceFamilyRev");break;
       
   299 		case HALData::ECPU:	halName=_L("ECPU");break;
       
   300 		case HALData::ECPUArch:	halName=_L("ECPUArch");break;
       
   301 		case HALData::ECPUABI:	halName=_L("ECPUABI");break;
       
   302 		case HALData::ECPUSpeed:	halName=_L("ECPUSpeed");break;
       
   303 		case HALData::ESystemStartupReason:	halName=_L("ESystemStartupReason");break;
       
   304 		case HALData::ESystemException:	halName=_L("ESystemException");break;
       
   305 		case HALData::ESystemTickPeriod:	halName=_L("ESystemTickPeriod");break;
       
   306 		case HALData::EMemoryRAM:	halName=_L("EMemoryRAM");break;
       
   307 		case HALData::EMemoryRAMFree:	halName=_L("EMemoryRAMFree");break;	
       
   308 		case HALData::EMemoryROM:	halName=_L("EMemoryROM");break;
       
   309 		case HALData::EMemoryPageSize:	halName=_L("EMemoryPageSize");break;
       
   310 		case HALData::EPowerGood:	halName=_L("EPowerGood");break;
       
   311 		case HALData::EPowerBatteryStatus:	halName=_L("EPowerBatteryStatus");break;
       
   312 		case HALData::EPowerBackup:	halName=_L("EPowerBackup");break;	
       
   313 		case HALData::EPowerBackupStatus:	halName=_L("EPowerBackupStatus");break;
       
   314 		case HALData::EPowerExternal:	halName=_L("EPowerExternal");break;
       
   315 		case HALData::EKeyboard:	halName=_L("EKeyboard");break;
       
   316 		case HALData::EKeyboardDeviceKeys:	halName=_L("EKeyboardDeviceKeys");break;
       
   317 		case HALData::EKeyboardAppKeys:	halName=_L("EKeyboardAppKeys");break;
       
   318 		case HALData::EKeyboardClick:	halName=_L("EKeyboardClick");break;
       
   319 		case HALData::EKeyboardClickState:	halName=_L("EKeyboardClickState");break;
       
   320 		case HALData::EKeyboardClickVolume:	halName=_L("EKeyboardClickVolume");break;
       
   321 		case HALData::EKeyboardClickVolumeMax:	halName=_L("EKeyboardClickVolumeMax");break;
       
   322 		case HALData::EDisplayXPixels:	halName=_L("EDisplayXPixels");break;
       
   323 		case HALData::EDisplayYPixels:	halName=_L("EDisplayYPixels");break;
       
   324 		case HALData::EDisplayXTwips:	halName=_L("EDisplayXTwips");break;
       
   325 		case HALData::EDisplayYTwips:	halName=_L("EDisplayYTwips");break;
       
   326 		case HALData::EDisplayColors:	halName=_L("EDisplayColors");break;
       
   327 		case HALData::EDisplayState:	halName=_L("EDisplayState");break;
       
   328 		case HALData::EDisplayContrast:	halName=_L("EDisplayContrast");break;
       
   329 		case HALData::EDisplayContrastMax:	halName=_L("EDisplayContrastMax");break;
       
   330 		case HALData::EBacklight:	halName=_L("EBacklight");break;
       
   331 		case HALData::EBacklightState:	halName=_L("EBacklightState");break;
       
   332 		case HALData::EPen:	halName=_L("EPen");break;
       
   333 		case HALData::EPenX:	halName=_L("EPenX");break;
       
   334 		case HALData::EPenY:	halName=_L("EPenY");break;
       
   335 		case HALData::EPenDisplayOn:	halName=_L("EPenDisplayOn");break;
       
   336 		case HALData::EPenClick:	halName=_L("EPenClick");break;
       
   337 		case HALData::EPenClickState:	halName=_L("EPenClickState");break;
       
   338 		case HALData::EPenClickVolume:	halName=_L("EPenClickVolume");break;
       
   339 		case HALData::EPenClickVolumeMax:	halName=_L("EPenClickVolumeMax");break;
       
   340 		case HALData::EMouse:	halName=_L("EMouse");break;
       
   341 		case HALData::EMouseX:	halName=_L("EMouseX");break;
       
   342 		case HALData::EMouseY:	halName=_L("EMouseY");break;
       
   343 		case HALData::EMouseState:	halName=_L("EMouseState");break;
       
   344 		case HALData::EMouseSpeed:	halName=_L("EMouseSpeed");break;
       
   345 		case HALData::EMouseAcceleration:	halName=_L("EMouseAcceleration");break;
       
   346 		case HALData::EMouseButtons:	halName=_L("EMouseButtons");break;
       
   347 		case HALData::EMouseButtonState:	halName=_L("EMouseButtonState");break;
       
   348 		case HALData::ECaseState:	halName=_L("ECaseState");break;
       
   349 		case HALData::ECaseSwitch:	halName=_L("ECaseSwitch");break;
       
   350 		case HALData::ECaseSwitchDisplayOn:	halName=_L("ECaseSwitchDisplayOn");break;
       
   351 		case HALData::ECaseSwitchDisplayOff:	halName=_L("ECaseSwitchDisplayOff");break;
       
   352 		case HALData::ELEDs:	halName=_L("ELEDs");break;
       
   353 		case HALData::ELEDmask:	halName=_L("ELEDmask");break;
       
   354 		case HALData::EIntegratedPhone:	halName=_L("EIntegratedPhone");break;
       
   355 		case HALData::EDisplayBrightness:	halName=_L("EDisplayBrightness");break;
       
   356 		case HALData::EDisplayBrightnessMax:	halName=_L("EDisplayBrightnessMax");break;
       
   357 		case HALData::EKeyboardBacklightState:	halName=_L("EKeyboardBacklightState");break;
       
   358 		case HALData::EAccessoryPower:	halName=_L("EAccessoryPower");break;
       
   359 		case HALData::ELanguageIndex:	halName=_L("ELanguageIndex");break;
       
   360 		case HALData::EKeyboardIndex:	halName=_L("EKeyboardIndex");break;
       
   361 		case HALData::EMaxRAMDriveSize:	halName=_L("EMaxRAMDriveSize");break;
       
   362 		case HALData::EKeyboardState:	halName=_L("EKeyboardState");break;
       
   363 		case HALData::ESystemDrive:	halName=_L("ESystemDrive");break;
       
   364 		case HALData::EPenState:	halName=_L("EPenState");break;
       
   365 		case HALData::EDisplayIsMono:	halName=_L("EDisplayIsMono");break;
       
   366 		case HALData::EDisplayIsPalettized:	halName=_L("EDisplayIsPalettized");break;
       
   367 		case HALData::EDisplayBitsPerPixel:	halName=_L("EDisplayBitsPerPixel");break;
       
   368 		case HALData::EDisplayNumModes:	halName=_L("EDisplayNumModes");break;
       
   369 		case HALData::EDisplayMemoryAddress:	halName=_L("EDisplayMemoryAddress");break;
       
   370 		case HALData::EDisplayOffsetToFirstPixel:	halName=_L("EDisplayOffsetToFirstPixel");break;
       
   371 		case HALData::EDisplayOffsetBetweenLines:	halName=_L("EDisplayOffsetBetweenLines");break;
       
   372 		case HALData::EDisplayPaletteEntry:	halName=_L("EDisplayPaletteEntry");break;
       
   373 		case HALData::EDisplayIsPixelOrderRGB:	halName=_L("EDisplayIsPixelOrderRGB");break;
       
   374 		case HALData::EDisplayIsPixelOrderLandscape:	halName=_L("EDisplayIsPixelOrderLandscape");break;
       
   375 		case HALData::EDisplayMode:	halName=_L("EDisplayMode");break;
       
   376 		case HALData::ESwitches:	halName=_L("ESwitches");break;
       
   377 		case HALData::EDebugPort:	halName=_L("EDebugPort");break;
       
   378 		case HALData::ELocaleLoaded:	halName=_L("ELocaleLoaded");break;
       
   379 		case HALData::ENumHalAttributes:	halName=_L("ENumHalAttributes");break;
       
   380 		default:halName=_L("Unknown");break;
       
   381 		}
       
   382 
       
   383 		iHalData.iName.Copy(halName);		
       
   384 
       
   385 		if (aSEntry[aValidEntryNum].iProperties & HAL::EEntryDynamic)
       
   386 			iHalData.iDynamicIndicator=_L("D");
       
   387 		else iHalData.iDynamicIndicator=_L("-");
       
   388 		
       
   389 		iHalData.iDecValString.Format(KFormatDec,aSEntry[aValidEntryNum].iValue);
       
   390 			
       
   391 		iHalData.iHexValString.Format(KFormatHex,aSEntry[aValidEntryNum].iValue);
       
   392 		}
       
   393 
       
   394 /**
       
   395 Appends dots (after 3 spaces) to a resource name.
       
   396 Used for names of resources in a table - so you can follow the dots to read the
       
   397 resource details.
       
   398 */
       
   399 void TResourceDetails::AppendDotsToResourceName(TFullName& aResourceName)
       
   400 	{
       
   401 	if (aResourceName.Length() < KMaxFullName - 3)
       
   402 			aResourceName.AppendFill(' ', 3);
       
   403 		aResourceName.AppendFill('.', KMaxFullName - aResourceName.Length());
       
   404 	}
       
   405