os/ossrv/genericservices/taskscheduler/Test/TSUtils/tscheduledeleter.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericservices/taskscheduler/Test/TSUtils/tscheduledeleter.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,62 @@
     1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// Tprocesskiller.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <f32file.h>
    1.22 +#include <e32debug.h>
    1.23 +	
    1.24 +//This function is used in the test code to kill SCHSVR or MinimalTaskHandler
    1.25 +//processes (or some other) when they leftover and may cause OOM condinitons.
    1.26 +static TInt DeleteScheduleFilesL()
    1.27 +	{
    1.28 +	RFs fs;
    1.29 +	_LIT(KFilePath, "_:\\Private\\10005399\\*.*");
    1.30 +	
    1.31 +	//Get the correct system drive
    1.32 +	TBuf<32> filePath(KFilePath);
    1.33 +	filePath[0] = RFs::GetSystemDriveChar();
    1.34 +	
    1.35 +	User::LeaveIfError(fs.Connect());
    1.36 +	CleanupClosePushL(fs);
    1.37 +	CFileMan* fileManager = CFileMan::NewL(fs);
    1.38 +	CleanupStack::PushL(fileManager);
    1.39 +	TInt ret = fileManager->Delete(filePath);
    1.40 +	if(ret != KErrNone && ret != KErrNotFound && ret != KErrPathNotFound)
    1.41 +		{
    1.42 +		RDebug::Print(_L("DeleteScheduleFilesL - err=%d\n"), ret);
    1.43 +		//Resource/memory/file deallocation is not the right place for User::Leave() call!
    1.44 +		//Sometimes fileManager->Delete() fails with error "-14" (KErrInUse), 
    1.45 +		//because SCHSVR server is alive!
    1.46 +		//User::Leave(ret);
    1.47 +		}
    1.48 +	CleanupStack::PopAndDestroy(fileManager);
    1.49 +	CleanupStack::PopAndDestroy(); //fs
    1.50 +	return KErrNone;
    1.51 +	}
    1.52 +
    1.53 +GLDEF_C TInt E32Main()
    1.54 +	{
    1.55 +	TInt err = KErrNoMemory;
    1.56 +	CTrapCleanup* cleanup=CTrapCleanup::New();	//can fail
    1.57 +	if (cleanup)
    1.58 +		{
    1.59 +		err = KErrNone;
    1.60 +		TRAP(err, DeleteScheduleFilesL())
    1.61 +		delete cleanup;
    1.62 +		}
    1.63 +	return err;
    1.64 +	}
    1.65 +