114 // Destruction |
114 // Destruction |
115 // --------------------------------------------------------------------------- |
115 // --------------------------------------------------------------------------- |
116 // |
116 // |
117 CUsbDevCon::~CUsbDevCon() |
117 CUsbDevCon::~CUsbDevCon() |
118 { |
118 { |
119 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::~CUsbDevCon" ) ); |
119 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::~CUsbDevCon" ) ); |
120 |
120 |
121 Cancel(); |
121 Cancel(); |
122 |
122 |
123 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::~CUsbDevCon Cancel" ) ); |
123 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::~CUsbDevCon Cancel" ) ); |
124 |
124 |
125 delete iStateMachine; |
125 delete iStateMachine; |
126 |
126 |
127 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::~CUsbDevCon StateMachine" ) ); |
127 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::~CUsbDevCon StateMachine" ) ); |
128 |
128 |
129 delete iRequestsHandler; |
129 delete iRequestsHandler; |
130 |
130 |
131 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::~CUsbDevCon RequestsHandler" ) ); |
131 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::~CUsbDevCon RequestsHandler" ) ); |
132 |
132 |
133 delete iUsbStateWatcher; |
133 delete iUsbStateWatcher; |
134 |
134 |
135 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::~CUsbDevCon UsbStateWatcher" ) ); |
135 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::~CUsbDevCon UsbStateWatcher" ) ); |
136 |
136 |
137 iUsbWatcher.Close(); |
137 iUsbWatcher.Close(); |
138 |
138 |
139 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::~CUsbDevCon UsbWatcher" ) ); |
139 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::~CUsbDevCon UsbWatcher" ) ); |
140 |
140 |
141 iUsbManager.Close(); |
141 iUsbManager.Close(); |
142 |
142 |
143 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::~CUsbDevCon UsbManager" ) ); |
143 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::~CUsbDevCon UsbManager" ) ); |
144 |
144 |
145 iLdd.Close(); |
145 iLdd.Close(); |
146 |
146 |
147 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::~CUsbDevCon LDD" ) ); |
147 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::~CUsbDevCon LDD" ) ); |
148 |
148 |
149 iShutdownTimer.Close(); |
149 iShutdownTimer.Close(); |
150 |
150 |
151 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::~CUsbDevCon Timer" ) ); |
151 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::~CUsbDevCon Timer" ) ); |
152 |
152 |
153 } |
153 } |
154 |
154 |
155 // --------------------------------------------------------------------------- |
155 // --------------------------------------------------------------------------- |
156 // Acts accordingly to USB state |
156 // Acts accordingly to USB state |
163 { |
163 { |
164 case EUsbcDeviceStateUndefined: |
164 case EUsbcDeviceStateUndefined: |
165 { |
165 { |
166 |
166 |
167 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::ActAccordinglyToUsbStateL State: Undefined" ) ); |
167 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::ActAccordinglyToUsbStateL State: Undefined" ) ); |
168 |
168 |
169 StopL(); |
169 StopL(); |
170 break; |
170 break; |
171 } |
171 } |
172 |
172 |
173 case EUsbcDeviceStateAttached: |
173 case EUsbcDeviceStateAttached: |
174 { |
174 { |
175 |
175 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::ActAccordinglyToUsbStateL State: Attached, ignored" ) ); |
176 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::ActAccordinglyToUsbStateL State: Attached" ) ); |
176 |
177 |
177 break; |
178 break; |
178 } |
179 } |
179 |
180 |
180 case EUsbcDeviceStateSuspended: |
|
181 { |
|
182 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::ActAccordinglyToUsbStateL State: Suspended" ) ); |
|
183 // NO break here |
|
184 } |
181 case EUsbcDeviceStatePowered: |
185 case EUsbcDeviceStatePowered: |
182 { |
186 { |
183 |
187 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::ActAccordinglyToUsbStateL State: Powered" ) ); |
184 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::ActAccordinglyToUsbStateL State: Powered" ) ); |
188 |
|
189 // In powered or suspended state, we are not allowed to do any data |
|
190 // communication. Hence if there are pending read/write requests, |
|
191 // we need cancel them. |
|
192 // Not call StopL() here because we do not want to shut down this |
|
193 // process so earlier but in Undefined state. |
|
194 if ( iStateMachine->IsStarted() ) |
|
195 { |
|
196 iStateMachine->Stop(); |
|
197 // release device control |
|
198 User::LeaveIfError(iLdd.ReleaseDeviceControl()); |
|
199 } |
|
200 break; |
|
201 } |
|
202 |
|
203 case EUsbcDeviceStateDefault: |
|
204 { |
|
205 // The request will only be started from default state. |
|
206 // If it has been started already, nothing will be done. |
|
207 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::ActAccordinglyToUsbStateL State: Default" ) ); |
185 |
208 |
186 StartL(); |
209 StartL(); |
187 break; |
210 break; |
188 } |
211 } |
189 |
212 |
190 case EUsbcDeviceStateDefault: |
213 case EUsbcDeviceStateAddress: |
191 { |
214 { |
192 |
215 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::ActAccordinglyToUsbStateL State: Addressed" ) ); |
193 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::ActAccordinglyToUsbStateL State: Default" ) ); |
|
194 |
216 |
195 StartL(); |
217 StartL(); |
196 break; |
218 break; |
197 } |
219 } |
198 |
220 |
199 case EUsbcDeviceStateAddress: |
221 case EUsbcDeviceStateConfigured: |
200 { |
222 { |
201 |
223 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::ActAccordinglyToUsbStateL State: Configured" ) ); |
202 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::ActAccordinglyToUsbStateL State: Addressed" ) ); |
|
203 |
224 |
204 StartL(); |
225 StartL(); |
205 break; |
226 |
206 } |
227 break; |
207 |
228 } |
208 case EUsbcDeviceStateConfigured: |
|
209 { |
|
210 |
|
211 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::ActAccordinglyToUsbStateL State: Configured" ) ); |
|
212 |
|
213 if(iPrevUsbState == EUsbcDeviceStateSuspended) |
|
214 { |
|
215 ResumeL(); |
|
216 } |
|
217 else |
|
218 { |
|
219 StartL(); |
|
220 } |
|
221 |
|
222 break; |
|
223 } |
|
224 case EUsbcDeviceStateSuspended: |
|
225 { |
|
226 |
|
227 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::ActAccordinglyToUsbStateL State: Suspended" ) ); |
|
228 |
|
229 break; |
|
230 } |
|
231 |
|
232 default: |
229 default: |
233 { |
230 { |
234 |
231 |
235 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::ActAccordinglyToUsbStateL State: ***Undefined***" ) ); |
232 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::ActAccordinglyToUsbStateL State: ***Unknown***" ) ); |
236 |
233 |
237 StopL(); |
234 StopL(); |
238 break; |
235 break; |
239 } |
236 } |
240 } |
237 } |
300 // start state machine |
297 // start state machine |
301 iStateMachine->Start(); |
298 iStateMachine->Start(); |
302 |
299 |
303 } |
300 } |
304 |
301 |
305 // Cancel shutdown timer, if it is started |
302 // Cancel shutdown timer, if it is started |
306 iShutdownTimer.Cancel(); |
303 iShutdownTimer.Cancel(); |
307 } |
304 } |
308 |
305 |
309 // --------------------------------------------------------------------------- |
306 // --------------------------------------------------------------------------- |
310 // Stops UsbDevCon services |
307 // Stops UsbDevCon services |
311 // --------------------------------------------------------------------------- |
308 // --------------------------------------------------------------------------- |
312 // |
309 // |
322 iStateMachine->Stop(); |
319 iStateMachine->Stop(); |
323 |
320 |
324 // release device control |
321 // release device control |
325 User::LeaveIfError(iLdd.ReleaseDeviceControl()); |
322 User::LeaveIfError(iLdd.ReleaseDeviceControl()); |
326 |
323 |
327 } |
324 } |
328 |
325 |
329 if(!IsActive()) // not waiting for timer |
326 if(!IsActive()) // not waiting for timer |
330 { |
327 { |
331 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::StopL Starting timer" ) ); |
328 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::StopL Starting timer" ) ); |
332 // run timer |
329 // run timer |
333 iShutdownTimer.Cancel(); |
330 iShutdownTimer.Cancel(); |
334 |
331 |
335 // RunL will be called after KInactiveTimeForShutDown milliseconds |
332 // RunL will be called after KInactiveTimeForShutDown milliseconds |
336 iShutdownTimer.After(iStatus, TTimeIntervalMicroSeconds32(KInactiveTimeForShutDown)); |
333 iShutdownTimer.After(iStatus, TTimeIntervalMicroSeconds32(KInactiveTimeForShutDown)); |
337 SetActive(); |
334 SetActive(); |
338 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::StopL Timer is started" ) ); |
335 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::StopL Timer is started" ) ); |
339 } |
336 } |
340 } |
337 } |
341 |
338 |
342 // --------------------------------------------------------------------------- |
|
343 // Resumes UsbDevCon services |
|
344 // --------------------------------------------------------------------------- |
|
345 // |
|
346 void CUsbDevCon::ResumeL() |
|
347 { |
|
348 |
|
349 FLOG( _L( "[USBDEVCON]\tCUsbDevCon::ResumeL" ) ); |
|
350 |
|
351 // Resume state machine |
|
352 StartL(); |
|
353 |
|
354 } |
|
355 |
339 |
356 // ---------------------------------------------------------------------------- |
340 // ---------------------------------------------------------------------------- |
357 // Constructs and installs the active scheduler, constructs UsbDevCon object. |
341 // Constructs and installs the active scheduler, constructs UsbDevCon object. |
358 // ---------------------------------------------------------------------------- |
342 // ---------------------------------------------------------------------------- |
359 // |
343 // |