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