1 /* |
1 /* |
2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
24 #include <cusbpersonalityplugin.h> |
24 #include <cusbpersonalityplugin.h> |
25 #include <tusbpersonalityparams.h> |
25 #include <tusbpersonalityparams.h> |
26 #include <startupdomainpskeys.h> //for global system state |
26 #include <startupdomainpskeys.h> //for global system state |
27 #include "cusbactivepersonalityhandler.h" |
27 #include "cusbactivepersonalityhandler.h" |
28 #include "cusbglobalsystemstateobserver.h" |
28 #include "cusbglobalsystemstateobserver.h" |
|
29 #include <usbuinotif.h> |
29 |
30 |
30 // CONSTANTS |
31 // CONSTANTS |
31 // const TInt KSerialNumberLength = 12; |
32 // const TInt KSerialNumberLength = 12; |
32 const TInt KContainerIdLength = 16; |
33 const TInt KContainerIdLength = 16; |
33 |
34 |
42 CUsbActivePersonalityHandler::CUsbActivePersonalityHandler( |
43 CUsbActivePersonalityHandler::CUsbActivePersonalityHandler( |
43 RUsb& aUsbMan, CUsbWatcher& aOwner ) |
44 RUsb& aUsbMan, CUsbWatcher& aOwner ) |
44 : CActive( EPriorityStandard ) |
45 : CActive( EPriorityStandard ) |
45 , iUsbMan( aUsbMan ) |
46 , iUsbMan( aUsbMan ) |
46 , iOwner( aOwner ) |
47 , iOwner( aOwner ) |
|
48 , isFailureCleanup( EFalse ) |
47 { |
49 { |
48 CActiveScheduler::Add( this ); |
50 CActiveScheduler::Add( this ); |
49 } |
51 } |
50 |
52 |
51 // ---------------------------------------------------------------------------- |
53 // ---------------------------------------------------------------------------- |
219 if( ( ret == KErrNone) && iCurrentPersonalityHandler ) |
221 if( ( ret == KErrNone) && iCurrentPersonalityHandler ) |
220 { |
222 { |
221 LOG( "PersonalityHandler created" ); |
223 LOG( "PersonalityHandler created" ); |
222 iCurrentPersonalityHandler->PreparePersonalityStart( iStatus ); |
224 iCurrentPersonalityHandler->PreparePersonalityStart( iStatus ); |
223 iState = EUsbPersonalityPrepareStart; |
225 iState = EUsbPersonalityPrepareStart; |
|
226 isFailureCleanup = EFalse; |
224 SetActive(); |
227 SetActive(); |
225 } |
228 } |
226 else |
229 else |
227 { |
230 { |
228 LOG( "Error: PersonalityHandler create failed" ); |
231 LOG( "Error: PersonalityHandler create failed" ); |
240 |
243 |
241 aStatus = KRequestPending; |
244 aStatus = KRequestPending; |
242 iRequestStatus = &aStatus; |
245 iRequestStatus = &aStatus; |
243 |
246 |
244 iState = EUsbPersonalityPrepareStop; |
247 iState = EUsbPersonalityPrepareStop; |
245 |
248 isFailureCleanup = EFalse; |
|
249 |
246 // prepare current personality for stop and return |
250 // prepare current personality for stop and return |
247 if( iCurrentPersonalityHandler ) |
251 if( iCurrentPersonalityHandler ) |
248 { |
252 { |
249 LOG( "Call PersonalityPlugin to prepare stop" ); |
253 LOG( "Call PersonalityPlugin to prepare stop" ); |
250 iCurrentPersonalityHandler->PreparePersonalityStop( iStatus ); |
254 iCurrentPersonalityHandler->PreparePersonalityStop( iStatus ); |
282 KCableConnectedNotifierUid, iDummy, |
286 KCableConnectedNotifierUid, iDummy, |
283 iPersonalityPckgBuf); |
287 iPersonalityPckgBuf); |
284 } |
288 } |
285 break; |
289 break; |
286 } |
290 } |
|
291 case EUsbDeviceStateUndefined: |
|
292 { |
|
293 iPersonalityNotifier->CancelQuery(KQueriesNotifier); |
|
294 break; |
|
295 } |
287 default: |
296 default: |
288 // We do not handle other state here |
297 // We do not handle other state here |
289 LOG( "DeviceStatechange ignored by ActivePersonalityhandler or EUsbDeviceStateConfigured" ); |
298 LOG( "DeviceStatechange ignored by ActivePersonalityhandler or EUsbDeviceStateConfigured" ); |
290 break; |
299 break; |
291 } |
300 } |
300 // ---------------------------------------------------------------------------- |
309 // ---------------------------------------------------------------------------- |
301 // Standard active object error function. Handle error and complete |
310 // Standard active object error function. Handle error and complete |
302 // outstanding request. We must not come here. |
311 // outstanding request. We must not come here. |
303 // ---------------------------------------------------------------------------- |
312 // ---------------------------------------------------------------------------- |
304 // |
313 // |
305 TInt CUsbActivePersonalityHandler::RunError( TInt /*aError*/ ) |
314 TInt CUsbActivePersonalityHandler::RunError( TInt aError ) |
306 { |
315 { |
307 LOG_FUNC |
316 LOG_FUNC |
|
317 |
|
318 LOG2("Returned error: %d, iState: %d", aError, iState); |
|
319 |
|
320 if (KErrNoMemory == aError) |
|
321 { |
|
322 iQueryParams().iQuery = EUSBNotEnoughRam; |
|
323 iPersonalityParams->PersonalityNotifier().ShowQuery(KQueriesNotifier, |
|
324 iQueryParams, iDummyBuf); |
|
325 } |
|
326 |
|
327 //only handle error when TryStart fails now |
|
328 //clean up work to be done in the personality |
|
329 if (iState == EUsbPersonalityStartUsb) |
|
330 { |
|
331 iState = EUsbPersonalityPrepareStop; |
|
332 isFailureCleanup = ETrue; |
|
333 |
|
334 // prepare current personality for stop and return |
|
335 if( iCurrentPersonalityHandler ) |
|
336 { |
|
337 LOG( "Call PersonalityPlugin to prepare stop" ); |
|
338 iCurrentPersonalityHandler->PreparePersonalityStop( iStatus ); |
|
339 SetActive(); |
|
340 } |
|
341 else |
|
342 { |
|
343 LOG( "No current PersonalityPlugin" ); |
|
344 } |
|
345 |
|
346 //complete StartPersonality with aError |
|
347 User::RequestComplete( iRequestStatus, aError ); |
|
348 } |
|
349 else |
|
350 { |
|
351 LOG( "Ignore error in other states" ); |
|
352 } |
308 |
353 |
309 return KErrNone; |
354 return KErrNone; |
310 } |
355 } |
311 |
356 |
312 // ---------------------------------------------------------------------------- |
357 // ---------------------------------------------------------------------------- |
316 void CUsbActivePersonalityHandler::RunL() |
361 void CUsbActivePersonalityHandler::RunL() |
317 { |
362 { |
318 LOG_FUNC |
363 LOG_FUNC |
319 |
364 |
320 TInt ret = iStatus.Int(); |
365 TInt ret = iStatus.Int(); |
321 if( KErrNone != ret ) |
366 |
322 { |
367 LOG2( "CUsbActivePersonalityHandler::RunL iStatus = %d, iState = %d", ret, iState ); |
323 LOG1( "ERROR: CUsbActivePersonalityHandler::RunL iStatus = %d", ret ); |
|
324 } |
|
325 |
368 |
326 switch( iState ) |
369 switch( iState ) |
327 { |
370 { |
328 case EUsbPersonalityIdle: |
371 case EUsbPersonalityIdle: |
329 break; |
372 break; |
338 SetActive(); |
381 SetActive(); |
339 } |
382 } |
340 break; |
383 break; |
341 |
384 |
342 case EUsbPersonalityStartUsb: |
385 case EUsbPersonalityStartUsb: |
|
386 LEAVEIFERROR( ret ); |
343 LOG( "EUsbPersonalityStartUsb" ); |
387 LOG( "EUsbPersonalityStartUsb" ); |
344 iState = EUsbPersonalityFinishStart; |
388 iState = EUsbPersonalityFinishStart; |
345 if( iCurrentPersonalityHandler ) |
389 if( iCurrentPersonalityHandler ) |
346 { |
390 { |
347 iCurrentPersonalityHandler->FinishPersonalityStart( iStatus ); |
391 iCurrentPersonalityHandler->FinishPersonalityStart( iStatus ); |
394 if ( iDeviceState == EUsbDeviceStateUndefined ) |
438 if ( iDeviceState == EUsbDeviceStateUndefined ) |
395 { |
439 { |
396 iPersonalityParams->PersonalityNotifier().CancelQuery( |
440 iPersonalityParams->PersonalityNotifier().CancelQuery( |
397 KCableConnectedNotifierUid ); |
441 KCableConnectedNotifierUid ); |
398 } |
442 } |
399 User::RequestComplete( iRequestStatus, ret ); |
443 //the request should be completed with error code in RunError if failed |
400 |
444 if ( !isFailureCleanup ) |
|
445 { |
|
446 User::RequestComplete( iRequestStatus, ret ); |
|
447 } |
|
448 |
401 iState = EUsbPersonalityIdle; |
449 iState = EUsbPersonalityIdle; |
402 break; |
450 break; |
403 |
451 |
404 case EUsbPersonalityStarted: |
452 case EUsbPersonalityStarted: |
405 // This must unload event. Let's complete. |
453 // This must unload event. Let's complete. |