62
|
1 |
/*
|
|
2 |
* Copyright (c) 2002 - 2007 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: CConsoleMain class implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// INCLUDES
|
|
19 |
#include "testbaseview.h"
|
|
20 |
#include "consolereader.h"
|
|
21 |
#include "scrollertimer.h"
|
|
22 |
#include "consolemain.h"
|
|
23 |
|
|
24 |
// CONSTANTS
|
|
25 |
_LIT(KNameTxt,"TEST FRAMEWORK");
|
|
26 |
|
|
27 |
// ---------------------------------------------------------------------------
|
|
28 |
// Class: CConsoleMain
|
|
29 |
// Method: NewL
|
|
30 |
// Description: Construct the console main class
|
|
31 |
// Parameters: None
|
|
32 |
// Return Values: CConsoleMain* New object
|
|
33 |
// ---------------------------------------------------------------------------
|
|
34 |
//
|
|
35 |
EXPORT_C CConsoleMain* CConsoleMain::NewL(CActiveScheduler* aScheduler)
|
|
36 |
{
|
|
37 |
|
|
38 |
CConsoleMain* self = new ( ELeave ) CConsoleMain(aScheduler);
|
|
39 |
CleanupStack::PushL( self );
|
|
40 |
self->ConstructL();
|
|
41 |
CleanupStack::Pop( self );
|
|
42 |
return self;
|
|
43 |
|
|
44 |
}
|
|
45 |
|
|
46 |
// ---------------------------------------------------------------------------
|
|
47 |
// Method: ActivateL
|
|
48 |
// Description: Activate a view and start the view handling
|
|
49 |
// Parameters: aRootView, a root view of test app
|
|
50 |
// Return Values: None
|
|
51 |
// ---------------------------------------------------------------------------
|
|
52 |
//
|
|
53 |
EXPORT_C void CConsoleMain::ActivateL( CTestBaseView* aRootView )
|
|
54 |
{
|
|
55 |
|
|
56 |
iReader = CConsoleReader::NewL( this, iConsole );
|
|
57 |
iScroller = CScrollerTimer::NewL ( this );
|
|
58 |
|
|
59 |
// Construct keystroke reader
|
|
60 |
iScroller->Start();
|
|
61 |
|
|
62 |
// Print the main menu
|
|
63 |
iCurrentView = aRootView;
|
|
64 |
iCurrentView->DisplayViewL();
|
|
65 |
|
|
66 |
// Start to process keyboard events
|
|
67 |
iReader->Start();
|
|
68 |
|
|
69 |
iSchedulerStarted = TRUE;
|
|
70 |
iScheduler->Start();
|
|
71 |
}
|
|
72 |
|
|
73 |
// ---------------------------------------------------------------------------
|
|
74 |
// Method: Stop
|
|
75 |
// Description: Stop refreshing menu and the timer
|
|
76 |
// Parameters: None
|
|
77 |
// Return Values: None
|
|
78 |
// ---------------------------------------------------------------------------
|
|
79 |
//
|
|
80 |
EXPORT_C void CConsoleMain::Stop()
|
|
81 |
{
|
|
82 |
if(iReader)
|
|
83 |
{
|
|
84 |
iReader->Cancel();
|
|
85 |
delete iReader;
|
|
86 |
iReader = NULL;
|
|
87 |
}
|
|
88 |
|
|
89 |
if(iScroller)
|
|
90 |
{
|
|
91 |
iScroller->Cancel();
|
|
92 |
delete iScroller;
|
|
93 |
iScroller = NULL;
|
|
94 |
}
|
|
95 |
|
|
96 |
if(iSchedulerStarted)
|
|
97 |
{
|
|
98 |
iScheduler->Stop();
|
|
99 |
iSchedulerStarted = FALSE;
|
|
100 |
}
|
|
101 |
}
|
|
102 |
|
|
103 |
// ---------------------------------------------------------------------------
|
|
104 |
// Method: ReadString
|
|
105 |
// Description: Reads user input into the start of the descriptor aDes
|
|
106 |
// Parameters: TDes& aDes :out: a user input string
|
|
107 |
// Return Values: None
|
|
108 |
// ---------------------------------------------------------------------------
|
|
109 |
//
|
|
110 |
EXPORT_C void CConsoleMain::ReadString( TDes& aDes )
|
|
111 |
{
|
|
112 |
TChar inputKey;
|
|
113 |
TInt count = 0;
|
|
114 |
|
|
115 |
aDes.Zero();
|
|
116 |
for (;;)
|
|
117 |
{
|
|
118 |
inputKey = (TInt) iConsole->Getch();
|
|
119 |
|
|
120 |
if ( inputKey == EKeyEnter || inputKey == EKeyOK )
|
|
121 |
{
|
|
122 |
break;
|
|
123 |
}
|
|
124 |
|
|
125 |
if(inputKey == EKeyBackspace)
|
|
126 |
{
|
|
127 |
if (count > 0)
|
|
128 |
{
|
|
129 |
iConsole->Printf(_L("%C"), (TInt)inputKey);
|
|
130 |
aDes.Delete(--count,1);
|
|
131 |
}
|
|
132 |
}
|
|
133 |
else if(inputKey.IsPrint())
|
|
134 |
{
|
|
135 |
iConsole->Printf(_L("%C"), (TInt)inputKey);
|
|
136 |
aDes.Append(inputKey);
|
|
137 |
count++;
|
|
138 |
}
|
|
139 |
}
|
|
140 |
}
|
|
141 |
|
|
142 |
// ---------------------------------------------------------------------------
|
|
143 |
// Method: ~CConsoleMain
|
|
144 |
// Description: Destructor
|
|
145 |
// Parameters: None
|
|
146 |
// Return Values: None
|
|
147 |
// ---------------------------------------------------------------------------
|
|
148 |
//
|
|
149 |
CConsoleMain::~CConsoleMain( )
|
|
150 |
{
|
|
151 |
delete iReader;
|
|
152 |
|
|
153 |
delete iScroller;
|
|
154 |
|
|
155 |
delete iConsole;
|
|
156 |
}
|
|
157 |
|
|
158 |
// ---------------------------------------------------------------------------
|
|
159 |
// Method: CurrentView
|
|
160 |
// Description: Return current View
|
|
161 |
// Parameters: None
|
|
162 |
// Return Values: CTestBaseView iCurrentView
|
|
163 |
// ---------------------------------------------------------------------------
|
|
164 |
//
|
|
165 |
CTestBaseView* CConsoleMain::CurrentView()
|
|
166 |
{
|
|
167 |
return iCurrentView;
|
|
168 |
}
|
|
169 |
|
|
170 |
// ---------------------------------------------------------------------------
|
|
171 |
// Method: GetConsole
|
|
172 |
// Description: Returns the console
|
|
173 |
// Parameters: None
|
|
174 |
// Return Values: CConsoleBase* Console
|
|
175 |
// ---------------------------------------------------------------------------
|
|
176 |
//
|
|
177 |
CConsoleBase* CConsoleMain::GetConsole()
|
|
178 |
{
|
|
179 |
return iConsole;
|
|
180 |
}
|
|
181 |
|
|
182 |
// ---------------------------------------------------------------------------
|
|
183 |
// Method: TimerUpdate
|
|
184 |
// Description: Updates current menu from timer
|
|
185 |
// Parameters: None
|
|
186 |
// Return Values: None
|
|
187 |
// ---------------------------------------------------------------------------
|
|
188 |
//
|
|
189 |
void CConsoleMain::TimerUpdate()
|
|
190 |
{
|
|
191 |
iCurrentView->TimerUpdate();
|
|
192 |
}
|
|
193 |
|
|
194 |
|
|
195 |
// ---------------------------------------------------------------------------
|
|
196 |
// Method: KeyPressed
|
|
197 |
// Description: Process keyboard events. Print new menu
|
|
198 |
// Parameters: None
|
|
199 |
// Return Values: None
|
|
200 |
// ---------------------------------------------------------------------------
|
|
201 |
//
|
|
202 |
void CConsoleMain::KeyPressedL()
|
|
203 |
{
|
|
204 |
|
|
205 |
TBool cont = ETrue;
|
|
206 |
|
|
207 |
// Read the key
|
|
208 |
TKeyCode key = iConsole->KeyCode();
|
|
209 |
|
|
210 |
// Let the menu handle the key press
|
|
211 |
TRAPD( err,
|
|
212 |
iCurrentView->SelectL( key, cont );
|
|
213 |
);
|
|
214 |
if( err != KErrNone )
|
|
215 |
{
|
|
216 |
User::InfoPrint(
|
|
217 |
_L("Processing keystroke failed") );
|
|
218 |
}
|
|
219 |
|
|
220 |
if( iCurrentView )
|
|
221 |
{
|
|
222 |
iCurrentView->DisplayViewL();
|
|
223 |
// For next key event
|
|
224 |
iReader->Start();
|
|
225 |
}
|
|
226 |
}
|
|
227 |
|
|
228 |
// ---------------------------------------------------------------------------
|
|
229 |
// Method: CConsoleMain
|
|
230 |
// Description: Constructor.
|
|
231 |
// Initialize non-zero member variables.
|
|
232 |
// Parameters: None
|
|
233 |
// Return Values: None
|
|
234 |
// ---------------------------------------------------------------------------
|
|
235 |
//
|
|
236 |
CConsoleMain::CConsoleMain(CActiveScheduler* aScheduler)
|
|
237 |
{
|
|
238 |
iScheduler = aScheduler;
|
|
239 |
iSchedulerStarted = FALSE;
|
|
240 |
}
|
|
241 |
|
|
242 |
// ---------------------------------------------------------------------------
|
|
243 |
// Method: ConstructL
|
|
244 |
// Description: Second level constructor.
|
|
245 |
// Construct the console
|
|
246 |
// Construct module and case containers
|
|
247 |
// Retrieve command line parameters
|
|
248 |
// Connect to test engine
|
|
249 |
// Parameters: None
|
|
250 |
// Return Values: None
|
|
251 |
// ---------------------------------------------------------------------------
|
|
252 |
//
|
|
253 |
void CConsoleMain::ConstructL( )
|
|
254 |
{
|
|
255 |
// Construct the console
|
|
256 |
iConsole = Console::NewL( KNameTxt,
|
|
257 |
TSize( KConsFullScreen, KConsFullScreen ) );
|
|
258 |
|
|
259 |
iConsole->Printf(_L("\nViewTest Framework\n"));
|
|
260 |
}
|
|
261 |
|
|
262 |
// ---------------------------------------------------------------------------
|
|
263 |
// Method: NextViewL
|
|
264 |
// Description: activate child view
|
|
265 |
// Parameters: aChild, a child view
|
|
266 |
// Return Values: None
|
|
267 |
// ---------------------------------------------------------------------------
|
|
268 |
//
|
|
269 |
void CConsoleMain::NextViewL(CTestBaseView* aChild)
|
|
270 |
{
|
|
271 |
iCurrentView = aChild;
|
|
272 |
|
|
273 |
// Start to process keyboard events
|
|
274 |
//<-iReader-StartL() will be call in CConsoleMain::KeyPressedL()
|
|
275 |
// otherwise, Panic because of activiting an activated CActive
|
|
276 |
//iReader->StartL();
|
|
277 |
}
|
|
278 |
|
|
279 |
// ---------------------------------------------------------------------------
|
|
280 |
// Method: CurrentViewDoneL
|
|
281 |
// Description: Remove current view and active parent view if any
|
|
282 |
// Parameters: None
|
|
283 |
// Return Values: None
|
|
284 |
// ---------------------------------------------------------------------------
|
|
285 |
//
|
|
286 |
void CConsoleMain::CurrentViewDoneL()
|
|
287 |
{
|
|
288 |
//iCurrentView = (iCurrentView) ? iCurrentView->Parent() : NULL;
|
|
289 |
if(iCurrentView != NULL)
|
|
290 |
{
|
|
291 |
Stop();
|
|
292 |
}
|
|
293 |
}
|
|
294 |
|
|
295 |
|
|
296 |
|
|
297 |
|
|
298 |
|