|
1 /* |
|
2 * Copyright (c) 2008 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: Implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <usbman.h> |
|
19 |
|
20 #include "cusbhosteventnotificationobserver.h" |
|
21 |
|
22 #include "definitions.h" |
|
23 #include "debug.h" |
|
24 #include "panic.h" |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 CUsbHostEventNotificationObserver::CUsbHostEventNotificationObserver( |
|
31 RUsb* aUsb) : |
|
32 CActive(EPriorityStandard), iUsb(aUsb) |
|
33 { |
|
34 CActiveScheduler::Add(this); |
|
35 } |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 void CUsbHostEventNotificationObserver::ConstructL() |
|
42 { |
|
43 LOG_FUNC |
|
44 |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 CUsbHostEventNotificationObserver* CUsbHostEventNotificationObserver::NewL( |
|
52 RUsb* aUsb) |
|
53 { |
|
54 LOG_FUNC |
|
55 |
|
56 CUsbHostEventNotificationObserver* self = |
|
57 new (ELeave) CUsbHostEventNotificationObserver(aUsb); |
|
58 CleanupStack::PushL(self); |
|
59 self->ConstructL(); |
|
60 CleanupStack::Pop(self); |
|
61 return self; |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 CUsbHostEventNotificationObserver::~CUsbHostEventNotificationObserver() |
|
69 { |
|
70 LOG_FUNC |
|
71 |
|
72 Cancel(); |
|
73 |
|
74 iObservers.Close(); |
|
75 |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 void CUsbHostEventNotificationObserver::SubscribeL( |
|
83 MUsbHostEventNotificationObserver& aObserver) |
|
84 { |
|
85 LOG_FUNC |
|
86 |
|
87 // check if the same observer already exist in a list |
|
88 if (KErrNotFound != iObservers.Find(&aObserver)) |
|
89 { |
|
90 LOG("Observer already exists" ); |
|
91 PANIC( EObserverAlreadyExists); |
|
92 return; |
|
93 } |
|
94 |
|
95 iObservers.AppendL(&aObserver); |
|
96 |
|
97 if (KFirst == iObservers.Count()) // first item |
|
98 { |
|
99 iUsb->HostEventNotification(iStatus, iEventInfo); |
|
100 SetActive(); |
|
101 |
|
102 } |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 void CUsbHostEventNotificationObserver::UnsubscribeL( |
|
110 MUsbHostEventNotificationObserver& aObserver) |
|
111 { |
|
112 LOG_FUNC |
|
113 |
|
114 TInt i(iObservers.Find(&aObserver)); |
|
115 if (KErrNotFound == i) |
|
116 { |
|
117 LOG("Observer not found"); |
|
118 PANIC( ECanNotFindHostEventNotificationObserver); |
|
119 return; |
|
120 } |
|
121 |
|
122 iObservers.Remove(i); |
|
123 |
|
124 if (0 == iObservers.Count()) // no observers anymore |
|
125 { |
|
126 // cancel pending request |
|
127 Cancel(); |
|
128 } |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 void CUsbHostEventNotificationObserver::RunL() |
|
136 { |
|
137 LOG_FUNC |
|
138 |
|
139 LOG1( "iStatus = %d", iStatus.Int()); |
|
140 |
|
141 // if error occured, tell to Observers |
|
142 if (KErrNone != iStatus.Int()) |
|
143 { |
|
144 for (TInt i(0); i < iObservers.Count(); ++i) |
|
145 { |
|
146 iObservers[i]->HostEventNotificationErrorL(iStatus.Int()); |
|
147 } |
|
148 return; |
|
149 } |
|
150 |
|
151 TDeviceEventInformation dei(iEventInfo); |
|
152 |
|
153 // re-issue request first |
|
154 iUsb->HostEventNotification(iStatus, iEventInfo); |
|
155 SetActive(); |
|
156 |
|
157 // Log the event |
|
158 LOG1( "iEventInfo.iDeviceId = %d" , dei.iDeviceId); |
|
159 LOG1( "iEventInfo.iEventType = %d" , dei.iEventType); |
|
160 LOG1( "iEventInfo.iError = %d" , dei.iError); |
|
161 LOG1( "iEventInfo.iDriverLoadStatus = %d" , dei.iDriverLoadStatus); |
|
162 LOG1( "iEventInfo.iVid = %d" , dei.iVid); |
|
163 LOG1( "iEventInfo.iPid = %d" , dei.iPid); |
|
164 |
|
165 // then process property change |
|
166 switch (dei.iEventType) |
|
167 { |
|
168 case EDeviceAttachment: |
|
169 { |
|
170 LOG("DeviceAttachment" ); |
|
171 |
|
172 for (TInt i(0); i < iObservers.Count(); ++i) |
|
173 { |
|
174 iObservers[i]->DeviceAttachedL(dei); |
|
175 } |
|
176 break; |
|
177 } |
|
178 |
|
179 case EDeviceDetachment: |
|
180 { |
|
181 LOG( "DeviceDetachment" ); |
|
182 |
|
183 for (TInt i(0); i < iObservers.Count(); ++i) |
|
184 { |
|
185 iObservers[i]->DeviceDetachedL(dei); |
|
186 } |
|
187 break; |
|
188 } |
|
189 |
|
190 case EDriverLoad: |
|
191 { |
|
192 switch (dei.iDriverLoadStatus) |
|
193 { |
|
194 case EDriverLoadSuccess: |
|
195 { |
|
196 LOG( "DriverLoadSuccess" ); |
|
197 |
|
198 for (TInt i(0); i < iObservers.Count(); ++i) |
|
199 { |
|
200 iObservers[i]->DriverLoadSuccessL(dei); |
|
201 } |
|
202 |
|
203 break; |
|
204 } |
|
205 case EDriverLoadPartialSuccess: |
|
206 { |
|
207 LOG( "DriverLoadPartialSuccess" ); |
|
208 |
|
209 for (TInt i(0); i < iObservers.Count(); ++i) |
|
210 { |
|
211 iObservers[i]->DriverLoadPartialSuccessL(dei); |
|
212 } |
|
213 |
|
214 break; |
|
215 } |
|
216 case EDriverLoadFailure: |
|
217 { |
|
218 LOG( "DriverLoadFailure"); |
|
219 |
|
220 for (TInt i(0); i < iObservers.Count(); ++i) |
|
221 { |
|
222 iObservers[i]->DriverLoadFailureL(dei); |
|
223 } |
|
224 break; |
|
225 } |
|
226 default: |
|
227 { |
|
228 LOG("WrongDriverLoadStatus" ); |
|
229 PANIC( EWrongDriverLoadStatus); |
|
230 } |
|
231 } |
|
232 break; |
|
233 |
|
234 } |
|
235 default: |
|
236 { |
|
237 LOG( "WrongHostEventNotification" ); |
|
238 PANIC( EWrongHostEventNotification); |
|
239 } |
|
240 } |
|
241 } |
|
242 |
|
243 // --------------------------------------------------------------------------- |
|
244 // |
|
245 // --------------------------------------------------------------------------- |
|
246 // |
|
247 void CUsbHostEventNotificationObserver::DoCancel() |
|
248 { |
|
249 iUsb->HostEventNotificationCancel(); |
|
250 } |
|
251 |
|
252 // --------------------------------------------------------------------------- |
|
253 // |
|
254 // --------------------------------------------------------------------------- |
|
255 // |
|
256 TInt CUsbHostEventNotificationObserver::RunError(TInt aError) |
|
257 { |
|
258 LOG_FUNC |
|
259 |
|
260 LOG1( "aError = %d" , aError); |
|
261 |
|
262 // try to recover and continue |
|
263 return KErrNone; |
|
264 |
|
265 } |
|
266 |