|
1 /* |
|
2 ============================================================================ |
|
3 Name : VRUSBStateHanlder.cpp |
|
4 Author : Junhua Xu |
|
5 Version : 1.0 |
|
6 Copyright : Your copyright notice |
|
7 Description : CVRUSBStateHanlder implementation |
|
8 ============================================================================ |
|
9 */ |
|
10 |
|
11 #include <e32cmn.h> |
|
12 #include <usbpersonalityids.h> |
|
13 #include <e32property.h> |
|
14 #include <UsbWatcherInternalPSKeys.h> |
|
15 #include <usbpersonalityids.h> |
|
16 |
|
17 #include <aknwaitdialog.h> |
|
18 #include <EIKENV.H> |
|
19 |
|
20 #include "VRUSBStateHanlder.h" |
|
21 #include "CVRRecView.h" |
|
22 |
|
23 CVRUSBStateHanlder::CVRUSBStateHanlder(MVRUSBStateObserver* aObserver) : |
|
24 CActive(EPriorityStandard), // Standard priority |
|
25 iObserver(aObserver) |
|
26 { |
|
27 } |
|
28 |
|
29 EXPORT_C CVRUSBStateHanlder* CVRUSBStateHanlder::NewL( |
|
30 MVRUSBStateObserver* aObserver) |
|
31 { |
|
32 CVRUSBStateHanlder* self = new (ELeave) CVRUSBStateHanlder(aObserver); |
|
33 CleanupStack::PushL(self); |
|
34 self->ConstructL(); |
|
35 CleanupStack::Pop(); // self; |
|
36 return self; |
|
37 } |
|
38 |
|
39 void CVRUSBStateHanlder::ConstructL() |
|
40 { |
|
41 #ifdef DUMMY_USB_TESTING |
|
42 User::LeaveIfError(iTimer.CreateLocal()); // Initialize timer |
|
43 #else |
|
44 iProperty.Attach(KPSUidUsbWatcher, KUsbWatcherSelectedPersonality); |
|
45 #endif |
|
46 CActiveScheduler::Add(this); // Add to scheduler |
|
47 StartL(); |
|
48 } |
|
49 |
|
50 CVRUSBStateHanlder::~CVRUSBStateHanlder() |
|
51 { |
|
52 Cancel(); // Cancel any request, if outstanding |
|
53 #ifdef DUMMY_USB_TESTING |
|
54 iTimer.Close(); |
|
55 #else |
|
56 iProperty.Close(); |
|
57 #endif |
|
58 } |
|
59 |
|
60 void CVRUSBStateHanlder::DoCancel() |
|
61 { |
|
62 #ifdef DUMMY_USB_TESTING |
|
63 iTimer.Cancel(); |
|
64 #else |
|
65 iProperty.Cancel(); |
|
66 #endif |
|
67 |
|
68 } |
|
69 |
|
70 void CVRUSBStateHanlder::StartL() |
|
71 { |
|
72 Cancel(); // Cancel any request, just to be sure |
|
73 #ifdef DUMMY_USB_TESTING |
|
74 iTimer.After(iStatus, 10000000); // Set for later |
|
75 SetActive(); // Tell scheduler a request is active |
|
76 #else |
|
77 SetActive(); |
|
78 iProperty.Subscribe(iStatus); |
|
79 #endif |
|
80 } |
|
81 |
|
82 void CVRUSBStateHanlder::RunL() |
|
83 { |
|
84 #ifdef DUMMY_USB_TESTING |
|
85 CDummyUSBState::HandleUSBEventL(); |
|
86 #endif |
|
87 if (IsUsbActive()) |
|
88 { |
|
89 iObserver->HandleUsbPlugInL(); |
|
90 } |
|
91 else |
|
92 { |
|
93 iObserver->HandleUsbPlugOutL(); |
|
94 } |
|
95 #ifdef DUMMY_USB_TESTING |
|
96 // iStatus = KRequestPending; |
|
97 SetActive(); // Tell scheduler a request is active |
|
98 iTimer.After(iStatus, 10000000); // Set for later |
|
99 #else |
|
100 StartL(); |
|
101 #endif |
|
102 } |
|
103 |
|
104 TInt CVRUSBStateHanlder::RunError(TInt aError) |
|
105 { |
|
106 return aError; |
|
107 } |
|
108 |
|
109 EXPORT_C TBool CVRUSBStateHanlder::IsUsbActive() |
|
110 { |
|
111 #ifdef DUMMY_USB_TESTING |
|
112 //dummy |
|
113 return CDummyUSBState::IsUSBActive(); |
|
114 #else |
|
115 |
|
116 TInt usbState; |
|
117 TInt err = RProperty::Get(KPSUidUsbWatcher, |
|
118 KUsbWatcherSelectedPersonality, usbState); |
|
119 |
|
120 if (KErrNone == err && KUsbPersonalityIdMS == usbState) |
|
121 { |
|
122 return true; |
|
123 } |
|
124 else |
|
125 { |
|
126 return false; |
|
127 } |
|
128 #endif |
|
129 } |
|
130 |