|
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: Part of TestConsole application. |
|
15 ** Methods for the class CTestAppConsole |
|
16 ** |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include <e32std.h> |
|
23 #include <e32base.h> |
|
24 #include <mmfcontroller.h> |
|
25 |
|
26 #include "TestConsole.h" |
|
27 #include "FileUtil.h" |
|
28 #include "mccuids.hrh" |
|
29 |
|
30 const TUid KControllerUID = { KImplUidMccController }; |
|
31 const TUid KSourceUID = { KImplUidRtpDataSource }; |
|
32 const TUid KSinkUID = { KImplUidRtpDataSink }; |
|
33 |
|
34 // Main Instruction Text |
|
35 _LIT(KTxtMainInstructions, "Please select one option:\n" |
|
36 L"1. Create instances from MccRtpDataSource and -Sink\n" |
|
37 L"9. Quit\n----------------------------"); |
|
38 |
|
39 //******************************************************************************* |
|
40 // Method : CTestAppConsole::NewL() |
|
41 // Purpose : |
|
42 // Parameters : |
|
43 // Return Value: |
|
44 //******************************************************************************* |
|
45 CTestAppConsole* CTestAppConsole::NewL( ) |
|
46 { |
|
47 CTestAppConsole* self = new(ELeave)CTestAppConsole(); |
|
48 CleanupStack::PushL(self); |
|
49 |
|
50 self->ConstructL(); |
|
51 |
|
52 CleanupStack::Pop(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 //******************************************************************************* |
|
57 // Method : CTestAppConsole::CTestAppConsole() |
|
58 // Purpose : Constructor |
|
59 // Parameters : |
|
60 // Return Value: |
|
61 //******************************************************************************* |
|
62 CTestAppConsole::CTestAppConsole( ) : CActive(EPriorityStandard) |
|
63 { |
|
64 CActiveScheduler::Add(this); |
|
65 } |
|
66 |
|
67 //******************************************************************************* |
|
68 // Method : CTestAppConsole::ConstructL() |
|
69 // Purpose : |
|
70 // Parameters : |
|
71 // Return Value: |
|
72 //******************************************************************************* |
|
73 void CTestAppConsole::ConstructL() |
|
74 { |
|
75 _LIT(KTxtTitle, " RTP Test "); |
|
76 iConsole = Console::NewL(KTxtTitle, TSize(KConsFullScreen, KConsFullScreen)); |
|
77 DisplayConsoleMenu(KTxtMainInstructions); |
|
78 |
|
79 // Create Log files |
|
80 TFileUtil::InitLogFile(KLogFileTest); // test events |
|
81 TFileUtil::InitLogFile(KLogFileRtp); // Rtp packets |
|
82 TFileUtil::InitLogFile(KLogFileRtcp); // Rtcp packets |
|
83 TFileUtil::InitLogFile(KLogFileStat); // Statistic |
|
84 } |
|
85 |
|
86 //******************************************************************************* |
|
87 // Method : CTestAppConsole::~CTestAppConsole() |
|
88 // Purpose : Destructor |
|
89 // Parameters : |
|
90 // Return Value: |
|
91 //******************************************************************************* |
|
92 CTestAppConsole::~CTestAppConsole() |
|
93 { |
|
94 Cancel(); // any outstanding request |
|
95 |
|
96 if (iConsole) |
|
97 { |
|
98 delete iConsole; |
|
99 } |
|
100 |
|
101 delete iInstruct; |
|
102 } |
|
103 |
|
104 //******************************************************************************* |
|
105 // Method : CRtpAppConsole::StartTesting() |
|
106 // Purpose : start this AO |
|
107 // Parameters : |
|
108 // Return Value: |
|
109 //******************************************************************************* |
|
110 void CTestAppConsole::StartTesting() |
|
111 { |
|
112 DoRead(); |
|
113 } |
|
114 |
|
115 //******************************************************************************* |
|
116 // Method : CRtpAppConsole::DoRead() |
|
117 // Purpose : get the user's option and send request to scheduler |
|
118 // Parameters : |
|
119 // Return Value: |
|
120 //******************************************************************************* |
|
121 void CTestAppConsole::DoRead() |
|
122 { |
|
123 iConsole->Read(iStatus); |
|
124 SetActive(); |
|
125 } |
|
126 |
|
127 //******************************************************************************* |
|
128 // Method : CRtpAppConsole::RunL() |
|
129 // Purpose : |
|
130 // Parameters : |
|
131 // Return Value: |
|
132 //******************************************************************************* |
|
133 void CTestAppConsole::RunL() |
|
134 { |
|
135 // According to current test case and direct the user's command |
|
136 // to proper command handler. |
|
137 ProcessMainInput(); |
|
138 } |
|
139 |
|
140 //******************************************************************************* |
|
141 // Method : CRtpAppConsole::DoCancel() |
|
142 // Purpose : |
|
143 // Parameters : |
|
144 // Return Value: |
|
145 //******************************************************************************* |
|
146 void CTestAppConsole::DoCancel() |
|
147 { |
|
148 iConsole->ReadCancel(); |
|
149 } |
|
150 |
|
151 |
|
152 //******************************************************************************* |
|
153 // Method : CRtpAppConsole::DisplayConsoleMenu() |
|
154 // Purpose : Display main or sub console menus for different test cases |
|
155 // Parameters : TDesc &aInstructions |
|
156 // Return Value: void |
|
157 //******************************************************************************* |
|
158 |
|
159 void CTestAppConsole::DisplayConsoleMenu(const TDesC &aInstructions) |
|
160 { |
|
161 if (iInstruct) |
|
162 { |
|
163 delete iInstruct; |
|
164 iInstruct = NULL; |
|
165 } |
|
166 iInstruct = aInstructions.AllocL(); |
|
167 iConsole->ClearScreen(); |
|
168 iConsole->Write(*iInstruct); |
|
169 } |
|
170 |
|
171 //******************************************************************************* |
|
172 // Method : CTestAppConsole::ProcessMainInput() |
|
173 // Purpose : Obtain user's option and decide which test case to run next. |
|
174 // Parameters : |
|
175 // Return Value: |
|
176 //******************************************************************************* |
|
177 void CTestAppConsole::ProcessMainInput() |
|
178 { |
|
179 TChar inputChar = iConsole->KeyCode(); |
|
180 |
|
181 switch(inputChar) |
|
182 { |
|
183 case '1': |
|
184 RunTest1(); |
|
185 break; |
|
186 case '2': |
|
187 //RunTest2(); |
|
188 break; |
|
189 case '9': |
|
190 CActiveScheduler::Stop(); |
|
191 Stop(); |
|
192 break; |
|
193 default: |
|
194 _LIT(KTxtWrongOption, "Wrong Option! Try Again."); |
|
195 DisplayMsg(KTxtWrongOption); |
|
196 break; |
|
197 } |
|
198 |
|
199 // Ready to get next input option. |
|
200 DoRead(); |
|
201 } |
|
202 |
|
203 //******************************************************************************* |
|
204 // Method : CRtpAppConsole::DisplayMsg() |
|
205 // Purpose : Display testing message on screen |
|
206 // Parameters : TDesC & |
|
207 // Return Value: |
|
208 //******************************************************************************* |
|
209 void CTestAppConsole::DisplayMsg(const TDesC &aMsg) |
|
210 { |
|
211 iConsole->ClearScreen(); |
|
212 iConsole->Write(*iInstruct); |
|
213 iConsole->Printf(KTxtLineBreak); |
|
214 iConsole->Printf(aMsg); |
|
215 iConsole->Printf(KTxtLineBreak); |
|
216 } |
|
217 |
|
218 //******************************************************************************* |
|
219 // Method : CTestAppConsole::GetAddrFromConsole() |
|
220 // Purpose : |
|
221 // Parameters : |
|
222 // Return Value: |
|
223 //******************************************************************************* |
|
224 TKeyCode CTestAppConsole::GetStringFromConsole(TDes &aAddr) |
|
225 { |
|
226 // Get a line from console |
|
227 TKeyCode input = EKeyNull; |
|
228 const TInt start_pos = iConsole->WhereX(); |
|
229 aAddr.Zero(); |
|
230 |
|
231 // loop until descriptor full or EKeyEnter or EKeyEscape entered |
|
232 do { |
|
233 // get one character |
|
234 input = iConsole->Getch(); |
|
235 // process it |
|
236 if(input == EKeyBackspace || input == EKeyDelete) |
|
237 { |
|
238 // backspace or delete |
|
239 if(iConsole->WhereX() > start_pos) |
|
240 { |
|
241 iConsole->SetPos(iConsole->WhereX() - 1); |
|
242 iConsole->ClearToEndOfLine(); |
|
243 if(aAddr.Length() > 0) |
|
244 { |
|
245 aAddr.SetLength(aAddr.Length() - 1); |
|
246 } |
|
247 } |
|
248 } |
|
249 else |
|
250 { |
|
251 // other than backspace or delete |
|
252 TChar ch(input); |
|
253 if(ch.IsPrint()) |
|
254 { |
|
255 aAddr.Append(ch); |
|
256 iConsole->Printf(_L("%c"), input); |
|
257 } |
|
258 } |
|
259 } |
|
260 while(aAddr.Length() < aAddr.MaxLength() && input != EKeyEnter && input != EKeyEscape); |
|
261 |
|
262 DisplayMsg(KTxtLineBreak); |
|
263 return input; |
|
264 } |
|
265 |
|
266 //******************************************************************************* |
|
267 // Method : CTestAppConsole::RunTest1() |
|
268 // Purpose : |
|
269 // Parameters : |
|
270 // Return Value: |
|
271 //******************************************************************************* |
|
272 |
|
273 void CTestAppConsole::RunTest1() |
|
274 { |
|
275 //DisplayMsg(_L("------Test2 End------\n")); |
|
276 RMMFController controller; |
|
277 TMMFPrioritySettings settings; |
|
278 settings.iPriority = EPriorityNormal; |
|
279 |
|
280 controller.Open( KControllerUID, settings ); |
|
281 |
|
282 TInt err = controller.AddDataSource( KSourceUID, KNullDesC8 ); |
|
283 |
|
284 err = controller.AddDataSink( KSinkUID, KNullDesC8 ); |
|
285 |
|
286 } |
|
287 |
|
288 |
|
289 //******************************************************************************* |
|
290 void CTestAppConsole::RunTest2() |
|
291 { |
|
292 } |
|
293 |
|
294 //******************************************************************************* |
|
295 void CTestAppConsole::Stop() |
|
296 { |
|
297 #ifdef DEBUG_INFO |
|
298 RDebug::Print (_L ("------The End------\n")); |
|
299 #endif |
|
300 |
|
301 DisplayMsg(_L("------The End------")); |
|
302 // iConsole->Getch(); |
|
303 } |
|
304 |
|
305 |