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