|
1 /* |
|
2 * Copyright (c) 2008-2009 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 |
|
19 #include "cusbotgstateobserver.h" |
|
20 |
|
21 #include "definitions.h" |
|
22 #include "debug.h" |
|
23 #include "panic.h" |
|
24 |
|
25 // --------------------------------------------------------------------------- |
|
26 // |
|
27 // --------------------------------------------------------------------------- |
|
28 // |
|
29 CUsbOtgStateObserver::CUsbOtgStateObserver() : |
|
30 CActive(EPriorityStandard) |
|
31 { |
|
32 CActiveScheduler::Add(this); |
|
33 } |
|
34 |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 void CUsbOtgStateObserver::ConstructL() |
|
40 { |
|
41 |
|
42 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgStateObserver::ConstructL" ) ); |
|
43 |
|
44 User::LeaveIfError(iOtgState.Attach(KUidUsbManCategory, |
|
45 KUsbOtgStateProperty)); |
|
46 |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 CUsbOtgStateObserver* CUsbOtgStateObserver::NewL() |
|
54 { |
|
55 |
|
56 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgStateObserver::NewL" ) ); |
|
57 |
|
58 CUsbOtgStateObserver* self = new (ELeave) CUsbOtgStateObserver(); |
|
59 CleanupStack::PushL(self); |
|
60 self->ConstructL(); |
|
61 CleanupStack::Pop(self); |
|
62 return self; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 CUsbOtgStateObserver::~CUsbOtgStateObserver() |
|
70 { |
|
71 |
|
72 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgStateObserver::~CUsbOtgStateObserver" ) ); |
|
73 |
|
74 Cancel(); |
|
75 |
|
76 iOtgState.Close(); |
|
77 |
|
78 iObservers.ResetAndDestroy(); |
|
79 |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 TUsbOtgState CUsbOtgStateObserver::OtgState() |
|
87 { |
|
88 |
|
89 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgStateObserver::OtgState" ) ); |
|
90 |
|
91 TInt val(0); |
|
92 |
|
93 TInt err = iOtgState.Get(val); |
|
94 |
|
95 if (KErrNone != err) |
|
96 { |
|
97 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgStateObserver::StOtgState CanNotGetOtgStateProperty" ) ); |
|
98 Panic(ECanNotGetOtgStateProperty); |
|
99 } |
|
100 |
|
101 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbOtgStateObserver::OtgState = %d" ), val )); |
|
102 |
|
103 return (TUsbOtgState) val; |
|
104 |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 void CUsbOtgStateObserver::SubscribeL(MUsbOtgStateObserver* aObserver) |
|
112 { |
|
113 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::SubscribeL" ) ); |
|
114 |
|
115 User::LeaveIfError(iObservers.Append(aObserver)); |
|
116 |
|
117 if (KFirst == iObservers.Count()) // first item |
|
118 { |
|
119 iOtgState.Subscribe(iStatus); |
|
120 SetActive(); |
|
121 |
|
122 } |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 void CUsbOtgStateObserver::UnsubscribeL(MUsbOtgStateObserver* aObserver) |
|
130 { |
|
131 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::UnsubscribeL" ) ); |
|
132 |
|
133 if (0 == iObservers.Count()) // no items |
|
134 { |
|
135 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgStateObserver::UnsubscribeL No observers" ) ); |
|
136 return; |
|
137 } |
|
138 |
|
139 TInt i(0); |
|
140 while (i < iObservers.Count() && aObserver != iObservers[i]) |
|
141 ++i; |
|
142 |
|
143 if (aObserver == iObservers[i]) // found |
|
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 { |
|
155 // cancel pending request |
|
156 Cancel(); |
|
157 } |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // |
|
162 // --------------------------------------------------------------------------- |
|
163 // |
|
164 void CUsbOtgStateObserver::RunL() |
|
165 { |
|
166 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbOtgStateObserver::RunL iStatus = %d" ), iStatus.Int())); |
|
167 |
|
168 // if error occured, tell to Observers |
|
169 if(KErrNone != iStatus.Int()) |
|
170 { |
|
171 for (TInt i(0); i < iObservers.Count(); ++i) |
|
172 { |
|
173 iObservers[i]->OtgStateErrorL(iStatus.Int()); |
|
174 } |
|
175 return; |
|
176 } |
|
177 |
|
178 // re-issue request first |
|
179 iOtgState.Subscribe(iStatus); |
|
180 SetActive(); |
|
181 |
|
182 // then process property change |
|
183 TUsbOtgState state(OtgState()); |
|
184 |
|
185 switch (state) |
|
186 { |
|
187 case EUsbOtgStateReset: |
|
188 { |
|
189 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::RunL OTGState == RESET" ) ); |
|
190 break; |
|
191 } |
|
192 case EUsbOtgStateAIdle: |
|
193 { |
|
194 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::RunL OTGState == AIdle" ) ); |
|
195 for (TInt i(0); i < iObservers.Count(); ++i) |
|
196 { |
|
197 iObservers[i]->AIdleL(); |
|
198 } |
|
199 break; |
|
200 } |
|
201 case EUsbOtgStateAHost: |
|
202 { |
|
203 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::RunL OTGState == AHost" ) ); |
|
204 for (TInt i(0); i < iObservers.Count(); ++i) |
|
205 { |
|
206 iObservers[i]->AHostL(); |
|
207 } |
|
208 break; |
|
209 } |
|
210 case EUsbOtgStateAPeripheral: |
|
211 { |
|
212 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::RunL OTGState == APeripheral" ) ); |
|
213 for (TInt i(0); i < iObservers.Count(); ++i) |
|
214 { |
|
215 iObservers[i]->APeripheralL(); |
|
216 } |
|
217 break; |
|
218 } |
|
219 case EUsbOtgStateAVbusError: |
|
220 { |
|
221 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::RunL OTGState == AVBusError" ) ); |
|
222 for (TInt i(0); i < iObservers.Count(); ++i) |
|
223 { |
|
224 iObservers[i]->AVBusErrorL(); |
|
225 } |
|
226 break; |
|
227 } |
|
228 case EUsbOtgStateBIdle: |
|
229 { |
|
230 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::RunL OTGState == BIdle" ) ); |
|
231 for (TInt i(0); i < iObservers.Count(); ++i) |
|
232 { |
|
233 iObservers[i]->BIdleL(); |
|
234 } |
|
235 break; |
|
236 } |
|
237 case EUsbOtgStateBPeripheral: |
|
238 { |
|
239 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::RunL OTGState == BPeripheral" ) ); |
|
240 for (TInt i(0); i < iObservers.Count(); ++i) |
|
241 { |
|
242 iObservers[i]->BPeripheralL(); |
|
243 } |
|
244 break; |
|
245 } |
|
246 case EUsbOtgStateBHost: |
|
247 { |
|
248 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::RunL OTGState == BHost" ) ); |
|
249 for (TInt i(0); i < iObservers.Count(); ++i) |
|
250 { |
|
251 iObservers[i]->BHostL(); |
|
252 } |
|
253 break; |
|
254 } |
|
255 default: |
|
256 { |
|
257 FLOG( _L( "[USBOTGWATCHER]\tCUsbOTGStateObserver::RunL WrongOtgState" ) ); |
|
258 Panic(EWrongOtgState); |
|
259 } |
|
260 } |
|
261 |
|
262 } |
|
263 |
|
264 // --------------------------------------------------------------------------- |
|
265 // |
|
266 // --------------------------------------------------------------------------- |
|
267 // |
|
268 void CUsbOtgStateObserver::DoCancel() |
|
269 { |
|
270 iOtgState.Cancel(); |
|
271 } |
|
272 |
|
273 // --------------------------------------------------------------------------- |
|
274 // |
|
275 // --------------------------------------------------------------------------- |
|
276 // |
|
277 TInt CUsbOtgStateObserver::RunError(TInt aError) |
|
278 { |
|
279 |
|
280 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbOtgStateObserver::RunError aError = %d" ), aError)); |
|
281 |
|
282 // try to continue |
|
283 return KErrNone; |
|
284 |
|
285 } |
|
286 |