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(); |
82 // --------------------------------------------------------------------------- |
78 // --------------------------------------------------------------------------- |
83 // |
79 // |
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 User::LeaveIfError(iObservers.Append(aObserver)); |
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); |
92 |
96 |
93 if (KFirst == iObservers.Count()) // first item |
97 if (KFirst == iObservers.Count()) // first item |
94 { |
98 { |
95 iUsb->HostEventNotification(iStatus, iEventInfo); |
99 iUsb->HostEventNotification(iStatus, iEventInfo); |
96 SetActive(); |
100 SetActive(); |
101 // --------------------------------------------------------------------------- |
105 // --------------------------------------------------------------------------- |
102 // |
106 // |
103 // --------------------------------------------------------------------------- |
107 // --------------------------------------------------------------------------- |
104 // |
108 // |
105 void CUsbHostEventNotificationObserver::UnsubscribeL( |
109 void CUsbHostEventNotificationObserver::UnsubscribeL( |
106 MUsbHostEventNotificationObserver* aObserver) |
110 MUsbHostEventNotificationObserver& aObserver) |
107 { |
111 { |
108 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::UnsubscribeL" ) ); |
112 LOG_FUNC |
109 if (0 == iObservers.Count()) // no items |
113 |
110 { |
114 TInt i(iObservers.Find(&aObserver)); |
111 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::UnsubscribeL No observers" ) ); |
115 if (KErrNotFound == i) |
|
116 { |
|
117 LOG("Observer not found"); |
|
118 Panic( ECanNotFindHostEventNotificationObserver); |
112 return; |
119 return; |
113 } |
120 } |
114 |
121 |
115 TInt i(0); |
122 iObservers.Remove(i); |
116 while (i < iObservers.Count() && aObserver != iObservers[i]) |
123 |
117 ++i; |
124 if (0 == iObservers.Count()) // no observers anymore |
118 |
|
119 if (aObserver == iObservers[i]) // found |
|
120 { |
|
121 iObservers.Remove(i); |
|
122 } |
|
123 else |
|
124 { |
|
125 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::UnsubscribeL CanNotFindIdPinObserver" ) ); |
|
126 Panic(ECanNotFindIdPinObserver); |
|
127 } |
|
128 |
|
129 if (0 == iObservers.Count()) // no items |
|
130 { |
125 { |
131 // cancel pending request |
126 // cancel pending request |
132 Cancel(); |
127 Cancel(); |
133 } |
128 } |
134 } |
129 } |
137 // |
132 // |
138 // --------------------------------------------------------------------------- |
133 // --------------------------------------------------------------------------- |
139 // |
134 // |
140 void CUsbHostEventNotificationObserver::RunL() |
135 void CUsbHostEventNotificationObserver::RunL() |
141 { |
136 { |
142 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iStatus = %d" ), iStatus.Int())); |
137 LOG_FUNC |
143 |
138 |
144 // if error occured, tell to Observers |
139 LOG1( "iStatus = %d", iStatus.Int()); |
145 if(KErrNone != iStatus.Int()) |
140 |
146 { |
141 // if error occured, tell to Observers |
147 for (TInt i(0); i < iObservers.Count(); ++i) |
142 if (KErrNone != iStatus.Int()) |
148 { |
143 { |
149 iObservers[i]->HostEventNotificationErrorL(iStatus.Int()); |
144 for (TInt i(0); i < iObservers.Count(); ++i) |
150 } |
145 { |
151 return; |
146 iObservers[i]->HostEventNotificationErrorL(iStatus.Int()); |
152 } |
147 } |
|
148 return; |
|
149 } |
153 |
150 |
154 TDeviceEventInformation dei(iEventInfo); |
151 TDeviceEventInformation dei(iEventInfo); |
155 |
152 |
156 // re-issue request first |
153 // re-issue request first |
157 iUsb->HostEventNotification(iStatus, iEventInfo); |
154 iUsb->HostEventNotification(iStatus, iEventInfo); |
158 SetActive(); |
155 SetActive(); |
159 |
156 |
160 // Log the event |
157 // Log the event |
161 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iDeviceId = %d" ), dei.iDeviceId)); |
158 LOG1( "iEventInfo.iDeviceId = %d" , dei.iDeviceId); |
162 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iEventType = %d" ), dei.iEventType)); |
159 LOG1( "iEventInfo.iEventType = %d" , dei.iEventType); |
163 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iError = %d" ), dei.iError)); |
160 LOG1( "iEventInfo.iError = %d" , dei.iError); |
164 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iDriverLoadStatus = %d" ), dei.iDriverLoadStatus)); |
161 LOG1( "iEventInfo.iDriverLoadStatus = %d" , dei.iDriverLoadStatus); |
165 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iVid = %d" ), dei.iVid)); |
162 LOG1( "iEventInfo.iVid = %d" , dei.iVid); |
166 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iPid = %d" ), dei.iPid)); |
163 LOG1( "iEventInfo.iPid = %d" , dei.iPid); |
167 |
164 |
168 // then process property change |
165 // then process property change |
169 switch (dei.iEventType) |
166 switch (dei.iEventType) |
170 { |
167 { |
171 case EDeviceAttachment: |
168 case EDeviceAttachment: |
172 { |
169 { |
173 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DeviceAttachment" ) ); |
170 LOG("DeviceAttachment" ); |
174 |
171 |
175 for (TInt i(0); i < iObservers.Count(); ++i) |
172 for (TInt i(0); i < iObservers.Count(); ++i) |
176 { |
173 { |
177 iObservers[i]->DeviceAttachedL(dei); |
174 iObservers[i]->DeviceAttachedL(dei); |
178 } |
175 } |
179 break; |
176 break; |
180 } |
177 } |
181 |
178 |
182 case EDeviceDetachment: |
179 case EDeviceDetachment: |
183 { |
180 { |
184 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DeviceDetachment" ) ); |
181 LOG( "DeviceDetachment" ); |
185 |
182 |
186 for (TInt i(0); i < iObservers.Count(); ++i) |
183 for (TInt i(0); i < iObservers.Count(); ++i) |
187 { |
184 { |
188 iObservers[i]->DeviceDetachedL(dei); |
185 iObservers[i]->DeviceDetachedL(dei); |
189 } |
186 } |
194 { |
191 { |
195 switch (dei.iDriverLoadStatus) |
192 switch (dei.iDriverLoadStatus) |
196 { |
193 { |
197 case EDriverLoadSuccess: |
194 case EDriverLoadSuccess: |
198 { |
195 { |
199 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DriverLoadSuccess" ) ); |
196 LOG( "DriverLoadSuccess" ); |
200 |
197 |
201 for (TInt i(0); i < iObservers.Count(); ++i) |
198 for (TInt i(0); i < iObservers.Count(); ++i) |
202 { |
199 { |
203 iObservers[i]->DriverLoadSuccessL(dei); |
200 iObservers[i]->DriverLoadSuccessL(dei); |
204 } |
201 } |
205 |
202 |
206 break; |
203 break; |
207 } |
204 } |
208 case EDriverLoadPartialSuccess: |
205 case EDriverLoadPartialSuccess: |
209 { |
206 { |
210 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DriverLoadPartialSuccess" ) ); |
207 LOG( "DriverLoadPartialSuccess" ); |
211 |
208 |
212 for (TInt i(0); i < iObservers.Count(); ++i) |
209 for (TInt i(0); i < iObservers.Count(); ++i) |
213 { |
210 { |
214 iObservers[i]->DriverLoadPartialSuccessL(dei); |
211 iObservers[i]->DriverLoadPartialSuccessL(dei); |
215 } |
212 } |
216 break; |
213 break; |
217 |
214 |
218 } |
215 } |
219 case EDriverLoadFailure: |
216 case EDriverLoadFailure: |
220 { |
217 { |
221 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DriverLoadFailure" ) ); |
218 LOG( "DriverLoadFailure"); |
222 |
219 |
223 for (TInt i(0); i < iObservers.Count(); ++i) |
220 for (TInt i(0); i < iObservers.Count(); ++i) |
224 { |
221 { |
225 iObservers[i]->DriverLoadFailureL(dei); |
222 iObservers[i]->DriverLoadFailureL(dei); |
226 } |
223 } |
227 break; |
224 break; |
228 } |
225 } |
229 default: |
226 default: |
230 { |
227 { |
231 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DriverLoadFailure WrongDriverLoadStatus" ) ); |
228 LOG("WrongDriverLoadStatus" ); |
232 Panic(EWrongDriverLoadStatus); |
229 Panic( EWrongDriverLoadStatus); |
233 } |
230 } |
234 } |
231 } |
235 break; |
232 break; |
236 |
233 |
237 } |
234 } |
238 default: |
235 default: |
239 { |
236 { |
240 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL WrongHostEventNotification" ) ); |
237 LOG( "WrongHostEventNotification" ); |
241 Panic(EWrongHostEventNotification); |
238 Panic( EWrongHostEventNotification); |
242 } |
239 } |
243 |
240 |
244 } |
241 } |
245 |
242 |
246 } |
243 } |