|
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 * |
|
16 */ |
|
17 |
|
18 #include "usbviewer.h" |
|
19 |
|
20 #include <e32cons.h> |
|
21 #include <e32debug.h> |
|
22 |
|
23 #include <d32otgdi_errors.h> |
|
24 #include <d32usbdi_errors.h> |
|
25 #include <usb/usbshared.h> |
|
26 // For moving windows using scancode events |
|
27 #include "e32event.h" |
|
28 #include "e32svr.h" |
|
29 |
|
30 |
|
31 #define PANIC Panic(__LINE__) |
|
32 #define LOG(A,B) RDebug::Print(_L("UsbViewer: " L##A),B) |
|
33 #define PNT(A) RDebug::Print(_L("UsbViewer: " L##A)) |
|
34 |
|
35 void Panic(TInt aLine) |
|
36 { |
|
37 RDebug::Printf("UsbViewer: PANIC line=%d", aLine); |
|
38 User::Panic(_L("USBVIEWER"), aLine); |
|
39 } |
|
40 |
|
41 void RunViewerL() |
|
42 { |
|
43 CUsbViewer* viewer = CUsbViewer::NewLC(); |
|
44 viewer->Start(); |
|
45 CleanupStack::PopAndDestroy(viewer); |
|
46 } |
|
47 |
|
48 TInt E32Main() |
|
49 { |
|
50 __UHEAP_MARK; |
|
51 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
52 CActiveScheduler* activeScheduler = new CActiveScheduler; |
|
53 TInt err = KErrNoMemory; |
|
54 if(cleanup && activeScheduler) |
|
55 { |
|
56 CActiveScheduler::Install(activeScheduler); |
|
57 PNT("*** UsbViewer E32Main ***\n"); |
|
58 TRAP(err, RunViewerL()); |
|
59 } |
|
60 delete activeScheduler; |
|
61 delete cleanup; |
|
62 __UHEAP_MARKEND; |
|
63 return err; |
|
64 } |
|
65 |
|
66 |
|
67 XUsbViewerEvent::~XUsbViewerEvent() |
|
68 { |
|
69 iLink.Deque(); |
|
70 iEvent.Close(); |
|
71 } |
|
72 |
|
73 |
|
74 |
|
75 CUsbViewer* CUsbViewer::NewLC() |
|
76 { |
|
77 PNT("CUsbViewer::NewLC"); |
|
78 CUsbViewer* self = new(ELeave) CUsbViewer; |
|
79 CleanupStack::PushL(self); |
|
80 self->ConstructL(); |
|
81 PNT("CUsbViewer::NewLC - Constructed Viewer"); |
|
82 return self; |
|
83 } |
|
84 |
|
85 CUsbViewer::~CUsbViewer() |
|
86 { |
|
87 PNT("CUsbViewer::~CUsbViewer"); |
|
88 |
|
89 delete iShutdownMonitor; |
|
90 |
|
91 delete iMessageWatcher; |
|
92 delete iHostEventWatcher; |
|
93 delete iOtgStateWatcher; |
|
94 delete iConnIdleWatcher; |
|
95 delete iVBusWatcher; |
|
96 delete iIdPinWatcher; |
|
97 delete iDeviceStateWatcher; |
|
98 delete iServiceStateWatcher; |
|
99 |
|
100 delete iUserMsgQWatcher; |
|
101 iUserMsgQ.Close(); |
|
102 |
|
103 TDblQueIter<XUsbViewerEvent> iter(iEventList); |
|
104 XUsbViewerEvent* event = NULL; |
|
105 while((event = iter++) != NULL) |
|
106 { |
|
107 delete event; |
|
108 } |
|
109 |
|
110 Cancel(); |
|
111 |
|
112 PNT("Closing USB Session"); |
|
113 iUsb.Close(); |
|
114 delete iConsole; |
|
115 } |
|
116 |
|
117 CUsbViewer::CUsbViewer() |
|
118 : CActive(EPriorityLow) // Low so all notifications that want to be serviced will be done first |
|
119 , iAutoSrpResponse(EFalse) |
|
120 , iDeviceType(ENoDevice) |
|
121 , iEventList(_FOFF(XUsbViewerEvent, iLink)) |
|
122 { |
|
123 CActiveScheduler::Add(this); |
|
124 } |
|
125 |
|
126 void CUsbViewer::ConstructL() |
|
127 { |
|
128 PNT("CUsbViewer::ConstructL"); |
|
129 iConsole = Console::NewL(KUsbViewerTitle, TSize(KViewerNumCharactersOnLine, KNumLinesInWindow)); |
|
130 Move(-3, -3); |
|
131 User::LeaveIfError(iUsb.Connect()); |
|
132 |
|
133 for(TInt i=0; i<KNumEventsInWindow; ++i) |
|
134 { |
|
135 XUsbViewerEvent* nullEvent = new(ELeave) XUsbViewerEvent; |
|
136 iEventList.AddFirst(*nullEvent); |
|
137 } |
|
138 |
|
139 // Open message queue to display user messages |
|
140 User::LeaveIfError(iUserMsgQ.OpenGlobal(KControlAppViewerMsgQName)); |
|
141 iUserMsgQWatcher = CUserMsgQWatcher::NewL(*this); |
|
142 |
|
143 iServiceStateWatcher = CServiceStateWatcher::NewL(*this); |
|
144 iDeviceStateWatcher = CDeviceStateWatcher::NewL(*this); |
|
145 iIdPinWatcher = CIdPinWatcher::NewL(*this); |
|
146 iVBusWatcher = CVBusWatcher::NewL(*this); |
|
147 iConnIdleWatcher = CConnectionIdleWatcher::NewL(*this); |
|
148 iOtgStateWatcher = COtgStateWatcher::NewL(*this); |
|
149 iHostEventWatcher = CHostEventWatcher::NewL(*this); |
|
150 iMessageWatcher = CMessageWatcher::NewL(*this); |
|
151 SetDriverLoading(EUnknown); |
|
152 SetDeviceType(ENoDevice); |
|
153 |
|
154 iShutdownMonitor = CShutdownMonitor::NewL(*this); |
|
155 } |
|
156 |
|
157 void CUsbViewer::Move(TInt aX, TInt aY) |
|
158 { |
|
159 TRawEvent event; |
|
160 |
|
161 event.Set(TRawEvent::EKeyDown, EStdKeyLeftShift); |
|
162 UserSvr::AddEvent(event); |
|
163 |
|
164 if (aX) |
|
165 { |
|
166 if ( aX > 0 ) |
|
167 { |
|
168 // Move to the right... |
|
169 for(TInt i=aX; i; i--) |
|
170 { |
|
171 event.Set(TRawEvent::EKeyDown, EStdKeyRightArrow); |
|
172 UserSvr::AddEvent(event); |
|
173 event.Set(TRawEvent::EKeyUp, EStdKeyRightArrow); |
|
174 UserSvr::AddEvent(event); |
|
175 } |
|
176 } |
|
177 else |
|
178 { |
|
179 // Move to the Left... |
|
180 for(TInt i=aX; i; i++) |
|
181 { |
|
182 event.Set(TRawEvent::EKeyDown, EStdKeyLeftArrow); |
|
183 UserSvr::AddEvent(event); |
|
184 event.Set(TRawEvent::EKeyUp, EStdKeyLeftArrow); |
|
185 UserSvr::AddEvent(event); |
|
186 } |
|
187 } |
|
188 } |
|
189 |
|
190 if (aY) |
|
191 { |
|
192 if ( aY > 0 ) |
|
193 { |
|
194 // Move downwards... |
|
195 for(TInt i=aY; i; i--) |
|
196 { |
|
197 event.Set(TRawEvent::EKeyDown, EStdKeyDownArrow); |
|
198 UserSvr::AddEvent(event); |
|
199 event.Set(TRawEvent::EKeyUp, EStdKeyDownArrow); |
|
200 UserSvr::AddEvent(event); |
|
201 } |
|
202 } |
|
203 else |
|
204 { |
|
205 // Move upwards... |
|
206 for(TInt i=aY; i; i++) |
|
207 { |
|
208 event.Set(TRawEvent::EKeyDown, EStdKeyUpArrow); |
|
209 UserSvr::AddEvent(event); |
|
210 event.Set(TRawEvent::EKeyUp, EStdKeyUpArrow); |
|
211 UserSvr::AddEvent(event); |
|
212 } |
|
213 } |
|
214 } |
|
215 |
|
216 event.Set(TRawEvent::EKeyUp, EStdKeyLeftShift); |
|
217 UserSvr::AddEvent(event); |
|
218 } |
|
219 |
|
220 void CUsbViewer::Start() |
|
221 { |
|
222 // Get everything running |
|
223 CActiveScheduler::Start(); |
|
224 } |
|
225 |
|
226 void CUsbViewer::Stop() const |
|
227 { |
|
228 CActiveScheduler::Stop(); |
|
229 } |
|
230 |
|
231 void CUsbViewer::DoCancel() |
|
232 { |
|
233 // Don't need to do anything as the AO is completed straight away. |
|
234 } |
|
235 |
|
236 void CUsbViewer::RunL() |
|
237 { |
|
238 __ASSERT_ALWAYS(iStatus.Int() == KErrNone, PANIC); |
|
239 Draw(); |
|
240 } |
|
241 |
|
242 void CUsbViewer::ScheduleDraw() |
|
243 { |
|
244 PNT("CUsbViewer::ScheduleDraw"); |
|
245 if(!IsActive()) |
|
246 { |
|
247 SetActive(); |
|
248 TRequestStatus* status = &iStatus; |
|
249 User::RequestComplete(status, KErrNone); |
|
250 |
|
251 TSize size = iConsole->ScreenSize(); |
|
252 iConsole->SetCursorPosAbs(TPoint(size.iWidth-1, 0)); |
|
253 iConsole->Write(_L("*")); |
|
254 } |
|
255 } |
|
256 |
|
257 RUsb& CUsbViewer::Usb() |
|
258 { |
|
259 return iUsb; |
|
260 } |
|
261 |
|
262 RMsgQueue<TBuf<KViewerNumCharactersOnLine> >& CUsbViewer::UserMsgQ() |
|
263 { |
|
264 return iUserMsgQ; |
|
265 } |
|
266 |
|
267 void CUsbViewer::SetServiceState(TUsbServiceState aServiceState) |
|
268 { |
|
269 switch(aServiceState) |
|
270 { |
|
271 case EUsbServiceIdle: |
|
272 iServStatus = |
|
273 // 12345678901 |
|
274 _L("Idle "); |
|
275 break; |
|
276 |
|
277 case EUsbServiceStarting: |
|
278 iServStatus = |
|
279 // 12345678901 |
|
280 _L("Starting "); |
|
281 break; |
|
282 |
|
283 case EUsbServiceStarted: |
|
284 iServStatus = |
|
285 // 12345678901 |
|
286 _L("Started "); |
|
287 break; |
|
288 |
|
289 case EUsbServiceStopping: |
|
290 iServStatus = |
|
291 // 12345678901 |
|
292 _L("Stopping "); |
|
293 break; |
|
294 |
|
295 case EUsbServiceFatalError: |
|
296 iServStatus = |
|
297 // 12345678901 |
|
298 _L("Error "); |
|
299 break; |
|
300 |
|
301 default: |
|
302 PANIC; |
|
303 break; |
|
304 } |
|
305 LOG("Service State => %S", &iServStatus); |
|
306 ScheduleDraw(); |
|
307 } |
|
308 |
|
309 void CUsbViewer::SetDeviceState(TUsbDeviceState aDeviceState) |
|
310 { |
|
311 switch(aDeviceState) |
|
312 { |
|
313 case EUsbDeviceStateUndefined: |
|
314 iDevStatus = |
|
315 // 12345678901 |
|
316 _L("Undefined "); |
|
317 break; |
|
318 |
|
319 case EUsbDeviceStateDefault: |
|
320 iDevStatus = |
|
321 // 12345678901 |
|
322 _L("Default "); |
|
323 break; |
|
324 |
|
325 case EUsbDeviceStateAttached: |
|
326 iDevStatus = |
|
327 // 12345678901 |
|
328 _L("Attached "); |
|
329 break; |
|
330 |
|
331 case EUsbDeviceStatePowered: |
|
332 iDevStatus = |
|
333 // 12345678901 |
|
334 _L("Powered "); |
|
335 break; |
|
336 |
|
337 case EUsbDeviceStateConfigured: |
|
338 iDevStatus = |
|
339 // 12345678901 |
|
340 _L("Configured "); |
|
341 break; |
|
342 |
|
343 case EUsbDeviceStateAddress: |
|
344 iDevStatus = |
|
345 // 12345678901 |
|
346 _L("Address "); |
|
347 break; |
|
348 |
|
349 case EUsbDeviceStateSuspended: |
|
350 iDevStatus = |
|
351 // 12345678901 |
|
352 _L("Suspended "); |
|
353 break; |
|
354 |
|
355 default: |
|
356 PANIC; |
|
357 break; |
|
358 } |
|
359 LOG("Device State => %S", &iDevStatus); |
|
360 ScheduleDraw(); |
|
361 } |
|
362 |
|
363 void CUsbViewer::SetIdPin(TInt aIdPin) |
|
364 { |
|
365 switch(aIdPin) |
|
366 { |
|
367 case 0: |
|
368 iIdPin = |
|
369 // 12345 |
|
370 _L("- "); |
|
371 break; |
|
372 |
|
373 case 1: |
|
374 iIdPin = |
|
375 // 12345 |
|
376 _L("+ "); |
|
377 break; |
|
378 |
|
379 default: |
|
380 PANIC; |
|
381 break; |
|
382 } |
|
383 LOG("Id Pin => %S", &iIdPin); |
|
384 ScheduleDraw(); |
|
385 } |
|
386 |
|
387 void CUsbViewer::SetVBus(TInt aVBus) |
|
388 { |
|
389 switch(aVBus) |
|
390 { |
|
391 case 0: |
|
392 iVBus = |
|
393 // 12345 |
|
394 _L("- "); |
|
395 break; |
|
396 |
|
397 case 1: |
|
398 iVBus = |
|
399 // 12345 |
|
400 _L("+ "); |
|
401 break; |
|
402 |
|
403 default: |
|
404 PANIC; |
|
405 break; |
|
406 } |
|
407 LOG("VBus => %S", &iVBus); |
|
408 ScheduleDraw(); |
|
409 } |
|
410 |
|
411 void CUsbViewer::SetConnectionIdle(TInt aConnIdle) |
|
412 { |
|
413 switch(aConnIdle) |
|
414 { |
|
415 case 0: |
|
416 iConnIdle = |
|
417 // 12345 |
|
418 _L("- "); |
|
419 break; |
|
420 |
|
421 case 1: |
|
422 iConnIdle = |
|
423 // 12345 |
|
424 _L("+ "); |
|
425 break; |
|
426 |
|
427 default: |
|
428 PANIC; |
|
429 break; |
|
430 } |
|
431 LOG("Connection Idle => %S", &iConnIdle); |
|
432 ScheduleDraw(); |
|
433 } |
|
434 |
|
435 void CUsbViewer::SetOtgState(TInt aOtgState) |
|
436 { |
|
437 switch(aOtgState) |
|
438 { |
|
439 case 0x01: |
|
440 iOtgState = |
|
441 // 123456789012 |
|
442 _L("Reset "); |
|
443 break; |
|
444 |
|
445 case 0x02: |
|
446 iOtgState = |
|
447 // 123456789012 |
|
448 _L("A-Idle "); |
|
449 break; |
|
450 |
|
451 case 0x04: |
|
452 iOtgState = |
|
453 // 123456789012 |
|
454 _L("A-Host "); |
|
455 break; |
|
456 |
|
457 case 0x08: |
|
458 iOtgState = |
|
459 // 1234567890123 |
|
460 _L("A-Peripheral"); |
|
461 break; |
|
462 |
|
463 case 0x10: |
|
464 iOtgState = |
|
465 // 123456789012 |
|
466 _L("A-Vbus Error"); |
|
467 break; |
|
468 |
|
469 case 0x20: |
|
470 iOtgState = |
|
471 // 123456789012 |
|
472 _L("B-Idle "); |
|
473 break; |
|
474 |
|
475 case 0x40: |
|
476 iOtgState = |
|
477 // 1234567890123 |
|
478 _L("B-Peripheral"); |
|
479 break; |
|
480 |
|
481 case 0x80: |
|
482 iOtgState = |
|
483 // 1234567890123 |
|
484 _L("B-Host "); |
|
485 break; |
|
486 |
|
487 default: |
|
488 iOtgState = |
|
489 // 1234567890123 |
|
490 _L("Don't Panic!"); |
|
491 break; |
|
492 } |
|
493 LOG("OTG State => %S", &iOtgState); |
|
494 ScheduleDraw(); |
|
495 } |
|
496 |
|
497 void CUsbViewer::SetDriverLoading(TFdfDriverLoadingState aDriverLoading) |
|
498 { |
|
499 switch(aDriverLoading) |
|
500 { |
|
501 case EUnknown: |
|
502 iDriverLoading = |
|
503 // 123 |
|
504 _L("???"); |
|
505 break; |
|
506 case EDisabled: |
|
507 iDriverLoading = |
|
508 // 123 |
|
509 _L("Off"); |
|
510 break; |
|
511 case EEnabled: |
|
512 iDriverLoading = |
|
513 // 123 |
|
514 _L("On "); |
|
515 break; |
|
516 default: |
|
517 PANIC; |
|
518 break; |
|
519 } |
|
520 LOG("Driver Loading => %S", &iDriverLoading); |
|
521 ScheduleDraw(); |
|
522 } |
|
523 |
|
524 void CUsbViewer::SetAttachedDevices(TUint aAttachedDevices) |
|
525 { |
|
526 if(aAttachedDevices > 999) |
|
527 { |
|
528 iAttachedDevices = |
|
529 // 123 |
|
530 _L("xxx"); |
|
531 } |
|
532 else |
|
533 { |
|
534 iAttachedDevices.NumFixedWidthUC(aAttachedDevices, EDecimal, 3); |
|
535 } |
|
536 LOG("Attached Devices => %S", &iAttachedDevices); |
|
537 ScheduleDraw(); |
|
538 } |
|
539 |
|
540 void CUsbViewer::SetDeviceType(TDeviceType aDeviceType) |
|
541 { |
|
542 iDeviceType = aDeviceType; |
|
543 |
|
544 switch ( aDeviceType ) |
|
545 { |
|
546 case ENoDevice: |
|
547 iAttachedDevice = |
|
548 // 12345 |
|
549 _L(" "); |
|
550 break; |
|
551 case EGenericDevice: |
|
552 iAttachedDevice = |
|
553 // 12345 |
|
554 _L("< >"); |
|
555 break; |
|
556 case ELogitechHeadset: |
|
557 iAttachedDevice = |
|
558 // 12345 |
|
559 _L("<<A>>"); |
|
560 break; |
|
561 } |
|
562 LOG("Audio Device => [%S]", &iAttachedDevice); |
|
563 ScheduleDraw(); |
|
564 } |
|
565 |
|
566 void CUsbViewer::NotifyEvent(XUsbViewerEvent* aEvent) |
|
567 { |
|
568 LOG("CUsbViewer::NotifyEvent event length = %d", aEvent->iEvent.Length()); |
|
569 __ASSERT_ALWAYS(aEvent, PANIC); |
|
570 __ASSERT_ALWAYS(aEvent->iEvent.Length() <= KViewerNumCharactersOnLine, PANIC); |
|
571 |
|
572 iEventList.AddFirst(*aEvent); |
|
573 delete iEventList.Last(); |
|
574 |
|
575 LOG("Event => %S", &(aEvent->iEvent)); |
|
576 ScheduleDraw(); |
|
577 } |
|
578 |
|
579 void CUsbViewer::Draw() |
|
580 { |
|
581 PNT("CUsbViewer::Draw"); |
|
582 iConsole->ClearScreen(); |
|
583 |
|
584 iConsole->Printf(_L( |
|
585 // 1 2 3 |
|
586 // 12345678901234567890123456789012 |
|
587 // |
|
588 // 12345 12345678901 |
|
589 "IdPin: %S" L"SrvSt : %S\n" |
|
590 // 12345 12345678901 |
|
591 L"VBus : %S" L"DevSt : %S\n" |
|
592 // 123 123 |
|
593 L"DLoad: %S " L"# Devs: %S\n" |
|
594 // 12345 1234 |
|
595 L"Dev : %S" L" \n" |
|
596 // 12345 1234567890123 |
|
597 L"C.Idl: %S" L"OTG : %S \n" |
|
598 ), |
|
599 &iIdPin, &iServStatus, |
|
600 &iVBus, &iDevStatus, |
|
601 &iDriverLoading, &iAttachedDevices, |
|
602 &iAttachedDevice, |
|
603 &iConnIdle, &iOtgState |
|
604 ); |
|
605 |
|
606 // Events... |
|
607 TDblQueIter<XUsbViewerEvent> iter(iEventList); |
|
608 XUsbViewerEvent* event = NULL; |
|
609 while((event = iter++) != NULL) |
|
610 { |
|
611 iConsole->Printf(_L("\n")); |
|
612 iConsole->Printf(event->iEvent.Left(KViewerNumCharactersOnLine)); |
|
613 } |
|
614 } |
|
615 |
|
616 |
|
617 |
|
618 CShutdownMonitor* CShutdownMonitor::NewL(MShutdownInterface& aParentUsbViewer) |
|
619 { |
|
620 CShutdownMonitor* self = new(ELeave) CShutdownMonitor(aParentUsbViewer); |
|
621 CleanupStack::PushL(self); |
|
622 self->ConstructL(); |
|
623 CleanupStack::Pop(self); |
|
624 return self; |
|
625 } |
|
626 |
|
627 CShutdownMonitor::CShutdownMonitor(MShutdownInterface& aParentUsbViewer) |
|
628 : CActive(EPriorityLow) // Low so all notifications that want to be serviced will be done first |
|
629 , iParentUsbViewer(aParentUsbViewer) |
|
630 { |
|
631 CActiveScheduler::Add(this); |
|
632 } |
|
633 |
|
634 void CShutdownMonitor::ConstructL() |
|
635 { |
|
636 // Monitor the KUsbControlAppShutdownKey property to tell us when to shut down |
|
637 TInt err = iShutdownProp.Attach(KUidUsbControlAppCategory, KUsbControlAppShutdownKey); |
|
638 LOG("CShutdownMonitor::ConstructL iShutdownProp.Attach() => %d", err); |
|
639 User::LeaveIfError(err); |
|
640 iShutdownProp.Subscribe(iStatus); |
|
641 SetActive(); |
|
642 TInt val; |
|
643 // Make sure the cuurent value is 0 - shut down when this changes to 1 |
|
644 err = iShutdownProp.Get(val); |
|
645 LOG("CShutdownMonitor::ConstructL() iShutdownProp.Get(val) val => %d", val); |
|
646 LOG("CShutdownMonitor::ConstructL() iShutdownProp.Get(val) err => %d", err); |
|
647 User::LeaveIfError(err); |
|
648 __ASSERT_ALWAYS(val==0, PANIC); |
|
649 } |
|
650 |
|
651 CShutdownMonitor::~CShutdownMonitor() |
|
652 { |
|
653 iShutdownProp.Close(); |
|
654 } |
|
655 |
|
656 void CShutdownMonitor::RunL() |
|
657 { |
|
658 // Request to shut everything down made in USB Aware App |
|
659 TInt val; |
|
660 TInt err = iShutdownProp.Get(val); |
|
661 LOG("CShutdownMonitor::RunL iShutdownProp.Get(val) err => %d", err); |
|
662 LOG("CShutdownMonitor::RunL iShutdownProp.Get(val) val => %d", val); |
|
663 Cancel(); // Not interested in any more notifications |
|
664 iParentUsbViewer.Stop(); // Stopping Active Scheduler will results in the destructor getting called |
|
665 } |
|
666 |
|
667 void CShutdownMonitor::DoCancel() |
|
668 { |
|
669 iShutdownProp.Cancel(); |
|
670 } |
|
671 |
|
672 |
|
673 |
|
674 CEventNotifier::CEventNotifier(TInt aPriority) |
|
675 : CActive(aPriority) |
|
676 { |
|
677 } |
|
678 |
|
679 XUsbViewerEvent* CEventNotifier::NewViewerEventL() |
|
680 { |
|
681 XUsbViewerEvent* event = new(ELeave) XUsbViewerEvent; |
|
682 CleanupStack::PushL(event); |
|
683 User::LeaveIfError(event->iEvent.Create(KViewerNumCharactersOnLine)); |
|
684 CleanupStack::Pop(); |
|
685 return event; |
|
686 } |
|
687 |
|
688 void CEventNotifier::RunL() |
|
689 { |
|
690 DoRunL(NewViewerEventL()); |
|
691 } |
|
692 |
|
693 |
|
694 |
|
695 |
|
696 CServiceStateWatcher* CServiceStateWatcher::NewL(CUsbViewer& aUsbViewer) |
|
697 { |
|
698 CServiceStateWatcher* self = new(ELeave) CServiceStateWatcher(aUsbViewer); |
|
699 CleanupStack::PushL(self); |
|
700 self->ConstructL(); |
|
701 CleanupStack::Pop(self); |
|
702 return self; |
|
703 } |
|
704 |
|
705 CServiceStateWatcher::~CServiceStateWatcher() |
|
706 { |
|
707 Cancel(); |
|
708 } |
|
709 |
|
710 CServiceStateWatcher::CServiceStateWatcher(CUsbViewer& aUsbViewer) |
|
711 : CEventNotifier(EPriorityStandard) |
|
712 , iUsbViewer(aUsbViewer) |
|
713 , iServiceState(EUsbServiceIdle) |
|
714 { |
|
715 CActiveScheduler::Add(this); |
|
716 } |
|
717 |
|
718 void CServiceStateWatcher::ConstructL() |
|
719 { |
|
720 iUsbViewer.Usb().ServiceStateNotification(iServiceState, iStatus); |
|
721 SetActive(); |
|
722 |
|
723 TUsbServiceState serviceState; |
|
724 User::LeaveIfError(iUsbViewer.Usb().GetServiceState(serviceState)); |
|
725 iUsbViewer.SetServiceState(serviceState); |
|
726 } |
|
727 |
|
728 void CServiceStateWatcher::DoCancel() |
|
729 { |
|
730 iUsbViewer.Usb().ServiceStateNotificationCancel(); |
|
731 } |
|
732 |
|
733 void CServiceStateWatcher::DoRunL(XUsbViewerEvent* aEvent) |
|
734 { |
|
735 iUsbViewer.SetServiceState(iServiceState); |
|
736 TPtrC res(NULL, 0); |
|
737 _LIT(KIdle, "Idle"); |
|
738 _LIT(KStarting, "Starting"); |
|
739 _LIT(KStarted, "Started"); |
|
740 _LIT(KStopping, "Stopping"); |
|
741 _LIT(KError, "Error"); |
|
742 switch(iServiceState) |
|
743 { |
|
744 case EUsbServiceIdle: |
|
745 res.Set(KIdle); |
|
746 break; |
|
747 case EUsbServiceStarting: |
|
748 res.Set(KStarting); |
|
749 break; |
|
750 case EUsbServiceStarted: |
|
751 res.Set(KStarted); |
|
752 break; |
|
753 case EUsbServiceStopping: |
|
754 res.Set(KStopping); |
|
755 break; |
|
756 case EUsbServiceFatalError: |
|
757 res.Set(KError); |
|
758 break; |
|
759 default: |
|
760 PANIC; |
|
761 break; |
|
762 } |
|
763 |
|
764 iUsbViewer.Usb().ServiceStateNotification(iServiceState, iStatus); |
|
765 SetActive(); |
|
766 // 16 8 1 -> 25 |
|
767 aEvent->iEvent.AppendFormat(_L("D:ServiceState [%S]"), &res); |
|
768 iUsbViewer.NotifyEvent(aEvent); |
|
769 |
|
770 // RunL call may have been delayed: ensure viewer has the very latest information |
|
771 TUsbServiceState serviceState; |
|
772 User::LeaveIfError(iUsbViewer.Usb().GetServiceState(serviceState)); |
|
773 |
|
774 iUsbViewer.SetServiceState(serviceState); |
|
775 } |
|
776 |
|
777 |
|
778 CDeviceStateWatcher* CDeviceStateWatcher::NewL(CUsbViewer& aUsbViewer) |
|
779 { |
|
780 CDeviceStateWatcher* self = new(ELeave) CDeviceStateWatcher(aUsbViewer); |
|
781 CleanupStack::PushL(self); |
|
782 self->ConstructL(); |
|
783 CleanupStack::Pop(self); |
|
784 return self; |
|
785 } |
|
786 |
|
787 CDeviceStateWatcher::~CDeviceStateWatcher() |
|
788 { |
|
789 Cancel(); |
|
790 } |
|
791 |
|
792 CDeviceStateWatcher::CDeviceStateWatcher(CUsbViewer& aUsbViewer) |
|
793 : CEventNotifier(EPriorityStandard) |
|
794 , iUsbViewer(aUsbViewer) |
|
795 { |
|
796 CActiveScheduler::Add(this); |
|
797 } |
|
798 |
|
799 void CDeviceStateWatcher::ConstructL() |
|
800 { |
|
801 iUsbViewer.Usb().DeviceStateNotification(0xffffffff, iDeviceState, iStatus); |
|
802 SetActive(); |
|
803 |
|
804 TUsbDeviceState deviceState; |
|
805 User::LeaveIfError(iUsbViewer.Usb().GetDeviceState(deviceState)); |
|
806 iUsbViewer.SetDeviceState(deviceState); |
|
807 } |
|
808 |
|
809 void CDeviceStateWatcher::DoCancel() |
|
810 { |
|
811 iUsbViewer.Usb().DeviceStateNotificationCancel(); |
|
812 } |
|
813 |
|
814 void CDeviceStateWatcher::DoRunL(XUsbViewerEvent* aEvent) |
|
815 { |
|
816 iUsbViewer.SetDeviceState(iDeviceState); |
|
817 TPtrC res(NULL, 0); |
|
818 _LIT(KUndefined, "Undefined"); |
|
819 _LIT(KDefault, "Default"); |
|
820 _LIT(KAttached, "Attached"); |
|
821 _LIT(KPowered, "Powered"); |
|
822 _LIT(KConfigured, "Configured"); |
|
823 _LIT(KAddress, "Address"); |
|
824 _LIT(KSuspended, "Suspended"); |
|
825 switch(iDeviceState) |
|
826 { |
|
827 case EUsbDeviceStateUndefined: |
|
828 res.Set(KUndefined); |
|
829 break; |
|
830 case EUsbDeviceStateDefault: |
|
831 res.Set(KDefault); |
|
832 break; |
|
833 case EUsbDeviceStateAttached: |
|
834 res.Set(KAttached); |
|
835 break; |
|
836 case EUsbDeviceStatePowered: |
|
837 res.Set(KPowered); |
|
838 break; |
|
839 case EUsbDeviceStateConfigured: |
|
840 res.Set(KConfigured); |
|
841 break; |
|
842 case EUsbDeviceStateAddress: |
|
843 res.Set(KAddress); |
|
844 break; |
|
845 case EUsbDeviceStateSuspended: |
|
846 res.Set(KSuspended); |
|
847 break; |
|
848 default: |
|
849 PANIC; |
|
850 break; |
|
851 } |
|
852 |
|
853 iUsbViewer.Usb().DeviceStateNotification(0xffffffff, iDeviceState, iStatus); |
|
854 SetActive(); |
|
855 // 15 10 1 -> 26 |
|
856 aEvent->iEvent.AppendFormat(_L("D:DeviceState [%S]"), &res); |
|
857 iUsbViewer.NotifyEvent(aEvent); |
|
858 |
|
859 // RunL call may have been delayed: ensure viewer has the very latest information |
|
860 TUsbDeviceState deviceState; |
|
861 User::LeaveIfError(iUsbViewer.Usb().GetDeviceState(deviceState)); |
|
862 |
|
863 iUsbViewer.SetDeviceState(deviceState); |
|
864 } |
|
865 |
|
866 |
|
867 CIdPinWatcher* CIdPinWatcher::NewL(CUsbViewer& aUsbViewer) |
|
868 { |
|
869 CIdPinWatcher* self = new(ELeave) CIdPinWatcher(aUsbViewer); |
|
870 CleanupStack::PushL(self); |
|
871 self->ConstructL(); |
|
872 CleanupStack::Pop(self); |
|
873 return self; |
|
874 } |
|
875 |
|
876 CIdPinWatcher::~CIdPinWatcher() |
|
877 { |
|
878 Cancel(); |
|
879 iIdPinProp.Close(); |
|
880 } |
|
881 |
|
882 CIdPinWatcher::CIdPinWatcher(CUsbViewer& aUsbViewer) |
|
883 : CEventNotifier(EPriorityStandard) |
|
884 , iUsbViewer(aUsbViewer) |
|
885 { |
|
886 CActiveScheduler::Add(this); |
|
887 } |
|
888 |
|
889 void CIdPinWatcher::ConstructL() |
|
890 { |
|
891 User::LeaveIfError(iIdPinProp.Attach(KUidUsbManCategory, KUsbOtgIdPinPresentProperty)); |
|
892 iIdPinProp.Subscribe(iStatus); |
|
893 SetActive(); |
|
894 |
|
895 TInt val; |
|
896 TInt err = iIdPinProp.Get(val); |
|
897 LOG("CIdPinWatcher::ConstructL iIdPinProp.Get(val) => %d",err); |
|
898 User::LeaveIfError(err); |
|
899 iUsbViewer.SetIdPin(val); |
|
900 } |
|
901 |
|
902 void CIdPinWatcher::DoCancel() |
|
903 { |
|
904 iIdPinProp.Cancel(); |
|
905 } |
|
906 |
|
907 void CIdPinWatcher::DoRunL(XUsbViewerEvent* aEvent) |
|
908 { |
|
909 CleanupStack::PushL(aEvent); |
|
910 |
|
911 iIdPinProp.Subscribe(iStatus); |
|
912 SetActive(); |
|
913 |
|
914 TInt val; |
|
915 User::LeaveIfError(iIdPinProp.Get(val)); |
|
916 |
|
917 TPtrC res(NULL, 0); |
|
918 _LIT(KIdPinInserted, "Inserted"); |
|
919 _LIT(KIdPinRemoved, "Removed"); |
|
920 switch(val) |
|
921 { |
|
922 case 0: |
|
923 res.Set(KIdPinRemoved); |
|
924 break; |
|
925 |
|
926 case 1: |
|
927 res.Set(KIdPinInserted); |
|
928 break; |
|
929 |
|
930 default: |
|
931 PANIC; |
|
932 break; |
|
933 } |
|
934 CleanupStack::Pop(); |
|
935 // 9 8 1 -> 18 |
|
936 aEvent->iEvent.AppendFormat(_L("O:IdPin [%S]"), &res); |
|
937 iUsbViewer.SetIdPin(val); |
|
938 iUsbViewer.NotifyEvent(aEvent); |
|
939 } |
|
940 |
|
941 |
|
942 CVBusWatcher* CVBusWatcher::NewL(CUsbViewer& aUsbViewer) |
|
943 { |
|
944 CVBusWatcher* self = new(ELeave) CVBusWatcher(aUsbViewer); |
|
945 CleanupStack::PushL(self); |
|
946 self->ConstructL(); |
|
947 CleanupStack::Pop(self); |
|
948 return self; |
|
949 } |
|
950 |
|
951 CVBusWatcher::~CVBusWatcher() |
|
952 { |
|
953 Cancel(); |
|
954 iVBusProp.Close(); |
|
955 } |
|
956 |
|
957 CVBusWatcher::CVBusWatcher(CUsbViewer& aUsbViewer) |
|
958 : CEventNotifier(EPriorityStandard) |
|
959 , iUsbViewer(aUsbViewer) |
|
960 { |
|
961 CActiveScheduler::Add(this); |
|
962 } |
|
963 |
|
964 void CVBusWatcher::ConstructL() |
|
965 { |
|
966 User::LeaveIfError(iVBusProp.Attach(KUidUsbManCategory, KUsbOtgVBusPoweredProperty)); |
|
967 iVBusProp.Subscribe(iStatus); |
|
968 SetActive(); |
|
969 |
|
970 TInt val; |
|
971 User::LeaveIfError(iVBusProp.Get(val)); |
|
972 iUsbViewer.SetVBus(val); |
|
973 } |
|
974 |
|
975 void CVBusWatcher::DoCancel() |
|
976 { |
|
977 iVBusProp.Cancel(); |
|
978 } |
|
979 |
|
980 void CVBusWatcher::DoRunL(XUsbViewerEvent* aEvent) |
|
981 { |
|
982 CleanupStack::PushL(aEvent); |
|
983 |
|
984 iVBusProp.Subscribe(iStatus); |
|
985 SetActive(); |
|
986 |
|
987 TInt val; |
|
988 User::LeaveIfError(iVBusProp.Get(val)); |
|
989 |
|
990 TPtrC res(NULL, 0); |
|
991 _LIT(KVBusRaised, "Raised"); |
|
992 _LIT(KVBusDropped, "Dropped"); |
|
993 switch(val) |
|
994 { |
|
995 case 0: |
|
996 res.Set(KVBusDropped); |
|
997 break; |
|
998 |
|
999 case 1: |
|
1000 res.Set(KVBusRaised); |
|
1001 break; |
|
1002 |
|
1003 default: |
|
1004 PANIC; |
|
1005 break; |
|
1006 } |
|
1007 CleanupStack::Pop(); |
|
1008 // 8 7 1 -> 16 |
|
1009 aEvent->iEvent.AppendFormat(_L("O:VBus [%S]"), &res); |
|
1010 iUsbViewer.SetVBus(val); |
|
1011 iUsbViewer.NotifyEvent(aEvent); |
|
1012 } |
|
1013 |
|
1014 |
|
1015 CConnectionIdleWatcher* CConnectionIdleWatcher::NewL(CUsbViewer& aUsbViewer) |
|
1016 { |
|
1017 CConnectionIdleWatcher* self = new(ELeave) CConnectionIdleWatcher(aUsbViewer); |
|
1018 CleanupStack::PushL(self); |
|
1019 self->ConstructL(); |
|
1020 CleanupStack::Pop(self); |
|
1021 return self; |
|
1022 } |
|
1023 |
|
1024 CConnectionIdleWatcher::~CConnectionIdleWatcher() |
|
1025 { |
|
1026 Cancel(); |
|
1027 iConnIdleProp.Close(); |
|
1028 } |
|
1029 |
|
1030 CConnectionIdleWatcher::CConnectionIdleWatcher(CUsbViewer& aUsbViewer) |
|
1031 : CEventNotifier(EPriorityStandard) |
|
1032 , iUsbViewer(aUsbViewer) |
|
1033 { |
|
1034 CActiveScheduler::Add(this); |
|
1035 } |
|
1036 |
|
1037 void CConnectionIdleWatcher::ConstructL() |
|
1038 { |
|
1039 User::LeaveIfError(iConnIdleProp.Attach(KUidUsbManCategory, KUsbOtgConnectionIdleProperty)); |
|
1040 iConnIdleProp.Subscribe(iStatus); |
|
1041 SetActive(); |
|
1042 |
|
1043 TInt val; |
|
1044 TInt err = iConnIdleProp.Get(val); |
|
1045 LOG("CConnectionIdleWatcher::ConstructL iConnIdleProp.Get(val) => %d",err); |
|
1046 User::LeaveIfError(err); |
|
1047 iUsbViewer.SetConnectionIdle(val); |
|
1048 } |
|
1049 |
|
1050 void CConnectionIdleWatcher::DoCancel() |
|
1051 { |
|
1052 iConnIdleProp.Cancel(); |
|
1053 } |
|
1054 |
|
1055 void CConnectionIdleWatcher::DoRunL(XUsbViewerEvent* aEvent) |
|
1056 { |
|
1057 CleanupStack::PushL(aEvent); |
|
1058 |
|
1059 iConnIdleProp.Subscribe(iStatus); |
|
1060 SetActive(); |
|
1061 |
|
1062 TInt val; |
|
1063 User::LeaveIfError(iConnIdleProp.Get(val)); |
|
1064 |
|
1065 TPtrC res(NULL, 0); |
|
1066 _LIT(KConnIdle, "Idle"); |
|
1067 _LIT(KConnActive, "Active"); |
|
1068 switch(val) |
|
1069 { |
|
1070 case 0: |
|
1071 res.Set(KConnActive); |
|
1072 break; |
|
1073 |
|
1074 case 1: |
|
1075 res.Set(KConnIdle); |
|
1076 break; |
|
1077 |
|
1078 default: |
|
1079 PANIC; |
|
1080 break; |
|
1081 } |
|
1082 CleanupStack::Pop(); |
|
1083 // 12 6 1 -> 19 |
|
1084 aEvent->iEvent.AppendFormat(_L("O:ConnIdle [%S]"), &res); |
|
1085 iUsbViewer.SetConnectionIdle(val); |
|
1086 iUsbViewer.NotifyEvent(aEvent); |
|
1087 } |
|
1088 |
|
1089 |
|
1090 COtgStateWatcher* COtgStateWatcher::NewL(CUsbViewer& aUsbViewer) |
|
1091 { |
|
1092 COtgStateWatcher* self = new(ELeave) COtgStateWatcher(aUsbViewer); |
|
1093 CleanupStack::PushL(self); |
|
1094 self->ConstructL(); |
|
1095 CleanupStack::Pop(self); |
|
1096 return self; |
|
1097 } |
|
1098 |
|
1099 COtgStateWatcher::~COtgStateWatcher() |
|
1100 { |
|
1101 Cancel(); |
|
1102 iOtgStateProp.Close(); |
|
1103 } |
|
1104 |
|
1105 COtgStateWatcher::COtgStateWatcher(CUsbViewer& aUsbViewer) |
|
1106 : CEventNotifier(EPriorityStandard) |
|
1107 , iUsbViewer(aUsbViewer) |
|
1108 { |
|
1109 CActiveScheduler::Add(this); |
|
1110 } |
|
1111 |
|
1112 void COtgStateWatcher::ConstructL() |
|
1113 { |
|
1114 User::LeaveIfError(iOtgStateProp.Attach(KUidUsbManCategory, KUsbOtgStateProperty)); |
|
1115 iOtgStateProp.Subscribe(iStatus); |
|
1116 SetActive(); |
|
1117 |
|
1118 TInt val; |
|
1119 User::LeaveIfError(iOtgStateProp.Get(val)); |
|
1120 iUsbViewer.SetOtgState(val); |
|
1121 } |
|
1122 |
|
1123 void COtgStateWatcher::DoCancel() |
|
1124 { |
|
1125 iOtgStateProp.Cancel(); |
|
1126 } |
|
1127 |
|
1128 void COtgStateWatcher::DoRunL(XUsbViewerEvent* aEvent) |
|
1129 { |
|
1130 CleanupStack::PushL(aEvent); |
|
1131 |
|
1132 iOtgStateProp.Subscribe(iStatus); |
|
1133 SetActive(); |
|
1134 |
|
1135 TInt val; |
|
1136 User::LeaveIfError(iOtgStateProp.Get(val)); |
|
1137 |
|
1138 TPtrC res(NULL, 0); |
|
1139 |
|
1140 _LIT(KReset, "Reset" ); |
|
1141 |
|
1142 _LIT(KAIdle, "A-Idle" ); |
|
1143 _LIT(KAHost, "A-Host" ); |
|
1144 _LIT(KAPeripheral, "A-Peripheral" ); |
|
1145 _LIT(KABusError, "A-Bus Error" ); |
|
1146 |
|
1147 _LIT(KBIdle, "B-Idle" ); |
|
1148 _LIT(KBPeripheral, "B-Peripheral" ); |
|
1149 _LIT(KBHost, "B-Host" ); |
|
1150 |
|
1151 _LIT(KUnknown, "Unknown" ); |
|
1152 |
|
1153 switch(val) |
|
1154 { |
|
1155 case EUsbOtgStateReset: |
|
1156 res.Set(KReset); |
|
1157 break; |
|
1158 |
|
1159 case EUsbOtgStateAIdle: |
|
1160 res.Set(KAIdle); |
|
1161 break; |
|
1162 |
|
1163 case EUsbOtgStateAHost: |
|
1164 res.Set(KAHost); |
|
1165 break; |
|
1166 |
|
1167 case EUsbOtgStateAPeripheral: |
|
1168 res.Set(KAPeripheral); |
|
1169 break; |
|
1170 |
|
1171 case EUsbOtgStateAVbusError: |
|
1172 res.Set(KABusError); |
|
1173 break; |
|
1174 |
|
1175 case EUsbOtgStateBIdle: |
|
1176 res.Set(KBIdle); |
|
1177 break; |
|
1178 |
|
1179 case EUsbOtgStateBPeripheral: |
|
1180 res.Set(KBPeripheral); |
|
1181 break; |
|
1182 |
|
1183 case EUsbOtgStateBHost: |
|
1184 res.Set(KBHost); |
|
1185 break; |
|
1186 |
|
1187 default: |
|
1188 res.Set(KUnknown); |
|
1189 break; |
|
1190 } |
|
1191 CleanupStack::Pop(); |
|
1192 |
|
1193 // 12 12 1 -> 25 |
|
1194 aEvent->iEvent.AppendFormat(_L("O:OtgState [%S]"), &res); |
|
1195 iUsbViewer.SetOtgState(val); |
|
1196 iUsbViewer.NotifyEvent(aEvent); |
|
1197 } |
|
1198 |
|
1199 CHostEventWatcher* CHostEventWatcher::NewL(CUsbViewer& aUsbViewer) |
|
1200 { |
|
1201 CHostEventWatcher* self = new(ELeave) CHostEventWatcher(aUsbViewer); |
|
1202 CleanupStack::PushL(self); |
|
1203 self->ConstructL(); |
|
1204 CleanupStack::Pop(self); |
|
1205 return self; |
|
1206 } |
|
1207 |
|
1208 CHostEventWatcher::~CHostEventWatcher() |
|
1209 { |
|
1210 Cancel(); |
|
1211 } |
|
1212 |
|
1213 CHostEventWatcher::CHostEventWatcher(CUsbViewer& aUsbViewer) |
|
1214 : CEventNotifier(EPriorityStandard) |
|
1215 , iUsbViewer(aUsbViewer) |
|
1216 { |
|
1217 CActiveScheduler::Add(this); |
|
1218 } |
|
1219 |
|
1220 void CHostEventWatcher::ConstructL() |
|
1221 { |
|
1222 iUsbViewer.Usb().HostEventNotification(iStatus, iDeviceInfo); |
|
1223 SetActive(); |
|
1224 iUsbViewer.SetAttachedDevices(0); |
|
1225 } |
|
1226 |
|
1227 void CHostEventWatcher::DoCancel() |
|
1228 { |
|
1229 iUsbViewer.Usb().HostEventNotificationCancel(); |
|
1230 } |
|
1231 |
|
1232 void CHostEventWatcher::DoRunL(XUsbViewerEvent* aEvent) |
|
1233 { |
|
1234 CleanupStack::PushL(aEvent); |
|
1235 |
|
1236 switch(iDeviceInfo.iEventType) |
|
1237 { |
|
1238 case EDeviceAttachment: |
|
1239 { |
|
1240 if(iDeviceInfo.iError == KErrNone) |
|
1241 { |
|
1242 User::LeaveIfError(iAttachedDevices.Append(iDeviceInfo.iDeviceId)); |
|
1243 } |
|
1244 // 5 8 6 4 1 4 1 -> 29 |
|
1245 aEvent->iEvent.AppendFormat(_L("H:At[%.08x] V,P[%.04x,%.04x]"), iDeviceInfo.iDeviceId, iDeviceInfo.iVid, iDeviceInfo.iPid); |
|
1246 |
|
1247 if ( (iDeviceInfo.iVid == 0x046D) |
|
1248 &&(iDeviceInfo.iPid == 0x0A02) |
|
1249 ) |
|
1250 { |
|
1251 iUsbViewer.SetDeviceType(CUsbViewer::ELogitechHeadset); |
|
1252 } |
|
1253 else |
|
1254 { |
|
1255 iUsbViewer.SetDeviceType(CUsbViewer::EGenericDevice); |
|
1256 } |
|
1257 } |
|
1258 break; |
|
1259 |
|
1260 case EDriverLoad: |
|
1261 { |
|
1262 TPtrC res(NULL, 0); |
|
1263 _LIT(KDriverLoadSuccess, "Success"); |
|
1264 _LIT(KDriverLoadPartialSuccess, "Warning"); |
|
1265 _LIT(KDriverLoadFailure, "Failure"); |
|
1266 switch(iDeviceInfo.iDriverLoadStatus) |
|
1267 { |
|
1268 case EDriverLoadSuccess: |
|
1269 res.Set(KDriverLoadSuccess); |
|
1270 break; |
|
1271 case EDriverLoadPartialSuccess: |
|
1272 res.Set(KDriverLoadPartialSuccess); |
|
1273 break; |
|
1274 case EDriverLoadFailure: |
|
1275 res.Set(KDriverLoadFailure); |
|
1276 break; |
|
1277 default: |
|
1278 PANIC; |
|
1279 break; |
|
1280 } |
|
1281 // 7 8 6 3 5 1 1 -> 31 |
|
1282 aEvent->iEvent.AppendFormat(_L("H:Load[%.08x] Err[%.3d] St[%1S]"), iDeviceInfo.iDeviceId, iDeviceInfo.iError, &res); |
|
1283 } |
|
1284 break; |
|
1285 |
|
1286 case EDeviceDetachment: |
|
1287 { |
|
1288 // 10 8 1 -> 19 |
|
1289 aEvent->iEvent.AppendFormat(_L("H:Detach [%.08x]"), iDeviceInfo.iDeviceId); |
|
1290 TInt ix = iAttachedDevices.Find(iDeviceInfo.iDeviceId); |
|
1291 if(ix == KErrNotFound) |
|
1292 { |
|
1293 // This is probably caused by starting a new instance of the test console. |
|
1294 break; |
|
1295 } |
|
1296 iAttachedDevices.Remove(ix); |
|
1297 iUsbViewer.SetDeviceType(CUsbViewer::ENoDevice); |
|
1298 } |
|
1299 break; |
|
1300 default: |
|
1301 PANIC; |
|
1302 break; |
|
1303 } |
|
1304 CleanupStack::Pop(); |
|
1305 iUsbViewer.SetAttachedDevices(iAttachedDevices.Count()); |
|
1306 iUsbViewer.NotifyEvent(aEvent); |
|
1307 iUsbViewer.Usb().HostEventNotification(iStatus, iDeviceInfo); |
|
1308 SetActive(); |
|
1309 } |
|
1310 |
|
1311 |
|
1312 CMessageWatcher* CMessageWatcher::NewL(CUsbViewer& aUsbViewer) |
|
1313 { |
|
1314 CMessageWatcher* self = new(ELeave) CMessageWatcher(aUsbViewer); |
|
1315 CleanupStack::PushL(self); |
|
1316 self->ConstructL(); |
|
1317 CleanupStack::Pop(self); |
|
1318 return self; |
|
1319 } |
|
1320 |
|
1321 CMessageWatcher::~CMessageWatcher() |
|
1322 { |
|
1323 Cancel(); |
|
1324 } |
|
1325 |
|
1326 CMessageWatcher::CMessageWatcher(CUsbViewer& aUsbViewer) |
|
1327 : CEventNotifier(EPriorityStandard) |
|
1328 , iUsbViewer(aUsbViewer) |
|
1329 { |
|
1330 CActiveScheduler::Add(this); |
|
1331 } |
|
1332 |
|
1333 void CMessageWatcher::ConstructL() |
|
1334 { |
|
1335 iUsbViewer.Usb().MessageNotification(iStatus, iMessage); |
|
1336 SetActive(); |
|
1337 } |
|
1338 |
|
1339 void CMessageWatcher::DoCancel() |
|
1340 { |
|
1341 iUsbViewer.Usb().MessageNotificationCancel(); |
|
1342 } |
|
1343 |
|
1344 void CMessageWatcher::DoRunL(XUsbViewerEvent* aEvent) |
|
1345 { |
|
1346 TInt err = iStatus.Int(); |
|
1347 |
|
1348 if (err) |
|
1349 { |
|
1350 aEvent->iEvent.AppendFormat(_L("O:Err! [%d] [%d]"), iMessage, err); // 32 chars max |
|
1351 } |
|
1352 else |
|
1353 { |
|
1354 TPtrC text(NULL, 0); |
|
1355 |
|
1356 // OTGDI |
|
1357 _LIT(KMessOtgdiEventQueueOverflow, "O:Event Queue Overflow" ); |
|
1358 _LIT(KMessOtgdiStateQueueOverflow, "O:State Queue Overflow" ); |
|
1359 _LIT(KMessOtgdiMessageQueueOverflow, "O:Message Queue Overflow" ); |
|
1360 _LIT(KMessOtgdiBadState, "O:Bad State" ); |
|
1361 _LIT(KMessOtgdiStackNotStarted, "O:Stack Not Started" ); |
|
1362 _LIT(KMessOtgdiVbusAlreadyRaised, "O:VBUS Already Raised" ); |
|
1363 _LIT(KMessOtgdiSrpForbidden, "O:SRP Forbidden" ); |
|
1364 _LIT(KMessOtgdiBusControlProblem, "O:Bus Control Problem" ); |
|
1365 _LIT(KMessOtgdiVbusError, "O:VBUS Error" ); |
|
1366 _LIT(KMessOtgdiSrpTimeout, "O:SRP Timeout" ); |
|
1367 _LIT(KMessOtgdiSrpActive, "O:SRP Already Active" ); |
|
1368 _LIT(KMessOtgdiSrpNotPermitted, "O:SRP Not Permitted" ); |
|
1369 _LIT(KMessOtgdiHnpNotPermitted, "O:HNP Not Permitted" ); |
|
1370 _LIT(KMessOtgdiHnpNotEnabled, "O:HNP Not Enabled" ); |
|
1371 _LIT(KMessOtgdiHnpNotSuspended, "O:HNP Not Suspended" ); |
|
1372 _LIT(KMessOtgdiVbusPowerUpNotPermitted, "O:VBUS Power Up Not Permitted" ); |
|
1373 _LIT(KMessOtgdiVbusPowerDownNotPermitted, "O:VBUS Power Down Not Permitted" ); |
|
1374 _LIT(KMessOtgdiVbusClearErrorNotPermitted, "O:VBUS Clear Error Not Permitted" ); |
|
1375 |
|
1376 // USBDI - Main |
|
1377 |
|
1378 _LIT(KMessUsbdiRequestsPending, "U:Requests Pending" ); |
|
1379 _LIT(KMessUsbdiBadAddress, "U:Bad Address" ); |
|
1380 _LIT(KMessUsbdiNoAddress, "U:No Address" ); |
|
1381 _LIT(KMessUsbdiSetAddrFailed, "U:Set Address Failed" ); |
|
1382 _LIT(KMessUsbdiNoPower, "U:No Power" ); |
|
1383 _LIT(KMessUsbdiTooDeep, "U:Too Deep" ); |
|
1384 _LIT(KMessUsbdiIOError, "U:IO Error" ); |
|
1385 _LIT(KMessUsbdiNotConfigured, "U:Not Configured" ); |
|
1386 _LIT(KMessUsbdiTimeout, "U:Timeout" ); |
|
1387 _LIT(KMessUsbdiStalled, "U:Stalled" ); |
|
1388 _LIT(KMessUsbdiTestFailure, "U:Test Failure" ); |
|
1389 _LIT(KMessUsbdiBadState, "U:Bad State" ); |
|
1390 _LIT(KMessUsbdiDeviceSuspended, "U:Device Suspended" ); |
|
1391 |
|
1392 // USBDI - Descriptors |
|
1393 |
|
1394 _LIT(KMessUsbdiBadDescriptorTopology, "U:Bad Descriptor Topology" ); |
|
1395 |
|
1396 // USBDI - DevMon |
|
1397 |
|
1398 _LIT(KMessUsbdiDeviceRejected, "U:Device Rejected" ); |
|
1399 _LIT(KMessUsbdiDeviceFailed, "U:Device failed" ); |
|
1400 _LIT(KMessUsbdiBadDevice, "U:Bad Device" ); |
|
1401 _LIT(KMessUsbdiBadHubPosition, "U:Bad Hub Position" ); |
|
1402 _LIT(KMessUsbdiBadHub, "U:Bad Hub" ); |
|
1403 _LIT(KMessUsbdiEventOverflow, "U:Event Overflow" ); |
|
1404 |
|
1405 // USBMAN |
|
1406 |
|
1407 _LIT(KMessUsbmanSrpInitiated, "M:SRP Initiated" ); |
|
1408 _LIT(KMessUsbmanSrpReceived, "M:SRP Received" ); |
|
1409 _LIT(KMessUsbmanHnpDisabled, "M:HNP Disabled" ); |
|
1410 _LIT(KMessUsbmanHnpEnabled, "M:HNP Enabled" ); |
|
1411 _LIT(KMessUsbmanVbusRaised, "M:VBUS Raised" ); |
|
1412 _LIT(KMessUsbmanVbusDropped, "M:VBUS Dropped" ); |
|
1413 _LIT(KMessUsbmanRequestSession, "M:Request Session" ); |
|
1414 |
|
1415 _LIT(KMessUnknown, "*:Unknown" ); |
|
1416 |
|
1417 switch(iMessage) |
|
1418 { |
|
1419 // OTGDI |
|
1420 |
|
1421 case KErrUsbOtgEventQueueOverflow: text.Set(KMessOtgdiEventQueueOverflow); break; |
|
1422 case KErrUsbOtgStateQueueOverflow: text.Set(KMessOtgdiStateQueueOverflow); break; |
|
1423 case KErrUsbOtgMessageQueueOverflow: text.Set(KMessOtgdiMessageQueueOverflow) ; break; |
|
1424 case KErrUsbOtgBadState: text.Set(KMessOtgdiBadState); break; |
|
1425 case KErrUsbOtgStackNotStarted: text.Set(KMessOtgdiStackNotStarted); break; |
|
1426 case KErrUsbOtgVbusAlreadyRaised: text.Set(KMessOtgdiVbusAlreadyRaised); break; |
|
1427 case KErrUsbOtgSrpForbidden: text.Set(KMessOtgdiSrpForbidden); break; |
|
1428 case KErrUsbOtgBusControlProblem: text.Set(KMessOtgdiBusControlProblem); break; |
|
1429 case KErrUsbOtgVbusError: text.Set(KMessOtgdiVbusError); break; |
|
1430 case KErrUsbOtgSrpTimeout: text.Set(KMessOtgdiSrpTimeout); break; |
|
1431 case KErrUsbOtgSrpActive: text.Set(KMessOtgdiSrpActive); break; |
|
1432 case KErrUsbOtgSrpNotPermitted: text.Set(KMessOtgdiSrpNotPermitted); break; |
|
1433 case KErrUsbOtgHnpNotPermitted: text.Set(KMessOtgdiHnpNotPermitted); break; |
|
1434 case KErrUsbOtgHnpNotEnabled: text.Set(KMessOtgdiHnpNotEnabled); break; |
|
1435 case KErrUsbOtgHnpNotSuspended: text.Set(KMessOtgdiHnpNotSuspended); break; |
|
1436 case KErrUsbOtgVbusPowerUpNotPermitted: text.Set(KMessOtgdiVbusPowerUpNotPermitted); break; |
|
1437 case KErrUsbOtgVbusPowerDownNotPermitted: text.Set(KMessOtgdiVbusPowerDownNotPermitted); break; |
|
1438 case KErrUsbOtgVbusClearErrorNotPermitted: text.Set(KMessOtgdiVbusClearErrorNotPermitted); break; |
|
1439 |
|
1440 // USBDI - Main |
|
1441 |
|
1442 case KErrUsbRequestsPending: text.Set(KMessUsbdiRequestsPending); break; |
|
1443 case KErrUsbBadAddress: text.Set(KMessUsbdiBadAddress); break; |
|
1444 case KErrUsbNoAddress: text.Set(KMessUsbdiNoAddress); break; |
|
1445 case KErrUsbSetAddrFailed: text.Set(KMessUsbdiSetAddrFailed); break; |
|
1446 case KErrUsbNoPower: text.Set(KMessUsbdiNoPower); break; |
|
1447 case KErrUsbTooDeep: text.Set(KMessUsbdiTooDeep); break; |
|
1448 case KErrUsbIOError: text.Set(KMessUsbdiIOError); break; |
|
1449 case KErrUsbNotConfigured: text.Set(KMessUsbdiNotConfigured); break; |
|
1450 case KErrUsbTimeout: text.Set(KMessUsbdiTimeout); break; |
|
1451 case KErrUsbStalled: text.Set(KMessUsbdiStalled); break; |
|
1452 case KErrUsbTestFailure: text.Set(KMessUsbdiTestFailure); break; |
|
1453 case KErrUsbBadState: text.Set(KMessUsbdiBadState); break; |
|
1454 case KErrUsbDeviceSuspended: text.Set(KMessUsbdiDeviceSuspended); break; |
|
1455 |
|
1456 // USBDI - Descriptors |
|
1457 |
|
1458 case KErrUsbBadDescriptorTopology: text.Set(KMessUsbdiBadDescriptorTopology); break; |
|
1459 |
|
1460 // USBDI - DevMon |
|
1461 |
|
1462 case KErrUsbDeviceRejected: text.Set(KMessUsbdiDeviceRejected); break; |
|
1463 case KErrUsbDeviceFailed: text.Set(KMessUsbdiDeviceFailed); break; |
|
1464 case KErrUsbBadDevice: text.Set(KMessUsbdiBadDevice); break; |
|
1465 case KErrUsbBadHubPosition: text.Set(KMessUsbdiBadHubPosition); break; |
|
1466 case KErrUsbBadHub: text.Set(KMessUsbdiBadHub); break; |
|
1467 case KErrUsbEventOverflow: text.Set(KMessUsbdiEventOverflow); break; |
|
1468 |
|
1469 // USBMAN |
|
1470 |
|
1471 case KUsbMessageSrpInitiated: text.Set(KMessUsbmanSrpInitiated); break; |
|
1472 case KUsbMessageSrpReceived: text.Set(KMessUsbmanSrpReceived); break; |
|
1473 case KUsbMessageHnpDisabled: text.Set(KMessUsbmanHnpDisabled); break; |
|
1474 case KUsbMessageHnpEnabled: text.Set(KMessUsbmanHnpEnabled); break; |
|
1475 case KUsbMessageVbusRaised: text.Set(KMessUsbmanVbusRaised); break; |
|
1476 case KUsbMessageVbusDropped: text.Set(KMessUsbmanVbusDropped); break; |
|
1477 case KUsbMessageRequestSession: text.Set(KMessUsbmanRequestSession); break; |
|
1478 |
|
1479 default: text.Set(KMessUnknown); break; |
|
1480 } // switch(iMessage) |
|
1481 |
|
1482 // The message number can be positive (USBMAN) or negative (OTGDI/USBDI) |
|
1483 |
|
1484 LOG("CMessageWatcher::DoRunL iMessage = [%d]",iMessage); |
|
1485 LOG("CMessageWatcher::DoRunL text = [%S]",&text); |
|
1486 |
|
1487 if ( iMessage > 0 ) |
|
1488 { |
|
1489 // 4 1 4 3 19 1 -> 32 |
|
1490 aEvent->iEvent.AppendFormat(_L("Msg[+%4.4d] [%.19S]"), iMessage, &text); // 32 chars max |
|
1491 } |
|
1492 else |
|
1493 { |
|
1494 // 4 1 4 3 19 1 -> 32 |
|
1495 aEvent->iEvent.AppendFormat(_L("Msg[-%4.4d] [%.19S]"), -iMessage, &text); // 32 chars max |
|
1496 } |
|
1497 } // else |
|
1498 |
|
1499 iUsbViewer.Usb().MessageNotification(iStatus, iMessage); |
|
1500 SetActive(); |
|
1501 iUsbViewer.NotifyEvent(aEvent); |
|
1502 } |
|
1503 |
|
1504 |
|
1505 |
|
1506 |
|
1507 CUserMsgQWatcher* CUserMsgQWatcher::NewL(CUsbViewer& aUsbViewer) |
|
1508 { |
|
1509 CUserMsgQWatcher* self = new(ELeave) CUserMsgQWatcher(aUsbViewer); |
|
1510 CleanupStack::PushL(self); |
|
1511 self->ConstructL(); |
|
1512 CleanupStack::Pop(self); |
|
1513 return self; |
|
1514 } |
|
1515 |
|
1516 CUserMsgQWatcher::~CUserMsgQWatcher() |
|
1517 { |
|
1518 Cancel(); |
|
1519 } |
|
1520 |
|
1521 CUserMsgQWatcher::CUserMsgQWatcher(CUsbViewer& aUsbViewer) |
|
1522 : CEventNotifier(EPriorityStandard) |
|
1523 , iUsbViewer(aUsbViewer) |
|
1524 { |
|
1525 CActiveScheduler::Add(this); |
|
1526 } |
|
1527 |
|
1528 void CUserMsgQWatcher::ConstructL() |
|
1529 { |
|
1530 iUsbViewer.UserMsgQ().NotifyDataAvailable(iStatus); |
|
1531 SetActive(); |
|
1532 } |
|
1533 |
|
1534 void CUserMsgQWatcher::DoCancel() |
|
1535 { |
|
1536 iUsbViewer.UserMsgQ().CancelDataAvailable(); |
|
1537 } |
|
1538 |
|
1539 void CUserMsgQWatcher::DoRunL(XUsbViewerEvent* aEvent) |
|
1540 { |
|
1541 CleanupStack::PushL(aEvent); |
|
1542 |
|
1543 User::LeaveIfError(iUsbViewer.UserMsgQ().Receive(iUserMsgLine)); |
|
1544 LOG("CUserMsgQWatcher::DoRunL iUsbViewer.UserMsgQ().Receive => %S", &iUserMsgLine); |
|
1545 CleanupStack::Pop(); |
|
1546 |
|
1547 aEvent->iEvent.AppendFormat(_L("%S"), &iUserMsgLine); |
|
1548 iUsbViewer.NotifyEvent(aEvent); |
|
1549 |
|
1550 iUsbViewer.UserMsgQ().NotifyDataAvailable(iStatus); // Re-subscribe |
|
1551 SetActive(); |
|
1552 } |
|
1553 |