|
1 /* |
|
2 * Copyright (c) 2008 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <centralrepository.h> |
|
19 #include <unsafprotocolscrkeys.h> |
|
20 #include <e32std.h> |
|
21 #include <e32base.h> |
|
22 #include <e32debug.h> |
|
23 #include <e32cons.h> |
|
24 #include <badesca.h> |
|
25 #include <sdpdocument.h> |
|
26 #include "nspplugin.h" |
|
27 #include "nsptestconsoleapp.h" |
|
28 #include "nsptestconsolestatemach.h" |
|
29 #include "nsptestmanager.h" |
|
30 #include "nsptest.h" |
|
31 |
|
32 _LIT( KMainTitle, " NSP Console " ); |
|
33 _LIT( KLineBreak, "\n" ); |
|
34 _LIT( KPrompt, "\\>" ); |
|
35 _LIT( KOne, "1" ); |
|
36 _LIT( KTwo, "2" ); |
|
37 _LIT( KThree, "3" ); |
|
38 _LIT( KFour, "4" ); |
|
39 |
|
40 const TInt KPluginUid = { 0x102832EF }; |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CNSPTestConsoleApp::NewLC |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CNSPTestConsoleApp* CNSPTestConsoleApp::NewLC() |
|
47 { |
|
48 CNSPTestConsoleApp* self = new ( ELeave ) CNSPTestConsoleApp; |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL(); |
|
51 return self; |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CNSPTestConsoleApp::CNSPTestConsoleApp |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CNSPTestConsoleApp::CNSPTestConsoleApp() |
|
59 : CActive( EPriorityStandard ) |
|
60 { |
|
61 CActiveScheduler::Add( this ); |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CNSPTestConsoleApp::ConstructL |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 void CNSPTestConsoleApp::ConstructL() |
|
69 { |
|
70 iPlugin = CNSPPlugin::NewL( TUid::Uid( KPluginUid ) ); |
|
71 iRepository = CRepository::NewL( KCRUidUNSAFProtocols ); |
|
72 iTestManager = CNSPTestManager::NewL( *iPlugin, *iRepository ); |
|
73 iStateMachine = CNSPTestConsoleStateMachine::NewL(); |
|
74 iConsole = Console::NewL( KMainTitle, |
|
75 TSize( KConsFullScreen, KConsFullScreen ) ); |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CNSPTestConsoleApp::CNSPTestConsoleApp |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 CNSPTestConsoleApp::~CNSPTestConsoleApp() |
|
83 { |
|
84 Cancel(); |
|
85 delete iConsole; |
|
86 delete iStateMachine; |
|
87 delete iTestManager; |
|
88 delete iRepository; |
|
89 delete iPlugin; |
|
90 REComSession::FinalClose(); |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CNSPTestConsoleApp::CNSPTestConsoleApp |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 void CNSPTestConsoleApp::StartTesting() |
|
98 { |
|
99 TNSPStateEvent event( *this, EKeyNull, KErrNone ); |
|
100 iStateMachine->Start( event ); |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CNSPTestConsoleApp::RunL |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 void CNSPTestConsoleApp::RunL() |
|
108 { |
|
109 TKeyCode keycode = iConsole->KeyCode(); |
|
110 |
|
111 switch ( keycode ) |
|
112 { |
|
113 case EKeyEscape: |
|
114 { |
|
115 iTestManager->CancelAll(); |
|
116 CActiveScheduler::Stop(); |
|
117 break; |
|
118 } |
|
119 |
|
120 default: |
|
121 { |
|
122 TNSPStateEvent event( *this, keycode, KErrNone ); |
|
123 iStateMachine->ProcessL( event ); |
|
124 } |
|
125 } |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CNSPTestConsoleApp::RunError |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 TInt CNSPTestConsoleApp::RunError( TInt aError ) |
|
133 { |
|
134 TNSPStateEvent event( *this, EKeyNull, aError ); |
|
135 TRAPD( err, iStateMachine->ProcessL( event ) ); |
|
136 return err; |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CNSPTestConsoleApp::DoCancel |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 void CNSPTestConsoleApp::DoCancel() |
|
144 { |
|
145 iConsole->ReadCancel(); |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CNSPTestConsoleApp::DisplayConsoleMenu |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 void CNSPTestConsoleApp::DisplayMenu( const TDesC& aText, TInt aError ) |
|
153 { |
|
154 iConsole->ClearScreen(); |
|
155 iConsole->Printf( KLineBreak() ); |
|
156 iConsole->Write( aText ); |
|
157 iConsole->Printf( KLineBreak() ); |
|
158 |
|
159 if ( KErrNone != aError ) |
|
160 { |
|
161 iConsole->Printf( _L("[error:%d]\n\n"), aError ); |
|
162 } |
|
163 else |
|
164 { |
|
165 iConsole->Printf( _L("[ESC to abort]\n\n") ); |
|
166 } |
|
167 } |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // CNSPTestConsoleApp::DisplaySelection |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 void CNSPTestConsoleApp::DisplaySelection( |
|
174 TInt aPrefix, const TDesC& aText, TBool aAddPreLinebreak ) |
|
175 { |
|
176 if ( aAddPreLinebreak ) |
|
177 { |
|
178 iConsole->Printf( KLineBreak() ); |
|
179 } |
|
180 |
|
181 iConsole->Printf( _L("%d."), aPrefix ); |
|
182 iConsole->Write( aText ); |
|
183 iConsole->Printf( KLineBreak() ); |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // CNSPTestConsoleApp::DisplaySelection |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 void CNSPTestConsoleApp::DisplaySelection( |
|
191 TInt aPrefix, const TDesC& aText, const TDesC& aSelect, TBool aAddPreLinebreak ) |
|
192 { |
|
193 if ( aAddPreLinebreak ) |
|
194 { |
|
195 iConsole->Printf( KLineBreak() ); |
|
196 } |
|
197 |
|
198 iConsole->Printf( _L("%d."), aPrefix ); |
|
199 iConsole->Write( aText ); |
|
200 iConsole->Printf( _L("[%S]\n"), &aSelect ); |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CNSPTestConsoleApp::DisplaySelection |
|
205 // ----------------------------------------------------------------------------- |
|
206 // |
|
207 void CNSPTestConsoleApp::DisplaySelection( |
|
208 TInt aPrefix, const TDesC& aText, TUint32 aSelect, TBool aAddPreLinebreak ) |
|
209 { |
|
210 if ( aAddPreLinebreak ) |
|
211 { |
|
212 iConsole->Printf( KLineBreak() ); |
|
213 } |
|
214 |
|
215 iConsole->Printf( _L("%d."), aPrefix ); |
|
216 iConsole->Write( aText ); |
|
217 iConsole->Printf( _L("[%u]\n"), aSelect ); |
|
218 } |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // CNSPTestConsoleApp::DisplaySelection |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 void CNSPTestConsoleApp::DisplaySelection( |
|
225 TInt aPrefix, const TDesC& aText, TInt aSelect, TBool aAddPreLinebreak ) |
|
226 { |
|
227 if ( aAddPreLinebreak ) |
|
228 { |
|
229 iConsole->Printf( KLineBreak() ); |
|
230 } |
|
231 |
|
232 iConsole->Printf( _L("%d."), aPrefix ); |
|
233 iConsole->Write( aText ); |
|
234 iConsole->Printf( _L("[%d]\n"), aSelect ); |
|
235 } |
|
236 |
|
237 // ----------------------------------------------------------------------------- |
|
238 // CNSPTestConsoleApp::DisplayPrompt |
|
239 // ----------------------------------------------------------------------------- |
|
240 // |
|
241 void CNSPTestConsoleApp::DisplayPrompt( TBool aAddPreLinebreak ) |
|
242 { |
|
243 if ( aAddPreLinebreak ) |
|
244 { |
|
245 iConsole->Printf( KLineBreak() ); |
|
246 } |
|
247 |
|
248 iConsole->Printf( KPrompt() ); |
|
249 } |
|
250 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // CNSPTestConsoleApp::DisplayPrompt |
|
253 // ----------------------------------------------------------------------------- |
|
254 // |
|
255 void CNSPTestConsoleApp::DisplayPrompt( const TDesC& aText, TBool aAddPreLinebreak ) |
|
256 { |
|
257 if ( aAddPreLinebreak ) |
|
258 { |
|
259 iConsole->Printf( KLineBreak() ); |
|
260 } |
|
261 |
|
262 iConsole->Printf( KPrompt() ); |
|
263 iConsole->Write( aText ); |
|
264 } |
|
265 |
|
266 // ----------------------------------------------------------------------------- |
|
267 // CNSPTestConsoleApp::DisplayOne |
|
268 // ----------------------------------------------------------------------------- |
|
269 // |
|
270 void CNSPTestConsoleApp::DisplayOne( TBool aAddPreLinebreak ) |
|
271 { |
|
272 if ( aAddPreLinebreak ) |
|
273 { |
|
274 iConsole->Printf( KLineBreak() ); |
|
275 } |
|
276 |
|
277 iConsole->Printf( KOne() ); |
|
278 iConsole->Printf( KLineBreak() ); |
|
279 } |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // CNSPTestConsoleApp::DisplayTwo |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 void CNSPTestConsoleApp::DisplayTwo( TBool aAddPreLinebreak ) |
|
286 { |
|
287 if ( aAddPreLinebreak ) |
|
288 { |
|
289 iConsole->Printf( KLineBreak() ); |
|
290 } |
|
291 |
|
292 iConsole->Printf( KTwo() ); |
|
293 iConsole->Printf( KLineBreak() ); |
|
294 } |
|
295 |
|
296 // ----------------------------------------------------------------------------- |
|
297 // CNSPTestConsoleApp::DisplayThree |
|
298 // ----------------------------------------------------------------------------- |
|
299 // |
|
300 void CNSPTestConsoleApp::DisplayThree( TBool aAddPreLinebreak ) |
|
301 { |
|
302 if ( aAddPreLinebreak ) |
|
303 { |
|
304 iConsole->Printf( KLineBreak() ); |
|
305 } |
|
306 |
|
307 iConsole->Printf( KThree() ); |
|
308 iConsole->Printf( KLineBreak() ); |
|
309 } |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // CNSPTestConsoleApp::DisplayFour |
|
313 // ----------------------------------------------------------------------------- |
|
314 // |
|
315 void CNSPTestConsoleApp::DisplayFour( TBool aAddPreLinebreak ) |
|
316 { |
|
317 if ( aAddPreLinebreak ) |
|
318 { |
|
319 iConsole->Printf( KLineBreak() ); |
|
320 } |
|
321 |
|
322 iConsole->Printf( KFour() ); |
|
323 iConsole->Printf( KLineBreak() ); |
|
324 } |
|
325 |
|
326 // ----------------------------------------------------------------------------- |
|
327 // CNSPTestConsoleApp::DoRead |
|
328 // ----------------------------------------------------------------------------- |
|
329 // |
|
330 void CNSPTestConsoleApp::DoRead() |
|
331 { |
|
332 iConsole->Read( iStatus ); |
|
333 |
|
334 if ( !IsActive() ) |
|
335 { |
|
336 SetActive(); |
|
337 } |
|
338 } |
|
339 |
|
340 // ----------------------------------------------------------------------------- |
|
341 // CNSPTestConsoleApp::GetStringFromConsole |
|
342 // ----------------------------------------------------------------------------- |
|
343 // |
|
344 TKeyCode CNSPTestConsoleApp::GetStringFromConsoleL( TDes& aBuffer ) |
|
345 { |
|
346 TKeyCode input = EKeyNull; |
|
347 const TInt startPos = iConsole->WhereX(); |
|
348 iConsole->Write( aBuffer ); |
|
349 |
|
350 do { |
|
351 input = iConsole->Getch(); |
|
352 |
|
353 if ( ( EKeyBackspace == input || EKeyDelete == input ) && |
|
354 startPos < iConsole->WhereX() ) // Backspace & Delete |
|
355 { |
|
356 iConsole->SetPos( iConsole->WhereX() - 1 ); |
|
357 iConsole->ClearToEndOfLine(); |
|
358 |
|
359 aBuffer.SetLength( 0 < aBuffer.Length() ? |
|
360 aBuffer.Length() - 1 : |
|
361 aBuffer.Length() ); |
|
362 } |
|
363 else{ |
|
364 TChar chr( input ); |
|
365 |
|
366 if ( chr.IsPrint() ) |
|
367 { |
|
368 aBuffer.Append( chr ); |
|
369 iConsole->Printf( _L("%c"), input ); |
|
370 } |
|
371 } |
|
372 } |
|
373 while ( EKeyEnter != input && EKeyEscape != input ); |
|
374 |
|
375 return input; |
|
376 } |
|
377 |
|
378 // ----------------------------------------------------------------------------- |
|
379 // CNSPTestConsoleApp::GetTUint32FromConsole |
|
380 // ----------------------------------------------------------------------------- |
|
381 // |
|
382 TKeyCode CNSPTestConsoleApp::GetTUint32FromConsoleL( TUint32& aTUint32 ) |
|
383 { |
|
384 TBuf<255> buffer; |
|
385 buffer.AppendNum( aTUint32, EDecimal ); |
|
386 TKeyCode input = GetStringFromConsoleL( buffer ); |
|
387 TLex lex( buffer ); |
|
388 User::LeaveIfError( lex.Val( aTUint32, EDecimal ) ); |
|
389 return input; |
|
390 } |
|
391 |
|
392 // ----------------------------------------------------------------------------- |
|
393 // CNSPTestConsoleApp::Cenrep |
|
394 // ----------------------------------------------------------------------------- |
|
395 // |
|
396 CRepository& CNSPTestConsoleApp::Cenrep() |
|
397 { |
|
398 return *iRepository; |
|
399 } |
|
400 |
|
401 // ----------------------------------------------------------------------------- |
|
402 // CNSPTestConsoleApp::Manager |
|
403 // ----------------------------------------------------------------------------- |
|
404 // |
|
405 CNSPTestManager& CNSPTestConsoleApp::Manager() |
|
406 { |
|
407 return *iTestManager; |
|
408 } |
|
409 |
|
410 // ----------------------------------------------------------------------------- |
|
411 // CNSPTestConsoleApp::Console |
|
412 // ----------------------------------------------------------------------------- |
|
413 // |
|
414 CConsoleBase& CNSPTestConsoleApp::Console() |
|
415 { |
|
416 return *iConsole; |
|
417 } |