os/ossrv/genericservices/taskscheduler/Test/TSUtils/tscheduledeleter.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Tprocesskiller.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <f32file.h>
sl@0
    19
#include <e32debug.h>
sl@0
    20
	
sl@0
    21
//This function is used in the test code to kill SCHSVR or MinimalTaskHandler
sl@0
    22
//processes (or some other) when they leftover and may cause OOM condinitons.
sl@0
    23
static TInt DeleteScheduleFilesL()
sl@0
    24
	{
sl@0
    25
	RFs fs;
sl@0
    26
	_LIT(KFilePath, "_:\\Private\\10005399\\*.*");
sl@0
    27
	
sl@0
    28
	//Get the correct system drive
sl@0
    29
	TBuf<32> filePath(KFilePath);
sl@0
    30
	filePath[0] = RFs::GetSystemDriveChar();
sl@0
    31
	
sl@0
    32
	User::LeaveIfError(fs.Connect());
sl@0
    33
	CleanupClosePushL(fs);
sl@0
    34
	CFileMan* fileManager = CFileMan::NewL(fs);
sl@0
    35
	CleanupStack::PushL(fileManager);
sl@0
    36
	TInt ret = fileManager->Delete(filePath);
sl@0
    37
	if(ret != KErrNone && ret != KErrNotFound && ret != KErrPathNotFound)
sl@0
    38
		{
sl@0
    39
		RDebug::Print(_L("DeleteScheduleFilesL - err=%d\n"), ret);
sl@0
    40
		//Resource/memory/file deallocation is not the right place for User::Leave() call!
sl@0
    41
		//Sometimes fileManager->Delete() fails with error "-14" (KErrInUse), 
sl@0
    42
		//because SCHSVR server is alive!
sl@0
    43
		//User::Leave(ret);
sl@0
    44
		}
sl@0
    45
	CleanupStack::PopAndDestroy(fileManager);
sl@0
    46
	CleanupStack::PopAndDestroy(); //fs
sl@0
    47
	return KErrNone;
sl@0
    48
	}
sl@0
    49
sl@0
    50
GLDEF_C TInt E32Main()
sl@0
    51
	{
sl@0
    52
	TInt err = KErrNoMemory;
sl@0
    53
	CTrapCleanup* cleanup=CTrapCleanup::New();	//can fail
sl@0
    54
	if (cleanup)
sl@0
    55
		{
sl@0
    56
		err = KErrNone;
sl@0
    57
		TRAP(err, DeleteScheduleFilesL())
sl@0
    58
		delete cleanup;
sl@0
    59
		}
sl@0
    60
	return err;
sl@0
    61
	}
sl@0
    62