?? taskmgrappview.cpp
字號:
CleanupStack::PopAndDestroy( aText1 );
CleanupStack::PopAndDestroy( aText );
AppThread.Close();
}
}
void CtaskmgrAppView::ShowSystemInfo()
{
HBufC *aText = iEikonEnv->AllocReadResourceLC( R_SYSTEM_INFO);
HBufC *aText1 = HBufC::NewLC(650);
TBuf<10> aCpu,aCpuAbi;
TBuf<12> aStartUpReason;
TBuf<10> aDeviceFamily;
TBuf<10> aPowerExternal;
TInt aTickPeriod,aCpuSpeed,aRam,aRamFree,aRom,aPageSize;
TInt aResult;
HAL::Get(HALData::ECPU,aResult);
if(aResult == HALData::ECPU_ARM){
aCpu.Copy(_L("ARM"));
}else
if(aResult == HALData::ECPU_ARM){
aCpu.Copy(_L("MCORE"));
}else{
aCpu.Copy(_L("X86"));
}
HAL::Get(HALData::ECPUABI,aResult);
if(aResult == HALData::ECPUABI_ARM4){
aCpuAbi.Copy(_L("ARM4"));
}else
if(aResult == HALData::ECPUABI_THUMB){
aCpuAbi.Copy(_L("THUMB"));
}else
if(aResult == HALData::ECPUABI_MCORE){
aCpuAbi.Copy(_L("MCORE"));
}else
if(aResult == HALData::ECPUABI_MSVC){
aCpuAbi.Copy(_L("MSVC"));
}else
if(aResult == HALData::ECPUABI_ARM5T){
aCpuAbi.Copy(_L("ARM5T"));
}else
if(aResult == HALData::ECPUABI_ARMI){
aCpuAbi.Copy(_L("ARMI"));
}
HAL::Get(HALData::ECPUSpeed,aCpuSpeed);
HAL::Get(HALData::ESystemTickPeriod,aTickPeriod);
HAL::Get(HALData::EMemoryRAM,aRam);
HAL::Get(HALData::EMemoryRAMFree,aRamFree);
HAL::Get(HALData::EMemoryROM,aRom);
HAL::Get(HALData::EMemoryPageSize,aPageSize);
HAL::Get(HALData::EPowerExternal,aResult);
if(aResult)
aPowerExternal.Copy(_L("YES"));
else
aPowerExternal.Copy(_L("NO"));
HAL::Get(HALData::EDeviceFamily,aResult);
if(aResult == HALData::EDeviceFamily_Crystal){
aDeviceFamily.Copy(_L("Crystal"));
}else
if(aResult == HALData::EDeviceFamily_Pearl){
aDeviceFamily.Copy(_L("Pearl"));
}else{
aDeviceFamily.Copy(_L("Quartz"));
}
HAL::Get(HALData::ESystemStartupReason,aResult);
if(aResult == HALData::ESystemStartupReason_Cold){
aStartUpReason.Copy(_L("Cold Reset"));
}else
if(aResult == HALData::ESystemStartupReason_Warm){
aStartUpReason.Copy(_L("Warm Reset"));
}else{
aStartUpReason.Copy(_L("Fault"));
}
_LIT(aCpuSpecs,"%S %d Mhz");
TBuf<50> aFinalSpecs;
aFinalSpecs.Format(aCpuSpecs,&aCpu,(aCpuSpeed/1000));
aText1->Des().Format(aText->Des(),
&aDeviceFamily,//Device Family : %S\n
&aFinalSpecs,//CPU Specs : %S \n
&aCpuAbi,//CPU ABI : %S\n
&aStartUpReason,//Startup Reason : %S \n
aTickPeriod,//Tick Period : %d \n
(aRam/1024),//Total RAM size : %d kb\n
(aRamFree/1024),//Free RAM size : %d kb\n
(aRom/1024),//Total ROM size : %d kb\n
aPageSize//Page size : %d bytes\n
);
ShowInfoDialog(R_SYSTEM_TITLE,*aText1);
CleanupStack::PopAndDestroy( aText1 );
CleanupStack::PopAndDestroy( aText );
}
void CtaskmgrAppView::ShowProcessInfo()
{
if(iAppState == EProcessListState){
HBufC *aText = iEikonEnv->AllocReadResourceLC( R_PROCESS_INFO);
HBufC *aText1 = HBufC::NewLC(600);
TPtrC aPtr = iListBox->Model()->ItemText(iListBox->CurrentItemIndex());
TFindProcess aProcess2(_L("*"));
TFullName aResult;
while(aProcess2.Next(aResult)==KErrNone){
TInt idx = aPtr.Find(aResult);
if(idx!=KErrNotFound){
/*"Process id : %d\nCmd line : %S\n File name : %S\n
Process RAM size : %d kb\nLoaded from : %S\n
Priority : %S\nProtected : %S";*/
RProcess aProcess;
aProcess.Open(aProcess2);
TProcessMemoryInfo aInfo ;
aProcess.GetMemoryInfo(aInfo);
TUint32 aSize = (aInfo.iCodeSize +
aInfo.iConstDataSize +
aInfo.iInitialisedDataSize +
aInfo.iUninitialisedDataSize);
TProcessPriority aPriority = aProcess.Priority();
TBuf<25> aBufPrio;
switch(aPriority){
case EPriorityLow:aBufPrio.Copy(_L("LOW"));break;
case EPriorityBackground:aBufPrio.Copy(_L("BACKGROUND"));break;
case EPriorityForeground:aBufPrio.Copy(_L("FOREGROUND"));break;
case EPriorityHigh:aBufPrio.Copy(_L("HIGH"));break;
case EPriorityWindowServer:aBufPrio.Copy(_L("*WINDOW SEVER"));break;
case EPriorityFileServer:aBufPrio.Copy(_L("*FILE SERVER"));break;
case EPriorityRealTimeServer:aBufPrio.Copy(_L("*REAL TIME SERVER"));break;
case EPrioritySupervisor:aBufPrio.Copy(_L("*SUPERVISOR"));break;
}
TBuf<5> BufProc;
BufProc.Copy(aProcess.Protected()?_L("YES"):_L("NO"));
TBuf<5> BufLoaded;
BufLoaded.Copy(aProcess.LoadedFromRam()?_L("RAM"):_L("ROM"));
TInt aLen = aProcess.CommandLineLength();
TBuf<200> CmdLine;
if(aLen)
aProcess.CommandLine(CmdLine);
else
CmdLine.Copy(_L("N/A"));
TBuf<200> aFileName;
aFileName.Copy(aProcess.FileName());
TUint32 IntUid = aProcess.Id();
aText1->Des().Format(aText->Des(),IntUid,&aFileName,
&CmdLine,aSize,&BufLoaded,&aBufPrio,&BufProc);
aProcess.Close();
ShowInfoDialog(R_PROCESS_TITLE,*aText1);
CleanupStack::PopAndDestroy( aText1 );
CleanupStack::PopAndDestroy( aText );
break;
}
}//end of while
}//end of if
}
void CtaskmgrAppView::ShowInfoDialog(TInt aTitleResId,TDesC& aInfoTxt)
{
HBufC *aTitle = iEikonEnv->AllocReadResourceLC( aTitleResId);
CAknMessageQueryDialog* dlg = new (ELeave)CAknMessageQueryDialog();
dlg->PrepareLC( R_MESSAGE_QUERY );
dlg->SetMessageTextL(aInfoTxt);
dlg->QueryHeading()->SetTextL( aTitle->Des() );
dlg->RunLD();
CleanupStack::PopAndDestroy( aTitle );
}
void CtaskmgrAppView::SwitchView()
{
if(iAppState == ETaskListState){
FillProcessList();
}else if(iAppState == EProcessListState){
FillTaskList();
}
}
void CtaskmgrAppView::CompressHeaps()
{
TBuf<200> aBuf;
TInt BeforeFree=0,AfterFree=0;
TInt FreeHeapSize = 0;
_LIT(KHeap,"Total heap freed \n [ %d kb ]");
CAknInformationNote* informationNote;
HAL::Get(HALData::EMemoryRAMFree,BeforeFree);
User::CompressAllHeaps();
HAL::Get(HALData::EMemoryRAMFree,AfterFree);
FreeHeapSize = (AfterFree - BeforeFree) / 1024;
aBuf.Format(KHeap,FreeHeapSize);
informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(aBuf);
}
void CtaskmgrAppView::FillProcessList()
{
InitProcessList();
iAppState = EProcessListState;
}
void CtaskmgrAppView::FillTaskList()
{
InitTaskList();
iAppState = ETaskListState;
}
void CtaskmgrAppView::SwitchToApp()
{
if(iAppState == ETaskListState){
TInt ItemSelected;
ItemSelected = iListBox->CurrentItemIndex();
TUid KillThisUid = UidArray[ItemSelected];
TApaTaskList aList(CEikonEnv::Static()->WsSession());
TApaTask ATask3 = aList.FindApp(KillThisUid);
ATask3.BringToForeground();
}
}
void CtaskmgrAppView::RestartDevice()
{
//UserSvr::ResetMachine(EStartupWarmReset);
//another method to restart the machine lets test this.
RDebug::Fault(0);
}
void CtaskmgrAppView::InitProcessList()
{
CEikStatusPane* sp=iEikonEnv->AppUiFactory()->StatusPane();
CAknTitlePane* tp=(CAknTitlePane*)sp->ControlL(TUid::Uid(EEikStatusPaneUidTitle));
tp->SetTextL(_L("Process List")); // Set the text string.
if(iAppList){
iAppList->Reset();
delete iAppList;
iAppList = NULL;
}
_LIT(KItemFormatString,"\t%S\t%S\t");
_LIT(KSecondItem,"Process No : %d");
iProcCount = 0;
iListBox->Reset();
TFindProcess aProcess(_L("*"));
TFullName aResult;
while(aProcess.Next(aResult)==KErrNone){
iProcCount++;
}
iProcList = new (ELeave) CDesCArrayFlat(iProcCount);
TFindProcess aProcess1(_L("*"));
TInt dummyCount = 0;
CDesCArray *itemList = new (ELeave) CDesCArrayFlat(iProcCount);
while(aProcess1.Next(aResult)==KErrNone){
TBuf<200> Item;
TBuf<200> Item1;
Item1.Format(KSecondItem,dummyCount++);
Item.Format(KItemFormatString,&aResult,&Item1);
itemList->AppendL(Item);
}
//set items and ownership
iListBox->Model()->SetItemTextArray(itemList);
iListBox->Model()->SetOwnershipType(ELbmOwnsItemArray);
iListBox->SetCurrentItemIndex(0);
iListBox->SetFocus(ETrue);
}
void CtaskmgrAppView::KillProcess()
{
if(iAppState == EProcessListState){
TPtrC aPtr = iListBox->Model()->ItemText(iListBox->CurrentItemIndex());
TFindProcess aProcess2(_L("*"));
TFullName aResult;
while(aProcess2.Next(aResult)==KErrNone){
TInt idx = aPtr.Find(aResult);
if(idx!=KErrNotFound){//found process
RProcess aProcess;
aProcess.Open(aProcess2);
aProcess.Kill(0);
aProcess.Close();
InitProcessList();
break;
}
}
}
}
void CtaskmgrAppView::ShowAbout()
{
HBufC *aText = iEikonEnv->AllocReadResourceLC( R_ABOUT);
ShowInfoDialog(R_ABOUT_TITLE,*aText);
CleanupStack::PopAndDestroy( aText );
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -