1 /* |
|
2 * Copyright (c) 2007-2008 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 of CWsfEventHandler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // CLASS HEADER |
|
22 #include "wsfeventhandler.h" |
|
23 |
|
24 // INTERNAL INCLUDES |
|
25 #include "wsfstatechangeobserver.h" |
|
26 #include "wsflogger.h" |
|
27 |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // CWsfEventHandler::NewL |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 CWsfEventHandler* CWsfEventHandler::NewL( RWsfSession& aSession, |
|
34 MWsfStateChangeObserver& aObserver ) |
|
35 { |
|
36 CWsfEventHandler* thisPtr = new (ELeave) CWsfEventHandler( aSession, |
|
37 aObserver ); |
|
38 CleanupStack::PushL( thisPtr ); |
|
39 thisPtr->ConstructL(); |
|
40 CleanupStack::Pop( thisPtr ); |
|
41 return thisPtr; |
|
42 } |
|
43 |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // CWsfEventHandler::~CWsfEventHandler |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CWsfEventHandler::~CWsfEventHandler() |
|
50 { |
|
51 Cancel(); |
|
52 iSession = NULL; |
|
53 iObserver = NULL; |
|
54 } |
|
55 |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // CWsfEventHandler::CWsfEventHandler |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 CWsfEventHandler::CWsfEventHandler( RWsfSession& aSession, |
|
62 MWsfStateChangeObserver& aObserver ): |
|
63 CActive( CActive::EPriorityStandard ) |
|
64 { |
|
65 iSession = &aSession; |
|
66 iObserver = &aObserver; |
|
67 } |
|
68 |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // CWsfEventHandler::ConstructL |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 void CWsfEventHandler::ConstructL() |
|
75 { |
|
76 CActiveScheduler::Add( this ); |
|
77 } |
|
78 |
|
79 |
|
80 // --------------------------------------------------------------------------- |
|
81 // CWsfEventHandler::DoRunL |
|
82 // --------------------------------------------------------------------------- |
|
83 // |
|
84 void CWsfEventHandler::DoRunL() |
|
85 { |
|
86 LOG_ENTERFN( "CWsfEventHandler::DoRunL" ); |
|
87 LOG_WRITEF( "CWsfEventHandler::DoRunL event = %d", iEvent().iEvent ); |
|
88 |
|
89 switch ( iEvent().iEvent ) |
|
90 { |
|
91 case EEngineWlanDataChanged: |
|
92 { |
|
93 iObserver->WlanListChangedL(); |
|
94 break; |
|
95 } |
|
96 |
|
97 case EEngineScanDisabled: |
|
98 { |
|
99 iObserver->ScanDisabledL(); |
|
100 break; |
|
101 } |
|
102 |
|
103 case EEngineScanEnabled: |
|
104 { |
|
105 iObserver->ScanEnabledL(); |
|
106 break; |
|
107 } |
|
108 |
|
109 case EEngineConnected: |
|
110 { |
|
111 if ( !iBlockConnectedEvent ) |
|
112 { |
|
113 // if the event wasn't blocked, notify the observer |
|
114 iObserver->WlanConnectionActivatedL(); |
|
115 } |
|
116 else |
|
117 { |
|
118 // if it was blocked, just clear the flag |
|
119 iBlockConnectedEvent = EFalse; |
|
120 } |
|
121 |
|
122 // anyhow, connecting process is finished |
|
123 if ( iConnecting ) |
|
124 { |
|
125 iConnecting = EFalse; |
|
126 iSession->StopConnectingWait(); |
|
127 iObserver->ConnectionCreationProcessFinishedL( |
|
128 KErrNone ); |
|
129 } |
|
130 break; |
|
131 } |
|
132 |
|
133 case EEngineDisconnected: |
|
134 { |
|
135 iObserver->WlanConnectionClosedL(); |
|
136 break; |
|
137 } |
|
138 |
|
139 case EEngineError: |
|
140 { |
|
141 iObserver->NotifyEngineError( iEvent().iError ); |
|
142 break; |
|
143 } |
|
144 |
|
145 case EEngineConnectingFailed: |
|
146 { |
|
147 if ( iConnecting ) |
|
148 { |
|
149 // connecting is over |
|
150 iConnecting = EFalse; |
|
151 |
|
152 // make client return with KErrCancel |
|
153 iSession->iConnectingResult = iEvent().iError; |
|
154 iSession->StopConnectingWait(); |
|
155 iObserver->ConnectionCreationProcessFinishedL( |
|
156 iSession->iConnectingResult ); |
|
157 } |
|
158 break; |
|
159 } |
|
160 |
|
161 default: |
|
162 __ASSERT_DEBUG(0, _L("CWsfEventHandler - Invalid EngineEvent")); |
|
163 break; |
|
164 } |
|
165 |
|
166 } |
|
167 |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // CWsfEventHandler::RunL |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 void CWsfEventHandler::RunL() |
|
174 { |
|
175 LOG_ENTERFN( "CWsfEventHandler::RunL" ); |
|
176 TInt notifyError( KErrNone ); |
|
177 TBool reissue( ETrue ); |
|
178 |
|
179 if ( iStatus.Int() >= KErrNone && iObserver ) |
|
180 { |
|
181 TRAP( notifyError, DoRunL() ); |
|
182 } |
|
183 |
|
184 if ( notifyError ) |
|
185 { |
|
186 // notified class leaved |
|
187 LOG_WRITEF( "CWsfEventHandler::RunL notify error %d", notifyError ); |
|
188 } |
|
189 else if ( iStatus.Int() != KErrNone ) |
|
190 { |
|
191 if ( iStatus.Int() == KErrCancel ) |
|
192 { |
|
193 // KErrCancel is the signal that we are going down |
|
194 LOG_WRITE( "going down..." ); |
|
195 reissue = EFalse; |
|
196 } |
|
197 else |
|
198 { |
|
199 // error on the server side |
|
200 LOG_WRITEF( "CWsfEventHandler::RunL engine error %d", |
|
201 iStatus.Int() ); |
|
202 |
|
203 TBool notify( ETrue ); |
|
204 |
|
205 if ( iStatus.Int() == KErrServerTerminated ) |
|
206 { |
|
207 reissue = EFalse; |
|
208 |
|
209 if ( iObserver |
|
210 && iSession->RecoverFromServerTermination( *iObserver ) ) |
|
211 { |
|
212 // no need to reissue if recovered since it is already |
|
213 // done in the recovery process |
|
214 notify = EFalse; |
|
215 } |
|
216 } |
|
217 |
|
218 if ( notify && iObserver ) |
|
219 { |
|
220 // let the client decide what to do |
|
221 iObserver->NotifyEngineError( iStatus.Int() ); |
|
222 } |
|
223 } |
|
224 } |
|
225 |
|
226 |
|
227 if ( reissue && iObserver ) |
|
228 { |
|
229 // reissue callback request |
|
230 iSession->NotifyEventL( *iObserver ); |
|
231 } |
|
232 } |
|
233 |
|
234 |
|
235 // --------------------------------------------------------------------------- |
|
236 // CWsfEventHandler::DoCancel |
|
237 // --------------------------------------------------------------------------- |
|
238 // |
|
239 void CWsfEventHandler::DoCancel() |
|
240 { |
|
241 LOG_ENTERFN( "CWsfEventHandler::DoCancel" ); |
|
242 iSession->DoCancelNotifyEvent(); |
|
243 } |
|
244 |
|
245 |
|
246 // --------------------------------------------------------------------------- |
|
247 // CWsfEventHandler::RunError |
|
248 // --------------------------------------------------------------------------- |
|
249 // |
|
250 TInt CWsfEventHandler::RunError( TInt aError ) |
|
251 { |
|
252 LOG_ENTERFN( "CWsfEventHandler::RunError" ); |
|
253 LOG_WRITEF( "CWsfEventHandler::RunError error = %d", aError ); |
|
254 if ( iObserver ) |
|
255 { |
|
256 iObserver->NotifyEngineError( aError ) ; |
|
257 } |
|
258 return KErrNone; // we don't wan't to panic euser-47 - do we? |
|
259 } |
|
260 |
|
261 |
|
262 // --------------------------------------------------------------------------- |
|
263 // CWsfEventHandler::Start |
|
264 // --------------------------------------------------------------------------- |
|
265 // |
|
266 void CWsfEventHandler::Start() |
|
267 { |
|
268 SetActive(); |
|
269 } |
|
270 |
|
271 |
|
272 // --------------------------------------------------------------------------- |
|
273 // CWsfEventHandler::EventContainer |
|
274 // --------------------------------------------------------------------------- |
|
275 // |
|
276 TPckgBuf<TWsfNotifyEventContainer>& CWsfEventHandler::EventContainer() |
|
277 { |
|
278 return iEvent; |
|
279 } |
|
280 |
|
281 |
|
282 // --------------------------------------------------------------------------- |
|
283 // CWsfEventHandler::ResetObserver |
|
284 // --------------------------------------------------------------------------- |
|
285 // |
|
286 void CWsfEventHandler::ResetObserver( MWsfStateChangeObserver& aObserver ) |
|
287 { |
|
288 LOG_ENTERFN( "CWsfEventHandler::ResetObserver" ); |
|
289 iObserver = &aObserver; |
|
290 } |
|
291 |
|
292 |
|
293 // --------------------------------------------------------------------------- |
|
294 // CWsfEventHandler::BlockNextConnectedEvent |
|
295 // --------------------------------------------------------------------------- |
|
296 // |
|
297 void CWsfEventHandler::BlockNextConnectedEvent() |
|
298 { |
|
299 LOG_ENTERFN( "CWsfEventHandler::BlockNextConnectedEvent" ); |
|
300 if ( iConnecting ) |
|
301 { |
|
302 LOG_WRITE( "iBlockConnectedEvent to true" ); |
|
303 // set the flag only if we are the ones who are connecting |
|
304 iBlockConnectedEvent = ETrue; |
|
305 } |
|
306 } |
|
307 |
|
308 |
|
309 // --------------------------------------------------------------------------- |
|
310 // CWsfEventHandler::UnBlockNextConnectedEvent |
|
311 // --------------------------------------------------------------------------- |
|
312 // |
|
313 void CWsfEventHandler::UnBlockNextConnectedEvent() |
|
314 { |
|
315 LOG_ENTERFN( "CWsfEventHandler::UnBlockNextConnectedEvent" ); |
|
316 LOG_WRITE( "iBlockConnectedEvent to false" ); |
|
317 iBlockConnectedEvent = EFalse; |
|
318 } |
|
319 |
|
320 |
|
321 // --------------------------------------------------------------------------- |
|
322 // CWsfEventHandler::SetConnecting |
|
323 // --------------------------------------------------------------------------- |
|
324 // |
|
325 void CWsfEventHandler::SetConnecting( TBool aConnecting ) |
|
326 { |
|
327 LOG_ENTERFN( "CWsfEventHandler::SetConnecting" ); |
|
328 LOG_WRITEF( "iConnecting=%d, aConnecting=%d", iConnecting, aConnecting ); |
|
329 iConnecting = aConnecting; |
|
330 } |
|
331 |
|
332 |
|
333 // --------------------------------------------------------------------------- |
|
334 // CWsfEventHandler::Connecting |
|
335 // --------------------------------------------------------------------------- |
|
336 // |
|
337 TBool CWsfEventHandler::Connecting() const |
|
338 { |
|
339 return iConnecting; |
|
340 } |
|
341 |
|