18 |
18 |
19 /** |
19 /** |
20 @file |
20 @file |
21 */ |
21 */ |
22 |
22 |
23 #include <usbstates.h> |
|
24 #include <usberrors.h> |
|
25 #include <usb/usbshared.h> |
|
26 #include <usb/usblogger.h> |
23 #include <usb/usblogger.h> |
27 |
|
28 #include "CUsbSession.h" |
24 #include "CUsbSession.h" |
29 #include "CUsbDevice.h" |
25 #include "CUsbDevice.h" |
30 #include "CUsbServer.h" |
26 #include "CUsbServer.h" |
31 |
27 |
32 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
28 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
33 #include "CUsbOtg.h" |
29 #include "CUsbOtg.h" |
34 #include "cusbhost.h" |
30 #include "cusbhost.h" |
35 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
31 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
36 |
32 |
|
33 #include <usbstates.h> |
|
34 #include <usberrors.h> |
|
35 |
|
36 #include <usb/usbshared.h> |
37 #include "CPersonality.h" |
37 #include "CPersonality.h" |
38 #include "rusb.h" |
38 #include "rusb.h" |
39 #include "UsbSettings.h" |
39 #include "UsbSettings.h" |
40 #include "OstTraceDefinitions.h" |
40 |
41 #ifdef OST_TRACE_COMPILER_IN_USE |
41 #ifdef __FLOG_ACTIVE |
42 #include "CUsbSessionTraces.h" |
42 _LIT8(KLogComponent, "USBSVR"); |
43 #endif |
43 #endif |
44 |
|
45 |
|
46 |
44 |
47 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
45 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
48 CUsbSession* CUsbSession::iCtlSession = NULL; |
46 CUsbSession* CUsbSession::iCtlSession = NULL; |
49 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
47 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
50 |
48 |
75 * @param aServer Service the session will be a member of |
73 * @param aServer Service the session will be a member of |
76 */ |
74 */ |
77 CUsbSession::CUsbSession(CUsbServer* aServer) |
75 CUsbSession::CUsbSession(CUsbServer* aServer) |
78 : iUsbServer(aServer) |
76 : iUsbServer(aServer) |
79 { |
77 { |
80 OstTraceFunctionEntry0( CUSBSESSION_CUSBSESSION_CONS_ENTRY ); |
78 LOG_FUNC |
81 |
79 |
82 iUsbServer->IncrementSessionCount(); |
80 iUsbServer->IncrementSessionCount(); |
83 OstTraceFunctionExit0( CUSBSESSION_CUSBSESSION_CONS_EXIT ); |
|
84 } |
81 } |
85 |
82 |
86 |
83 |
87 /** |
84 /** |
88 * Destructor. |
85 * Destructor. |
89 */ |
86 */ |
90 CUsbSession::~CUsbSession() |
87 CUsbSession::~CUsbSession() |
91 { |
88 { |
92 OstTraceFunctionEntry0( CUSBSESSION_CUSBSESSION_DES_ENTRY ); |
89 LOG_FUNC |
93 |
90 |
94 OstTrace1( TRACE_NORMAL, CUSBSESSION_CUSBSESSION, "CUsbSession::~CUsbSession;About to Device().DeRegisterObserver(%08x)", this ); |
91 LOGTEXT2(_L8("About to Device().DeRegisterObserver(%08x"),this); |
95 iUsbServer->Device().DeRegisterObserver(*this); |
92 iUsbServer->Device().DeRegisterObserver(*this); |
96 |
93 |
97 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
94 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
98 #ifndef __OVER_DUMMYUSBDI__ |
95 #ifndef __OVER_DUMMYUSBDI__ |
99 OstTrace1( TRACE_NORMAL, CUSBSESSION_CUSBSESSION_DUP1, "CUsbSession::~CUsbSession;About to Otg().DeRegisterObserver(%08x)", this ); |
96 LOGTEXT2(_L8("About to Otg().DeRegisterObserver(%08x"),this); |
100 iUsbServer->Otg().DeRegisterObserver(*this); |
97 iUsbServer->Otg().DeRegisterObserver(*this); |
101 #endif |
98 #endif |
102 |
99 |
103 OstTrace1( TRACE_NORMAL, CUSBSESSION_CUSBSESSION_DUP2, "CUsbSession::~CUsbSession;About to Host().DeRegisterObserver(%08x)", this ); |
100 LOGTEXT2(_L8("About to Host().DeRegisterObserver(%08x"),this); |
104 iUsbServer->Host().DeregisterObserver(*this); |
101 iUsbServer->Host().DeregisterObserver(*this); |
105 |
102 |
106 if ( iCtlSession && (iCtlSession == this) ) |
103 if ( iCtlSession && (iCtlSession == this) ) |
107 { |
104 { |
108 iCtlSession = NULL; |
105 iCtlSession = NULL; |
109 } |
106 } |
110 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
107 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
111 |
108 |
112 OstTrace0( TRACE_NORMAL, CUSBSESSION_CUSBSESSION_DUP3, "CUsbSession::~CUsbSession;About to iUsbServer->DecrementSessionCount()" ); |
109 LOGTEXT(_L8("About to iUsbServer->DecrementSessionCount()")); |
113 iUsbServer->DecrementSessionCount(); |
110 iUsbServer->DecrementSessionCount(); |
114 OstTraceFunctionExit0( CUSBSESSION_CUSBSESSION_DES_EXIT ); |
|
115 } |
111 } |
116 |
112 |
117 |
113 |
118 /** |
114 /** |
119 * Called when a message is received from the client. |
115 * Called when a message is received from the client. |
120 * |
116 * |
121 * @param aMessage Message received from the client |
117 * @param aMessage Message received from the client |
122 */ |
118 */ |
123 void CUsbSession::ServiceL(const RMessage2& aMessage) |
119 void CUsbSession::ServiceL(const RMessage2& aMessage) |
124 { |
120 { |
125 OstTraceFunctionEntry0( CUSBSESSION_SERVICEL_ENTRY ); |
121 LOG_FUNC |
126 |
122 |
127 DispatchMessageL(aMessage); |
123 DispatchMessageL(aMessage); |
128 OstTraceFunctionExit0( CUSBSESSION_SERVICEL_EXIT ); |
|
129 } |
124 } |
130 |
125 |
131 /** |
126 /** |
132 * Handles 2nd Phase Construction. Implementation of the virtual method defined in CSession2 and called from |
127 * Handles 2nd Phase Construction. Implementation of the virtual method defined in CSession2 and called from |
133 * CServer2::DoConnectL() which executes when the client makes a connection request through CServer2::Connect(). If |
128 * CServer2::DoConnectL() which executes when the client makes a connection request through CServer2::Connect(). If |
134 * a Leave occurs at any point the CUsbSession object is cleaned up in CServer2::DoConnect(). |
129 * a Leave occurs at any point the CUsbSession object is cleaned up in CServer2::DoConnect(). |
135 */ |
130 */ |
136 void CUsbSession::CreateL() |
131 void CUsbSession::CreateL() |
137 { |
132 { |
138 OstTraceFunctionEntry0( CUSBSESSION_CREATEL_ENTRY ); |
133 LOG_FUNC |
139 |
134 |
140 // This code originally existed in the typical non-virtual ConstructL() method. |
135 // This code originally existed in the typical non-virtual ConstructL() method. |
141 // However it was moved to this method for minor optimisation reasons [three less |
136 // However it was moved to this method for minor optimisation reasons [three less |
142 // function calls and several lines less code in the NewL() method]. |
137 // function calls and several lines less code in the NewL() method]. |
143 |
138 |
144 iPersonalityCfged = iUsbServer->Device().isPersonalityCfged(); |
139 iPersonalityCfged = iUsbServer->Device().isPersonalityCfged(); |
145 |
140 |
146 OstTrace0( TRACE_NORMAL, CUSBSESSION_CREATEL, "CUsbSession::CreateL;Registering Device Observer" ); |
141 LOGTEXT(_L8("Registering Device Observer\n")); |
147 iUsbServer->Device().RegisterObserverL(*this); |
142 iUsbServer->Device().RegisterObserverL(*this); |
148 |
143 |
149 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
144 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
150 #ifndef __OVER_DUMMYUSBDI__ |
145 #ifndef __OVER_DUMMYUSBDI__ |
151 OstTrace0( TRACE_NORMAL, CUSBSESSION_CREATEL_DUP1, "CUsbSession::CreateL;Registering OTG Observer" ); |
146 LOGTEXT(_L8("Registering OTG Observer\n")); |
152 iUsbServer->Otg().RegisterObserverL(*this); |
147 iUsbServer->Otg().RegisterObserverL(*this); |
153 #endif |
148 #endif |
154 |
149 |
155 OstTrace0( TRACE_NORMAL, CUSBSESSION_CREATEL_DUP2, "CUsbSession::CreateL;Registering HOST Observer" ); |
150 LOGTEXT(_L8("Registering HOST Observer\n")); |
156 iUsbServer->Host().RegisterObserverL(*this); |
151 iUsbServer->Host().RegisterObserverL(*this); |
157 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
152 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
158 OstTraceFunctionExit0( CUSBSESSION_CREATEL_EXIT ); |
|
159 } |
153 } |
160 |
154 |
161 /** |
155 /** |
162 * Called by CUsbDevice when the service state changes. |
156 * Called by CUsbDevice when the service state changes. |
163 * CUsbSession is an observer of the device. |
157 * CUsbSession is an observer of the device. |
167 * @param aNewState The device's new and current service state |
161 * @param aNewState The device's new and current service state |
168 */ |
162 */ |
169 void CUsbSession::UsbServiceStateChange(TInt aLastError, TUsbServiceState aOldState, |
163 void CUsbSession::UsbServiceStateChange(TInt aLastError, TUsbServiceState aOldState, |
170 TUsbServiceState aNewState) |
164 TUsbServiceState aNewState) |
171 { |
165 { |
172 OstTraceFunctionEntry0( CUSBSESSION_USBSERVICESTATECHANGE_ENTRY ); |
166 LOG_FUNC |
173 OstTraceExt2( TRACE_NORMAL, CUSBSESSION_USBSERVICESTATECHANGE, "CUsbSession::UsbServiceStateChange;aOldState=0x%X, aNewState=0x%X", aOldState, aNewState ); |
167 LOGTEXT3(_L8(" aOldState=0x%X, aNewState=0x%X"), aOldState, aNewState); |
174 (void) aOldState; // a-void build warning in UREL |
168 (void) aOldState; // a-void build warning in UREL |
175 |
169 |
176 // Note that it's possible to have both a start and a stop outstanding! |
170 // Note that it's possible to have both a start and a stop outstanding! |
177 |
171 |
178 if (iStartOutstanding) |
172 if (iStartOutstanding) |
204 * @param aNewState The state we've moved to |
197 * @param aNewState The state we've moved to |
205 */ |
198 */ |
206 void CUsbSession::HandleServiceStateChangeWhileStarting(TInt aLastError, |
199 void CUsbSession::HandleServiceStateChangeWhileStarting(TInt aLastError, |
207 TUsbServiceState aNewState) |
200 TUsbServiceState aNewState) |
208 { |
201 { |
209 OstTraceFunctionEntry0( CUSBSESSION_HANDLESERVICESTATECHANGEWHILESTARTING_ENTRY ); |
202 LOG_FUNC |
210 |
203 |
211 switch (aNewState) |
204 switch (aNewState) |
212 { |
205 { |
213 case EUsbServiceStarted: |
206 case EUsbServiceStarted: |
214 OstTrace0( TRACE_NORMAL, CUSBSESSION_HANDLESERVICESTATECHANGEWHILESTARTING, "CUsbSession::HandleServiceStateChangeWhileStarting Completing Start successfully" ); |
207 LOGTEXT(_L8(" Completing Start successfully")); |
215 |
208 |
216 // If the user has tried to cancel the start, they're too late! |
209 // If the user has tried to cancel the start, they're too late! |
217 if (iCancelOutstanding) |
210 if (iCancelOutstanding) |
218 { |
211 { |
219 OstTrace0( TRACE_NORMAL, CUSBSESSION_HANDLESERVICESTATECHANGEWHILESTARTING_DUP1, "CUsbSession::HandleServiceStateChangeWhileStarting Completing cancel request with KErrNone" ); |
212 LOGTEXT(_L8(" Completing cancel request with KErrNone")); |
220 iCancelOutstanding = EFalse; |
213 iCancelOutstanding = EFalse; |
221 iCancelMessage.Complete(KErrNone); |
214 iCancelMessage.Complete(KErrNone); |
222 } |
215 } |
223 |
216 |
224 iStartMessage.Complete(KErrNone); |
217 iStartMessage.Complete(KErrNone); |
225 iStartOutstanding = EFalse; |
218 iStartOutstanding = EFalse; |
226 break; |
219 break; |
227 |
220 |
228 case EUsbServiceIdle: |
221 case EUsbServiceIdle: |
229 OstTrace1( TRACE_NORMAL, CUSBSESSION_HANDLESERVICESTATECHANGEWHILESTARTING_DUP2, "CUsbSession::HandleServiceStateChangeWhileStarting; Completing Start with error=%d", aLastError ); |
222 LOGTEXT2(_L8(" Completing Start with error=%d"), aLastError); |
230 |
223 |
231 // If there hasn't actually been an error, but we're in an unexpected |
224 // If there hasn't actually been an error, but we're in an unexpected |
232 // state now, that means that this client cancelled the request, or |
225 // state now, that means that this client cancelled the request, or |
233 // another client stopped the service. |
226 // another client stopped the service. |
234 if (aLastError == KErrNone) |
227 if (aLastError == KErrNone) |
235 { |
228 { |
236 // If there's a cancel outstanding, then that message succeeded, but |
229 // If there's a cancel outstanding, then that message succeeded, but |
237 // the start message should be completed with KErrCancel. |
230 // the start message should be completed with KErrCancel. |
238 if (iCancelOutstanding) |
231 if (iCancelOutstanding) |
239 { |
232 { |
240 OstTrace0( TRACE_NORMAL, CUSBSESSION_HANDLESERVICESTATECHANGEWHILESTARTING_DUP3, "CUsbSession::HandleServiceStateChangeWhileStarting Completing original message with KErrCancel" ); |
233 LOGTEXT(_L8(" Completing original message with KErrCancel")); |
241 iCancelOutstanding = EFalse; |
234 iCancelOutstanding = EFalse; |
242 iCancelMessage.Complete(KErrNone); |
235 iCancelMessage.Complete(KErrNone); |
243 iStartMessage.Complete(KErrCancel); |
236 iStartMessage.Complete(KErrCancel); |
244 } |
237 } |
245 else |
238 else |
275 * @param aNewState The state we've moved to |
267 * @param aNewState The state we've moved to |
276 */ |
268 */ |
277 void CUsbSession::HandleServiceStateChangeWhileStopping(TInt aLastError, |
269 void CUsbSession::HandleServiceStateChangeWhileStopping(TInt aLastError, |
278 TUsbServiceState aNewState) |
270 TUsbServiceState aNewState) |
279 { |
271 { |
280 OstTraceFunctionEntry0( CUSBSESSION_HANDLESERVICESTATECHANGEWHILESTOPPING_ENTRY ); |
272 LOG_FUNC |
281 |
273 |
282 switch (aNewState) |
274 switch (aNewState) |
283 { |
275 { |
284 case EUsbServiceStarted: |
276 case EUsbServiceStarted: |
285 OstTrace1( TRACE_NORMAL, CUSBSESSION_HANDLESERVICESTATECHANGEWHILESTOPPING, "CUsbSession::HandleServiceStateChangeWhileStopping; Completing Stop with error=%d", aLastError ); |
277 LOGTEXT2(_L8(" Completing Stop with error=%d"), aLastError); |
286 |
278 |
287 // If there hasn't actually been an error, but we're in an unexpected |
279 // If there hasn't actually been an error, but we're in an unexpected |
288 // state now, that means that this client cancelled the request, or |
280 // state now, that means that this client cancelled the request, or |
289 // another client has started the service. |
281 // another client has started the service. |
290 if (aLastError == KErrNone) |
282 if (aLastError == KErrNone) |
291 { |
283 { |
292 // If there's a cancel outstanding, then that message succeeded, but |
284 // If there's a cancel outstanding, then that message succeeded, but |
293 // the stop message should be completed with KErrCancel. |
285 // the stop message should be completed with KErrCancel. |
294 if (iCancelOutstanding) |
286 if (iCancelOutstanding) |
295 { |
287 { |
296 OstTrace0( TRACE_NORMAL, CUSBSESSION_HANDLESERVICESTATECHANGEWHILESTOPPING_DUP1, "CUsbSession::HandleServiceStateChangeWhileStopping; Completing original message with KErrCancel" ); |
288 LOGTEXT(_L8(" Completing original message with KErrCancel")); |
297 iCancelOutstanding = EFalse; |
289 iCancelOutstanding = EFalse; |
298 iCancelMessage.Complete(KErrNone); |
290 iCancelMessage.Complete(KErrNone); |
299 iStopMessage.Complete(KErrCancel); |
291 iStopMessage.Complete(KErrCancel); |
300 } |
292 } |
301 else |
293 else |
317 |
309 |
318 iStopOutstanding = EFalse; |
310 iStopOutstanding = EFalse; |
319 break; |
311 break; |
320 |
312 |
321 case EUsbServiceIdle: |
313 case EUsbServiceIdle: |
322 OstTrace0( TRACE_NORMAL, CUSBSESSION_HANDLESERVICESTATECHANGEWHILESTOPPING_DUP2, "CUsbSession::HandleServiceStateChangeWhileStopping Completing Stop with KErrNone" ); |
314 LOGTEXT(_L8(" Completing Stop with KErrNone")); |
323 |
315 |
324 // If the user has tried to cancel the stop, they're too late! |
316 // If the user has tried to cancel the stop, they're too late! |
325 if (iCancelOutstanding) |
317 if (iCancelOutstanding) |
326 { |
318 { |
327 OstTrace0( TRACE_NORMAL, CUSBSESSION_HANDLESERVICESTATECHANGEWHILESTOPPING_DUP3, "CUsbSession::HandleServiceStateChangeWhileStopping Completing cancel request with KErrNone" ); |
319 LOGTEXT(_L8(" Completing cancel request with KErrNone")); |
328 iCancelOutstanding = EFalse; |
320 iCancelOutstanding = EFalse; |
329 iCancelMessage.Complete(KErrNone); |
321 iCancelMessage.Complete(KErrNone); |
330 } |
322 } |
331 |
323 |
332 iStopMessage.Complete(KErrNone); |
324 iStopMessage.Complete(KErrNone); |
411 if (addToQueue) |
403 if (addToQueue) |
412 { |
404 { |
413 // add event to head of queue |
405 // add event to head of queue |
414 iDeviceStateQueue[iDevStateQueueHead] = aNewState; |
406 iDeviceStateQueue[iDevStateQueueHead] = aNewState; |
415 iDevStateQueueHead = (iDevStateQueueHead + 1) % KDeviceStatesQueueSize; |
407 iDevStateQueueHead = (iDevStateQueueHead + 1) % KDeviceStatesQueueSize; |
416 OstTraceExt2( TRACE_NORMAL, CUSBSESSION_USBDEVICESTATECHANGE_DUP1, "CUsbSession::UsbDeviceStateChange;+++ addqueue (%d, %d)", iDevStateQueueHead, iDevStateQueueTail ); |
408 LOGTEXT3(_L8("+++ addqueue (%d, %d)"), iDevStateQueueHead, |
|
409 iDevStateQueueTail); |
417 } |
410 } |
418 |
411 |
419 // UsbDeviceDequeueEvent() will read from queue when RegisterObserver() |
412 // UsbDeviceDequeueEvent() will read from queue when RegisterObserver() |
420 // is next called. |
413 // is next called. |
421 } |
414 } |
422 OstTraceFunctionExit0( CUSBSESSION_USBDEVICESTATECHANGE_EXIT ); |
|
423 } |
415 } |
424 |
416 |
425 /** |
417 /** |
426 * Dequeues an event and completes the observer's request with it. |
418 * Dequeues an event and completes the observer's request with it. |
427 */ |
419 */ |
428 void CUsbSession::UsbDeviceDequeueEvent() |
420 void CUsbSession::UsbDeviceDequeueEvent() |
429 { |
421 { |
430 OstTraceFunctionEntry0( CUSBSESSION_USBDEVICEDEQUEUEEVENT_ENTRY ); |
422 LOG_FUNC |
431 |
423 |
432 // Work our way through the queue, until we reach the end |
424 // Work our way through the queue, until we reach the end |
433 // OR we find an event the current observer wants. |
425 // OR we find an event the current observer wants. |
434 while ((iDeviceObserverOutstanding) && (iDevStateQueueHead != iDevStateQueueTail)) |
426 while ((iDeviceObserverOutstanding) && (iDevStateQueueHead != iDevStateQueueTail)) |
435 { |
427 { |
446 { |
438 { |
447 TPckg<TUint32> pckg(newState); |
439 TPckg<TUint32> pckg(newState); |
448 |
440 |
449 iNotifiedDevState = newState; |
441 iNotifiedDevState = newState; |
450 |
442 |
451 OstTraceExt2( TRACE_NORMAL, CUSBSESSION_USBDEVICEDEQUEUEEVENT, "CUsbSession::UsbDeviceDequeueEvent;dequeued event #%d (0x%x)", iDevStateQueueTail, newState ); |
443 LOGTEXT3(_L8(">>> dequeued event #%d (0x%x)"), iDevStateQueueTail, newState); |
452 |
444 |
453 iDeviceObserverOutstanding = EFalse; |
445 iDeviceObserverOutstanding = EFalse; |
454 const TInt err = iDeviceObserverMessage.Write(1, pckg); |
446 const TInt err = iDeviceObserverMessage.Write(1, pckg); |
455 iDeviceObserverMessage.Complete(err); |
447 iDeviceObserverMessage.Complete(err); |
456 break; |
448 break; |
457 } |
449 } |
458 } |
450 } |
459 OstTraceFunctionExit0( CUSBSESSION_USBDEVICEDEQUEUEEVENT_EXIT ); |
|
460 } |
451 } |
461 |
452 |
462 /** |
453 /** |
463 * Handles the request (in the form of a the message) received from the client |
454 * Handles the request (in the form of a the message) received from the client |
464 * |
455 * |
465 * @internalComponent |
456 * @internalComponent |
466 * @param aMessage The received message |
457 * @param aMessage The received message |
467 */ |
458 */ |
468 void CUsbSession::DispatchMessageL(const RMessage2& aMessage) |
459 void CUsbSession::DispatchMessageL(const RMessage2& aMessage) |
469 { |
460 { |
470 OstTraceFunctionEntry0( CUSBSESSION_DISPATCHMESSAGEL_ENTRY ); |
461 LOG_FUNC |
471 |
462 |
472 TBool complete = ETrue; |
463 TBool complete = ETrue; |
473 TInt ret = KErrNone; |
464 TInt ret = KErrNone; |
474 |
465 |
475 OstTrace1( TRACE_NORMAL, CUSBSESSION_DISPATCHMESSAGEL, "CUsbSession::DispatchMessageL;func#=%d", aMessage.Function() ); |
466 LOGTEXT2(_L8("CUsbSession::DispatchMessageL(): func# %d"), aMessage.Function()); |
476 |
467 |
477 switch (aMessage.Function()) |
468 switch (aMessage.Function()) |
478 { |
469 { |
479 case EUsbStart: |
470 case EUsbStart: |
480 ret = StartDeviceL(aMessage, complete); |
471 ret = StartDeviceL(aMessage, complete); |
536 |
530 |
537 #ifdef _DEBUG |
531 #ifdef _DEBUG |
538 // Heap failure debug APIs. |
532 // Heap failure debug APIs. |
539 |
533 |
540 case EUsbDbgMarkHeap: |
534 case EUsbDbgMarkHeap: |
541 OstTrace0( TRACE_NORMAL, CUSBSESSION_DISPATCHMESSAGEL_DUP1, "CUsbSession::DispatchMessageL;Marking heap" ); |
535 LOGTEXT(_L8("Marking heap")); |
542 __UHEAP_MARK; |
536 __UHEAP_MARK; |
543 break; |
537 break; |
544 case EUsbDbgCheckHeap: |
538 case EUsbDbgCheckHeap: |
545 OstTrace1( TRACE_NORMAL, CUSBSESSION_DISPATCHMESSAGEL_DUP2, "CUsbSession::DispatchMessageL;Checking heap (expecting %d cells)", aMessage.Int0() ); |
539 LOGTEXT2(_L8("Checking heap (expecting %d cells)"), aMessage.Int0()); |
546 __UHEAP_CHECK(aMessage.Int0()); |
540 __UHEAP_CHECK(aMessage.Int0()); |
547 break; |
541 break; |
548 case EUsbDbgMarkEnd: |
542 case EUsbDbgMarkEnd: |
549 OstTrace1( TRACE_NORMAL, CUSBSESSION_DISPATCHMESSAGEL_DUP3, "CUsbSession::DispatchMessageL;End of marking heap (expecting %d cells)", aMessage.Int0() ); |
543 LOGTEXT2(_L8("End of marking heap (expecting %d cells)"), aMessage.Int0()); |
550 __UHEAP_MARKENDC(aMessage.Int0()); |
544 __UHEAP_MARKENDC(aMessage.Int0()); |
551 break; |
545 break; |
552 case EUsbDbgFailNext: |
546 case EUsbDbgFailNext: |
553 { |
547 { |
554 OstTrace1( TRACE_NORMAL, CUSBSESSION_DISPATCHMESSAGEL_DUP4, "CUsbSession::DispatchMessageL;Simulating failure after %d allocation(s)", aMessage.Int0() ); |
548 LOGTEXT2(_L8("Simulating failure after %d allocation(s)"), aMessage.Int0()); |
555 if (aMessage.Int0() == 0) |
549 if (aMessage.Int0() == 0) |
556 __UHEAP_RESET; |
550 __UHEAP_RESET; |
557 else |
551 else |
558 __UHEAP_FAILNEXT(aMessage.Int0()); |
552 __UHEAP_FAILNEXT(aMessage.Int0()); |
559 } |
553 } |
560 break; |
554 break; |
561 case EUsbDbgAlloc: |
555 case EUsbDbgAlloc: |
562 { |
556 { |
563 ret = KErrNone; |
557 ret = KErrNone; |
564 #ifdef _DEBUG |
558 #ifdef _DEBUG |
565 OstTrace0( TRACE_NORMAL, CUSBSESSION_DISPATCHMESSAGEL_DUP5, "CUsbSession::DispatchMessageL;allocate on the heap" ); |
559 LOGTEXT(_L8("\tallocate on the heap")); |
566 TInt* x = NULL; |
560 TInt* x = NULL; |
567 TRAP(ret, x = new(ELeave) TInt); |
561 TRAP(ret, x = new(ELeave) TInt); |
568 delete x; |
562 delete x; |
569 #endif // _DEBUG |
563 #endif // _DEBUG |
570 } |
564 } |
737 * @param aComplete Whether the request is complete or not |
727 * @param aComplete Whether the request is complete or not |
738 * @return Any error that occurred or KErrNone |
728 * @return Any error that occurred or KErrNone |
739 */ |
729 */ |
740 TInt CUsbSession::StopDeviceL(const RMessage2& aMessage, TBool& aComplete) |
730 TInt CUsbSession::StopDeviceL(const RMessage2& aMessage, TBool& aComplete) |
741 { |
731 { |
742 OstTraceFunctionEntry0( CUSBSESSION_STOPDEVICEL_ENTRY ); |
732 LOG_FUNC |
743 |
733 |
744 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
734 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
745 // Only 'control' session is allowed to stop USB support |
735 // Only 'control' session is allowed to stop USB support |
746 if ( !iSessionCtlMode ) |
736 if ( !iSessionCtlMode ) |
747 { |
737 { |
748 OstTraceFunctionExit0( CUSBSESSION_STOPDEVICEL_EXIT ); |
|
749 return KErrAccessDenied; |
738 return KErrAccessDenied; |
750 } |
739 } |
751 #endif |
740 #endif |
752 |
741 |
753 if (iStopOutstanding) |
742 if (iStopOutstanding) |
754 { |
743 { |
755 OstTraceFunctionExit0( CUSBSESSION_STOPDEVICEL_EXIT_DUP1 ); |
|
756 return KErrInUse; |
744 return KErrInUse; |
757 } |
745 } |
758 |
746 |
759 #ifndef __OVER_DUMMYUSBDI__ |
747 #ifndef __OVER_DUMMYUSBDI__ |
760 |
748 |
839 * @param aComplete Whether the message is complete or not |
823 * @param aComplete Whether the message is complete or not |
840 * @return KErrNone on success, otherwise standard error codes |
824 * @return KErrNone on success, otherwise standard error codes |
841 */ |
825 */ |
842 TInt CUsbSession::StopCancel(const RMessage2& aMessage, TBool& aComplete) |
826 TInt CUsbSession::StopCancel(const RMessage2& aMessage, TBool& aComplete) |
843 { |
827 { |
844 OstTraceFunctionEntry0( CUSBSESSION_STOPCANCEL_ENTRY ); |
828 LOG_FUNC |
|
829 |
845 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
830 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
846 // Only 'control' session is allowed to cancel outstaning stop request |
831 // Only 'control' session is allowed to cancel outstaning stop request |
847 if ( !iSessionCtlMode ) |
832 if ( !iSessionCtlMode ) |
848 { |
833 { |
849 OstTraceFunctionExit0( CUSBSESSION_STOPCANCEL_EXIT ); |
|
850 return KErrAccessDenied; |
834 return KErrAccessDenied; |
851 } |
835 } |
852 #endif |
836 #endif |
853 |
837 |
854 if (!iStopOutstanding) |
838 if (!iStopOutstanding) |
855 { |
839 { |
856 OstTraceFunctionExit0( CUSBSESSION_STOPCANCEL_EXIT_DUP1 ); |
|
857 return KErrNone; |
840 return KErrNone; |
858 } |
841 } |
859 |
842 |
860 aComplete = EFalse; |
843 aComplete = EFalse; |
861 iCancelMessage = aMessage; |
844 iCancelMessage = aMessage; |
897 |
878 |
898 if (iObserverQueueEvents == EFalse) |
879 if (iObserverQueueEvents == EFalse) |
899 { |
880 { |
900 // This is the first observer after c'tor or DeregisterObserver(), |
881 // This is the first observer after c'tor or DeregisterObserver(), |
901 // so zap the device event queue. |
882 // so zap the device event queue. |
902 OstTrace0( TRACE_NORMAL, CUSBSESSION_REGISTERDEVICEOBSERVER, "CUsbSession::RegisterDeviceObserver Reset Device Event Queue" ); |
883 LOGTEXT(_L8(" Reset Device Event Queue")); |
903 iDevStateQueueHead = 0; |
884 iDevStateQueueHead = 0; |
904 iDevStateQueueTail = 0; |
885 iDevStateQueueTail = 0; |
905 iObserverQueueEvents = ETrue; |
886 iObserverQueueEvents = ETrue; |
906 } |
887 } |
907 else if (iDevStateQueueHead != iDevStateQueueTail) |
888 else if (iDevStateQueueHead != iDevStateQueueTail) |
908 { |
889 { |
909 // event(s) queued, we can de-queue one now |
890 // event(s) queued, we can de-queue one now |
910 UsbDeviceDequeueEvent(); |
891 UsbDeviceDequeueEvent(); |
911 } |
892 } |
912 |
893 |
913 OstTraceFunctionExit0( CUSBSESSION_REGISTERDEVICEOBSERVER_EXIT_DUP1 ); |
|
914 return KErrNone; |
894 return KErrNone; |
915 } |
895 } |
916 |
896 |
917 /** |
897 /** |
918 * Client request to observe the service (for state changes) |
898 * Client request to observe the service (for state changes) |
1039 * @param aComplete set to true to complete the request |
1013 * @param aComplete set to true to complete the request |
1040 * @return Any error that occurred or KErrNone |
1014 * @return Any error that occurred or KErrNone |
1041 */ |
1015 */ |
1042 TInt CUsbSession::TryStartDeviceL(const RMessage2& aMessage, TBool& aComplete) |
1016 TInt CUsbSession::TryStartDeviceL(const RMessage2& aMessage, TBool& aComplete) |
1043 { |
1017 { |
1044 OstTraceFunctionEntry0( CUSBSESSION_TRYSTARTDEVICEL_ENTRY ); |
1018 LOG_FUNC |
1045 |
1019 |
1046 #ifndef __OVER_DUMMYUSBDI__ |
1020 #ifndef __OVER_DUMMYUSBDI__ |
1047 |
1021 |
1048 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
1022 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
1049 // Only 'control' session is allowed to start USB support |
1023 // Only 'control' session is allowed to start USB support |
1050 if ( !iSessionCtlMode ) |
1024 if ( !iSessionCtlMode ) |
1051 { |
1025 { |
1052 OstTraceFunctionExit0( CUSBSESSION_TRYSTARTDEVICEL_EXIT ); |
|
1053 return KErrAccessDenied; |
1026 return KErrAccessDenied; |
1054 } |
1027 } |
1055 #endif |
1028 #endif |
1056 |
1029 |
1057 if (!iPersonalityCfged) |
1030 if (!iPersonalityCfged) |
1058 { |
1031 { |
1059 OstTraceFunctionExit0( CUSBSESSION_TRYSTARTDEVICEL_EXIT_DUP1 ); |
|
1060 return KErrNotSupported; |
1032 return KErrNotSupported; |
1061 } |
1033 } |
1062 |
1034 |
1063 if (iStartOutstanding || iStopOutstanding) |
1035 if (iStartOutstanding || iStopOutstanding) |
1064 { |
1036 { |
1065 OstTraceFunctionExit0( CUSBSESSION_TRYSTARTDEVICEL_EXIT_DUP2 ); |
|
1066 return KErrServerBusy; |
1037 return KErrServerBusy; |
1067 } |
1038 } |
1068 |
1039 |
1069 // Obtains the curent service state |
1040 // Obtains the curent service state |
1070 TUsbServiceState state = iUsbServer->Device().ServiceState(); |
1041 TUsbServiceState state = iUsbServer->Device().ServiceState(); |
1140 * @param aComplete Whether the request is complete or not |
1107 * @param aComplete Whether the request is complete or not |
1141 * @return Any error that occurred or KErrNone |
1108 * @return Any error that occurred or KErrNone |
1142 */ |
1109 */ |
1143 TInt CUsbSession::TryStopDeviceL(const RMessage2& aMessage, TBool& aComplete) |
1110 TInt CUsbSession::TryStopDeviceL(const RMessage2& aMessage, TBool& aComplete) |
1144 { |
1111 { |
1145 OstTraceFunctionEntry0( CUSBSESSION_TRYSTOPDEVICEL_ENTRY ); |
1112 LOG_FUNC |
1146 |
1113 |
1147 #ifndef __OVER_DUMMYUSBDI__ |
1114 #ifndef __OVER_DUMMYUSBDI__ |
1148 |
1115 |
1149 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
1116 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
1150 // Only 'control' session is allowed to stop USB support |
1117 // Only 'control' session is allowed to stop USB support |
1151 if ( !iSessionCtlMode ) |
1118 if ( !iSessionCtlMode ) |
1152 { |
1119 { |
1153 OstTraceFunctionExit0( CUSBSESSION_TRYSTOPDEVICEL_EXIT ); |
|
1154 return KErrAccessDenied; |
1120 return KErrAccessDenied; |
1155 } |
1121 } |
1156 #endif |
1122 #endif |
1157 |
1123 |
1158 if (!iPersonalityCfged) |
1124 if (!iPersonalityCfged) |
1159 { |
1125 { |
1160 OstTraceFunctionExit0( CUSBSESSION_TRYSTOPDEVICEL_EXIT_DUP1 ); |
|
1161 return KErrNotSupported; |
1126 return KErrNotSupported; |
1162 } |
1127 } |
1163 |
1128 |
1164 if (iStartOutstanding || iStopOutstanding) |
1129 if (iStartOutstanding || iStopOutstanding) |
1165 { |
1130 { |
1166 OstTraceFunctionExit0( CUSBSESSION_TRYSTOPDEVICEL_EXIT_DUP2 ); |
|
1167 return KErrServerBusy; |
1131 return KErrServerBusy; |
1168 } |
1132 } |
1169 |
1133 |
1170 // Obtains the curent service state |
1134 // Obtains the curent service state |
1171 TUsbServiceState state = iUsbServer->Device().ServiceState(); |
1135 TUsbServiceState state = iUsbServer->Device().ServiceState(); |
1191 iStopMessage = aMessage; |
1155 iStopMessage = aMessage; |
1192 iStopOutstanding = ETrue; |
1156 iStopOutstanding = ETrue; |
1193 } |
1157 } |
1194 else if (state == EUsbServiceStarting) |
1158 else if (state == EUsbServiceStarting) |
1195 { |
1159 { |
1196 OstTraceFunctionExit0( CUSBSESSION_TRYSTOPDEVICEL_EXIT_DUP3 ); |
|
1197 return KErrServerBusy; |
1160 return KErrServerBusy; |
1198 } |
1161 } |
1199 else if (state == EUsbServiceStopping) |
1162 else if (state == EUsbServiceStopping) |
1200 { |
1163 { |
1201 aComplete = EFalse; |
1164 aComplete = EFalse; |
1202 iStopMessage = aMessage; |
1165 iStopMessage = aMessage; |
1203 iStopOutstanding = ETrue; |
1166 iStopOutstanding = ETrue; |
1204 } |
1167 } |
1205 |
1168 |
1206 OstTraceFunctionExit0( CUSBSESSION_TRYSTOPDEVICEL_EXIT_DUP4 ); |
|
1207 return KErrNone; |
1169 return KErrNone; |
1208 |
1170 |
1209 #else |
1171 #else |
1210 // pretend that the server is in Started state |
1172 // pretend that the server is in Started state |
1211 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
1173 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
1212 iUsbServer->Host().Stop(); |
1174 iUsbServer->Host().Stop(); |
1213 #endif |
1175 #endif |
1214 aMessage.IsNull(); |
1176 aMessage.IsNull(); |
1215 aComplete = ETrue; |
1177 aComplete = ETrue; |
1216 iStopOutstanding = EFalse; |
1178 iStopOutstanding = EFalse; |
1217 OstTraceFunctionExit0( CUSBSESSION_TRYSTOPDEVICEL_EXIT_DUP5 ); |
|
1218 return KErrNone; |
1179 return KErrNone; |
1219 #endif |
1180 #endif |
1220 } |
1181 } |
1221 |
1182 |
1222 /** |
1183 /** |
1266 * @param aMessage Message received from the client |
1225 * @param aMessage Message received from the client |
1267 * @return Any error that occurred or KErrNone |
1226 * @return Any error that occurred or KErrNone |
1268 */ |
1227 */ |
1269 TInt CUsbSession::GetCurrentPersonalityId(const RMessage2& aMessage) |
1228 TInt CUsbSession::GetCurrentPersonalityId(const RMessage2& aMessage) |
1270 { |
1229 { |
1271 OstTraceFunctionEntry0( CUSBSESSION_GETCURRENTPERSONALITYID_ENTRY ); |
1230 LOG_FUNC |
1272 |
1231 |
1273 if (!iPersonalityCfged) |
1232 if (!iPersonalityCfged) |
1274 { |
1233 { |
1275 OstTraceFunctionExit0( CUSBSESSION_GETCURRENTPERSONALITYID_EXIT ); |
|
1276 return KErrNotSupported; |
1234 return KErrNotSupported; |
1277 } |
1235 } |
1278 |
1236 |
1279 TInt currentPersonalityId = iUsbServer->Device().CurrentPersonalityId(); |
1237 TInt currentPersonalityId = iUsbServer->Device().CurrentPersonalityId(); |
1280 OstTrace1( TRACE_NORMAL, CUSBSESSION_GETCURRENTPERSONALITYID, "CUsbSession::GetCurrentPersonalityId;currentPersonalityId=%d", currentPersonalityId ); |
1238 LOGTEXT2(_L8("\tcurrentPersonalityId = %d"), currentPersonalityId); |
1281 TPckgC<TInt> pckg(currentPersonalityId); |
1239 TPckgC<TInt> pckg(currentPersonalityId); |
1282 return aMessage.Write(0, pckg); |
1240 return aMessage.Write(0, pckg); |
1283 } |
1241 } |
1284 |
1242 |
1285 /** |
1243 /** |
1307 // Gets all class uids for the given personality |
1264 // Gets all class uids for the given personality |
1308 const RPointerArray<CPersonality>& personalities = iUsbServer->Device().Personalities(); |
1265 const RPointerArray<CPersonality>& personalities = iUsbServer->Device().Personalities(); |
1309 TInt personalityCount = personalities.Count(); |
1266 TInt personalityCount = personalities.Count(); |
1310 for (TInt i = 0; i < personalityCount; i++) |
1267 for (TInt i = 0; i < personalityCount; i++) |
1311 { |
1268 { |
1312 if(personalities[i] == NULL) |
1269 __ASSERT_ALWAYS(personalities[i] != NULL, _USB_PANIC(KUsbSvrPncCat, ENullPersonalityPointer)); |
1313 { |
|
1314 OstTrace1( TRACE_NORMAL, CUSBSESSION_GETSUPPORTEDCLASSES, "CUsbSession::GetSupportedClasses;ENullPersonalityPointer=%d", ENullPersonalityPointer ); |
|
1315 User::Panic(KUsbSvrPncCat, ENullPersonalityPointer); |
|
1316 } |
|
1317 if (aMessage.Int0() == personalities[i]->PersonalityId()) |
1270 if (aMessage.Int0() == personalities[i]->PersonalityId()) |
1318 { |
1271 { |
1319 classUids[0] = personalities[i]->SupportedClasses().Count(); |
1272 classUids[0] = personalities[i]->SupportedClasses().Count(); |
1320 for (TInt j = 1; j <= classUids[0]; j++) |
1273 for (TInt j = 1; j <= classUids[0]; j++) |
1321 { |
1274 { |
1322 if (j < KUsbMaxSupportedClasses + 1) |
1275 if (j < KUsbMaxSupportedClasses + 1) |
1323 { |
1276 { |
1324 classUids[j] = personalities[i]->SupportedClasses()[j - 1].iClassUid.iUid; |
1277 classUids[j] = personalities[i]->SupportedClasses()[j - 1].iUid; |
1325 OstTrace1( TRACE_NORMAL, CUSBSESSION_GETSUPPORTEDCLASSES_DUP1, "CUsbSession::GetSupportedClasses;classUids[%d] = ", j ); |
1278 LOGTEXT3(_L8("\tclassUids[%d] = %d"), j, classUids[j]); |
1326 OstTrace1( TRACE_NORMAL, CUSBSESSION_GETSUPPORTEDCLASSES_DUP2, "%d", classUids[j] ); |
|
1327 } |
1279 } |
1328 else |
1280 else |
1329 { |
1281 { |
1330 OstTraceFunctionExit0( CUSBSESSION_GETSUPPORTEDCLASSES_EXIT_DUP1 ); |
|
1331 return KErrTooBig; |
1282 return KErrTooBig; |
1332 } |
1283 } |
1333 } |
1284 } |
1334 break; |
1285 break; |
1335 } |
1286 } |
1336 } |
1287 } |
1337 |
1288 |
1338 if (classUids[0] == 0) |
1289 if (classUids[0] == 0) |
1339 { |
1290 { |
1340 // No supported classes are found |
1291 // No supported classes are found |
1341 OstTraceFunctionExit0( CUSBSESSION_GETSUPPORTEDCLASSES_EXIT_DUP2 ); |
|
1342 return KErrNotSupported; |
1292 return KErrNotSupported; |
1343 } |
1293 } |
1344 |
1294 |
1345 TInt ret; |
1295 TInt ret; |
1346 HBufC8* buf = NULL; |
1296 HBufC8* buf = NULL; |
1364 * @param aMessage Message received from the client |
1313 * @param aMessage Message received from the client |
1365 * @return Any error that occurred or KErrNone |
1314 * @return Any error that occurred or KErrNone |
1366 */ |
1315 */ |
1367 TInt CUsbSession::GetPersonalityIds(const RMessage2& aMessage) |
1316 TInt CUsbSession::GetPersonalityIds(const RMessage2& aMessage) |
1368 { |
1317 { |
1369 OstTraceFunctionEntry0( CUSBSESSION_GETPERSONALITYIDS_ENTRY ); |
1318 LOG_FUNC |
1370 |
1319 |
1371 if (!iPersonalityCfged) |
1320 if (!iPersonalityCfged) |
1372 { |
1321 { |
1373 OstTraceFunctionExit0( CUSBSESSION_GETPERSONALITYIDS_EXIT ); |
|
1374 return KErrNotSupported; |
1322 return KErrNotSupported; |
1375 } |
1323 } |
1376 |
1324 |
1377 // +1 for the size of actual personality id count |
1325 // +1 for the size of actual personality id count |
1378 TInt personalityIds[KUsbMaxSupportedPersonalities + 1]; |
1326 TInt personalityIds[KUsbMaxSupportedPersonalities + 1]; |
1379 |
1327 |
1380 const RPointerArray<CPersonality>& personalities = iUsbServer->Device().Personalities(); |
1328 const RPointerArray<CPersonality>& personalities = iUsbServer->Device().Personalities(); |
1381 TInt personalityCount = personalities.Count(); |
1329 TInt personalityCount = personalities.Count(); |
1382 for (TInt i = 0; i < personalityCount; ++i) |
1330 for (TInt i = 0; i < personalityCount; ++i) |
1383 { |
1331 { |
1384 if(personalities[i] == NULL) |
1332 __ASSERT_ALWAYS(personalities[i] != NULL, _USB_PANIC(KUsbSvrPncCat, ENullPersonalityPointer)); |
1385 { |
|
1386 OstTrace1( TRACE_NORMAL, CUSBSESSION_GETPERSONALITYIDS, "CUsbSession::GetPersonalityIds;Panic reason=%d", ENullPersonalityPointer ); |
|
1387 User::Panic(KUsbSvrPncCat, ENullPersonalityPointer); |
|
1388 } |
|
1389 personalityIds[i + 1] = personalities[i]->PersonalityId(); |
1333 personalityIds[i + 1] = personalities[i]->PersonalityId(); |
1390 } |
1334 } |
1391 personalityIds[0] = personalityCount; |
1335 personalityIds[0] = personalityCount; |
1392 |
1336 |
1393 TInt ret; |
1337 TInt ret; |
1428 { |
1370 { |
1429 return aMessage.Write(1, *(personality->Description())); |
1371 return aMessage.Write(1, *(personality->Description())); |
1430 } |
1372 } |
1431 |
1373 |
1432 // We should never reach here |
1374 // We should never reach here |
1433 OstTraceFunctionExit0( CUSBSESSION_GETDESCRIPTION_EXIT_DUP1 ); |
|
1434 return KErrNotSupported; |
1375 return KErrNotSupported; |
1435 } |
1376 } |
1436 |
1377 |
1437 |
1378 /** |
1438 /** |
1379 * Gets personality detailed description |
1439 * Gets personality property |
|
1440 * |
1380 * |
1441 * @internalComponent |
1381 * @internalComponent |
1442 * @param aMessage Message received from the client |
1382 * @param aMessage Message received from the client |
1443 * @return Any error that occurred or KErrNone |
1383 * @return Any error that occurred or KErrNone |
1444 */ |
1384 */ |
|
1385 TInt CUsbSession::GetDetailedDescription(const RMessage2& aMessage) |
|
1386 { |
|
1387 LOG_FUNC |
|
1388 |
|
1389 if (!iPersonalityCfged) |
|
1390 { |
|
1391 return KErrNotSupported; |
|
1392 } |
|
1393 |
|
1394 TInt personalityId = aMessage.Int0(); |
|
1395 const CPersonality* personality = iUsbServer->Device().GetPersonality(personalityId); |
|
1396 if (personality) |
|
1397 { |
|
1398 if(personality->Version() < EUsbManagerResourceVersionTwo) |
|
1399 { |
|
1400 return KErrNotFound; |
|
1401 } |
|
1402 return aMessage.Write(1, *(personality->DetailedDescription())); |
|
1403 } |
|
1404 |
|
1405 // We should never reach here |
|
1406 return KErrNotSupported; |
|
1407 } |
|
1408 |
|
1409 /** |
|
1410 * Gets personality property |
|
1411 * |
|
1412 * @internalComponent |
|
1413 * @param aMessage Message received from the client |
|
1414 * @return Any error that occurred or KErrNone |
|
1415 */ |
1445 TInt CUsbSession::GetPersonalityProperty(const RMessage2& aMessage) |
1416 TInt CUsbSession::GetPersonalityProperty(const RMessage2& aMessage) |
1446 { |
1417 { |
1447 OstTraceFunctionEntry0( CUSBSESSION_GETPERSONALITYPROPERTY_ENTRY ); |
1418 LOG_FUNC |
1448 |
1419 |
1449 if (!iPersonalityCfged) |
1420 if (!iPersonalityCfged) |
1450 { |
1421 { |
1451 OstTraceFunctionExit0( CUSBSESSION_GETPERSONALITYPROPERTY_EXIT ); |
|
1452 return KErrNotSupported; |
1422 return KErrNotSupported; |
1453 } |
1423 } |
1454 |
1424 |
1455 TInt personalityId = aMessage.Int0(); |
1425 TInt personalityId = aMessage.Int0(); |
1456 const CPersonality* personality = iUsbServer->Device().GetPersonality(personalityId); |
1426 const CPersonality* personality = iUsbServer->Device().GetPersonality(personalityId); |
1457 if (personality) |
1427 if (personality) |
1458 { |
1428 { |
|
1429 if(personality->Version() < EUsbManagerResourceVersionThree) |
|
1430 { |
|
1431 return KErrNotFound; |
|
1432 } |
1459 TPckg<TUint32> pckg(personality->Property()); |
1433 TPckg<TUint32> pckg(personality->Property()); |
1460 return aMessage.Write(1, pckg); |
1434 return aMessage.Write(1, pckg); |
1461 } |
1435 } |
1462 |
1436 |
1463 OstTraceFunctionExit0( CUSBSESSION_GETPERSONALITYPROPERTY_EXIT_DUP2 ); |
|
1464 return KErrNotSupported; |
1437 return KErrNotSupported; |
1465 } |
1438 } |
1466 |
1439 |
1467 /** |
1440 /** |
1468 * Checks if a given class is supported by a personality. |
1441 * Checks if a given class is supported by a personality. |
1471 * @param aMessage Message received from the client |
1444 * @param aMessage Message received from the client |
1472 * @return Any error that occurred or KErrNone |
1445 * @return Any error that occurred or KErrNone |
1473 */ |
1446 */ |
1474 TInt CUsbSession::ClassSupported(const RMessage2& aMessage) |
1447 TInt CUsbSession::ClassSupported(const RMessage2& aMessage) |
1475 { |
1448 { |
1476 OstTraceFunctionEntry0( CUSBSESSION_CLASSSUPPORTED_ENTRY ); |
1449 LOG_FUNC |
|
1450 |
1477 if (!iPersonalityCfged) |
1451 if (!iPersonalityCfged) |
1478 { |
1452 { |
1479 OstTraceFunctionExit0( CUSBSESSION_CLASSSUPPORTED_EXIT ); |
|
1480 return KErrNotSupported; |
1453 return KErrNotSupported; |
1481 } |
1454 } |
1482 |
1455 |
1483 TBool isSupported = EFalse; |
1456 TBool isSupported = EFalse; |
1484 TInt personalityId = aMessage.Int0(); |
1457 TInt personalityId = aMessage.Int0(); |
1485 TUid classUid = TUid::Uid(aMessage.Int1()); |
1458 TUid classUid = TUid::Uid(aMessage.Int1()); |
1486 const CPersonality* personality = iUsbServer->Device().GetPersonality(personalityId); |
1459 const CPersonality* personality = iUsbServer->Device().GetPersonality(personalityId); |
1487 if (personality) |
1460 if (personality) |
1488 { |
1461 { |
1489 isSupported = personality->ClassSupported(classUid); |
1462 isSupported = (personality->ClassSupported(classUid) != KErrNotFound); |
1490 TPckg<TBool> pkg2(isSupported); |
1463 TPckg<TBool> pkg2(isSupported); |
1491 return aMessage.Write(2, pkg2); |
1464 return aMessage.Write(2, pkg2); |
1492 } |
1465 } |
1493 |
1466 |
1494 // We should never reach here |
1467 // We should never reach here |
1495 OstTraceFunctionExit0( CUSBSESSION_CLASSSUPPORTED_EXIT_DUP1 ); |
|
1496 return KErrNotSupported; |
1468 return KErrNotSupported; |
1497 } |
1469 } |
1498 |
1470 |
1499 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
1471 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
1500 /** |
1472 /** |
1504 * @param aMessage Message received from the client |
1476 * @param aMessage Message received from the client |
1505 * @return Any error that occurred or KErrNone |
1477 * @return Any error that occurred or KErrNone |
1506 */ |
1478 */ |
1507 TInt CUsbSession::SetCtlSessionMode(const RMessage2& aMessage) |
1479 TInt CUsbSession::SetCtlSessionMode(const RMessage2& aMessage) |
1508 { |
1480 { |
1509 OstTraceFunctionEntry0( CUSBSESSION_SETCTLSESSIONMODE_ENTRY ); |
1481 LOG_FUNC |
1510 |
1482 |
1511 TInt ret = KErrNone; |
1483 TInt ret = KErrNone; |
1512 |
1484 |
1513 TBool value = (TBool)aMessage.Int0(); |
1485 TBool value = (TBool)aMessage.Int0(); |
1514 OstTrace1( TRACE_NORMAL, CUSBSESSION_SETCTLSESSIONMODE, "CUsbSession::SetCtlSessionMode;Setting = %d", static_cast<TInt>(value) ); |
1486 LOGTEXT2(_L8("\tSetting = %d"), static_cast<TInt>(value)); |
1515 |
1487 |
1516 // Verify if this is the same session which set the value before |
1488 // Verify if this is the same session which set the value before |
1517 if ( iCtlSession && (iCtlSession != this) ) |
1489 if ( iCtlSession && (iCtlSession != this) ) |
1518 { |
1490 { |
1519 ret = KErrAccessDenied; |
1491 ret = KErrAccessDenied; |
1712 * @param aMessage Message received from the client |
1676 * @param aMessage Message received from the client |
1713 * @return Any error that occurred or KErrNone |
1677 * @return Any error that occurred or KErrNone |
1714 */ |
1678 */ |
1715 TInt CUsbSession::GetSupportedLanguagesL(const RMessage2& aMessage) |
1679 TInt CUsbSession::GetSupportedLanguagesL(const RMessage2& aMessage) |
1716 { |
1680 { |
1717 OstTraceFunctionEntry0( CUSBSESSION_GETSUPPORTEDLANGUAGESL_ENTRY ); |
1681 LOG_FUNC |
|
1682 |
1718 |
1683 |
1719 const TUint deviceId = aMessage.Int0(); |
1684 const TUint deviceId = aMessage.Int0(); |
1720 OstTrace1( TRACE_NORMAL, CUSBSESSION_GETSUPPORTEDLANGUAGESL, "CUsbSession::GetSupportedLanguagesL;deviceId=%d", deviceId ); |
1685 LOGTEXT2(_L8("\tdeviceId = %d"), deviceId); |
1721 |
1686 |
1722 RArray<TUint> langIds; |
1687 RArray<TUint> langIds; |
1723 CleanupClosePushL(langIds); |
1688 CleanupClosePushL(langIds); |
1724 TInt ret = iUsbServer->Host().GetSupportedLanguages(deviceId,langIds); |
1689 TInt ret = iUsbServer->Host().GetSupportedLanguages(deviceId,langIds); |
1725 |
1690 |
1726 if (ret == KErrNone) |
1691 if (ret == KErrNone) |
1727 { |
1692 { |
1728 const TUint count = langIds.Count(); |
1693 const TUint count = langIds.Count(); |
1729 OstTrace1( TRACE_NORMAL, CUSBSESSION_GETSUPPORTEDLANGUAGESL_DUP1, "CUsbSession::GetSupportedLanguagesL;count=%d", count ); |
1694 LOGTEXT2(_L8("\tcount = %d"), count); |
1730 |
1695 |
1731 // Set error code if there is no languages or there are too many |
1696 // Set error code if there is no languages or there are too many |
1732 if ( count == 0 ) |
1697 if ( count == 0 ) |
1733 { |
1698 { |
1734 ret = KErrNotSupported; |
1699 ret = KErrNotSupported; |
1750 |
1715 |
1751 // Save all received language Ids |
1716 // Save all received language Ids |
1752 for ( TUint ii = 0 ; ii < count; ++ii ) |
1717 for ( TUint ii = 0 ; ii < count; ++ii ) |
1753 { |
1718 { |
1754 buf.Append((TUint8*)&(langIds[ii]), sizeof(TUint)); |
1719 buf.Append((TUint8*)&(langIds[ii]), sizeof(TUint)); |
1755 OstTraceExt2( TRACE_NORMAL, CUSBSESSION_GETSUPPORTEDLANGUAGESL_DUP2, "CUsbSession::GetSupportedLanguagesL;Append langID[%d] = %d", ii, langIds[ii] ); |
1720 LOGTEXT3(_L8("Append langID[%d] = %d"),ii,langIds[ii]); |
1756 } |
1721 } |
1757 |
1722 |
1758 // Write back to the client. |
1723 // Write back to the client. |
1759 ret = aMessage.Write(1, buf); |
1724 ret = aMessage.Write(1, buf); |
1760 CleanupStack::PopAndDestroy(&buf); |
1725 CleanupStack::PopAndDestroy(&buf); |
1761 } |
1726 } |
1762 } |
1727 } |
1763 |
1728 |
1764 CleanupStack::PopAndDestroy(); |
1729 CleanupStack::PopAndDestroy(); |
1765 |
1730 |
1766 OstTraceFunctionExit0( CUSBSESSION_GETSUPPORTEDLANGUAGESL_EXIT ); |
|
1767 return ret; |
1731 return ret; |
1768 } |
1732 } |
1769 |
1733 |
1770 /** |
1734 /** |
1771 * Requests a manufacturer string descriptor of connected device. |
1735 * Requests a manufacturer string descriptor of connected device. |
1774 * @param aMessage Message received from the client |
1738 * @param aMessage Message received from the client |
1775 * @return Any error that occurred or KErrNone |
1739 * @return Any error that occurred or KErrNone |
1776 */ |
1740 */ |
1777 TInt CUsbSession::GetManufacturerStringDescriptor(const RMessage2& aMessage) |
1741 TInt CUsbSession::GetManufacturerStringDescriptor(const RMessage2& aMessage) |
1778 { |
1742 { |
1779 OstTraceFunctionEntry0( CUSBSESSION_GETMANUFACTURERSTRINGDESCRIPTOR_ENTRY ); |
1743 LOG_FUNC |
1780 |
1744 |
1781 const TUint deviceId = aMessage.Int0(); |
1745 const TUint deviceId = aMessage.Int0(); |
1782 const TUint langId = aMessage.Int1(); |
1746 const TUint langId = aMessage.Int1(); |
1783 OstTraceExt2( TRACE_NORMAL, CUSBSESSION_GETMANUFACTURERSTRINGDESCRIPTOR, "CUsbSession::GetManufacturerStringDescriptor;langId=%d;deviceId=%d", langId, deviceId ); |
1747 LOGTEXT3(_L8("\tdeviceId = %d, langId = %d"), deviceId, langId); |
1784 |
1748 |
1785 TName string; |
1749 TName string; |
1786 TInt ret = iUsbServer->Host().GetManufacturerStringDescriptor(deviceId,langId,string); |
1750 TInt ret = iUsbServer->Host().GetManufacturerStringDescriptor(deviceId,langId,string); |
1787 if (ret == KErrNone) |
1751 if (ret == KErrNone) |
1788 { |
1752 { |
1789 OstTraceExt1( TRACE_NORMAL, CUSBSESSION_GETMANUFACTURERSTRINGDESCRIPTOR_DUP1, "CUsbSession::GetManufacturerStringDescriptor;string = \"%S\"", string ); |
1753 LOGTEXT2(_L("\tstring = \"%S\""), &string); |
1790 ret = aMessage.Write(2, string); |
1754 ret = aMessage.Write(2, string); |
1791 } |
1755 } |
1792 |
1756 |
1793 OstTraceFunctionExit0( CUSBSESSION_GETMANUFACTURERSTRINGDESCRIPTOR_EXIT ); |
|
1794 return ret; |
1757 return ret; |
1795 } |
1758 } |
1796 |
1759 |
1797 /** |
1760 /** |
1798 * Requests a product string descriptor of connected device. |
1761 * Requests a product string descriptor of connected device. |
1801 * @param aMessage Message received from the client |
1764 * @param aMessage Message received from the client |
1802 * @return Any error that occurred or KErrNone |
1765 * @return Any error that occurred or KErrNone |
1803 */ |
1766 */ |
1804 TInt CUsbSession::GetProductStringDescriptor(const RMessage2& aMessage) |
1767 TInt CUsbSession::GetProductStringDescriptor(const RMessage2& aMessage) |
1805 { |
1768 { |
1806 OstTraceFunctionEntry0( CUSBSESSION_GETPRODUCTSTRINGDESCRIPTOR_ENTRY ); |
1769 LOG_FUNC |
1807 |
1770 |
1808 const TUint deviceId = aMessage.Int0(); |
1771 const TUint deviceId = aMessage.Int0(); |
1809 const TUint langId = aMessage.Int1(); |
1772 const TUint langId = aMessage.Int1(); |
1810 OstTraceExt2( TRACE_NORMAL, CUSBSESSION_GETPRODUCTSTRINGDESCRIPTOR, "CUsbSession::GetProductStringDescriptor;deviceId=%d;langId=%d", deviceId, langId ); |
1773 LOGTEXT3(_L8("\tdeviceId = %d, langId = %d"), deviceId, langId); |
1811 |
1774 |
1812 TName string; |
1775 TName string; |
1813 TInt ret = iUsbServer->Host().GetProductStringDescriptor(deviceId,langId,string); |
1776 TInt ret = iUsbServer->Host().GetProductStringDescriptor(deviceId,langId,string); |
1814 if (ret == KErrNone) |
1777 if (ret == KErrNone) |
1815 { |
1778 { |
1816 OstTraceExt1( TRACE_NORMAL, CUSBSESSION_GETPRODUCTSTRINGDESCRIPTOR_DUP1, "CUsbSession::GetProductStringDescriptor;string = \"%S\"", string ); |
1779 LOGTEXT2(_L("\tstring = \"%S\""), &string); |
1817 ret = aMessage.Write(2, string); |
1780 ret = aMessage.Write(2, string); |
1818 } |
1781 } |
1819 |
1782 |
1820 OstTraceFunctionExit0( CUSBSESSION_GETPRODUCTSTRINGDESCRIPTOR_EXIT ); |
|
1821 return ret; |
1783 return ret; |
1822 } |
1784 } |
1823 |
1785 |
1824 /** |
1786 /** |
1825 * Requests a OTG descriptor of connected device. |
1787 * Requests a OTG descriptor of connected device. |
1828 * @param aMessage Message received from the client |
1790 * @param aMessage Message received from the client |
1829 * @return Any error that occurred or KErrNone |
1791 * @return Any error that occurred or KErrNone |
1830 */ |
1792 */ |
1831 TInt CUsbSession::GetOtgDescriptor(const RMessage2& aMessage) |
1793 TInt CUsbSession::GetOtgDescriptor(const RMessage2& aMessage) |
1832 { |
1794 { |
1833 OstTraceFunctionEntry0( CUSBSESSION_GETOTGDESCRIPTOR_ENTRY ); |
1795 LOG_FUNC |
1834 |
1796 |
1835 const TUint deviceId = aMessage.Int0(); |
1797 const TUint deviceId = aMessage.Int0(); |
1836 OstTrace1( TRACE_NORMAL, CUSBSESSION_GETOTGDESCRIPTOR, "CUsbSession::GetOtgDescriptor;deviceId=%d", deviceId ); |
1798 LOGTEXT2(_L8("\tdeviceId = %d"), deviceId); |
1837 |
1799 |
1838 TOtgDescriptor otgDescriptor; |
1800 TOtgDescriptor otgDescriptor; |
1839 TInt ret = iUsbServer->Host().GetOtgDescriptor(deviceId, otgDescriptor); |
1801 TInt ret = iUsbServer->Host().GetOtgDescriptor(deviceId, otgDescriptor); |
1840 if (ret == KErrNone) |
1802 if (ret == KErrNone) |
1841 { |
1803 { |
1842 TPckg<TOtgDescriptor> buf(otgDescriptor); |
1804 TPckg<TOtgDescriptor> buf(otgDescriptor); |
1843 ret = aMessage.Write(1, buf); |
1805 ret = aMessage.Write(1, buf); |
1844 } |
1806 } |
1845 |
1807 |
1846 OstTraceFunctionExit0( CUSBSESSION_GETOTGDESCRIPTOR_EXIT ); |
|
1847 return ret; |
1808 return ret; |
1848 } |
1809 } |
1849 |
1810 |
1850 /** |
1811 /** |
1851 * Client request to observe the host (for state changes). |
1812 * Client request to observe the host (for state changes). |
1875 |
1835 |
1876 if (iHostEventObserverQueueEvents == EFalse) |
1836 if (iHostEventObserverQueueEvents == EFalse) |
1877 { |
1837 { |
1878 // This is the first observer after c'tor or DeregisterObserver(), |
1838 // This is the first observer after c'tor or DeregisterObserver(), |
1879 // so zap the device event queue. |
1839 // so zap the device event queue. |
1880 OstTrace0( TRACE_NORMAL, CUSBSESSION_REGISTERHOSTOBSERVER, "CUsbSession::RegisterHostObserver; Reset OTG Host State Queue" ); |
1840 LOGTEXT(_L8(" Reset OTG Host State Queue")); |
1881 iHostEventQueueHead = 0; |
1841 iHostEventQueueHead = 0; |
1882 iHostEventQueueTail = 0; |
1842 iHostEventQueueTail = 0; |
1883 iHostEventObserverQueueEvents = ETrue; |
1843 iHostEventObserverQueueEvents = ETrue; |
1884 } |
1844 } |
1885 else if (iHostEventQueueHead != iHostEventQueueTail) |
1845 else if (iHostEventQueueHead != iHostEventQueueTail) |
1886 { |
1846 { |
1887 // event(s) queued, we can de-queue one now |
1847 // event(s) queued, we can de-queue one now |
1888 UsbHostEventDequeue(); |
1848 UsbHostEventDequeue(); |
1889 } |
1849 } |
1890 |
1850 |
1891 OstTraceFunctionExit0( CUSBSESSION_REGISTERHOSTOBSERVER_EXIT_DUP1 ); |
|
1892 return KErrNone; |
1851 return KErrNone; |
1893 } |
1852 } |
1894 |
1853 |
1895 /** |
1854 /** |
1896 * Deregister the client as an observer of host state changes. |
1855 * Deregister the client as an observer of host state changes. |
1898 * @internalComponent |
1857 * @internalComponent |
1899 * @return Always KErrNone |
1858 * @return Always KErrNone |
1900 */ |
1859 */ |
1901 TInt CUsbSession::DeRegisterHostObserver() |
1860 TInt CUsbSession::DeRegisterHostObserver() |
1902 { |
1861 { |
1903 OstTraceFunctionEntry0( CUSBSESSION_DEREGISTERHOSTOBSERVER_ENTRY ); |
1862 LOG_FUNC |
|
1863 |
1904 |
1864 |
1905 if (!iHostEventObserverQueueEvents) |
1865 if (!iHostEventObserverQueueEvents) |
1906 { |
1866 { |
1907 //Never register |
1867 //Never register |
1908 OstTrace0( TRACE_NORMAL, CUSBSESSION_DEREGISTERHOSTOBSERVER, "CUsbSession::DeRegisterHostObserver;iHostEventObserverQueueEvents is FALSE!" ); |
1868 LOGTEXT(_L8("iHostEventObserverQueueEvents is FALSE!")); |
1909 OstTraceFunctionExit0( CUSBSESSION_DEREGISTERHOSTOBSERVER_EXIT ); |
|
1910 return KErrNone; |
1869 return KErrNone; |
1911 } |
1870 } |
1912 |
1871 |
1913 if (iHostEventObserverOutstanding) |
1872 if (iHostEventObserverOutstanding) |
1914 { |
1873 { |
1915 iHostEventObserverOutstanding = EFalse; |
1874 iHostEventObserverOutstanding = EFalse; |
1916 iHostEventObserverMessage.Complete(KErrCancel); |
1875 iHostEventObserverMessage.Complete(KErrCancel); |
1917 OstTrace0( TRACE_NORMAL, CUSBSESSION_DEREGISTERHOSTOBSERVER_DUP1, "CUsbSession::DeRegisterHostObserver;iHostEventObserverMessage.Complete(KErrCancel);" ); |
1876 LOGTEXT(_L8("iHostEventObserverMessage.Complete(KErrCancel);")); |
1918 } |
1877 } |
1919 |
1878 |
1920 // client doesn't need events queuing any more |
1879 // client doesn't need events queuing any more |
1921 iHostEventObserverQueueEvents = EFalse; |
1880 iHostEventObserverQueueEvents = EFalse; |
1922 //Reset OTG Host State Queue |
1881 //Reset OTG Host State Queue |
1923 iHostEventQueueHead = 0; |
1882 iHostEventQueueHead = 0; |
1924 iHostEventQueueTail = 0; |
1883 iHostEventQueueTail = 0; |
1925 |
1884 |
1926 OstTraceFunctionExit0( CUSBSESSION_DEREGISTERHOSTOBSERVER_EXIT_DUP1 ); |
|
1927 return KErrNone; |
1885 return KErrNone; |
1928 } |
1886 } |
1929 |
1887 |
1930 /** |
1888 /** |
1931 * Client request to observe both OTG and HOST (for events and errors). |
1889 * Client request to observe both OTG and HOST (for events and errors). |
2024 else if (iMsgObserverQueueEvents) |
1978 else if (iMsgObserverQueueEvents) |
2025 { |
1979 { |
2026 // add event to head of queue |
1980 // add event to head of queue |
2027 iMsgQueue[iMsgQueueHead] = aMessage; |
1981 iMsgQueue[iMsgQueueHead] = aMessage; |
2028 iMsgQueueHead = (iMsgQueueHead + 1) % KOtgHostMessageQueueSize; |
1982 iMsgQueueHead = (iMsgQueueHead + 1) % KOtgHostMessageQueueSize; |
2029 OstTraceExt2( TRACE_NORMAL, CUSBSESSION_USBOTGHOSTMESSAGE, "CUsbSession::UsbOtgHostMessage; addqueue (%d, %d)", iMsgQueueHead, iMsgQueueTail ); |
1983 LOGTEXT3(_L8("+++ CUsbSession::UsbOtgMessage() addqueue (%d, %d)"), iMsgQueueHead, |
|
1984 iMsgQueueTail); |
2030 |
1985 |
2031 // UsbMsgDequeueEvent() will read from queue when RegisterMsgObserver() |
1986 // UsbMsgDequeueEvent() will read from queue when RegisterMsgObserver() |
2032 // is next called. |
1987 // is next called. |
2033 } |
1988 } |
2034 OstTraceFunctionExit0( CUSBSESSION_USBOTGHOSTMESSAGE_EXIT ); |
|
2035 } |
1989 } |
2036 |
1990 |
2037 /** |
1991 /** |
2038 * Called by CUsbHost when it state change. CUsbSession is an observer of |
1992 * Called by CUsbHost when it state change. CUsbSession is an observer of |
2039 * the device. If the client has an Observer outstanding then complete it, |
1993 * the device. If the client has an Observer outstanding then complete it, |
2043 * @param aDevInfo The information about the device being attached or detached |
1997 * @param aDevInfo The information about the device being attached or detached |
2044 * along with the status of Function Driver loading |
1998 * along with the status of Function Driver loading |
2045 */ |
1999 */ |
2046 void CUsbSession::UsbHostEvent(TDeviceEventInformation& aDevInfo) |
2000 void CUsbSession::UsbHostEvent(TDeviceEventInformation& aDevInfo) |
2047 { |
2001 { |
2048 OstTraceFunctionEntry0( CUSBSESSION_USBHOSTEVENT_ENTRY ); |
2002 LOG_FUNC |
2049 |
2003 |
2050 // can we bypass the queue? |
2004 // can we bypass the queue? |
2051 if ((iHostEventObserverOutstanding) && (iHostEventQueueHead == iHostEventQueueTail)) |
2005 if ((iHostEventObserverOutstanding) && (iHostEventQueueHead == iHostEventQueueTail)) |
2052 { |
2006 { |
2053 iNotifiedHostState = aDevInfo; |
2007 iNotifiedHostState = aDevInfo; |
2054 iHostEventObserverOutstanding = EFalse; |
2008 iHostEventObserverOutstanding = EFalse; |
2055 |
2009 |
2056 OstTrace0( TRACE_NORMAL, CUSBSESSION_USBHOSTEVENT, "CUsbSession::UsbHostEvent detected outstanding request" ); |
2010 LOGTEXT(_L8("CUsbSession::UsbHostEvent() detected outstanding request")); |
2057 |
2011 |
2058 TPckg<TDeviceEventInformation> info(aDevInfo); |
2012 TPckg<TDeviceEventInformation> info(aDevInfo); |
2059 const TInt err = iHostEventObserverMessage.Write(0, info); |
2013 const TInt err = iHostEventObserverMessage.Write(0, info); |
2060 iHostEventObserverMessage.Complete(err); |
2014 iHostEventObserverMessage.Complete(err); |
2061 OstTrace1( TRACE_NORMAL, CUSBSESSION_USBHOSTEVENT_DUP1, "CUsbSession::UsbHostEvent; detects outstanding request: request is compeleted with %d", err ); |
2015 LOGTEXT2(_L8("CUsbSession::UsbHostEvent() detects outstanding request: request is compeleted with %d"), err); |
2062 } |
2016 } |
2063 else if (iHostEventObserverQueueEvents) |
2017 else if (iHostEventObserverQueueEvents) |
2064 { |
2018 { |
2065 // add dev info to head of queue |
2019 // add dev info to head of queue |
2066 iHostStateQueue[iHostEventQueueHead] = aDevInfo; |
2020 iHostStateQueue[iHostEventQueueHead] = aDevInfo; |
2067 iHostEventQueueHead = (iHostEventQueueHead + 1) % KDeviceStatesQueueSize; |
2021 iHostEventQueueHead = (iHostEventQueueHead + 1) % KDeviceStatesQueueSize; |
2068 OstTraceExt2( TRACE_NORMAL, CUSBSESSION_USBHOSTEVENT_DUP2, "CUsbSession::UsbHostEvent; addqueue (%d, %d)", iHostEventQueueHead, iHostEventQueueTail ); |
2022 LOGTEXT3(_L8("+++ CUsbSession::UsbHostEvent() addqueue (%d, %d)"), iHostEventQueueHead, |
|
2023 iHostEventQueueTail); |
2069 |
2024 |
2070 // UsbHostStateDequeueEvent() will read from queue when RegisterHostObserver() |
2025 // UsbHostStateDequeueEvent() will read from queue when RegisterHostObserver() |
2071 // is next called. |
2026 // is next called. |
2072 } |
2027 } |
2073 OstTraceFunctionExit0( CUSBSESSION_USBHOSTEVENT_EXIT ); |
|
2074 } |
2028 } |
2075 |
2029 |
2076 /** |
2030 /** |
2077 * Dequeues an event and completes the observer's request with it. |
2031 * Dequeues an event and completes the observer's request with it. |
2078 */ |
2032 */ |
2079 void CUsbSession::UsbMsgDequeue() |
2033 void CUsbSession::UsbMsgDequeue() |
2080 { |
2034 { |
2081 OstTraceFunctionEntry0( CUSBSESSION_USBMSGDEQUEUE_ENTRY ); |
2035 LOG_FUNC |
2082 |
2036 |
2083 // Work our way through the queue, until we reach the end |
2037 // Work our way through the queue, until we reach the end |
2084 // OR we find an event the current observer wants. |
2038 // OR we find an event the current observer wants. |
2085 if ((iMsgObserverOutstanding) && (iMsgQueueHead != iMsgQueueTail)) |
2039 if ((iMsgObserverOutstanding) && (iMsgQueueHead != iMsgQueueTail)) |
2086 { |
2040 { |
2090 iMsgQueueTail = (iMsgQueueTail + 1) % KOtgHostMessageQueueSize; |
2044 iMsgQueueTail = (iMsgQueueTail + 1) % KOtgHostMessageQueueSize; |
2091 |
2045 |
2092 TPckg<TUint32> pckg(newMsg); |
2046 TPckg<TUint32> pckg(newMsg); |
2093 iNotifiedMsg = newMsg; |
2047 iNotifiedMsg = newMsg; |
2094 |
2048 |
2095 OstTraceExt2( TRACE_NORMAL, CUSBSESSION_USBMSGDEQUEUE, "CUsbSession::UsbMsgDequeue;dequeued event #%d (0x%x)", iMsgQueueTail, newMsg ); |
2049 LOGTEXT3(_L8(">>> dequeued event #%d (0x%x)"), iMsgQueueTail, newMsg); |
2096 |
2050 |
2097 iMsgObserverOutstanding = EFalse; |
2051 iMsgObserverOutstanding = EFalse; |
2098 const TInt err = iMsgObserverMessage.Write(0, pckg); |
2052 const TInt err = iMsgObserverMessage.Write(0, pckg); |
2099 iMsgObserverMessage.Complete(err); |
2053 iMsgObserverMessage.Complete(err); |
2100 } |
2054 } |
2101 OstTraceFunctionExit0( CUSBSESSION_USBMSGDEQUEUE_EXIT ); |
|
2102 } |
2055 } |
2103 |
2056 |
2104 /** |
2057 /** |
2105 * Dequeues an event and completes the observer's request with it. |
2058 * Dequeues an event and completes the observer's request with it. |
2106 */ |
2059 */ |
2107 void CUsbSession::UsbHostEventDequeue() |
2060 void CUsbSession::UsbHostEventDequeue() |
2108 { |
2061 { |
2109 OstTraceFunctionEntry0( CUSBSESSION_USBHOSTEVENTDEQUEUE_ENTRY ); |
2062 LOG_FUNC |
2110 |
2063 |
2111 // Work our way through the queue, until we reach the end |
2064 // Work our way through the queue, until we reach the end |
2112 // OR we find an event the current observer wants. |
2065 // OR we find an event the current observer wants. |
2113 if ((iHostEventObserverOutstanding) && (iHostEventQueueHead != iHostEventQueueTail)) |
2066 if ((iHostEventObserverOutstanding) && (iHostEventQueueHead != iHostEventQueueTail)) |
2114 { |
2067 { |
2118 iNotifiedHostState = newDevInfo; |
2071 iNotifiedHostState = newDevInfo; |
2119 |
2072 |
2120 // advance tail towards the head |
2073 // advance tail towards the head |
2121 iHostEventQueueTail = (iHostEventQueueTail + 1) % KDeviceStatesQueueSize; |
2074 iHostEventQueueTail = (iHostEventQueueTail + 1) % KDeviceStatesQueueSize; |
2122 |
2075 |
2123 OstTraceExt2( TRACE_NORMAL, CUSBSESSION_USBHOSTEVENTDEQUEUE, "CUsbSession::UsbHostEventDequeue; dequeued event #%d (0x%x)", iHostEventQueueTail, newDevInfo.iEventType ); |
2076 LOGTEXT3(_L8(">>> CUsbSession::UsbHostStateDequeueEvent() dequeued event #%d (0x%x)"), iHostEventQueueTail, newDevInfo.iEventType); |
2124 |
2077 |
2125 TPckg<TDeviceEventInformation> info(newDevInfo); |
2078 TPckg<TDeviceEventInformation> info(newDevInfo); |
2126 iHostEventObserverOutstanding = EFalse; |
2079 iHostEventObserverOutstanding = EFalse; |
2127 const TInt err = iHostEventObserverMessage.Write(0, info); |
2080 const TInt err = iHostEventObserverMessage.Write(0, info); |
2128 iHostEventObserverMessage.Complete(err); |
2081 iHostEventObserverMessage.Complete(err); |
2129 |
2082 |
2130 OstTrace1( TRACE_NORMAL, CUSBSESSION_USBHOSTEVENTDEQUEUE_DUP1, "CUsbSession::UsbHostStateDequeueEvent() detects outstanding request: request is compeleted with %d", err ); |
2083 LOGTEXT2(_L8("CUsbSession::UsbHostStateDequeueEvent() detects outstanding request: request is compeleted with %d"), err); |
2131 } |
2084 } |
2132 OstTraceFunctionExit0( CUSBSESSION_USBHOSTEVENTDEQUEUE_EXIT ); |
|
2133 } |
2085 } |
2134 |
2086 |
2135 TInt CUsbSession::RequestSession() |
2087 TInt CUsbSession::RequestSession() |
2136 { |
2088 { |
2137 return DoRequestSession(); |
2089 return DoRequestSession(); |