LOCAL_C void ProfileAllThreads() { TFindThread ft(_L("*")); TFullName fullname; test.Console()->ClearScreen(); FOREVER { TInt r=ft.Next(fullname); if (r!=KErrNone) break; RThread t; r=t.Open(ft); if (r==KErrNone) { TProfileData data; r=Profile.Read(t,data); if (r==KErrNone) { while(fullname.Length()<40) fullname.Append(TChar(' ')); test.Printf(_L("%S T=%9d C=%9d Y=%9d\n"), &fullname,data.iTotalCpuTime,data.iMaxContinuousCpuTime,data.iMaxTimeBeforeYield); } t.Close(); } } }
// ----------------------------------------------------------------------------- // CHtiFramework::IsHtiRunning // Checks whether HTI Framework process is already running. // ----------------------------------------------------------------------------- TBool CHtiFramework::IsHtiRunning() { HTI_LOG_FUNC_IN( "CHtiFramework::IsHtiRunning" ); TInt htiInstanceCount = 0; TBool isRunning = EFalse; TFullName processName; TFindProcess finder( KHtiFrameworkMatchPattern ); TInt err = finder.Next( processName ); while ( err == KErrNone && processName.Length() > 0 ) { HTI_LOG_FORMAT( "Found process %S", &processName ); RProcess process; err = process.Open( finder ); if ( err == KErrNone ) { if ( process.ExitType() == EExitPending ) { HTI_LOG_TEXT( "Process is running" ); htiInstanceCount++; } process.Close(); } err = finder.Next( processName ); } if ( htiInstanceCount > 1 ) { isRunning = ETrue; } HTI_LOG_FUNC_OUT( "CHtiFramework::IsHtiRunning" ); return isRunning; }
//This function is used in the test code to kill ECOMSERVER //processes (or some other) when they leftover and may problem in ECOMSERVERTEST static TInt KillProcess(const TDesC& aProcessName) { TFullName name; RDebug::Print(_L("Find and kill \"%S\" process.\n"), &aProcessName); TBuf<64> pattern(aProcessName); TInt length = pattern.Length(); pattern += _L("*"); TFindProcess procFinder(pattern); while(procFinder.Next(name) == KErrNone) { if(name.Length() > length) { //If found name is a string containing aProcessName string. TChar c(name[length]); if(c.IsAlphaDigit() || c == TChar('_') || c == TChar('-')) { //If the found name is other valid application name starting with aProcessName string. RDebug::Print(_L(":: Process name: \"%S\".\n"), &name); continue; } } RProcess proc; if(proc.Open(name) == KErrNone) { proc.Kill(0); RDebug::Print(_L("\"%S\" process killed.\n"), &name); } proc.Close(); } return KErrNone; }
void CSuspendTest::CreateL() { // // Create the eraser thread // iEraser = new(ELeave) CEraser; iEraser->CreateL(); // // Load the device drivers // TInt r; #ifndef SKIP_PDD_LOAD test.Printf( _L("Loading %S\n"), &KLfsDriverName ); r = User::LoadPhysicalDevice( KLfsDriverName ); test( KErrNone == r || KErrAlreadyExists == r ); #endif #ifdef UNMOUNT_DRIVE RFs fs; test( KErrNone == fs.Connect() ); test( KErrNone == fs.SetSessionPath( _L("Z:\\") ) ); TFullName name; fs.FileSystemName( name, KLffsLogicalDriveNumber ); if( name.Length() > 0 ) { test.Printf( _L("Unmounting drive") ); test( KErrNone == fs.DismountFileSystem( _L("Lffs"), KLffsLogicalDriveNumber) ); User::After( 2000000 ); test.Printf( _L("Drive unmounted") ); } fs.Close(); #endif // // Open a TBusLogicalDevice to it // test.Printf( _L("Opening media channel\n") ); TBool changedFlag = EFalse; r = iDrive.Connect( KDriveNumber, changedFlag ); User::LeaveIfError( r ); iDriveOpened = ETrue; // // Get size of Flash drive, block size, block count // TLocalDriveCapsV2Buf info; iDrive.Caps(info); iFlashSize = I64LOW(info().iSize); iBlockSize = info().iEraseBlockSize; iBlockCount = iFlashSize / iBlockSize; test.Printf( _L("Flash size is 0x%x bytes\n"), iFlashSize ); test.Printf( _L("Block size is 0x%x bytes\n"), iBlockSize ); test.Printf( _L("Block count is %d\n"), iBlockCount ); test.Printf( _L("CreateL complete\n") ); }
/** * Writes the required process details to the stop mode response buffer in the form of a * TProcessListEntry structure * @param aProc Process to write * @param aBuffer Buffer to write to * @param aBufferEnd Where the buffer ends * @return TInt KErrTooBig if there is no more space in buffer or one of the other system wide error codes */ TInt StopModeDebug::AppendProcessToBuffer(DProcess* aProc, TUint8* aBuffer, TUint8* aBufferEnd, TUint32& aProcSize) { TFullName procName; GetObjectFullName(aProc, procName); TUint32 dynamicNameLength = procName.Length(); DCodeSeg* codeSeg = aProc->iCodeSeg; TUint16 fileNameLength = (codeSeg) ? (*codeSeg->iFileName).Length() : 0; //Struct size is unicode so the filenames are twice as long, plus the size of the struct minus one character that //lives inside the struct itself. Also, this is word aligned TUint32 structSize = Align4( (2*fileNameLength) + (2*dynamicNameLength) + sizeof(TProcessListEntry) - sizeof(TUint16)); aProcSize = structSize; //Is there space to write this to the buffer if(aBuffer + structSize < aBufferEnd) { TProcessListEntry& entry = *(TProcessListEntry*)(aBuffer); entry.iProcessId = (TUint64)aProc->iId; entry.iFileNameLength = fileNameLength; entry.iDynamicNameLength = dynamicNameLength; entry.iUid3 = aProc->iUids.iUid[2].iUid; entry.iAttributes = aProc->iAttributes; //Write the filename if(codeSeg) { //create TPtr to where the file name should be written TPtr name = TPtr((TUint8*)&(entry.iNames[0]), fileNameLength*2, fileNameLength*2); //copy the file name TInt err = CopyAndExpandDes(*codeSeg->iFileName, name); if(KErrNone != err) { return KErrGeneral; } } //create TPtr to where the dynamic name should be written TPtr name = TPtr((TUint8*)(&(entry.iNames[0]) + fileNameLength), dynamicNameLength*2, dynamicNameLength*2); //copy the dynamic name TInt err = CopyAndExpandDes(procName, name); if(KErrNone != err) { return KErrGeneral; } return KErrNone; } else { return KErrTooBig; } }
TBool IsProcessRunning(const TDesC& aProcessName) { TFullName name; TBool IsProcessRunning(EFalse); TBuf<64> pattern(aProcessName); TInt length = pattern.Length(); pattern += _L("*"); TFindProcess procFinder(pattern); while(procFinder.Next(name) == KErrNone) { if(name.Length() > length) {//If found name is a string containing aProcessName string. TChar c(name[length]); if(c.IsAlphaDigit() || c == TChar('_') || c == TChar('-')) {//If the found name is other valid application name starting with aProcessName string. RDebug::Print(_L(":: Process name: \"%S\".\n"), &name); continue; } } RProcess proc; if(proc.Open(name) == KErrNone) { if (EExitKill == proc.ExitType()) { RDebug::Print(_L("\"%S\" process killed.\n"), &name); proc.Close(); IsProcessRunning = EFalse; } else { IsProcessRunning = ETrue; RDebug::Print(_L("\"%S\" process is running.\n"), &name); } if(IsProcessRunning) { RDebug::Print(_L("Waiting additional time...\n"), &name); User::After(1000000); if (EExitKill == proc.ExitType()) { RDebug::Print(_L("\"%S\" process now killed.\n"), &name); IsProcessRunning = EFalse; } proc.Close(); } } } return IsProcessRunning; }
wchar_t * PosixFilesystem::getcwd (RFs& aFs, wchar_t* buf, unsigned long len, int& anErrno) { TFullName name; TInt err = aFs.SessionPath(name); if (!err) { TPtr16 pathdes((TText16 *)buf, len); if (pathdes.MaxLength() >= (name.Length() + 1)) //+1 to allow for the null terminator { pathdes.Copy(name); pathdes.ZeroTerminate(); return buf; } else err = ERANGE; //out of range } MapError(err, anErrno); return 0; }
TInt MountNTFS() { TBuf<256> cmd; User::CommandLine(cmd); TLex cmdlex(cmd); cmdlex.SkipSpace(); TUint c = (TUint)cmdlex.Get(); if (c>='a' && c<='z') c-=0x20; if (c<'A' || c>'Z') return KErrArgument; TBuf<4> driveLetter; driveLetter.SetLength(1); driveLetter[0] = (TText)c; RDebug::Print(_L("Drive %S"), &driveLetter); TInt driveNumber = TInt(c-'A') + TInt(EDriveA); TInt r; driveLetter.Append(_L(":\\")); RDebug::Print(_L("Add file system: %S"), &KFileSystemDllName); r=TheFs.AddFileSystem(KFileSystemDllName); if (r!=KErrNone && r!=KErrAlreadyExists) { RDebug::Print(_L("Failed: %d"), r); return r; } TFullName name; r = TheFs.FileSystemName(name, driveNumber); if (name.Length() != 0) { RDebug::Print(_L("Dismounting %S on drive %S\r\n"), &name, &driveLetter); r=TheFs.DismountFileSystem(name, driveNumber); RDebug::Print(_L("Dismount ret=%d"), r); } RDebug::Print(_L("Mount NTFS on drive %S\r\n"), &driveLetter); r = TheFs.MountFileSystem(KFileSystemName, driveNumber); RDebug::Print(_L("Mount r=%d"),r); return KErrNone; }
// ----------------------------------------------------------------------------- // CDevEncStarterMmcObserver::CheckMMC // // ----------------------------------------------------------------------------- TInt CDevEncStarterMmcObserver::CheckMMC() { // Check if MMC mounted, mount if required TFullName fsname; // If can't use the drive, returns KErrNotFound TInt err = iFs.FileSystemName( fsname, mmcDrive ); if ( !err ) { // MMC found. Checking if it is mounted if ( fsname.Length( ) == 0 ) { // MMC not mounted ( file system name is empty ) DFLOG( "Mmc not mounted" ); err = KErrDisMounted; } } return err; }
static TInt KillProcess(const TDesC& aProcessName) { TFullName name; //TheTest.Printf(_L("Find and kill \"%S\" process.\n"), &aProcessName); TBuf<64> pattern(aProcessName); TInt length = pattern.Length(); pattern += _L("*"); TFindProcess procFinder(pattern); while (procFinder.Next(name) == KErrNone) { if (name.Length() > length) {//If found name is a string containing aProcessName string. TChar c(name[length]); if (c.IsAlphaDigit() || c == TChar('_') || c == TChar('-')) { // If the found name is other valid application name // starting with aProcessName string. //TheTest.Printf(_L(":: Process name: \"%S\".\n"), &name); continue; } } RProcess proc; if (proc.Open(name) == KErrNone) { //RPorcess::Kill() is expected to be used here. //But it is impossible, because the test application will need "PowerMgmt" capability. //But if the test application has "PowerMgmt" capability, then it won't be possible to use the //sqlite3_secure library, which has "ProtServ" capability only. } proc.Close(); } return KErrNone; }
int PosixFilesystem::stat (RFs& aFs, const wchar_t* name, struct stat *st, int& anErrno) { TFullName fullName; TInt err=GetFullFile(fullName,(const TText16*)name,aFs); if (!err) { TEntry entry; if (fullName.Length()==3) { entry.iAtt=KEntryAttDir; entry.iModified==TTime(0); } else err=aFs.Entry(fullName,entry); if (!err) { st->st_size = entry.iSize; st->st_dev = st->st_rdev = (dev_t)TDriveUnit(fullName); CFileDesc::MapStat(*st, entry.iModified, entry.iAtt); return 0; } } return MapError(err, anErrno); }