|
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 <usbotgdefs.h> |
|
20 |
|
21 #include "cusbidpinobserver.h" |
|
22 |
|
23 #include "definitions.h" |
|
24 #include "debug.h" |
|
25 #include "panic.h" |
|
26 |
|
27 // --------------------------------------------------------------------------- |
|
28 // |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 CUsbIdPinObserver::CUsbIdPinObserver() : |
|
32 CActive(EPriorityStandard) |
|
33 { |
|
34 CActiveScheduler::Add(this); |
|
35 } |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 void CUsbIdPinObserver::ConstructL() |
|
42 { |
|
43 |
|
44 FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::ConstructL" ) ); |
|
45 |
|
46 User::LeaveIfError(iIdPin.Attach(KUidUsbManCategory, |
|
47 KUsbOtgIdPinPresentProperty)); |
|
48 |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CUsbIdPinObserver* CUsbIdPinObserver::NewL() |
|
56 { |
|
57 |
|
58 FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::NewL" ) ); |
|
59 |
|
60 CUsbIdPinObserver* self = new (ELeave) CUsbIdPinObserver(); |
|
61 CleanupStack::PushL(self); |
|
62 self->ConstructL(); |
|
63 CleanupStack::Pop(self); |
|
64 return self; |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 CUsbIdPinObserver::~CUsbIdPinObserver() |
|
72 { |
|
73 |
|
74 FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::~CUsbIdPinObserver" ) ); |
|
75 |
|
76 Cancel(); |
|
77 |
|
78 iIdPin.Close(); |
|
79 |
|
80 iObservers.Close(); |
|
81 |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 CUsbIdPinObserver::TState CUsbIdPinObserver::IdPin() |
|
89 /* this getter is not const, because for some reason RProperty::Get is not const */ |
|
90 { |
|
91 |
|
92 FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::IdPin" ) ); |
|
93 |
|
94 TInt val(0); |
|
95 |
|
96 TInt err = iIdPin.Get(val); |
|
97 |
|
98 if (KErrNone != err) |
|
99 { |
|
100 FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::IdPin CanNotGetIdPinProperty" ) ); |
|
101 Panic(ECanNotGetIdPinProperty); |
|
102 } |
|
103 |
|
104 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbIdPinObserver::IdPin = %d" ), val )); |
|
105 |
|
106 // not found in docs clear definition of this property. Verification is needed |
|
107 return (0 == val ? EIdPinOff : EIdPinOn); |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 // --------------------------------------------------------------------------- |
|
113 // |
|
114 void CUsbIdPinObserver::SubscribeL(MUsbIdPinObserver* aObserver) |
|
115 { |
|
116 FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::SubscribeL" ) ); |
|
117 |
|
118 User::LeaveIfError(iObservers.Append(aObserver)); |
|
119 |
|
120 if (KFirst == iObservers.Count()) // first item |
|
121 { |
|
122 iIdPin.Subscribe(iStatus); |
|
123 SetActive(); |
|
124 |
|
125 } |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 void CUsbIdPinObserver::UnsubscribeL(MUsbIdPinObserver* aObserver) |
|
133 { |
|
134 FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::UnsubscribeL" ) ); |
|
135 if (0 == iObservers.Count()) // no items |
|
136 { |
|
137 FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::UnsubscribeL No observers" ) ); |
|
138 return; |
|
139 } |
|
140 |
|
141 TInt i(0); |
|
142 while (i < iObservers.Count() && aObserver != iObservers[i]) |
|
143 ++i; |
|
144 |
|
145 if (aObserver == iObservers[i]) // found |
|
146 { |
|
147 iObservers.Remove(i); |
|
148 } |
|
149 else |
|
150 { |
|
151 FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::UnsubscribeL CanNotGetIdPinObserver" ) ); |
|
152 Panic(ECanNotFindIdPinObserver); |
|
153 } |
|
154 |
|
155 if (0 == iObservers.Count()) // no items |
|
156 { |
|
157 // cancel pending request |
|
158 Cancel(); |
|
159 } |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------------------------- |
|
163 // |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 void CUsbIdPinObserver::RunL() |
|
167 { |
|
168 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbIdPinObserver::RunL iStatus = %d" ), iStatus.Int())); |
|
169 |
|
170 // if error occured, tell to Observers |
|
171 if(KErrNone != iStatus.Int()) |
|
172 { |
|
173 for (TInt i(0); i < iObservers.Count(); ++i) |
|
174 { |
|
175 iObservers[i]->IdPinErrorL(iStatus.Int()); |
|
176 } |
|
177 return; |
|
178 } |
|
179 |
|
180 // re-issue request first |
|
181 iIdPin.Subscribe(iStatus); |
|
182 SetActive(); |
|
183 |
|
184 // then process property change |
|
185 TState state(IdPin()); |
|
186 |
|
187 // report change |
|
188 switch (state) |
|
189 { |
|
190 case EIdPinOn: |
|
191 { |
|
192 FLOG(_L( "[USBOTGWATCHER]\tCUsbIdPinObserver::RunL IdPin ON")); |
|
193 |
|
194 for (TInt i(0); i < iObservers.Count(); ++i) |
|
195 { |
|
196 iObservers[i]->IdPinOnL(); |
|
197 } |
|
198 break; |
|
199 } |
|
200 ; |
|
201 |
|
202 case EIdPinOff: |
|
203 { |
|
204 FLOG(_L( "[USBOTGWATCHER]\tCUsbIdPinObserver::RunL IdPin OFF")); |
|
205 |
|
206 for (TInt i(0); i < iObservers.Count(); ++i) |
|
207 { |
|
208 iObservers[i]->IdPinOffL(); |
|
209 } |
|
210 break; |
|
211 } |
|
212 ; |
|
213 |
|
214 default: |
|
215 { |
|
216 FLOG(_L( "[USBOTGWATCHER]\tCUsbIdPinObserver::RunL WrongIdPinState")); |
|
217 Panic(EWrongIdPinState); |
|
218 } |
|
219 } |
|
220 |
|
221 } |
|
222 |
|
223 // --------------------------------------------------------------------------- |
|
224 // |
|
225 // --------------------------------------------------------------------------- |
|
226 // |
|
227 void CUsbIdPinObserver::DoCancel() |
|
228 { |
|
229 iIdPin.Cancel(); |
|
230 } |
|
231 |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 // --------------------------------------------------------------------------- |
|
235 // |
|
236 TInt CUsbIdPinObserver::RunError(TInt aError) |
|
237 { |
|
238 |
|
239 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbIdPinObserver::RunError aError = %d" ), aError)); |
|
240 |
|
241 // try to continue |
|
242 return KErrNone; |
|
243 |
|
244 } |