|
1 /* |
|
2 * Copyright (c) 2002-2009 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 implements CUsbActiveState class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <usbman.h> |
|
21 #include "debug.h" |
|
22 #include "cusbactivestate.h" |
|
23 #include "cusbwatcher.h" |
|
24 |
|
25 // CONSTANTS |
|
26 const TUint KUsbAllStates = 0xFFFFFFFF; |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS ============================== |
|
29 |
|
30 // ---------------------------------------------------------------------------- |
|
31 // C++ default constructor can NOT contain any code, that might leave. |
|
32 // ---------------------------------------------------------------------------- |
|
33 // |
|
34 CUsbActiveState::CUsbActiveState( RUsb& aUsbMan, CUsbWatcher& aOwner ) |
|
35 : CActive( EPriorityStandard ) |
|
36 , iUsbMan( aUsbMan ) |
|
37 , iOwner( aOwner ) |
|
38 , iPreviousState( EUsbDeviceStateUndefined ) |
|
39 { |
|
40 LOG_FUNC |
|
41 |
|
42 CActiveScheduler::Add( this ); |
|
43 } |
|
44 |
|
45 // ---------------------------------------------------------------------------- |
|
46 // Symbian 2nd phase constructor can leave. |
|
47 // ---------------------------------------------------------------------------- |
|
48 // |
|
49 void CUsbActiveState::ConstructL() |
|
50 { |
|
51 LOG_FUNC |
|
52 |
|
53 LEAVEIFERROR( iUsbMan.GetDeviceState( iCurrentState ) ); |
|
54 LOG1( "Intial UsbDeviceState = %d" , iCurrentState ); |
|
55 |
|
56 // start USB if cable is pluged-in at bootup |
|
57 if( EUsbDeviceStateUndefined != iCurrentState ) |
|
58 { |
|
59 iOwner.StateChangeNotify( iPreviousState, iCurrentState ); |
|
60 iPreviousState = iCurrentState; |
|
61 } |
|
62 iUsbMan.DeviceStateNotification( KUsbAllStates, iCurrentState, iStatus ); |
|
63 SetActive(); |
|
64 } |
|
65 |
|
66 // ---------------------------------------------------------------------------- |
|
67 // Two-phased constructor. |
|
68 // ---------------------------------------------------------------------------- |
|
69 // |
|
70 CUsbActiveState* CUsbActiveState::NewL( RUsb& aUsbMan, CUsbWatcher& aOwner ) |
|
71 { |
|
72 LOG_FUNC |
|
73 |
|
74 CUsbActiveState* self = new ( ELeave ) CUsbActiveState( aUsbMan, aOwner ); |
|
75 CleanupStack::PushL( self ); |
|
76 self->ConstructL(); |
|
77 CleanupStack::Pop(); // pop self |
|
78 return self; |
|
79 } |
|
80 |
|
81 // Destructor |
|
82 CUsbActiveState::~CUsbActiveState() |
|
83 { |
|
84 LOG_FUNC |
|
85 |
|
86 Cancel(); |
|
87 } |
|
88 |
|
89 // ---------------------------------------------------------------------------- |
|
90 // This function is called when device state is changed. |
|
91 // ---------------------------------------------------------------------------- |
|
92 // |
|
93 void CUsbActiveState::RunL() |
|
94 { |
|
95 LOG_FUNC |
|
96 |
|
97 LEAVEIFERROR( iStatus.Int() ); // Close process if error happens here |
|
98 LOG2( "DeviceState change: %d ==> %d", iPreviousState, iCurrentState ); |
|
99 TUsbDeviceState newState = iCurrentState; |
|
100 iUsbMan.DeviceStateNotification( KUsbAllStates, iCurrentState, |
|
101 iStatus ); |
|
102 SetActive(); |
|
103 iOwner.StateChangeNotify( iPreviousState, newState ); |
|
104 iPreviousState = newState; |
|
105 } |
|
106 |
|
107 // ---------------------------------------------------------------------------- |
|
108 // Standard active object cancellation function. |
|
109 // ---------------------------------------------------------------------------- |
|
110 // |
|
111 void CUsbActiveState::DoCancel() |
|
112 { |
|
113 LOG_FUNC |
|
114 |
|
115 iUsbMan.DeviceStateNotificationCancel(); |
|
116 } |
|
117 |
|
118 // ---------------------------------------------------------------------------- |
|
119 // Get current device state. |
|
120 // ---------------------------------------------------------------------------- |
|
121 // |
|
122 TUsbDeviceState CUsbActiveState::CurrentState() |
|
123 { |
|
124 LOG_FUNC |
|
125 |
|
126 return iCurrentState; |
|
127 } |
|
128 |
|
129 // ---------------------------------------------------------------------------- |
|
130 // Get previous device state. |
|
131 // ---------------------------------------------------------------------------- |
|
132 // |
|
133 TUsbDeviceState CUsbActiveState::PreviousState() |
|
134 { |
|
135 LOG_FUNC |
|
136 |
|
137 return iPreviousState; |
|
138 } |
|
139 |
|
140 // End of file |