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 "cusbotgstateobserver.h" |
18 #include "cusbotgstateobserver.h" |
20 |
19 |
21 #include "definitions.h" |
20 #include "definitions.h" |
22 #include "debug.h" |
21 #include "debug.h" |
83 // |
79 // |
84 // --------------------------------------------------------------------------- |
80 // --------------------------------------------------------------------------- |
85 // |
81 // |
86 TUsbOtgState CUsbOtgStateObserver::OtgState() |
82 TUsbOtgState CUsbOtgStateObserver::OtgState() |
87 { |
83 { |
88 |
|
89 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgStateObserver::OtgState" ) ); |
|
90 |
|
91 TInt val(0); |
84 TInt val(0); |
92 |
85 |
93 TInt err = iOtgState.Get(val); |
86 TInt err = iOtgState.Get(val); |
94 |
87 |
95 if (KErrNone != err) |
88 if (KErrNone != err) |
96 { |
89 { |
97 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgStateObserver::StOtgState CanNotGetOtgStateProperty" ) ); |
90 LOG("CanNotGetOtgStateProperty" ); |
98 Panic(ECanNotGetOtgStateProperty); |
91 Panic( ECanNotGetOtgStateProperty); |
99 } |
92 } |
100 |
|
101 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbOtgStateObserver::OtgState = %d" ), val )); |
|
102 |
93 |
103 return (TUsbOtgState) val; |
94 return (TUsbOtgState) val; |
104 |
95 |
105 } |
96 } |
106 |
97 |
108 // |
99 // |
109 // --------------------------------------------------------------------------- |
100 // --------------------------------------------------------------------------- |
110 // |
101 // |
111 void CUsbOtgStateObserver::SubscribeL(MUsbOtgStateObserver& aObserver) |
102 void CUsbOtgStateObserver::SubscribeL(MUsbOtgStateObserver& aObserver) |
112 { |
103 { |
113 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::SubscribeL" ) ); |
104 LOG_FUNC |
|
105 |
114 // check if the same observer already exist in a list |
106 // check if the same observer already exist in a list |
115 if(KErrNotFound != iObservers.Find(&aObserver)) |
107 if (KErrNotFound != iObservers.Find(&aObserver)) |
116 { |
108 { |
117 FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::SubscribeL Observer already exists." ) ); |
109 LOG( "Observer already exists" ); |
118 Panic(EObserverAlreadyExists); |
110 Panic( EObserverAlreadyExists); |
119 return; |
111 return; |
120 } |
112 } |
121 iObservers.AppendL(&aObserver); |
113 iObservers.AppendL(&aObserver); |
122 |
114 |
123 if (KFirst == iObservers.Count()) // first item |
115 if (KFirst == iObservers.Count()) // first item |
132 // |
124 // |
133 // --------------------------------------------------------------------------- |
125 // --------------------------------------------------------------------------- |
134 // |
126 // |
135 void CUsbOtgStateObserver::UnsubscribeL(MUsbOtgStateObserver& aObserver) |
127 void CUsbOtgStateObserver::UnsubscribeL(MUsbOtgStateObserver& aObserver) |
136 { |
128 { |
137 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgStateObserver::UnsubscribeL" ) ); |
129 LOG_FUNC |
138 |
130 |
139 TInt i(iObservers.Find(&aObserver)); |
131 TInt i(iObservers.Find(&aObserver)); |
140 if(KErrNotFound == i) |
132 if (KErrNotFound == i) |
141 { |
133 { |
142 FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::UnsubscribeL Observer not found." ) ); |
134 LOG("Observer not found"); |
143 Panic(ECanNotFindOtgStateObserver); |
135 Panic( ECanNotFindOtgStateObserver); |
144 return; |
136 return; |
145 } |
137 } |
146 |
138 |
147 iObservers.Remove(i); |
139 iObservers.Remove(i); |
148 |
140 |
149 if (0 == iObservers.Count()) // no observers anymore |
141 if (0 == iObservers.Count()) // no observers anymore |
150 { |
142 { |
151 // cancel pending request |
143 // cancel pending request |
152 Cancel(); |
144 Cancel(); |
153 } |
145 } |
157 // |
149 // |
158 // --------------------------------------------------------------------------- |
150 // --------------------------------------------------------------------------- |
159 // |
151 // |
160 void CUsbOtgStateObserver::RunL() |
152 void CUsbOtgStateObserver::RunL() |
161 { |
153 { |
162 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbOtgStateObserver::RunL iStatus = %d" ), iStatus.Int())); |
154 LOG_FUNC |
|
155 |
|
156 LOG1( "iStatus = %d" , iStatus.Int()); |
163 |
157 |
164 // if error occured, tell to Observers |
158 // if error occured, tell to Observers |
165 if(KErrNone != iStatus.Int()) |
159 if (KErrNone != iStatus.Int()) |
166 { |
160 { |
167 for (TInt i(0); i < iObservers.Count(); ++i) |
161 for (TInt i(0); i < iObservers.Count(); ++i) |
168 { |
162 { |
169 iObservers[i]->OtgStateErrorL(iStatus.Int()); |
163 iObservers[i]->OtgStateErrorL(iStatus.Int()); |
170 } |
164 } |
171 return; |
165 return; |
172 } |
166 } |
173 |
167 |
174 // re-issue request first |
168 // re-issue request first |
175 iOtgState.Subscribe(iStatus); |
169 iOtgState.Subscribe(iStatus); |
176 SetActive(); |
170 SetActive(); |
177 |
171 |
178 // then process property change |
172 // then process property change |
180 |
174 |
181 switch (state) |
175 switch (state) |
182 { |
176 { |
183 case EUsbOtgStateReset: |
177 case EUsbOtgStateReset: |
184 { |
178 { |
185 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::RunL OTGState == RESET" ) ); |
179 LOG("OTGState == RESET" ); |
186 break; |
180 break; |
187 } |
181 } |
188 case EUsbOtgStateAIdle: |
182 case EUsbOtgStateAIdle: |
189 { |
183 { |
190 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::RunL OTGState == AIdle" ) ); |
184 LOG("OTGState == AIdle" ); |
191 for (TInt i(0); i < iObservers.Count(); ++i) |
185 for (TInt i(0); i < iObservers.Count(); ++i) |
192 { |
186 { |
193 iObservers[i]->AIdleL(); |
187 iObservers[i]->AIdleL(); |
194 } |
188 } |
195 break; |
189 break; |
196 } |
190 } |
197 case EUsbOtgStateAHost: |
191 case EUsbOtgStateAHost: |
198 { |
192 { |
199 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::RunL OTGState == AHost" ) ); |
193 LOG( "OTGState == AHost"); |
200 for (TInt i(0); i < iObservers.Count(); ++i) |
194 for (TInt i(0); i < iObservers.Count(); ++i) |
201 { |
195 { |
202 iObservers[i]->AHostL(); |
196 iObservers[i]->AHostL(); |
203 } |
197 } |
204 break; |
198 break; |
205 } |
199 } |
206 case EUsbOtgStateAPeripheral: |
200 case EUsbOtgStateAPeripheral: |
207 { |
201 { |
208 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::RunL OTGState == APeripheral" ) ); |
202 LOG("OTGState == APeripheral" ); |
209 for (TInt i(0); i < iObservers.Count(); ++i) |
203 for (TInt i(0); i < iObservers.Count(); ++i) |
210 { |
204 { |
211 iObservers[i]->APeripheralL(); |
205 iObservers[i]->APeripheralL(); |
212 } |
206 } |
213 break; |
207 break; |
214 } |
208 } |
215 case EUsbOtgStateAVbusError: |
209 case EUsbOtgStateAVbusError: |
216 { |
210 { |
217 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::RunL OTGState == AVBusError" ) ); |
211 LOG("OTGState == AVBusError" ); |
218 for (TInt i(0); i < iObservers.Count(); ++i) |
212 for (TInt i(0); i < iObservers.Count(); ++i) |
219 { |
213 { |
220 iObservers[i]->AVBusErrorL(); |
214 iObservers[i]->AVBusErrorL(); |
221 } |
215 } |
222 break; |
216 break; |
223 } |
217 } |
224 case EUsbOtgStateBIdle: |
218 case EUsbOtgStateBIdle: |
225 { |
219 { |
226 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::RunL OTGState == BIdle" ) ); |
220 LOG( "OTGState == BIdle" ); |
227 for (TInt i(0); i < iObservers.Count(); ++i) |
221 for (TInt i(0); i < iObservers.Count(); ++i) |
228 { |
222 { |
229 iObservers[i]->BIdleL(); |
223 iObservers[i]->BIdleL(); |
230 } |
224 } |
231 break; |
225 break; |
232 } |
226 } |
233 case EUsbOtgStateBPeripheral: |
227 case EUsbOtgStateBPeripheral: |
234 { |
228 { |
235 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::RunL OTGState == BPeripheral" ) ); |
229 LOG("OTGState == BPeripheral" ); |
236 for (TInt i(0); i < iObservers.Count(); ++i) |
230 for (TInt i(0); i < iObservers.Count(); ++i) |
237 { |
231 { |
238 iObservers[i]->BPeripheralL(); |
232 iObservers[i]->BPeripheralL(); |
239 } |
233 } |
240 break; |
234 break; |
241 } |
235 } |
242 case EUsbOtgStateBHost: |
236 case EUsbOtgStateBHost: |
243 { |
237 { |
244 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::RunL OTGState == BHost" ) ); |
238 LOG("OTGState == BHost" ); |
245 for (TInt i(0); i < iObservers.Count(); ++i) |
239 for (TInt i(0); i < iObservers.Count(); ++i) |
246 { |
240 { |
247 iObservers[i]->BHostL(); |
241 iObservers[i]->BHostL(); |
248 } |
242 } |
249 break; |
243 break; |
250 } |
244 } |
251 default: |
245 default: |
252 { |
246 { |
253 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::RunL WrongOtgState" ) ); |
247 LOG("WrongOtgState" ); |
254 Panic(EWrongOtgState); |
248 Panic( EWrongOtgState); |
255 } |
249 } |
256 } |
250 } |
257 |
251 |
258 } |
252 } |
259 |
253 |