genericservices/taskscheduler/Test/TSUtils/tscheduledeleter.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     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 // Tprocesskiller.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <f32file.h>
       
    19 #include <e32debug.h>
       
    20 	
       
    21 //This function is used in the test code to kill SCHSVR or MinimalTaskHandler
       
    22 //processes (or some other) when they leftover and may cause OOM condinitons.
       
    23 static TInt DeleteScheduleFilesL()
       
    24 	{
       
    25 	RFs fs;
       
    26 	_LIT(KFilePath, "_:\\Private\\10005399\\*.*");
       
    27 	
       
    28 	//Get the correct system drive
       
    29 	TBuf<32> filePath(KFilePath);
       
    30 	filePath[0] = RFs::GetSystemDriveChar();
       
    31 	
       
    32 	User::LeaveIfError(fs.Connect());
       
    33 	CleanupClosePushL(fs);
       
    34 	CFileMan* fileManager = CFileMan::NewL(fs);
       
    35 	CleanupStack::PushL(fileManager);
       
    36 	TInt ret = fileManager->Delete(filePath);
       
    37 	if(ret != KErrNone && ret != KErrNotFound && ret != KErrPathNotFound)
       
    38 		{
       
    39 		RDebug::Print(_L("DeleteScheduleFilesL - err=%d\n"), ret);
       
    40 		//Resource/memory/file deallocation is not the right place for User::Leave() call!
       
    41 		//Sometimes fileManager->Delete() fails with error "-14" (KErrInUse), 
       
    42 		//because SCHSVR server is alive!
       
    43 		//User::Leave(ret);
       
    44 		}
       
    45 	CleanupStack::PopAndDestroy(fileManager);
       
    46 	CleanupStack::PopAndDestroy(); //fs
       
    47 	return KErrNone;
       
    48 	}
       
    49 
       
    50 GLDEF_C TInt E32Main()
       
    51 	{
       
    52 	TInt err = KErrNoMemory;
       
    53 	CTrapCleanup* cleanup=CTrapCleanup::New();	//can fail
       
    54 	if (cleanup)
       
    55 		{
       
    56 		err = KErrNone;
       
    57 		TRAP(err, DeleteScheduleFilesL())
       
    58 		delete cleanup;
       
    59 		}
       
    60 	return err;
       
    61 	}
       
    62