|
1 /* |
|
2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "TCmdTerminateProcess.h" |
|
19 #include "SIPConstants.h" |
|
20 #include <flogger.h> |
|
21 #include <f32file.h> |
|
22 |
|
23 /** |
|
24 * INPUT: |
|
25 * Headers: - |
|
26 * Parameters: Process |
|
27 * IDs: - |
|
28 * |
|
29 * OUTPUT: |
|
30 * Parameters: - |
|
31 * IDs: - |
|
32 */ |
|
33 |
|
34 _LIT(KFileDir, "Sip"); |
|
35 _LIT(KFileName, "Tester.txt"); |
|
36 // Literals used for action name |
|
37 _LIT8( KIsRunning, "running" ); |
|
38 _LIT8( KTerminate, "terminate" ); |
|
39 |
|
40 void TCmdTerminateProcess::ExecuteL() |
|
41 { |
|
42 // -- Setup --------------------------------------------------------------- |
|
43 |
|
44 TPtrC8 action = ExtractTextL( KParamActionName ); |
|
45 // Get action name pattern for the process to be found |
|
46 TPtrC8 processPattern = ExtractTextL( KParamProcess ); |
|
47 |
|
48 TFullName procName; |
|
49 procName.Copy(processPattern); |
|
50 |
|
51 // -- Execution ----------------------------------------------------------- |
|
52 |
|
53 if( !action.CompareC( KTerminate ) ) |
|
54 { |
|
55 TerminateProcessL(procName); |
|
56 } |
|
57 else if( !action.CompareC( KIsRunning ) ) |
|
58 { |
|
59 if(IsProcessRunning(procName)) |
|
60 { |
|
61 AddBooleanResponseL(_L8("IsRunning"), ETrue); |
|
62 } |
|
63 else |
|
64 { |
|
65 AddBooleanResponseL(_L8("IsRunning"), EFalse); |
|
66 } |
|
67 } |
|
68 else {} |
|
69 |
|
70 // -- Response creation --------------------------------------------------- |
|
71 } |
|
72 |
|
73 TBool TCmdTerminateProcess::Match( const TTcIdentifier& aId ) |
|
74 { |
|
75 return TTcSIPCommandBase::Match( aId, _L8("TerminateProcess") ); |
|
76 } |
|
77 |
|
78 TTcCommandBase* TCmdTerminateProcess::CreateL( MTcTestContext& aContext ) |
|
79 { |
|
80 return new( ELeave ) TCmdTerminateProcess( aContext ); |
|
81 } |
|
82 |
|
83 void TCmdTerminateProcess::TerminateProcessL(const TDesC& aName) |
|
84 { |
|
85 |
|
86 #if ( !defined(EKA2) && ( defined(__WINS__) || defined(__WINSCW__) ) ) |
|
87 // WINS doesn't have a concept of process (in EKA1) |
|
88 RThread process; |
|
89 TFindThread processFinder (aName); |
|
90 #else |
|
91 RProcess process; |
|
92 TFindProcess processFinder (aName); |
|
93 #endif |
|
94 |
|
95 // Find the process |
|
96 TFullName processName; |
|
97 while ( processFinder.Next( processName ) == KErrNone ) |
|
98 { |
|
99 User::InfoPrint(_L("Found")); |
|
100 RFileLogger::Write (KFileDir,KFileName,EFileLoggingModeAppend,processName); |
|
101 User::LeaveIfError( process.Open( processFinder ) ); |
|
102 // ..and terminate it |
|
103 // process.Terminate( KErrNone ); |
|
104 process.Kill( KErrNone ); |
|
105 process.Close(); |
|
106 |
|
107 AddTextResponseL( KParamClientInfo, _L8("Process terminated") ); |
|
108 } |
|
109 } |
|
110 |
|
111 TBool TCmdTerminateProcess::IsProcessRunning(const TDesC& aName) |
|
112 { |
|
113 TBool Ret(EFalse); |
|
114 |
|
115 TFullName result; |
|
116 TFindProcess find(aName); |
|
117 TInt count = 0; |
|
118 while(find.Next(result) == KErrNone) |
|
119 { |
|
120 ++count; |
|
121 if(count >= 1) |
|
122 { |
|
123 Ret = ETrue; |
|
124 break; |
|
125 } |
|
126 } |
|
127 return Ret; |
|
128 } |
|
129 /* |
|
130 |
|
131 |
|
132 |
|
133 This should be |
|
134 _LIT(KProcess,"A["); |
|
135 |
|
136 Match expects wildcards. The 0 means it only considers it found if it is |
|
137 the start of the string. |
|
138 |
|
139 > TInt perr = User::LeaveIfError (processHandle.Open |
|
140 > (processFinder,EOwnerThread)); |
|
141 > RProcess processHandle; |
|
142 > if ( perr == KErrNone ) processHandle.Kill(0); |
|
143 > CleanupClosePushL (processHandle); |
|
144 |
|
145 The CleanupClosePushL should be immediatly after the Open - least chance |
|
146 of a leaving statment being added before it is on the cleanup stack. |
|
147 |
|
148 |
|
149 > CleanupStack::PopAndDestroy (&processHandle); |
|
150 */ |