|
1 /* |
|
2 * Copyright (c) 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: This is the class module for the Diag Headset Cable Test Engine |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 // Class Declaration |
|
22 #include "diagheadsetcableengine.h" |
|
23 |
|
24 #include <StringLoader.h> // StringLoader |
|
25 #include <HeadsetStatus.h> // CHeadsetStatus |
|
26 #include <aknmessagequerydialog.h> // CAknMessageQueryDialog |
|
27 #include <DiagFrameworkDebug.h> // debug macros |
|
28 #include <devdiagheadsetcabletestpluginrsc.rsg> // resources |
|
29 #include <DiagPluginWaitingDialogWrapper.h> // CDiagPluginWaitingDialogWrapper |
|
30 |
|
31 #include "diagheadsetcabletestplugin.hrh" // command ids |
|
32 |
|
33 // EXTERNAL DATA STRUCTURES |
|
34 |
|
35 // EXTERNAL FUNCTION PROTOTYPES |
|
36 |
|
37 // CONSTANTS |
|
38 |
|
39 // MACROS |
|
40 |
|
41 // LOCAL CONSTANTS AND MACROS |
|
42 |
|
43 // MODULE DATA STRUCTURES |
|
44 |
|
45 // LOCAL FUNCTION PROTOTYPES |
|
46 |
|
47 // FORWARD DECLARATIONS |
|
48 |
|
49 // ============================= LOCAL FUNCTIONS ============================== |
|
50 |
|
51 // ========================= MEMBER FUNCTIONS ================================ |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // Symbian OS default constructor |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 CDiagHeadsetCableTestEngine* CDiagHeadsetCableTestEngine::NewL( |
|
58 MDiagHeadsetTestCallBackInterface& aInterface, |
|
59 TBool aIsSinglePluginExecution) |
|
60 { |
|
61 LOGSTRING( "CDiagHeadsetCableTestEngine instance created" ) |
|
62 CDiagHeadsetCableTestEngine* self = new (ELeave) |
|
63 CDiagHeadsetCableTestEngine(aInterface, aIsSinglePluginExecution); |
|
64 |
|
65 CleanupStack::PushL( self ); |
|
66 self->ConstructL(); |
|
67 CleanupStack::Pop( self ); |
|
68 return self; |
|
69 } |
|
70 |
|
71 |
|
72 // ---------------------------------------------------------------------------- |
|
73 // Constructor |
|
74 // ---------------------------------------------------------------------------- |
|
75 // |
|
76 CDiagHeadsetCableTestEngine::CDiagHeadsetCableTestEngine( |
|
77 MDiagHeadsetTestCallBackInterface& aInterface, |
|
78 TBool aIsSinglePluginExecution) |
|
79 : CActive( EPriorityStandard ), |
|
80 iInterface(aInterface), |
|
81 iWaitingDialogWrapper( NULL ), |
|
82 iIsSinglePluginExecution(aIsSinglePluginExecution) |
|
83 { |
|
84 CActiveScheduler::Add( this ); |
|
85 } |
|
86 |
|
87 // ---------------------------------------------------------------------------- |
|
88 // Destructor |
|
89 // ---------------------------------------------------------------------------- |
|
90 // |
|
91 CDiagHeadsetCableTestEngine::~CDiagHeadsetCableTestEngine() |
|
92 { |
|
93 LOGSTRING( "CDiagHeadsetCableTestEngine instance destroyed" ) |
|
94 Cancel(); |
|
95 |
|
96 delete iWaitingDialogWrapper; // deleting will dismiss active dialog |
|
97 iWaitingDialogWrapper = NULL; |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // Symbian OS second phase constructor |
|
102 // --------------------------------------------------------------------------- |
|
103 void CDiagHeadsetCableTestEngine::ConstructL() |
|
104 { |
|
105 // nothting needed here |
|
106 } |
|
107 |
|
108 // ---------------------------------------------------------------------------- |
|
109 // This function starts the Headset cable test |
|
110 // ---------------------------------------------------------------------------- |
|
111 void CDiagHeadsetCableTestEngine::RunHeadsetCableTestL() |
|
112 { |
|
113 TInt userResponse; |
|
114 if ( !ConnectAndPressOkL( userResponse ) ) |
|
115 { |
|
116 // "Connect Headset and Press OK" dialog was dismisses internally by framework |
|
117 // return immediately |
|
118 LOGSTRING( "CDiagHeadsetCableTestEngine : Connect Headset and press ok dialog dismissed internally" ) |
|
119 return; |
|
120 } |
|
121 |
|
122 switch( userResponse ) |
|
123 { |
|
124 // User select OK for "Connect Headset and Press OK" dialog |
|
125 case EAknSoftkeyOk: |
|
126 { |
|
127 //TInt keySelect; |
|
128 // check if headset cable is connected |
|
129 if( CheckIfHeadsetDetectedL() ) |
|
130 { |
|
131 // Headset cable is detected. |
|
132 LOGSTRING( "CDiagHeadsetCableTestEngine : Headset detected" ) |
|
133 // if ( !RemoveAllCablesL( keySelect ) ) |
|
134 // { |
|
135 // LOGSTRING( "CDiagHeadsetCableTestEngine : Remove All Cable dialog was dismissed internally pressed" ) |
|
136 // return; |
|
137 // } |
|
138 |
|
139 // if ( keySelect != EAknSoftkeyOk ) |
|
140 // { |
|
141 // LOGSTRING( "CDiagHeadsetCableTestEngine : EndKey has pressed" ) |
|
142 // return; |
|
143 // } |
|
144 LOGSTRING( "CDiagHeadsetCableTestEngine : Report result Success" ) |
|
145 ReportResultToPluginL(CDiagResultsDatabaseItem::ESuccess); |
|
146 } |
|
147 else |
|
148 { |
|
149 // Headset cable is not detected |
|
150 if ( !AskIfRetryL( userResponse ) ) |
|
151 { |
|
152 // Retry Back dialog was dismissed internally by framework internally |
|
153 LOGSTRING( "CDiagHeadsetCableTestEngine : Ask for retry dialog dismissed internally" ) |
|
154 return; |
|
155 } |
|
156 |
|
157 //if( userResponse == EAknSoftkeyOk ) // ADO & Platformization Changes |
|
158 if( userResponse == EHeadsetTestConnectHeadsetNo ) |
|
159 { |
|
160 // User selects Ok to confirm, Test fails |
|
161 ReportResultToPluginL(CDiagResultsDatabaseItem::EFailed); |
|
162 } |
|
163 // else if( userResponse == EHeadsetTestConnectHeadsetBack ) // ADO & Platformization Changes |
|
164 else if( userResponse == EHeadsetTestConnectHeadsetYes ) |
|
165 { |
|
166 // User selectes Back to retry the test |
|
167 TRequestStatus* status = &iStatus; |
|
168 SetActive(); |
|
169 User::RequestComplete( status, KErrNone ); |
|
170 } |
|
171 else |
|
172 { |
|
173 // User cancels the test using Canceld end key, return immediately |
|
174 return; |
|
175 } |
|
176 } |
|
177 } |
|
178 break; |
|
179 // User select CANCEL softkey for "Connect Headset and Press OK" dialog |
|
180 case EHeadsetTestConnectHeadsetSkip: |
|
181 case EHeadsetTestConnectHeadsetCancel: |
|
182 { |
|
183 if(!iIsSinglePluginExecution) |
|
184 { |
|
185 if( iInterface.AskCancelExecutionL(userResponse) ) |
|
186 { |
|
187 switch(userResponse) |
|
188 { |
|
189 case EAknSoftkeyOk: |
|
190 { |
|
191 //CompleteTestL( CDiagResultsDatabaseItem::ECancelled ); |
|
192 LOGSTRING( "CDiagHeadsetCableTestEngine User cancelled the test" ) |
|
193 return; |
|
194 } |
|
195 |
|
196 default: |
|
197 { |
|
198 // currently no way distinguish between Cancel and No key |
|
199 |
|
200 // user selected "No" to cancel |
|
201 // do a self-trigger to start again |
|
202 TRequestStatus* status = &iStatus; |
|
203 SetActive(); |
|
204 User::RequestComplete( status, KErrNone ); |
|
205 |
|
206 // this trigger for Cancel key is cancelled by CActive::Cancel() in destructor |
|
207 } |
|
208 break; |
|
209 } |
|
210 } |
|
211 else |
|
212 { |
|
213 // though cancel dialog should not be dismissed internally by the framework |
|
214 // this is just a safeguard to make sure we dont do anything |
|
215 LOGSTRING( "CDiagHeadsetCableTestEngine Cancel dialog was dismissed internally" ) |
|
216 return; |
|
217 } |
|
218 } |
|
219 else |
|
220 { |
|
221 ReportResultToPluginL( CDiagResultsDatabaseItem::ESkipped ); |
|
222 return; |
|
223 } |
|
224 } |
|
225 break; |
|
226 |
|
227 // User select CANCEL (RED End KEY) for "Connect Headset and Press OK" dialog |
|
228 default: |
|
229 { |
|
230 LOGSTRING( "CDiagHeadsetCableTestEngine Connect Headset and press OK dialog was cancelled by end key." ) |
|
231 } |
|
232 break; |
|
233 }; |
|
234 |
|
235 } |
|
236 |
|
237 // ---------------------------------------------------------------------------- |
|
238 // CDiagHeadsetCableTestEngine::CheckIfHeadsetDetectedL |
|
239 // |
|
240 // This function reports the result to plugin |
|
241 // ---------------------------------------------------------------------------- |
|
242 TBool CDiagHeadsetCableTestEngine::CheckIfHeadsetDetectedL() |
|
243 { |
|
244 TBool retval = EFalse; |
|
245 TBool isConnected = EFalse; |
|
246 CHeadsetStatus* aHeadsetStatus = CHeadsetStatus::NewL(); |
|
247 |
|
248 CleanupStack::PushL( aHeadsetStatus ); |
|
249 TInt err( aHeadsetStatus->HeadsetConnectedL( isConnected ) ); |
|
250 CleanupStack::PopAndDestroy( aHeadsetStatus ); |
|
251 |
|
252 if(err == KErrNone) |
|
253 { |
|
254 if( isConnected ) |
|
255 { |
|
256 LOGSTRING( "CDiagHeadsetCableTestEngine Headset cable is connected" ) |
|
257 retval = ETrue; // headset is connected |
|
258 } |
|
259 else |
|
260 { |
|
261 LOGSTRING( "CDiagHeadsetCableTestEngine Headset cable is not connected" ) |
|
262 retval = EFalse; // headset is not connected |
|
263 } |
|
264 } |
|
265 else |
|
266 { |
|
267 LOGSTRING( "CDiagHeadsetCableTestEngine some error occurred in detecting Headset cable" ) |
|
268 retval = EFalse; // some error occurred |
|
269 } |
|
270 |
|
271 return retval; |
|
272 } |
|
273 |
|
274 |
|
275 |
|
276 // ---------------------------------------------------------------------------- |
|
277 // CDiagHeadsetCableTestEngine::ReportResultToPluginL |
|
278 // |
|
279 // This function reports the result to plugin |
|
280 // ---------------------------------------------------------------------------- |
|
281 void CDiagHeadsetCableTestEngine::ReportResultToPluginL(CDiagResultsDatabaseItem::TResult aResult) |
|
282 { |
|
283 iInterface.ReportTestResultL( aResult ); |
|
284 } |
|
285 |
|
286 // --------------------------------------------------------------------------------------- |
|
287 // CDiagHeadsetCableTestEngine::ConnectAndPressOkL |
|
288 // This function shows the query dialog "Connect your Headset charger. Press OK when ready." |
|
289 // --------------------------------------------------------------------------------------- |
|
290 TBool CDiagHeadsetCableTestEngine::ConnectAndPressOkL( TInt& aUserResponse ) |
|
291 { |
|
292 ASSERT( iWaitingDialogWrapper == NULL ); |
|
293 |
|
294 CAknQueryDialog* dialog = CAknQueryDialog::NewL( CAknQueryDialog::ENoTone ); |
|
295 CleanupStack::PushL( dialog ); |
|
296 dialog->PrepareLC( R_DIAG_HEADSET_CABLE_TEST_CONNECT_AND_PRESS_OK ); |
|
297 if( iIsSinglePluginExecution ) |
|
298 { |
|
299 CEikButtonGroupContainer& cba = dialog->ButtonGroupContainer(); |
|
300 cba.SetCommandSetL( R_CBA_CONNECT_AND_PRESS_OK_SINGLE_EXECUTION ); |
|
301 } |
|
302 CleanupStack::Pop( dialog ); |
|
303 |
|
304 // dialog ownership to bepassed to iWaitingDialogWrapper |
|
305 // CDiagPluginWaitingDialogWrapper::NewL will push dialog into clean up stack |
|
306 iWaitingDialogWrapper = CDiagPluginWaitingDialogWrapper::NewL( dialog ); |
|
307 dialog = NULL; |
|
308 |
|
309 TBool isDialogDismissedByUser = iWaitingDialogWrapper->RunLD( aUserResponse ); |
|
310 if ( isDialogDismissedByUser ) |
|
311 { |
|
312 // local variable can be accessed only if it was returned due to |
|
313 // user response. iWaitingDialogWrapper self destructs. |
|
314 iWaitingDialogWrapper = NULL; |
|
315 } |
|
316 |
|
317 return isDialogDismissedByUser; |
|
318 } |
|
319 |
|
320 // --------------------------------------------------------------------------------------- |
|
321 // CDiagHeadsetCableTestEngine::RemoveAllCables |
|
322 // This function shows the query dialog : Please remove all cables |
|
323 // --------------------------------------------------------------------------------------- |
|
324 TBool CDiagHeadsetCableTestEngine::RemoveAllCablesL( TInt& aUserResponse ) |
|
325 { |
|
326 ASSERT( iWaitingDialogWrapper == NULL ); |
|
327 |
|
328 CAknQueryDialog* dialog = CAknQueryDialog::NewL( CAknQueryDialog::ENoTone ); |
|
329 |
|
330 dialog->PrepareLC( R_DIAG_CABLE_TEST_REMOVE_ALL_CABLES ); |
|
331 |
|
332 // dialog ownership to bepassed to iWaitingDialogWrapper |
|
333 // CDiagPluginWaitingDialogWrapper::NewL will push dialog into clean up stack |
|
334 iWaitingDialogWrapper = CDiagPluginWaitingDialogWrapper::NewL( dialog ); |
|
335 dialog = NULL; |
|
336 |
|
337 TBool isDialogDismissedByUser = iWaitingDialogWrapper->RunLD( aUserResponse ); |
|
338 if ( isDialogDismissedByUser ) |
|
339 { |
|
340 // local variable can be accessed only if it was returned due to |
|
341 // user response. iWaitingDialogWrapper self destructs. |
|
342 iWaitingDialogWrapper = NULL; |
|
343 } |
|
344 |
|
345 return isDialogDismissedByUser; |
|
346 } |
|
347 |
|
348 // ---------------------------------------------------------------------------- |
|
349 // CDiagHeadsetCableTestEngine::AskIfRetryL |
|
350 // This function shows the query dialog "No cable detected. Press OK to continue |
|
351 // tests or press Back to retry this test." |
|
352 // ---------------------------------------------------------------------------- |
|
353 TBool CDiagHeadsetCableTestEngine::AskIfRetryL( TInt& aUserResponse ) |
|
354 { |
|
355 return DisplayQueryDialogWithHeaderL( R_DIAG_HEADSET_CABLE_TEST_NO_CABLE_DETECTED, |
|
356 aUserResponse ); |
|
357 } |
|
358 |
|
359 // --------------------------------------------------------------------------------------- |
|
360 // CDiagHeadsetCableTestEngine::DisplayQueryDialogWithHeaderL |
|
361 // This function shows the query dialog with header. It returns ETrue, |
|
362 // if the dialog is dismissed by user. If the dialog was dismissed because of time-out, |
|
363 // it returns EFalse. The user response (softkey) is returned in the reference |
|
364 // argument aUserResponse |
|
365 // --------------------------------------------------------------------------------------- |
|
366 TBool CDiagHeadsetCableTestEngine::DisplayQueryDialogWithHeaderL( |
|
367 TInt aDialogResourceId, |
|
368 TInt& aUserResponse ) |
|
369 { |
|
370 ASSERT( iWaitingDialogWrapper == NULL ); |
|
371 |
|
372 CAknMessageQueryDialog * dialog = new ( ELeave ) |
|
373 CAknMessageQueryDialog ( CAknQueryDialog::ENoTone ); |
|
374 CleanupStack::PushL( dialog ); |
|
375 dialog->PrepareLC( aDialogResourceId ); |
|
376 CleanupStack::Pop( dialog ); |
|
377 |
|
378 // dialog ownership to bepassed to iWaitingDialogWrapper |
|
379 // CDiagPluginWaitingDialogWrapper::NewL will push dialog into clean up stack |
|
380 iWaitingDialogWrapper = CDiagPluginWaitingDialogWrapper::NewL( dialog ); |
|
381 dialog = NULL; |
|
382 |
|
383 TBool isDialogDismissedByUser = iWaitingDialogWrapper->RunLD( aUserResponse ); |
|
384 if ( isDialogDismissedByUser ) |
|
385 { |
|
386 // local variable can be accessed only if it was returned due to |
|
387 // user response. iWaitingDialogWrapper self destructs. |
|
388 iWaitingDialogWrapper = NULL; |
|
389 } |
|
390 |
|
391 return isDialogDismissedByUser; |
|
392 } |
|
393 |
|
394 |
|
395 // --------------------------------------------------------------------------------------- |
|
396 // CDiagHeadsetCableTestEngine::RunL |
|
397 // RunL() function is used in this plug-in to handle internal trigger |
|
398 // --------------------------------------------------------------------------------------- |
|
399 void CDiagHeadsetCableTestEngine::RunL() |
|
400 { |
|
401 if(iStatus == KErrNone) |
|
402 { |
|
403 RunHeadsetCableTestL(); |
|
404 } |
|
405 } |
|
406 |
|
407 // --------------------------------------------------------------------------------------- |
|
408 // CDiagHeadsetCableTestEngine::DoCancel |
|
409 // Handles cancel request |
|
410 // --------------------------------------------------------------------------------------- |
|
411 void CDiagHeadsetCableTestEngine::DoCancel() |
|
412 { |
|
413 // no implementation needed |
|
414 } |
|
415 |
|
416 // End of File |