|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Talks directly to the USB Logical Device Driver (LDD) and |
|
16 * watches any state changes |
|
17 * |
|
18 */ |
|
19 |
|
20 /** |
|
21 @file |
|
22 */ |
|
23 |
|
24 #include <usb/usblogger.h> |
|
25 #include "CUsbScheduler.h" |
|
26 #include "cusbotgwatcher.h" |
|
27 #include "CUsbOtg.h" |
|
28 #include <usb/usbshared.h> |
|
29 |
|
30 #ifdef __FLOG_ACTIVE |
|
31 _LIT8(KLogComponent, "USBSVR-OTGWATCHER"); |
|
32 #endif |
|
33 |
|
34 static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy); |
|
35 static _LIT_SECURITY_POLICY_S1(KNetworkControlPolicy,KUsbmanSvrSid,ECapabilityNetworkControl); |
|
36 static _LIT_SECURITY_POLICY_C1(KRequestSessionPolicy,ECapabilityCommDD); |
|
37 |
|
38 //----------------------------------------------------------------------------- |
|
39 //------------------------------ Helper watchers ------------------------------ |
|
40 //----------------------------------------------------------------------------- |
|
41 //--------------------- Base class for all helper watchers -------------------- |
|
42 /** |
|
43 * The CUsbOtgBaseWatcher::CUsbOtgBaseWatcher method |
|
44 * |
|
45 * Constructor |
|
46 * |
|
47 * @param aOwner The device that owns the state watcher |
|
48 * @param aLdd A reference to the USB Logical Device Driver |
|
49 */ |
|
50 CUsbOtgBaseWatcher::CUsbOtgBaseWatcher(RUsbOtgDriver& aLdd) |
|
51 : CActive(CActive::EPriorityStandard), iLdd(aLdd) |
|
52 { |
|
53 LOG_FUNC |
|
54 CActiveScheduler::Add(this); |
|
55 } |
|
56 |
|
57 /** |
|
58 * The CUsbOtgBaseWatcher::~CUsbOtgBaseWatcher method |
|
59 * |
|
60 * Destructor |
|
61 * |
|
62 * @internalComponent |
|
63 */ |
|
64 CUsbOtgBaseWatcher::~CUsbOtgBaseWatcher() |
|
65 { |
|
66 LOG_FUNC |
|
67 Cancel(); |
|
68 } |
|
69 |
|
70 /** |
|
71 * Instructs the state watcher to start watching. |
|
72 */ |
|
73 void CUsbOtgBaseWatcher::Start() |
|
74 { |
|
75 LOG_FUNC |
|
76 Post(); |
|
77 } |
|
78 |
|
79 //---------------------------- Id-Pin watcher class --------------------------- |
|
80 /** |
|
81 * The CUsbOtgIdPinWatcher::NewL method |
|
82 * |
|
83 * Constructs a new CUsbOtgWatcher object |
|
84 * |
|
85 * @internalComponent |
|
86 * @param aLdd A reference to the USB Logical Device Driver |
|
87 * |
|
88 * @return A new CUsbOtgWatcher object |
|
89 */ |
|
90 CUsbOtgIdPinWatcher* CUsbOtgIdPinWatcher::NewL(RUsbOtgDriver& aLdd) |
|
91 { |
|
92 LOG_STATIC_FUNC_ENTRY |
|
93 |
|
94 CUsbOtgIdPinWatcher* self = new (ELeave) CUsbOtgIdPinWatcher(aLdd); |
|
95 CleanupStack::PushL(self); |
|
96 self->ConstructL(); |
|
97 CleanupStack::Pop(self); |
|
98 return self; |
|
99 } |
|
100 |
|
101 |
|
102 /** |
|
103 * The CUsbOtgIdPinWatcher::~CUsbOtgIdPinWatcher method |
|
104 * |
|
105 * Destructor |
|
106 * |
|
107 * @internalComponent |
|
108 */ |
|
109 CUsbOtgIdPinWatcher::~CUsbOtgIdPinWatcher() |
|
110 { |
|
111 LOG_FUNC |
|
112 Cancel(); |
|
113 RProperty::Delete(KUsbOtgIdPinPresentProperty); |
|
114 } |
|
115 |
|
116 void CUsbOtgIdPinWatcher::ConstructL() |
|
117 /** |
|
118 * Performs 2nd phase construction of the OTG object. |
|
119 */ |
|
120 { |
|
121 LOG_FUNC |
|
122 |
|
123 TInt err = RProperty::Define(KUsbOtgIdPinPresentProperty, RProperty::EInt, KAllowAllPolicy, KNetworkControlPolicy); |
|
124 if ( err != KErrNone && err != KErrAlreadyExists ) |
|
125 { |
|
126 User::LeaveIfError(err); |
|
127 } |
|
128 err = RProperty::Set(KUidUsbManCategory,KUsbOtgIdPinPresentProperty,EFalse); |
|
129 if ( err != KErrNone ) |
|
130 { |
|
131 User::LeaveIfError(err); |
|
132 } |
|
133 } |
|
134 |
|
135 /** |
|
136 * The CUsbOtgIdPinWatcher::CUsbOtgIdPinWatcher method |
|
137 * |
|
138 * Constructor |
|
139 * |
|
140 * @param aLdd A reference to the USB Logical Device Driver |
|
141 */ |
|
142 |
|
143 CUsbOtgIdPinWatcher::CUsbOtgIdPinWatcher(RUsbOtgDriver& aLdd) |
|
144 : CUsbOtgBaseWatcher(aLdd) |
|
145 { |
|
146 LOG_FUNC |
|
147 } |
|
148 |
|
149 /** |
|
150 * Called when the ID-Pin status change is reported |
|
151 */ |
|
152 void CUsbOtgIdPinWatcher::RunL() |
|
153 { |
|
154 LOG_FUNC |
|
155 LOGTEXT2(_L8(">>CUsbOtgIdPinWatcher::RunL [iStatus=%d]"), iStatus.Int()); |
|
156 |
|
157 LEAVEIFERRORL(iStatus.Int()); |
|
158 |
|
159 Post(); |
|
160 |
|
161 LOGTEXT(_L8("<<CUsbOtgIdPinWatcher::RunL")); |
|
162 } |
|
163 |
|
164 |
|
165 /** |
|
166 * Automatically called when the ID-Pin watcher is cancelled. |
|
167 */ |
|
168 void CUsbOtgIdPinWatcher::DoCancel() |
|
169 { |
|
170 LOG_FUNC |
|
171 iLdd.CancelOtgIdPinNotification(); |
|
172 } |
|
173 |
|
174 /** |
|
175 * Sets state watcher in active state |
|
176 */ |
|
177 void CUsbOtgIdPinWatcher::Post() |
|
178 { |
|
179 LOG_FUNC |
|
180 |
|
181 LOGTEXT(_L8("CUsbOtgIdPinWatcher::Post() - About to call QueueOtgIdPinNotification")); |
|
182 iLdd.QueueOtgIdPinNotification(iOtgIdPin, iStatus); |
|
183 switch (iOtgIdPin) |
|
184 { |
|
185 case RUsbOtgDriver::EIdPinAPlug: |
|
186 if (RProperty::Set(KUidUsbManCategory,KUsbOtgIdPinPresentProperty,ETrue) != KErrNone) |
|
187 { |
|
188 LOGTEXT2(_L8(">>CUsbOtgIdPinWatcher::Post [iOtgIdPin=%d] - failed to set the property value"), iOtgIdPin); |
|
189 } |
|
190 else |
|
191 { |
|
192 LOGTEXT2(_L8(">>CUsbOtgIdPinWatcher::Post [iOtgIdPin=%d] - property is set to 1"), iOtgIdPin); |
|
193 } |
|
194 break; |
|
195 case RUsbOtgDriver::EIdPinBPlug: |
|
196 case RUsbOtgDriver::EIdPinUnknown: |
|
197 if (RProperty::Set(KUidUsbManCategory,KUsbOtgIdPinPresentProperty,EFalse) != KErrNone) |
|
198 { |
|
199 LOGTEXT2(_L8(">>CUsbOtgIdPinWatcher::Post [iOtgIdPin=%d] - failed to set the property value"), iOtgIdPin); |
|
200 } |
|
201 else |
|
202 { |
|
203 LOGTEXT2(_L8(">>CUsbOtgIdPinWatcher::Post [iOtgIdPin=%d] - property is set to 0"), iOtgIdPin); |
|
204 } |
|
205 break; |
|
206 default: |
|
207 LOGTEXT2(_L8(">>CUsbOtgIdPinWatcher::Post [iOtgIdPin=%d] is unrecognized, re-request QueueOtgIdPinNotification"), iOtgIdPin); |
|
208 break; |
|
209 } |
|
210 SetActive(); |
|
211 } |
|
212 |
|
213 //----------------------------- VBus watcher class ---------------------------- |
|
214 /** |
|
215 * The CUsbOtgVbusWatcher::NewL method |
|
216 * |
|
217 * Constructs a new CUsbOtgVbusWatcher object |
|
218 * |
|
219 * @internalComponent |
|
220 * @param aLdd A reference to the USB OTG Logical Device Driver |
|
221 * |
|
222 * @return A new CUsbOtgVbusWatcher object |
|
223 */ |
|
224 CUsbOtgVbusWatcher* CUsbOtgVbusWatcher::NewL(RUsbOtgDriver& aLdd) |
|
225 { |
|
226 LOG_STATIC_FUNC_ENTRY |
|
227 |
|
228 CUsbOtgVbusWatcher* self = new (ELeave) CUsbOtgVbusWatcher(aLdd); |
|
229 CleanupStack::PushL(self); |
|
230 self->ConstructL(); |
|
231 CleanupStack::Pop(self); |
|
232 return self; |
|
233 } |
|
234 |
|
235 |
|
236 /** |
|
237 * The CUsbOtgVbusWatcher::~CUsbOtgVbusWatcher method |
|
238 * |
|
239 * Destructor |
|
240 * |
|
241 * @internalComponent |
|
242 */ |
|
243 CUsbOtgVbusWatcher::~CUsbOtgVbusWatcher() |
|
244 { |
|
245 LOG_FUNC |
|
246 Cancel(); |
|
247 |
|
248 RProperty::Delete(KUsbOtgVBusPoweredProperty); |
|
249 } |
|
250 |
|
251 void CUsbOtgVbusWatcher::ConstructL() |
|
252 /** |
|
253 * Performs 2nd phase construction of the OTG object. |
|
254 */ |
|
255 { |
|
256 LOG_FUNC |
|
257 |
|
258 TInt err = RProperty::Define(KUsbOtgVBusPoweredProperty, RProperty::EInt, KAllowAllPolicy, KNetworkControlPolicy); |
|
259 if ( err != KErrNone && err != KErrAlreadyExists ) |
|
260 { |
|
261 User::LeaveIfError(err); |
|
262 } |
|
263 err = RProperty::Set(KUidUsbManCategory,KUsbOtgVBusPoweredProperty,EFalse); |
|
264 if ( err != KErrNone ) |
|
265 { |
|
266 User::LeaveIfError(err); |
|
267 } |
|
268 } |
|
269 |
|
270 /** |
|
271 * The CUsbOtgVbusWatcher::CUsbOtgVbusWatcher method |
|
272 * |
|
273 * Constructor |
|
274 * |
|
275 * @param aLdd A reference to the USB OTG Logical Device Driver |
|
276 */ |
|
277 CUsbOtgVbusWatcher::CUsbOtgVbusWatcher(RUsbOtgDriver& aLdd) |
|
278 : CUsbOtgBaseWatcher(aLdd) |
|
279 { |
|
280 LOG_FUNC |
|
281 } |
|
282 |
|
283 /** |
|
284 * Called when the Vbus status is changed |
|
285 */ |
|
286 void CUsbOtgVbusWatcher::RunL() |
|
287 { |
|
288 LOG_FUNC |
|
289 LOGTEXT2(_L8(">>CUsbOtgVbusWatcher::RunL [iStatus=%d]"), iStatus.Int()); |
|
290 |
|
291 LEAVEIFERRORL(iStatus.Int()); |
|
292 |
|
293 Post(); |
|
294 |
|
295 LOGTEXT(_L8("<<CUsbOtgVbusWatcher::RunL")); |
|
296 } |
|
297 |
|
298 |
|
299 /** |
|
300 * Automatically called when the VBus status watcher is cancelled. |
|
301 */ |
|
302 void CUsbOtgVbusWatcher::DoCancel() |
|
303 { |
|
304 LOG_FUNC |
|
305 iLdd.CancelOtgVbusNotification(); |
|
306 } |
|
307 |
|
308 /** |
|
309 * Sets state watcher in active state |
|
310 */ |
|
311 void CUsbOtgVbusWatcher::Post() |
|
312 { |
|
313 LOG_FUNC |
|
314 |
|
315 LOGTEXT(_L8("CUsbOtgVbusWatcher::Post() - About to call QueueOtgVbusNotification")); |
|
316 iLdd.QueueOtgVbusNotification(iOtgVbus, iStatus); |
|
317 switch (iOtgVbus) |
|
318 { |
|
319 case RUsbOtgDriver::EVbusHigh: |
|
320 if (RProperty::Set(KUidUsbManCategory,KUsbOtgVBusPoweredProperty,ETrue) != KErrNone) |
|
321 { |
|
322 LOGTEXT2(_L8(">>CUsbOtgVbusWatcher::Post [iOtgVbus=%d](EVbusHigh) - failed to set the property value"), iOtgVbus); |
|
323 } |
|
324 else |
|
325 { |
|
326 LOGTEXT2(_L8(">>CUsbOtgVbusWatcher::Post [iOtgVbus=%d](EVbusHigh) - property is set to ETrue"), iOtgVbus); |
|
327 } |
|
328 break; |
|
329 case RUsbOtgDriver::EVbusLow: |
|
330 case RUsbOtgDriver::EVbusUnknown: |
|
331 if (RProperty::Set(KUidUsbManCategory,KUsbOtgVBusPoweredProperty,EFalse) != KErrNone) |
|
332 { |
|
333 LOGTEXT2(_L8(">>CUsbOtgVbusWatcher::Post [iOtgVbus=%d](1 - EVbusLow, 2 - EVbusUnknown) - failed to set the property value"), iOtgVbus); |
|
334 } |
|
335 else |
|
336 { |
|
337 LOGTEXT2(_L8(">>CUsbOtgVbusWatcher::Post [iOtgVbus=%d](1 - EVbusLow, 2 - EVbusUnknown) - property is set to EFalse"), iOtgVbus); |
|
338 } |
|
339 break; |
|
340 default: |
|
341 LOGTEXT2(_L8(">>CUsbOtgVbusWatcher::RunL [iOtgVbus=%d] is unrecognized, re-request QueueOtgVbusNotification"), iOtgVbus); |
|
342 break; |
|
343 } |
|
344 SetActive(); |
|
345 } |
|
346 |
|
347 |
|
348 //-------------------------- OTG State watcher class -------------------------- |
|
349 /** |
|
350 * The CUsbOtgStateWatcher::NewL method |
|
351 * |
|
352 * Constructs a new CUsbOtgWatcher object |
|
353 * |
|
354 * @internalComponent |
|
355 * @param aLdd A reference to the USB Logical Device Driver |
|
356 * |
|
357 * @return A new CUsbOtgWatcher object |
|
358 */ |
|
359 CUsbOtgStateWatcher* CUsbOtgStateWatcher::NewL(RUsbOtgDriver& aLdd) |
|
360 { |
|
361 LOG_STATIC_FUNC_ENTRY |
|
362 |
|
363 CUsbOtgStateWatcher* self = new (ELeave) CUsbOtgStateWatcher(aLdd); |
|
364 CleanupStack::PushL(self); |
|
365 self->ConstructL(); |
|
366 CleanupStack::Pop(self); |
|
367 return self; |
|
368 } |
|
369 |
|
370 |
|
371 /** |
|
372 * The CUsbOtgStateWatcher::~CUsbOtgStateWatcher method |
|
373 * |
|
374 * Destructor |
|
375 * |
|
376 * @internalComponent |
|
377 */ |
|
378 CUsbOtgStateWatcher::~CUsbOtgStateWatcher() |
|
379 { |
|
380 LOG_FUNC |
|
381 Cancel(); |
|
382 RProperty::Delete(KUsbOtgStateProperty); |
|
383 } |
|
384 |
|
385 void CUsbOtgStateWatcher::ConstructL() |
|
386 /** |
|
387 * Performs 2nd phase construction of the OTG object. |
|
388 */ |
|
389 { |
|
390 LOG_FUNC |
|
391 |
|
392 TInt err = RProperty::Define(KUsbOtgStateProperty, RProperty::EInt, KAllowAllPolicy, KNetworkControlPolicy); |
|
393 if ( err != KErrNone && err != KErrAlreadyExists ) |
|
394 { |
|
395 User::LeaveIfError(err); |
|
396 } |
|
397 err = RProperty::Set(KUidUsbManCategory,KUsbOtgStateProperty,RUsbOtgDriver::EStateReset); |
|
398 if ( err != KErrNone ) |
|
399 { |
|
400 User::LeaveIfError(err); |
|
401 } |
|
402 } |
|
403 |
|
404 /** |
|
405 * The CUsbOtgIdPinWatcher::CUsbOtgIdPinWatcher method |
|
406 * |
|
407 * Constructor |
|
408 * |
|
409 * @param aLdd A reference to the USB Logical Device Driver |
|
410 */ |
|
411 |
|
412 CUsbOtgStateWatcher::CUsbOtgStateWatcher(RUsbOtgDriver& aLdd) |
|
413 : CUsbOtgBaseWatcher(aLdd) |
|
414 { |
|
415 LOG_FUNC |
|
416 iOtgState = RUsbOtgDriver::EStateReset; |
|
417 } |
|
418 |
|
419 /** |
|
420 * Called when the OTG State change is reported |
|
421 */ |
|
422 void CUsbOtgStateWatcher::RunL() |
|
423 { |
|
424 LOG_FUNC |
|
425 LOGTEXT2(_L8(">>CUsbOtgStateWatcher::RunL [iStatus=%d]"), iStatus.Int()); |
|
426 |
|
427 LEAVEIFERRORL(iStatus.Int()); |
|
428 |
|
429 Post(); |
|
430 |
|
431 LOGTEXT(_L8("<<CUsbOtgStateWatcher::RunL")); |
|
432 } |
|
433 |
|
434 |
|
435 /** |
|
436 * Automatically called when the OTG State watcher is cancelled. |
|
437 */ |
|
438 void CUsbOtgStateWatcher::DoCancel() |
|
439 { |
|
440 LOG_FUNC |
|
441 iLdd.CancelOtgStateNotification(); |
|
442 } |
|
443 |
|
444 /** |
|
445 * Sets state watcher in active state |
|
446 */ |
|
447 void CUsbOtgStateWatcher::Post() |
|
448 { |
|
449 LOG_FUNC |
|
450 |
|
451 LOGTEXT(_L8("CUsbOtgStateWatcher::Post() - About to call QueueOtgStateNotification")); |
|
452 iLdd.QueueOtgStateNotification(iOtgState, iStatus); |
|
453 LOGTEXT3(_L8(">>CUsbOtgStateWatcher::RunL [iStatus=%d], iOtgState = %d"), iStatus.Int(), iOtgState); |
|
454 if (RProperty::Set(KUidUsbManCategory,KUsbOtgStateProperty,(TInt)iOtgState) != KErrNone) |
|
455 { |
|
456 LOGTEXT3(_L8(">>CUsbOtgStateWatcher::RunL [iStatus=%d], iOtgState = %d - failed to set the property"), iStatus.Int(), iOtgState); |
|
457 } |
|
458 |
|
459 SetActive(); |
|
460 } |
|
461 |
|
462 //-------------------------- OTG Events watcher class ------------------------- |
|
463 /** |
|
464 * The CUsbOtgEventWatcher::NewL method |
|
465 * |
|
466 * Constructs a new CUsbOtgEventWatcher object |
|
467 * |
|
468 * @internalComponent |
|
469 * @param aOwner The CUsbOtg that owns the state watcher |
|
470 * @param aLdd A reference to the USB Logical Device Driver |
|
471 * @param aOtgEvent A reference to the OTG Event |
|
472 * |
|
473 * @return A new CUsbOtgEventWatcher object |
|
474 */ |
|
475 CUsbOtgEventWatcher* CUsbOtgEventWatcher::NewL(CUsbOtg& aOwner, RUsbOtgDriver& aLdd, |
|
476 RUsbOtgDriver::TOtgEvent& aOtgEvent) |
|
477 { |
|
478 LOG_STATIC_FUNC_ENTRY |
|
479 |
|
480 CUsbOtgEventWatcher* self = new (ELeave) CUsbOtgEventWatcher(aOwner, aLdd, aOtgEvent); |
|
481 CleanupStack::PushL(self); |
|
482 self->ConstructL(); |
|
483 CleanupStack::Pop(self); |
|
484 return self; |
|
485 } |
|
486 |
|
487 |
|
488 /** |
|
489 * The CUsbOtgEventWatcher::~CUsbOtgEventWatcher method |
|
490 * |
|
491 * Destructor |
|
492 * |
|
493 * @internalComponent |
|
494 */ |
|
495 CUsbOtgEventWatcher::~CUsbOtgEventWatcher() |
|
496 { |
|
497 LOG_FUNC |
|
498 Cancel(); |
|
499 } |
|
500 |
|
501 void CUsbOtgEventWatcher::ConstructL() |
|
502 /** |
|
503 * Performs 2nd phase construction of the OTG object. |
|
504 */ |
|
505 { |
|
506 LOG_FUNC |
|
507 } |
|
508 |
|
509 /** |
|
510 * The CUsbOtgEventWatcher::CUsbOtgEventWatcher method |
|
511 * |
|
512 * Constructor |
|
513 * |
|
514 * @param aOwner A reference to the CUsbOtg object that owns the state watcher |
|
515 * @param aLdd A reference to the USB Logical Device Driver |
|
516 * @param aOtgEvent A reference to the OTG Event |
|
517 */ |
|
518 CUsbOtgEventWatcher::CUsbOtgEventWatcher(CUsbOtg& aOwner, RUsbOtgDriver& aLdd, |
|
519 RUsbOtgDriver::TOtgEvent& aOtgEvent) |
|
520 : CUsbOtgBaseWatcher(aLdd), iOwner(aOwner), iOtgEvent(aOtgEvent) |
|
521 { |
|
522 LOG_FUNC |
|
523 } |
|
524 |
|
525 /** |
|
526 * Called when the OTG Event is reported |
|
527 */ |
|
528 void CUsbOtgEventWatcher::RunL() |
|
529 { |
|
530 LOG_FUNC |
|
531 LOGTEXT2(_L8(">>CUsbOtgEventWatcher::RunL [iStatus=%d]"), iStatus.Int()); |
|
532 |
|
533 LEAVEIFERRORL(iStatus.Int()); |
|
534 LOGTEXT2(_L8("CUsbOtgEventWatcher::RunL() - Otg Event reported: %d"), (TInt)iOtgEvent); |
|
535 if ( ( iOtgEvent == RUsbOtgDriver::EEventHnpDisabled ) |
|
536 ||( iOtgEvent == RUsbOtgDriver::EEventHnpEnabled ) |
|
537 ||( iOtgEvent == RUsbOtgDriver::EEventSrpInitiated ) |
|
538 ||( iOtgEvent == RUsbOtgDriver::EEventSrpReceived ) |
|
539 ||( iOtgEvent == RUsbOtgDriver::EEventVbusRaised ) |
|
540 ||( iOtgEvent == RUsbOtgDriver::EEventVbusDropped ) |
|
541 ) |
|
542 { |
|
543 iOwner.NotifyOtgEvent(); |
|
544 LOGTEXT2(_L8("CUsbOtgEventWatcher::RunL() - The owner is notified about Otg Event = %d"), (TInt)iOtgEvent); |
|
545 } |
|
546 Post(); |
|
547 LOGTEXT(_L8("<<CUsbOtgEventWatcher::RunL")); |
|
548 } |
|
549 |
|
550 #ifndef __FLOG_ACTIVE |
|
551 void CUsbOtgEventWatcher::LogEventText(RUsbOtgDriver::TOtgEvent /*aState*/) |
|
552 { |
|
553 } |
|
554 #else |
|
555 void CUsbOtgEventWatcher::LogEventText(RUsbOtgDriver::TOtgEvent aEvent) |
|
556 { |
|
557 switch (aEvent) |
|
558 { |
|
559 case RUsbOtgDriver::EEventAPlugInserted: |
|
560 LOGTEXT(_L8(" ***** A-Plug Inserted *****")); |
|
561 break; |
|
562 case RUsbOtgDriver::EEventAPlugRemoved: |
|
563 LOGTEXT(_L8(" ***** A-Plug Removed *****")); |
|
564 break; |
|
565 case RUsbOtgDriver::EEventVbusRaised: |
|
566 LOGTEXT(_L8(" ***** VBus Raised *****")); |
|
567 break; |
|
568 case RUsbOtgDriver::EEventVbusDropped: |
|
569 LOGTEXT(_L8(" ***** VBus Dropped *****")); |
|
570 break; |
|
571 case RUsbOtgDriver::EEventSrpInitiated: |
|
572 LOGTEXT(_L8(" ***** SRP Initiated *****")); |
|
573 break; |
|
574 case RUsbOtgDriver::EEventSrpReceived: |
|
575 LOGTEXT(_L8(" ***** SRP Received *****")); |
|
576 break; |
|
577 case RUsbOtgDriver::EEventHnpEnabled: |
|
578 LOGTEXT(_L8(" ***** HNP Enabled *****")); |
|
579 break; |
|
580 case RUsbOtgDriver::EEventHnpDisabled: |
|
581 LOGTEXT(_L8(" ***** HNP Disabled *****")); |
|
582 break; |
|
583 case RUsbOtgDriver::EEventRoleChangedToHost: |
|
584 LOGTEXT(_L8(" ***** Role Changed to Host *****")); |
|
585 break; |
|
586 case RUsbOtgDriver::EEventRoleChangedToDevice: |
|
587 LOGTEXT(_L8(" ***** Role Changed to Device *****")); |
|
588 break; |
|
589 case RUsbOtgDriver::EEventRoleChangedToIdle: |
|
590 LOGTEXT(_L8(" ***** Role Changed to Idle *****")); |
|
591 break; |
|
592 default: |
|
593 break; |
|
594 } |
|
595 } |
|
596 #endif |
|
597 |
|
598 /** |
|
599 * Automatically called when the OTG Event watcher is cancelled. |
|
600 */ |
|
601 void CUsbOtgEventWatcher::DoCancel() |
|
602 { |
|
603 LOG_FUNC |
|
604 iLdd.CancelOtgEventRequest(); |
|
605 } |
|
606 |
|
607 /** |
|
608 * Sets state watcher in active state |
|
609 */ |
|
610 void CUsbOtgEventWatcher::Post() |
|
611 { |
|
612 LOG_FUNC |
|
613 |
|
614 LOGTEXT(_L8("CUsbOtgEventWatcher::Post() - About to call QueueOtgEventRequest")); |
|
615 iLdd.QueueOtgEventRequest(iOtgEvent, iStatus); |
|
616 SetActive(); |
|
617 } |
|
618 |
|
619 |
|
620 //----------------------------------------------------------------------------- |
|
621 //----------------- OTG watcher class to monitor OTG Messages ----------------- |
|
622 //----------------------------------------------------------------------------- |
|
623 /** |
|
624 * The CUsbOtgWatcher::NewL method |
|
625 * |
|
626 * Constructs a new CUsbOtgWatcher object |
|
627 * |
|
628 * @internalComponent |
|
629 * @param aOwner A reference to the object that owns the state watcher |
|
630 * @param aLdd A reference to the USB Logical Device Driver |
|
631 * |
|
632 * @return A new CUsbOtgWatcher object |
|
633 */ |
|
634 CUsbOtgWatcher* CUsbOtgWatcher::NewL(MUsbOtgObserver& aOwner, RUsbOtgDriver& aLdd, TUint& aOtgMessage) |
|
635 { |
|
636 LOG_STATIC_FUNC_ENTRY |
|
637 |
|
638 CUsbOtgWatcher* r = new (ELeave) CUsbOtgWatcher(aOwner, aLdd, aOtgMessage); |
|
639 return r; |
|
640 } |
|
641 |
|
642 |
|
643 /** |
|
644 * The CUsbOtgWatcher::~CUsbOtgWatcher method |
|
645 * |
|
646 * Destructor |
|
647 * |
|
648 * @internalComponent |
|
649 */ |
|
650 CUsbOtgWatcher::~CUsbOtgWatcher() |
|
651 { |
|
652 LOG_FUNC |
|
653 LOGTEXT2(_L8(">CUsbOtgWatcher::~CUsbOtgWatcher (0x%08x)"), (TUint32) this); |
|
654 Cancel(); |
|
655 } |
|
656 |
|
657 |
|
658 /** |
|
659 * The CUsbOtgWatcher::CUsbOtgWatcher method |
|
660 * |
|
661 * Constructor |
|
662 * |
|
663 * @param aOwner The device that owns the state watcher |
|
664 * @param aLdd A reference to the USB Logical Device Driver |
|
665 */ |
|
666 CUsbOtgWatcher::CUsbOtgWatcher(MUsbOtgObserver& aOwner, RUsbOtgDriver& aLdd, TUint& aOtgMessage) |
|
667 : CActive(CActive::EPriorityStandard), iOwner(aOwner), iLdd(aLdd), iOtgMessage(aOtgMessage) |
|
668 { |
|
669 LOG_FUNC |
|
670 CActiveScheduler::Add(this); |
|
671 } |
|
672 |
|
673 /** |
|
674 * Called when the OTG component changes its state. |
|
675 */ |
|
676 void CUsbOtgWatcher::RunL() |
|
677 { |
|
678 LOG_FUNC |
|
679 if (iStatus.Int() != KErrNone) |
|
680 { |
|
681 LOGTEXT2(_L8("CUsbOtgWatcher::RunL() - Error = %d"), iStatus.Int()); |
|
682 return; |
|
683 } |
|
684 |
|
685 LOGTEXT2(_L8("CUsbOtgWatcher::RunL() - Otg Message reported: %d"), iOtgMessage); |
|
686 iOwner.NotifyMessage(); |
|
687 |
|
688 Post(); |
|
689 } |
|
690 |
|
691 |
|
692 /** |
|
693 * Automatically called when the state watcher is cancelled. |
|
694 */ |
|
695 void CUsbOtgWatcher::DoCancel() |
|
696 { |
|
697 LOG_FUNC |
|
698 iLdd.CancelOtgMessageRequest(); |
|
699 } |
|
700 |
|
701 |
|
702 /** |
|
703 * Instructs the state watcher to start watching. |
|
704 */ |
|
705 void CUsbOtgWatcher::Start() |
|
706 { |
|
707 LOG_FUNC |
|
708 Post(); |
|
709 } |
|
710 |
|
711 /** |
|
712 * Sets state watcher in active state |
|
713 */ |
|
714 void CUsbOtgWatcher::Post() |
|
715 { |
|
716 LOG_FUNC |
|
717 |
|
718 LOGTEXT(_L8("CUsbOtgWatcher::Post() - About to call QueueOtgMessageRequest")); |
|
719 iLdd.QueueOtgMessageRequest((RUsbOtgDriver::TOtgMessage&)iOtgMessage, iStatus); |
|
720 SetActive(); |
|
721 } |
|
722 |
|
723 |
|
724 |
|
725 |
|
726 //----------------------------------------------------------------------------- |
|
727 //------ A watcher class to monitor the P&S property for VBus marshalling ----- |
|
728 //----------------------------------------------------------------------------- |
|
729 |
|
730 CRequestSessionWatcher* CRequestSessionWatcher::NewL(MUsbOtgObserver& aOwner) |
|
731 { |
|
732 CRequestSessionWatcher* self = new(ELeave) CRequestSessionWatcher(aOwner); |
|
733 CleanupStack::PushL(self); |
|
734 self->ConstructL(); |
|
735 CleanupStack::Pop(self); |
|
736 return self; |
|
737 } |
|
738 |
|
739 CRequestSessionWatcher::~CRequestSessionWatcher() |
|
740 { |
|
741 Cancel(); |
|
742 iProp.Close(); |
|
743 } |
|
744 |
|
745 void CRequestSessionWatcher::ConstructL() |
|
746 /** |
|
747 * Performs 2nd phase construction of the OTG object. |
|
748 */ |
|
749 { |
|
750 LOG_FUNC |
|
751 |
|
752 TInt err = RProperty::Define(KUsbRequestSessionProperty, RProperty::EInt, KAllowAllPolicy, KRequestSessionPolicy); |
|
753 if ( err != KErrNone && err != KErrAlreadyExists ) |
|
754 { |
|
755 User::LeaveIfError(err); |
|
756 } |
|
757 err = RProperty::Set(KUidUsbManCategory,KUsbRequestSessionProperty,0); |
|
758 if ( err != KErrNone ) |
|
759 { |
|
760 User::LeaveIfError(err); |
|
761 } |
|
762 User::LeaveIfError(iProp.Attach(KUidUsbManCategory, KUsbRequestSessionProperty)); |
|
763 iProp.Subscribe(iStatus); |
|
764 SetActive(); |
|
765 } |
|
766 |
|
767 CRequestSessionWatcher::CRequestSessionWatcher(MUsbOtgObserver& aOwner) |
|
768 : CActive(CActive::EPriorityStandard), iOwner(aOwner) |
|
769 { |
|
770 LOG_FUNC |
|
771 CActiveScheduler::Add(this); |
|
772 } |
|
773 |
|
774 /** |
|
775 * Called when the OTG Event is reported |
|
776 */ |
|
777 void CRequestSessionWatcher::RunL() |
|
778 { |
|
779 LOG_FUNC |
|
780 LOGTEXT2(_L8(">>CRequestSessionWatcher::RunL [iStatus=%d]"), iStatus.Int()); |
|
781 RDebug::Printf(">>CRequestSessionWatcher::RunL [iStatus=%d]", iStatus.Int()); |
|
782 |
|
783 iProp.Subscribe(iStatus); |
|
784 SetActive(); |
|
785 |
|
786 TInt val; |
|
787 User::LeaveIfError(iProp.Get(val)); |
|
788 RDebug::Printf(">>value=%d", val); |
|
789 |
|
790 iOwner.NotifyMessage(KUsbMessageRequestSession); |
|
791 |
|
792 LOGTEXT(_L8("<<CRequestSessionWatcher::RunL")); |
|
793 } |
|
794 |
|
795 |
|
796 /** |
|
797 * Automatically called when the OTG Event watcher is cancelled. |
|
798 */ |
|
799 void CRequestSessionWatcher::DoCancel() |
|
800 { |
|
801 LOG_FUNC |
|
802 iProp.Cancel(); |
|
803 } |
|
804 |
|
805 //---------------------------- Connection Idle watcher class --------------------------- |
|
806 /** |
|
807 * The CUsbOtgConnectionIdleWatcher::NewL method |
|
808 * |
|
809 * Constructs a new CUsbOtgWatcher object |
|
810 * |
|
811 * @internalComponent |
|
812 * @param aLdd A reference to the USB Logical Device Driver |
|
813 * |
|
814 * @return A new CUsbOtgWatcher object |
|
815 */ |
|
816 CUsbOtgConnectionIdleWatcher* CUsbOtgConnectionIdleWatcher::NewL(RUsbOtgDriver& aLdd) |
|
817 { |
|
818 LOG_STATIC_FUNC_ENTRY |
|
819 |
|
820 CUsbOtgConnectionIdleWatcher* self = new (ELeave) CUsbOtgConnectionIdleWatcher(aLdd); |
|
821 CleanupStack::PushL(self); |
|
822 self->ConstructL(); |
|
823 CleanupStack::Pop(self); |
|
824 return self; |
|
825 } |
|
826 |
|
827 |
|
828 /** |
|
829 * The CUsbOtgConnectionIdleWatcher::~CUsbOtgConnectionIdleWatcher method |
|
830 * |
|
831 * Destructor |
|
832 * |
|
833 * @internalComponent |
|
834 */ |
|
835 CUsbOtgConnectionIdleWatcher::~CUsbOtgConnectionIdleWatcher() |
|
836 { |
|
837 LOG_FUNC |
|
838 Cancel(); |
|
839 RProperty::Delete(KUsbOtgConnectionIdleProperty); |
|
840 } |
|
841 |
|
842 /** |
|
843 * Performs 2nd phase construction of the OTG object. |
|
844 */ |
|
845 void CUsbOtgConnectionIdleWatcher::ConstructL() |
|
846 { |
|
847 LOG_FUNC |
|
848 |
|
849 TInt err = RProperty::Define(KUsbOtgConnectionIdleProperty, RProperty::EInt, KAllowAllPolicy, KNetworkControlPolicy); |
|
850 if ( err != KErrNone && err != KErrAlreadyExists ) |
|
851 { |
|
852 User::LeaveIfError(err); |
|
853 } |
|
854 err = RProperty::Set(KUidUsbManCategory,KUsbOtgConnectionIdleProperty,ETrue); |
|
855 if ( err != KErrNone ) |
|
856 { |
|
857 User::LeaveIfError(err); |
|
858 } |
|
859 } |
|
860 |
|
861 /** |
|
862 * The CUsbOtgConnectionIdleWatcher::CUsbOtgConnectionIdleWatcher method |
|
863 * |
|
864 * Constructor |
|
865 * |
|
866 * @param aLdd A reference to the USB Logical Device Driver |
|
867 */ |
|
868 |
|
869 CUsbOtgConnectionIdleWatcher::CUsbOtgConnectionIdleWatcher(RUsbOtgDriver& aLdd) |
|
870 : CUsbOtgBaseWatcher(aLdd) |
|
871 { |
|
872 LOG_FUNC |
|
873 } |
|
874 |
|
875 /** |
|
876 * Called when the Connection Idle status change is reported |
|
877 */ |
|
878 void CUsbOtgConnectionIdleWatcher::RunL() |
|
879 { |
|
880 LOG_FUNC |
|
881 LOGTEXT2(_L8(">>CUsbOtgConnectionIdleWatcher::RunL [iStatus=%d]"), iStatus.Int()); |
|
882 |
|
883 LEAVEIFERRORL(iStatus.Int()); |
|
884 |
|
885 Post(); |
|
886 |
|
887 LOGTEXT(_L8("<<CUsbOtgConnectionIdleWatcher::RunL")); |
|
888 } |
|
889 |
|
890 |
|
891 /** |
|
892 * Automatically called when the Connection Idle watcher is cancelled. |
|
893 */ |
|
894 void CUsbOtgConnectionIdleWatcher::DoCancel() |
|
895 { |
|
896 LOG_FUNC |
|
897 iLdd.CancelOtgConnectionNotification(); |
|
898 } |
|
899 |
|
900 /** |
|
901 * Sets state watcher in active state |
|
902 */ |
|
903 void CUsbOtgConnectionIdleWatcher::Post() |
|
904 { |
|
905 LOG_FUNC |
|
906 |
|
907 LOGTEXT(_L8("CUsbOtgConnectionIdleWatcher::Post() - About to call QueueOtgIdPinNotification")); |
|
908 iLdd.QueueOtgConnectionNotification(iConnectionIdle, iStatus); |
|
909 switch (iConnectionIdle) |
|
910 { |
|
911 case RUsbOtgDriver::EConnectionIdle: |
|
912 case RUsbOtgDriver::EConnectionUnknown: |
|
913 RProperty::Set(KUidUsbManCategory,KUsbOtgConnectionIdleProperty,ETrue); |
|
914 LOGTEXT2(_L8(">>CUsbOtgConnectionIdleWatcher::Post [iConnectionIdle=%d] - property is set to 1"), iConnectionIdle); |
|
915 break; |
|
916 case RUsbOtgDriver::EConnectionBusy: |
|
917 RProperty::Set(KUidUsbManCategory,KUsbOtgConnectionIdleProperty,EFalse); |
|
918 LOGTEXT2(_L8(">>CUsbOtgConnectionIdleWatcher::Post [iConnectionIdle=%d] - property is set to 0"), iConnectionIdle); |
|
919 break; |
|
920 default: |
|
921 LOGTEXT2(_L8(">>CUsbOtgConnectionIdleWatcher::Post [iConnectionIdle=%d] is unrecognized, re-request QueueOtgIdPinNotification"), iConnectionIdle); |
|
922 break; |
|
923 } |
|
924 SetActive(); |
|
925 } |
|
926 |
|
927 |