19 |
19 |
20 /** |
20 /** |
21 @file |
21 @file |
22 */ |
22 */ |
23 |
23 |
|
24 #include <e32property.h> //Publish & Subscribe header |
24 #include "CUsbOtg.h" |
25 #include "CUsbOtg.h" |
25 #include "cusbotgwatcher.h" |
26 #include "cusbotgwatcher.h" |
26 #include "CUsbDevice.h" |
27 #include "CUsbDevice.h" |
27 #include "musbotghostnotifyobserver.h" |
28 #include "musbotghostnotifyobserver.h" |
28 #include "CUsbServer.h" |
29 #include "CUsbServer.h" |
29 #include <e32property.h> //Publish & Subscribe header |
|
30 #include "usberrors.h" |
30 #include "usberrors.h" |
|
31 #include "OstTraceDefinitions.h" |
|
32 #ifdef OST_TRACE_COMPILER_IN_USE |
|
33 #include "CUsbOtgTraces.h" |
|
34 #endif |
|
35 |
31 |
36 |
32 //Name used in call to User::LoadLogicalDevice/User::FreeLogicalDevice |
37 //Name used in call to User::LoadLogicalDevice/User::FreeLogicalDevice |
33 _LIT(KUsbOtgLDDName,"otgdi"); |
38 _LIT(KUsbOtgLDDName,"otgdi"); |
34 |
39 |
35 #ifdef __FLOG_ACTIVE |
|
36 _LIT8(KLogComponent, "USBSVR-OTG"); |
|
37 #endif |
|
38 |
40 |
39 |
41 |
40 CUsbOtg* CUsbOtg::NewL() |
42 CUsbOtg* CUsbOtg::NewL() |
41 /** |
43 /** |
42 * Constructs a CUsbOtg object. |
44 * Constructs a CUsbOtg object. |
43 * |
45 * |
44 * @return A new CUsbOtg object |
46 * @return A new CUsbOtg object |
45 */ |
47 */ |
46 { |
48 { |
47 LOG_STATIC_FUNC_ENTRY |
49 OstTraceFunctionEntry0( CUSBOTG_NEWL_ENTRY ); |
48 |
50 |
49 CUsbOtg* self = new (ELeave) CUsbOtg(); |
51 CUsbOtg* self = new (ELeave) CUsbOtg(); |
50 CleanupStack::PushL(self); |
52 CleanupStack::PushL(self); |
51 self->ConstructL(); |
53 self->ConstructL(); |
52 CleanupStack::Pop(self); |
54 CleanupStack::Pop(self); |
|
55 OstTraceFunctionExit0( CUSBOTG_NEWL_EXIT ); |
53 return self; |
56 return self; |
54 } |
57 } |
55 |
58 |
56 |
59 |
57 CUsbOtg::~CUsbOtg() |
60 CUsbOtg::~CUsbOtg() |
58 /** |
61 /** |
59 * Destructor. |
62 * Destructor. |
60 */ |
63 */ |
61 { |
64 { |
62 LOG_FUNC |
65 OstTraceFunctionEntry0( CUSBOTG_CUSBOTG_DES_ENTRY ); |
63 |
|
64 // Cancel any outstanding asynchronous operation. |
66 // Cancel any outstanding asynchronous operation. |
65 Stop(); |
67 Stop(); |
66 |
68 |
67 // Free any memory allocated to the list of observers. Note that |
69 // Free any memory allocated to the list of observers. Note that |
68 // we don't want to call ResetAndDestroy, because we don't own |
70 // we don't want to call ResetAndDestroy, because we don't own |
69 // the observers themselves. |
71 // the observers themselves. |
70 iObservers.Reset(); |
72 iObservers.Reset(); |
71 |
73 |
72 LOGTEXT2(_L8("about to stop Id-Pin watcher @ %08x"), (TUint32) iIdPinWatcher); |
74 OstTrace1( TRACE_NORMAL, CUSBOTG_CUSBOTG, "CUsbOtg::~CUsbOtg;iIdPinWatcher=%08x", (TUint32)iIdPinWatcher ); |
|
75 |
73 if (iIdPinWatcher) |
76 if (iIdPinWatcher) |
74 { |
77 { |
75 iIdPinWatcher->Cancel(); |
78 iIdPinWatcher->Cancel(); |
76 delete iIdPinWatcher; |
79 delete iIdPinWatcher; |
77 iIdPinWatcher = NULL; |
80 iIdPinWatcher = NULL; |
78 LOGTEXT(_L8("deleted Id-Pin watcher")); |
81 OstTrace0( TRACE_NORMAL, CUSBOTG_CUSBOTG_DUP1, "CUsbOtg::~CUsbOtg;deleted Id-Pin watcher" ); |
79 } |
82 |
80 LOGTEXT2(_L8("about to stop Vbus watcher @ %08x"), (TUint32) iVbusWatcher); |
83 } |
|
84 OstTrace1( TRACE_NORMAL, CUSBOTG_CUSBOTG_DUP2, "CUsbOtg::~CUsbOtg;about to stop Vbus watcher @ %08x", (TUint32)iVbusWatcher ); |
|
85 |
81 if (iVbusWatcher) |
86 if (iVbusWatcher) |
82 { |
87 { |
83 iVbusWatcher->Cancel(); |
88 iVbusWatcher->Cancel(); |
84 delete iVbusWatcher; |
89 delete iVbusWatcher; |
85 iVbusWatcher = NULL; |
90 iVbusWatcher = NULL; |
86 LOGTEXT(_L8("deleted Vbus watcher")); |
91 OstTrace0( TRACE_NORMAL, CUSBOTG_CUSBOTG_DUP3, "CUsbOtg::~CUsbOtg;deleted Vbus watcher" ); |
87 } |
92 |
88 LOGTEXT2(_L8("about to stop OTG State watcher @ %08x"), (TUint32) iVbusWatcher); |
93 } |
|
94 OstTrace1( TRACE_NORMAL, CUSBOTG_CUSBOTG_DUP4, "CUsbOtg::~CUsbOtg;about to stop OTG State watcher @ %08x", (TUint32) iVbusWatcher ); |
|
95 |
89 if (iOtgStateWatcher) |
96 if (iOtgStateWatcher) |
90 { |
97 { |
91 iOtgStateWatcher->Cancel(); |
98 iOtgStateWatcher->Cancel(); |
92 delete iOtgStateWatcher; |
99 delete iOtgStateWatcher; |
93 iOtgStateWatcher = NULL; |
100 iOtgStateWatcher = NULL; |
94 LOGTEXT(_L8("deleted OTG State watcher")); |
101 OstTrace0( TRACE_NORMAL, CUSBOTG_CUSBOTG_DUP5, "CUsbOtg::~CUsbOtg;deleted OTG State watcher" ); |
95 } |
102 |
96 LOGTEXT2(_L8("about to stop OTG Event watcher @ %08x"), (TUint32) iVbusWatcher); |
103 } |
|
104 OstTrace1( TRACE_NORMAL, CUSBOTG_CUSBOTG_DUP6, "CUsbOtg::~CUsbOtg;about to stop OTG Event watcher @ %08x", (TUint32) iVbusWatcher ); |
|
105 |
97 if (iOtgEventWatcher) |
106 if (iOtgEventWatcher) |
98 { |
107 { |
99 iOtgEventWatcher->Cancel(); |
108 iOtgEventWatcher->Cancel(); |
100 delete iOtgEventWatcher; |
109 delete iOtgEventWatcher; |
101 iOtgEventWatcher = NULL; |
110 iOtgEventWatcher = NULL; |
102 LOGTEXT(_L8("deleted OTG Event watcher")); |
111 OstTrace0( TRACE_NORMAL, CUSBOTG_CUSBOTG_DUP7, "CUsbOtg::~CUsbOtg;deleted OTG Event watcher" ); |
|
112 |
103 } |
113 } |
104 |
114 |
105 if (iRequestSessionWatcher) |
115 if (iRequestSessionWatcher) |
106 { |
116 { |
107 delete iRequestSessionWatcher; |
117 delete iRequestSessionWatcher; |
108 LOGTEXT(_L8("deleted Session Request watcher")); |
118 OstTrace0( TRACE_NORMAL, CUSBOTG_CUSBOTG_DUP8, "CUsbOtg::~CUsbOtg;deleted Session Request watcher" ); |
109 } |
119 |
110 |
120 } |
111 LOGTEXT2(_L8("about to stop Connection Idle watcher @ %08x"), (TUint32)iOtgConnectionIdleWatcher); |
121 |
|
122 OstTrace1( TRACE_NORMAL, CUSBOTG_CUSBOTG_DUP9, |
|
123 "CUsbOtg::~CUsbOtg;about to stop Connection Idle watcher @ %08x", (TUint32)iOtgConnectionIdleWatcher ); |
|
124 |
112 if (iOtgConnectionIdleWatcher) |
125 if (iOtgConnectionIdleWatcher) |
113 { |
126 { |
114 iOtgConnectionIdleWatcher->Cancel(); |
127 iOtgConnectionIdleWatcher->Cancel(); |
115 delete iOtgConnectionIdleWatcher; |
128 delete iOtgConnectionIdleWatcher; |
116 iOtgConnectionIdleWatcher= NULL; |
129 iOtgConnectionIdleWatcher= NULL; |
117 LOGTEXT(_L8("deleted Connection Idle watcher")); |
130 OstTrace0( TRACE_NORMAL, CUSBOTG_CUSBOTG_DUP10, "CUsbOtg::~CUsbOtg;deleted Connection Idle watcher" ); |
|
131 |
118 } |
132 } |
119 |
133 |
120 // Unload OTGDI components if it was ever started |
134 // Unload OTGDI components if it was ever started |
121 if ( iOtgDriver.Handle() ) |
135 if ( iOtgDriver.Handle() ) |
122 { |
136 { |
123 LOGTEXT(_L8("Stopping stacks")); |
137 OstTrace0( TRACE_NORMAL, CUSBOTG_CUSBOTG_DUP11, "CUsbOtg::~CUsbOtg; Stopping stacks" ); |
|
138 |
124 iOtgDriver.StopStacks(); |
139 iOtgDriver.StopStacks(); |
125 iOtgDriver.Close(); |
140 iOtgDriver.Close(); |
126 } |
141 } |
127 else |
142 else |
128 { |
143 { |
129 LOGTEXT(_L8("No OTG Driver session was opened, nothing to do")); |
144 OstTrace0( TRACE_NORMAL, CUSBOTG_CUSBOTG_DUP12, "CUsbOtg::~CUsbOtg; No OTG Driver session was opened, nothing to do" ); |
130 } |
145 |
131 |
146 } |
132 LOGTEXT(_L8("Freeing logical device")); |
147 |
|
148 OstTrace0( TRACE_NORMAL, CUSBOTG_CUSBOTG_DUP13, "CUsbOtg::~CUsbOtg; Freeing logical device" ); |
|
149 |
133 TInt err = User::FreeLogicalDevice(KUsbOtgLDDName); |
150 TInt err = User::FreeLogicalDevice(KUsbOtgLDDName); |
134 //Putting the LOGTEXT2 inside the if statement prevents a compiler |
151 //Putting the LOGTEXT2 inside the if statement prevents a compiler |
135 //warning about err being unused in UREL builds. |
152 //warning about err being unused in UREL builds. |
136 if(err) |
153 if(err) |
137 { |
154 { |
138 LOGTEXT2(_L8(" User::FreeLogicalDevice returned %d"),err); |
155 OstTrace1( TRACE_NORMAL, CUSBOTG_CUSBOTG_DUP14, "CUsbOtg::~CUsbOtg; User::FreeLogicalDevice returned %d", err ); |
|
156 |
139 } |
157 } |
140 |
158 |
141 iCriticalSection.Close(); |
159 iCriticalSection.Close(); |
|
160 OstTraceFunctionExit0( CUSBOTG_CUSBOTG_DES_EXIT ); |
142 } |
161 } |
143 |
162 |
144 |
163 |
145 CUsbOtg::CUsbOtg() |
164 CUsbOtg::CUsbOtg() |
146 /** |
165 /** |
147 * Constructor. |
166 * Constructor. |
148 */ |
167 */ |
149 { |
168 { |
150 LOG_FUNC |
169 OstTraceFunctionEntry0( CUSBOTG_CUSBOTG_CONS_ENTRY ); |
|
170 |
|
171 OstTraceFunctionExit0( CUSBOTG_CUSBOTG_CONS_EXIT ); |
151 } |
172 } |
152 |
173 |
153 |
174 |
154 void CUsbOtg::ConstructL() |
175 void CUsbOtg::ConstructL() |
155 /** |
176 /** |
156 * Performs 2nd phase construction of the OTG object. |
177 * Performs 2nd phase construction of the OTG object. |
157 */ |
178 */ |
158 { |
179 { |
159 LOG_FUNC |
180 OstTraceFunctionEntry0( CUSBOTG_CONSTRUCTL_ENTRY ); |
160 |
181 |
161 LOGTEXT(_L8("About to open LDD")); |
182 OstTrace0( TRACE_NORMAL, CUSBOTG_CONSTRUCTL, "CUsbOtg::ConstructL; About to open LDD" ); |
|
183 |
162 iLastError = User::LoadLogicalDevice(KUsbOtgLDDName); |
184 iLastError = User::LoadLogicalDevice(KUsbOtgLDDName); |
163 if ( (iLastError != KErrNone) && (iLastError != KErrAlreadyExists) ) |
185 if ( (iLastError != KErrNone) && (iLastError != KErrAlreadyExists) ) |
164 { |
186 { |
165 LOGTEXT3(_L8("Error %d: Unable to load driver: %S"), iLastError, &KUsbOtgLDDName); |
187 if(iLastError < 0) |
166 LEAVEIFERRORL(iLastError); |
188 { |
167 } |
189 OstTraceExt2( TRACE_NORMAL, CUSBOTG_CONSTRUCTL_DUP1, "CUsbOtg::ConstructL; Error %d: Unable to load driver: %S", iLastError, KUsbOtgLDDName ); |
168 |
190 User::Leave(iLastError); |
169 LOGTEXT(_L8("About to open RUsbOtgDriver")); |
191 } |
|
192 } |
|
193 OstTrace0( TRACE_NORMAL, CUSBOTG_CONSTRUCTL_DUP3, "CUsbOtg::ConstructL; About to open RUsbOtgDriver" ); |
|
194 |
170 iLastError = iOtgDriver.Open(); |
195 iLastError = iOtgDriver.Open(); |
171 if ( (iLastError != KErrNone) && (iLastError != KErrAlreadyExists) ) |
196 if ( (iLastError != KErrNone) && (iLastError != KErrAlreadyExists) ) |
172 { |
197 { |
173 LOGTEXT2(_L8("Error %d: Unable to open RUsbOtgDriver session"), iLastError); |
198 if(iLastError < 0) |
174 LEAVEIFERRORL(iLastError); |
199 { |
175 } |
200 OstTrace1( TRACE_NORMAL, CUSBOTG_CONSTRUCTL_DUP4, "CUsbOtg::ConstructL; Error %d: Unable to open RUsbOtgDriver session", iLastError ); |
176 |
201 User::Leave(iLastError); |
177 |
202 } |
178 LOGTEXT(_L8("About to start OTG stacks")); |
203 } |
|
204 |
|
205 OstTrace0( TRACE_NORMAL, CUSBOTG_CONSTRUCTL_DUP2, "CUsbOtg::ConstructL; About to start OTG stacks" ); |
|
206 |
179 iLastError = iOtgDriver.StartStacks(); |
207 iLastError = iOtgDriver.StartStacks(); |
180 if (iLastError != KErrNone) |
208 if (iLastError != KErrNone) |
181 { |
209 { |
182 LOGTEXT2(_L8("Error %d: Unable to open start OTG stacks"), iLastError); |
210 if(iLastError < 0) |
183 LEAVEIFERRORL(iLastError); |
211 { |
|
212 OstTrace1( TRACE_NORMAL, CUSBOTG_CONSTRUCTL_DUP5, "CUsbOtg::ConstructL; Error %d: Unable to open start OTG stacks", iLastError ); |
|
213 User::Leave(iLastError); |
|
214 } |
184 } |
215 } |
185 |
216 |
186 // Request Otg notifications |
217 // Request Otg notifications |
187 iIdPinWatcher = CUsbOtgIdPinWatcher::NewL(iOtgDriver); |
218 iIdPinWatcher = CUsbOtgIdPinWatcher::NewL(iOtgDriver); |
188 iIdPinWatcher->Start(); |
219 iIdPinWatcher->Start(); |
291 * Presently, the device supports watching state. |
326 * Presently, the device supports watching state. |
292 * |
327 * |
293 * @param aObserver New Observer of the OTG events |
328 * @param aObserver New Observer of the OTG events |
294 */ |
329 */ |
295 { |
330 { |
296 LOG_FUNC |
331 OstTraceFunctionEntry0( CUSBOTG_REGISTEROBSERVERL_ENTRY ); |
297 |
332 |
298 LEAVEIFERRORL(iObservers.Append(&aObserver)); |
333 TInt err = iObservers.Append(&aObserver); |
|
334 if(err < 0) |
|
335 { |
|
336 OstTrace1( TRACE_NORMAL, CUSBOTG_REGISTEROBSERVERL, "CUsbOtg::RegisterObserverL; iObservers.Append(&aObserver) error, Leave error=%d", err ); |
|
337 User::Leave(err); |
|
338 } |
|
339 |
|
340 OstTraceFunctionExit0( CUSBOTG_REGISTEROBSERVERL_EXIT ); |
299 } |
341 } |
300 |
342 |
301 |
343 |
302 void CUsbOtg::DeRegisterObserver(MUsbOtgHostNotifyObserver& aObserver) |
344 void CUsbOtg::DeRegisterObserver(MUsbOtgHostNotifyObserver& aObserver) |
303 /** |
345 /** |
304 * De-registers an existing OTG events observer. |
346 * De-registers an existing OTG events observer. |
305 * |
347 * |
306 * @param aObserver The existing OTG events observer to be de-registered |
348 * @param aObserver The existing OTG events observer to be de-registered |
307 */ |
349 */ |
308 { |
350 { |
309 LOG_FUNC |
351 OstTraceFunctionEntry0( CUSBOTG_DEREGISTEROBSERVER_ENTRY ); |
310 |
352 |
311 TInt index = iObservers.Find(&aObserver); |
353 TInt index = iObservers.Find(&aObserver); |
312 |
354 |
313 if (index >= 0 && index < iObservers.Count()) |
355 if (index >= 0 && index < iObservers.Count()) |
314 { |
356 { |
315 iObservers.Remove(index); |
357 iObservers.Remove(index); |
316 } |
358 } |
|
359 OstTraceFunctionExit0( CUSBOTG_DEREGISTEROBSERVER_EXIT ); |
317 } |
360 } |
318 |
361 |
319 |
362 |
320 void CUsbOtg::StartL() |
363 void CUsbOtg::StartL() |
321 /** |
364 /** |
322 * Start the USB OTG events watcher |
365 * Start the USB OTG events watcher |
323 * Reports errors and OTG events via observer interface. |
366 * Reports errors and OTG events via observer interface. |
324 */ |
367 */ |
325 { |
368 { |
326 LOG_FUNC |
369 OstTraceFunctionEntry0( CUSBOTG_STARTL_ENTRY ); |
327 |
370 |
328 iOtgWatcher = CUsbOtgWatcher::NewL(*this, iOtgDriver, iOtgMessage); |
371 iOtgWatcher = CUsbOtgWatcher::NewL(*this, iOtgDriver, iOtgMessage); |
329 iOtgWatcher->Start(); |
372 iOtgWatcher->Start(); |
|
373 OstTraceFunctionExit0( CUSBOTG_STARTL_EXIT ); |
330 } |
374 } |
331 |
375 |
332 void CUsbOtg::Stop() |
376 void CUsbOtg::Stop() |
333 /** |
377 /** |
334 * Stop the USB OTG events watcher |
378 * Stop the USB OTG events watcher |
335 */ |
379 */ |
336 { |
380 { |
337 LOG_FUNC |
381 OstTraceFunctionEntry0( CUSBOTG_STOP_ENTRY ); |
338 |
382 |
339 LOGTEXT2(_L8("about to stop OTG watcher @ %08x"), (TUint32) iOtgWatcher); |
383 OstTrace1( TRACE_NORMAL, CUSBOTG_STOP, "CUsbOtg::Stop;about to stop OTG watcher @ %08x", (TUint32)iOtgWatcher ); |
|
384 |
340 |
385 |
341 if (iOtgWatcher) |
386 if (iOtgWatcher) |
342 { |
387 { |
343 iOtgWatcher->Cancel(); |
388 iOtgWatcher->Cancel(); |
344 delete iOtgWatcher; |
389 delete iOtgWatcher; |
345 iOtgWatcher = NULL; |
390 iOtgWatcher = NULL; |
346 LOGTEXT(_L8("deleted OTG watcher")); |
391 OstTrace0( TRACE_NORMAL, CUSBOTG_STOP_DUP1, "CUsbOtg::Stop" ); |
|
392 |
347 } |
393 } |
348 |
394 |
349 iLastError = KErrNone; |
395 iLastError = KErrNone; |
|
396 OstTraceFunctionExit0( CUSBOTG_STOP_EXIT ); |
350 } |
397 } |
351 |
398 |
352 TInt CUsbOtg::BusRequest() |
399 TInt CUsbOtg::BusRequest() |
353 { |
400 { |
354 LOG_FUNC |
401 OstTraceFunctionEntry0( CUSBOTG_BUSREQUEST_ENTRY ); |
355 return iOtgDriver.BusRequest(); |
402 return iOtgDriver.BusRequest(); |
356 } |
403 } |
357 |
404 |
358 TInt CUsbOtg::BusRespondSrp() |
405 TInt CUsbOtg::BusRespondSrp() |
359 { |
406 { |
360 LOG_FUNC |
407 OstTraceFunctionEntry0( CUSBOTG_BUSRESPONDSRP_ENTRY ); |
361 return iOtgDriver.BusRespondSrp(); |
408 return iOtgDriver.BusRespondSrp(); |
362 } |
409 } |
363 |
410 |
364 TInt CUsbOtg::BusClearError() |
411 TInt CUsbOtg::BusClearError() |
365 { |
412 { |
366 LOG_FUNC |
413 OstTraceFunctionEntry0( CUSBOTG_BUSCLEARERROR_ENTRY ); |
367 return iOtgDriver.BusClearError(); |
414 return iOtgDriver.BusClearError(); |
368 } |
415 } |
369 |
416 |
370 TInt CUsbOtg::BusDrop() |
417 TInt CUsbOtg::BusDrop() |
371 { |
418 { |
372 LOG_FUNC |
419 OstTraceFunctionEntry0( CUSBOTG_BUSDROP_ENTRY ); |
373 return iOtgDriver.BusDrop(); |
420 return iOtgDriver.BusDrop(); |
374 } |
421 } |