lowlevellibsandfws/pluginfw/Framework/EcomTestUtils/t_processkillprocess.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 //
       
    15 
       
    16 #include <f32file.h>
       
    17 #include <e32debug.h>
       
    18 	
       
    19 //This function is used in the test code to kill ECOMSERVER
       
    20 //processes (or some other) when they leftover and may problem in ECOMSERVERTEST
       
    21 static TInt KillProcess(const TDesC& aProcessName)
       
    22 	{
       
    23 	TFullName name;
       
    24 
       
    25 	RDebug::Print(_L("Find and kill \"%S\" process.\n"), &aProcessName);
       
    26 
       
    27 	TBuf<64> pattern(aProcessName);
       
    28 	TInt length = pattern.Length();
       
    29 	pattern += _L("*");
       
    30 	TFindProcess procFinder(pattern);
       
    31 
       
    32 	while(procFinder.Next(name) == KErrNone)
       
    33 		{
       
    34 		if(name.Length() > length) 
       
    35 			{//If found name is a string containing aProcessName string.
       
    36 			TChar c(name[length]);
       
    37 			if(c.IsAlphaDigit() || c == TChar('_') || c == TChar('-'))
       
    38 				{//If the found name is other valid application name starting with aProcessName string.
       
    39 				RDebug::Print(_L(":: Process name: \"%S\".\n"), &name);
       
    40 				continue;
       
    41 				}
       
    42 			}
       
    43 		RProcess proc;
       
    44 		if(proc.Open(name) == KErrNone)
       
    45 			{
       
    46 			proc.Kill(0);
       
    47 			RDebug::Print(_L("\"%S\" process killed.\n"), &name);
       
    48 			}
       
    49 		proc.Close();
       
    50 		}
       
    51 	return KErrNone;
       
    52 	}
       
    53 
       
    54 GLDEF_C TInt E32Main()
       
    55 	{
       
    56 	TFileName name;
       
    57 	User::CommandLine(name);
       
    58 	return KillProcess(name);
       
    59 	}
       
    60