1 /* |
1 /* |
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
8 * |
8 * |
9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: Implementation |
14 * Description: Implementation |
15 * |
15 * |
16 */ |
16 */ |
17 |
|
18 |
17 |
19 #include <usbman.h> |
18 #include <usbman.h> |
20 |
19 |
21 #include "cusbhosteventnotificationobserver.h" |
20 #include "cusbhosteventnotificationobserver.h" |
22 |
21 |
39 // |
38 // |
40 // --------------------------------------------------------------------------- |
39 // --------------------------------------------------------------------------- |
41 // |
40 // |
42 void CUsbHostEventNotificationObserver::ConstructL() |
41 void CUsbHostEventNotificationObserver::ConstructL() |
43 { |
42 { |
44 |
43 LOG_FUNC |
45 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::ConstructL" ) ); |
|
46 |
44 |
47 } |
45 } |
48 |
46 |
49 // --------------------------------------------------------------------------- |
47 // --------------------------------------------------------------------------- |
50 // |
48 // |
51 // --------------------------------------------------------------------------- |
49 // --------------------------------------------------------------------------- |
52 // |
50 // |
53 CUsbHostEventNotificationObserver* CUsbHostEventNotificationObserver::NewL( |
51 CUsbHostEventNotificationObserver* CUsbHostEventNotificationObserver::NewL( |
54 RUsb* aUsb) |
52 RUsb* aUsb) |
55 { |
53 { |
56 |
54 LOG_FUNC |
57 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::NewL" ) ); |
|
58 |
55 |
59 CUsbHostEventNotificationObserver* self = |
56 CUsbHostEventNotificationObserver* self = |
60 new (ELeave) CUsbHostEventNotificationObserver(aUsb); |
57 new (ELeave) CUsbHostEventNotificationObserver(aUsb); |
61 CleanupStack::PushL(self); |
58 CleanupStack::PushL(self); |
62 self->ConstructL(); |
59 self->ConstructL(); |
84 // --------------------------------------------------------------------------- |
80 // --------------------------------------------------------------------------- |
85 // |
81 // |
86 void CUsbHostEventNotificationObserver::SubscribeL( |
82 void CUsbHostEventNotificationObserver::SubscribeL( |
87 MUsbHostEventNotificationObserver& aObserver) |
83 MUsbHostEventNotificationObserver& aObserver) |
88 { |
84 { |
89 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::SubscribeL" ) ); |
85 LOG_FUNC |
90 |
86 |
91 // check if the same observer already exist in a list |
87 // check if the same observer already exist in a list |
92 if(KErrNotFound != iObservers.Find(&aObserver)) |
88 if (KErrNotFound != iObservers.Find(&aObserver)) |
93 { |
89 { |
94 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::SubscribeL Observer already exists." ) ); |
90 LOG("Observer already exists" ); |
95 Panic(EObserverAlreadyExists); |
91 Panic( EObserverAlreadyExists); |
96 return; |
92 return; |
97 } |
93 } |
98 |
94 |
99 iObservers.AppendL(&aObserver); |
95 iObservers.AppendL(&aObserver); |
100 |
96 |
101 if (KFirst == iObservers.Count()) // first item |
97 if (KFirst == iObservers.Count()) // first item |
102 { |
98 { |
103 iUsb->HostEventNotification(iStatus, iEventInfo); |
99 iUsb->HostEventNotification(iStatus, iEventInfo); |
111 // --------------------------------------------------------------------------- |
107 // --------------------------------------------------------------------------- |
112 // |
108 // |
113 void CUsbHostEventNotificationObserver::UnsubscribeL( |
109 void CUsbHostEventNotificationObserver::UnsubscribeL( |
114 MUsbHostEventNotificationObserver& aObserver) |
110 MUsbHostEventNotificationObserver& aObserver) |
115 { |
111 { |
116 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::UnsubscribeL" ) ); |
112 LOG_FUNC |
117 TInt i(iObservers.Find(&aObserver)); |
113 |
118 if(KErrNotFound == i) |
114 TInt i(iObservers.Find(&aObserver)); |
119 { |
115 if (KErrNotFound == i) |
120 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::UnsubscribeL Observer not found." ) ); |
116 { |
121 Panic(ECanNotFindHostEventNotificationObserver); |
117 LOG("Observer not found"); |
122 return; |
118 Panic( ECanNotFindHostEventNotificationObserver); |
123 } |
119 return; |
124 |
120 } |
125 iObservers.Remove(i); |
121 |
126 |
122 iObservers.Remove(i); |
127 if (0 == iObservers.Count()) // no observers anymore |
123 |
128 { |
124 if (0 == iObservers.Count()) // no observers anymore |
129 // cancel pending request |
125 { |
130 Cancel(); |
126 // cancel pending request |
131 } |
127 Cancel(); |
|
128 } |
132 } |
129 } |
133 |
130 |
134 // --------------------------------------------------------------------------- |
131 // --------------------------------------------------------------------------- |
135 // |
132 // |
136 // --------------------------------------------------------------------------- |
133 // --------------------------------------------------------------------------- |
137 // |
134 // |
138 void CUsbHostEventNotificationObserver::RunL() |
135 void CUsbHostEventNotificationObserver::RunL() |
139 { |
136 { |
140 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iStatus = %d" ), iStatus.Int())); |
137 LOG_FUNC |
141 |
138 |
142 // if error occured, tell to Observers |
139 LOG1( "iStatus = %d", iStatus.Int()); |
143 if(KErrNone != iStatus.Int()) |
140 |
144 { |
141 // if error occured, tell to Observers |
145 for (TInt i(0); i < iObservers.Count(); ++i) |
142 if (KErrNone != iStatus.Int()) |
146 { |
143 { |
147 iObservers[i]->HostEventNotificationErrorL(iStatus.Int()); |
144 for (TInt i(0); i < iObservers.Count(); ++i) |
148 } |
145 { |
149 return; |
146 iObservers[i]->HostEventNotificationErrorL(iStatus.Int()); |
150 } |
147 } |
|
148 return; |
|
149 } |
151 |
150 |
152 TDeviceEventInformation dei(iEventInfo); |
151 TDeviceEventInformation dei(iEventInfo); |
153 |
152 |
154 // re-issue request first |
153 // re-issue request first |
155 iUsb->HostEventNotification(iStatus, iEventInfo); |
154 iUsb->HostEventNotification(iStatus, iEventInfo); |
156 SetActive(); |
155 SetActive(); |
157 |
156 |
158 // Log the event |
157 // Log the event |
159 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iDeviceId = %d" ), dei.iDeviceId)); |
158 LOG1( "iEventInfo.iDeviceId = %d" , dei.iDeviceId); |
160 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iEventType = %d" ), dei.iEventType)); |
159 LOG1( "iEventInfo.iEventType = %d" , dei.iEventType); |
161 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iError = %d" ), dei.iError)); |
160 LOG1( "iEventInfo.iError = %d" , dei.iError); |
162 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iDriverLoadStatus = %d" ), dei.iDriverLoadStatus)); |
161 LOG1( "iEventInfo.iDriverLoadStatus = %d" , dei.iDriverLoadStatus); |
163 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iVid = %d" ), dei.iVid)); |
162 LOG1( "iEventInfo.iVid = %d" , dei.iVid); |
164 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iPid = %d" ), dei.iPid)); |
163 LOG1( "iEventInfo.iPid = %d" , dei.iPid); |
165 |
164 |
166 // then process property change |
165 // then process property change |
167 switch (dei.iEventType) |
166 switch (dei.iEventType) |
168 { |
167 { |
169 case EDeviceAttachment: |
168 case EDeviceAttachment: |
170 { |
169 { |
171 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DeviceAttachment" ) ); |
170 LOG("DeviceAttachment" ); |
172 |
171 |
173 for (TInt i(0); i < iObservers.Count(); ++i) |
172 for (TInt i(0); i < iObservers.Count(); ++i) |
174 { |
173 { |
175 iObservers[i]->DeviceAttachedL(dei); |
174 iObservers[i]->DeviceAttachedL(dei); |
176 } |
175 } |
177 break; |
176 break; |
178 } |
177 } |
179 |
178 |
180 case EDeviceDetachment: |
179 case EDeviceDetachment: |
181 { |
180 { |
182 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DeviceDetachment" ) ); |
181 LOG( "DeviceDetachment" ); |
183 |
182 |
184 for (TInt i(0); i < iObservers.Count(); ++i) |
183 for (TInt i(0); i < iObservers.Count(); ++i) |
185 { |
184 { |
186 iObservers[i]->DeviceDetachedL(dei); |
185 iObservers[i]->DeviceDetachedL(dei); |
187 } |
186 } |
192 { |
191 { |
193 switch (dei.iDriverLoadStatus) |
192 switch (dei.iDriverLoadStatus) |
194 { |
193 { |
195 case EDriverLoadSuccess: |
194 case EDriverLoadSuccess: |
196 { |
195 { |
197 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DriverLoadSuccess" ) ); |
196 LOG( "DriverLoadSuccess" ); |
198 |
197 |
199 for (TInt i(0); i < iObservers.Count(); ++i) |
198 for (TInt i(0); i < iObservers.Count(); ++i) |
200 { |
199 { |
201 iObservers[i]->DriverLoadSuccessL(dei); |
200 iObservers[i]->DriverLoadSuccessL(dei); |
202 } |
201 } |
203 |
202 |
204 break; |
203 break; |
205 } |
204 } |
206 case EDriverLoadPartialSuccess: |
205 case EDriverLoadPartialSuccess: |
207 { |
206 { |
208 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DriverLoadPartialSuccess" ) ); |
207 LOG( "DriverLoadPartialSuccess" ); |
209 |
208 |
210 for (TInt i(0); i < iObservers.Count(); ++i) |
209 for (TInt i(0); i < iObservers.Count(); ++i) |
211 { |
210 { |
212 iObservers[i]->DriverLoadPartialSuccessL(dei); |
211 iObservers[i]->DriverLoadPartialSuccessL(dei); |
213 } |
212 } |
214 break; |
213 break; |
215 |
214 |
216 } |
215 } |
217 case EDriverLoadFailure: |
216 case EDriverLoadFailure: |
218 { |
217 { |
219 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DriverLoadFailure" ) ); |
218 LOG( "DriverLoadFailure"); |
220 |
219 |
221 for (TInt i(0); i < iObservers.Count(); ++i) |
220 for (TInt i(0); i < iObservers.Count(); ++i) |
222 { |
221 { |
223 iObservers[i]->DriverLoadFailureL(dei); |
222 iObservers[i]->DriverLoadFailureL(dei); |
224 } |
223 } |
225 break; |
224 break; |
226 } |
225 } |
227 default: |
226 default: |
228 { |
227 { |
229 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DriverLoadFailure WrongDriverLoadStatus" ) ); |
228 LOG("WrongDriverLoadStatus" ); |
230 Panic(EWrongDriverLoadStatus); |
229 Panic( EWrongDriverLoadStatus); |
231 } |
230 } |
232 } |
231 } |
233 break; |
232 break; |
234 |
233 |
235 } |
234 } |
236 default: |
235 default: |
237 { |
236 { |
238 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL WrongHostEventNotification" ) ); |
237 LOG( "WrongHostEventNotification" ); |
239 Panic(EWrongHostEventNotification); |
238 Panic( EWrongHostEventNotification); |
240 } |
239 } |
241 |
240 |
242 } |
241 } |
243 |
242 |
244 } |
243 } |