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 CWsfWLANListActiveWrapper. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "wsflogger.h" |
|
21 #include "wsfmodel.h" |
|
22 #include "wsfwlaninfoarray.h" |
|
23 #include "wsfaicontroller.h" |
|
24 #include "wsfwlanlistactivewrapper.h" |
|
25 |
|
26 |
|
27 /** |
|
28 * Number of retries to fetch wlan data |
|
29 */ |
|
30 static const TInt KRetries = 5; |
|
31 |
|
32 |
|
33 // ---------------------------------------------------------------------------- |
|
34 // CWsfWLANListActiveWrapper::CWsfWLANListActiveWrapper |
|
35 // ---------------------------------------------------------------------------- |
|
36 // |
|
37 CWsfWLANListActiveWrapper::CWsfWLANListActiveWrapper() : |
|
38 CActive( EPriorityStandard ), // Standard priority |
|
39 iPtr( NULL, 0 ) |
|
40 { |
|
41 } |
|
42 |
|
43 |
|
44 // ---------------------------------------------------------------------------- |
|
45 // CWsfWLANListActiveWrapper::NewLC |
|
46 // ---------------------------------------------------------------------------- |
|
47 // |
|
48 CWsfWLANListActiveWrapper* CWsfWLANListActiveWrapper::NewLC( CWsfModel* aModel, |
|
49 TWsfAiController &aController ) |
|
50 { |
|
51 LOG_ENTERFN( "CWsfWLANListActiveWrapper::NewLC" ); |
|
52 CWsfWLANListActiveWrapper* self = |
|
53 new (ELeave) CWsfWLANListActiveWrapper(); |
|
54 CleanupStack::PushL(self); |
|
55 self->ConstructL( aModel, aController ); |
|
56 return self; |
|
57 } |
|
58 |
|
59 |
|
60 // ---------------------------------------------------------------------------- |
|
61 // CWsfWLANListActiveWrapper::NewL |
|
62 // ---------------------------------------------------------------------------- |
|
63 // |
|
64 CWsfWLANListActiveWrapper* CWsfWLANListActiveWrapper::NewL( CWsfModel* aModel, |
|
65 TWsfAiController &aController ) |
|
66 { |
|
67 LOG_ENTERFN( "CWsfWLANListActiveWrapper::NewL" ); |
|
68 CWsfWLANListActiveWrapper* self = CWsfWLANListActiveWrapper::NewLC( |
|
69 aModel, aController ); |
|
70 CleanupStack::Pop(); // self; |
|
71 return self; |
|
72 } |
|
73 |
|
74 |
|
75 // ---------------------------------------------------------------------------- |
|
76 // CWsfWLANListActiveWrapper::ConstructL |
|
77 // ---------------------------------------------------------------------------- |
|
78 // |
|
79 void CWsfWLANListActiveWrapper::ConstructL( CWsfModel* aModel, |
|
80 TWsfAiController &aController ) |
|
81 { |
|
82 LOG_ENTERFN( "CWsfWLANListActiveWrapper::ConstructL" ); |
|
83 CActiveScheduler::Add(this); // Add to scheduler |
|
84 iModel = aModel; |
|
85 iController = &aController; |
|
86 iArray = CWsfWlanInfoArray::NewL(); |
|
87 } |
|
88 |
|
89 // ---------------------------------------------------------------------------- |
|
90 // CWsfWLANListActiveWrapper::~CWsfWLANListActiveWrapper |
|
91 // ---------------------------------------------------------------------------- |
|
92 // |
|
93 CWsfWLANListActiveWrapper::~CWsfWLANListActiveWrapper() |
|
94 { |
|
95 LOG_ENTERFN( "CWsfWLANListActiveWrapper::~CWsfWLANListActiveWrapper" ); |
|
96 Cancel(); // Cancel any request, if outstanding |
|
97 // Delete instance variables if any |
|
98 if ( iBuffer ) |
|
99 { |
|
100 delete iBuffer; |
|
101 } |
|
102 delete iArray; |
|
103 } |
|
104 |
|
105 // ---------------------------------------------------------------------------- |
|
106 // CWsfWLANListActiveWrapper::DoCancel |
|
107 // ---------------------------------------------------------------------------- |
|
108 // |
|
109 void CWsfWLANListActiveWrapper::DoCancel() |
|
110 { |
|
111 } |
|
112 |
|
113 // ---------------------------------------------------------------------------- |
|
114 // CWsfWLANListActiveWrapper::Start |
|
115 // ---------------------------------------------------------------------------- |
|
116 // |
|
117 void CWsfWLANListActiveWrapper::Start( TBool aStarUp ) |
|
118 { |
|
119 LOG_ENTERFN( "CWsfWLANListActiveWrapper::Start" ); |
|
120 Cancel(); // Cancel any request, just to be sure |
|
121 iStartUp = aStarUp; |
|
122 iState = EUninitialized; |
|
123 iRetriesLeft = KRetries; |
|
124 iPckgAllocatedSize() = 0; |
|
125 iPckgNeededSize() = 0; |
|
126 SetActive(); |
|
127 TRequestStatus* status = &iStatus; |
|
128 User::RequestComplete(status, KErrNone); |
|
129 } |
|
130 |
|
131 // ---------------------------------------------------------------------------- |
|
132 // CWsfWLANListActiveWrapper::GetWlanList |
|
133 // ---------------------------------------------------------------------------- |
|
134 // |
|
135 CWsfWlanInfoArray* CWsfWLANListActiveWrapper::GetWlanList() |
|
136 { |
|
137 LOG_ENTERFN( "CWsfWLANListActiveWrapper::GetWlanList" ); |
|
138 return iArray; |
|
139 } |
|
140 |
|
141 // ---------------------------------------------------------------------------- |
|
142 // CWsfWLANListActiveWrapper::GetConnectedWLANNetwork |
|
143 // ---------------------------------------------------------------------------- |
|
144 // |
|
145 TWsfWlanInfo CWsfWLANListActiveWrapper::GetConnectedWLANNetwork() |
|
146 { |
|
147 LOG_ENTERFN( "CWsfWLANListActiveWrapper::GetConnectedWLANNetwork" ); |
|
148 return iConnectedWlan; |
|
149 } |
|
150 |
|
151 // ---------------------------------------------------------------------------- |
|
152 // CWsfWLANListActiveWrapper::RunL |
|
153 // ---------------------------------------------------------------------------- |
|
154 // |
|
155 void CWsfWLANListActiveWrapper::RunL() |
|
156 { |
|
157 LOG_ENTERFN( "CWsfWLANListActiveWrapper::RunL" ); |
|
158 if (iStatus == KErrNone) |
|
159 { |
|
160 if ( iState == EUninitialized ) |
|
161 { |
|
162 LOG_WRITE( "Get WLAN list size" ); |
|
163 iModel->GetWlanListSize( iPckgNeededSize, iStatus ); |
|
164 iState = EInitialized; |
|
165 SetActive(); // Tell scheduler a request is active |
|
166 } |
|
167 else if ( iState == EInitialized ) |
|
168 { |
|
169 LOG_WRITEF( "WLAN data buffer size = %d", iPckgNeededSize() ); |
|
170 |
|
171 if ( !iPckgNeededSize() ) |
|
172 { |
|
173 LOG_WRITE( "no data.." ); |
|
174 iState = EProcessWLANListData; |
|
175 SetActive(); |
|
176 TRequestStatus* status = &iStatus; |
|
177 User::RequestComplete(status, KErrNone); |
|
178 } |
|
179 else |
|
180 { |
|
181 // alloc the required size buffer... |
|
182 delete iBuffer; |
|
183 iBuffer = NULL; |
|
184 iBuffer = HBufC8::NewL( iPckgNeededSize() ); |
|
185 iPtr.Set( iBuffer->Des() ); |
|
186 |
|
187 LOG_WRITE( "Get WLAN list" ); |
|
188 iModel->GetWlanList( iPckgAllocatedSize, iPtr, iStatus ); |
|
189 iState = EProcessWLANListData; |
|
190 SetActive(); // Tell scheduler a request is active |
|
191 } |
|
192 } |
|
193 else if ( iState == EProcessWLANListData ) |
|
194 { |
|
195 LOG_WRITEF( "actual bytes occupied = %d", iPckgAllocatedSize() ); |
|
196 |
|
197 if ( iPckgNeededSize() != iPckgAllocatedSize() ) |
|
198 { |
|
199 // the buffer is not long enough... stop |
|
200 if ( iRetriesLeft > 0 ) |
|
201 { |
|
202 LOG_WRITEF( "iRetriesLeft = %d", iRetriesLeft ); |
|
203 iRetriesLeft--; |
|
204 iState = EUninitialized; |
|
205 SetActive(); |
|
206 TRequestStatus* status = &iStatus; |
|
207 User::RequestComplete( status, KErrNone ); |
|
208 return; |
|
209 } |
|
210 else |
|
211 { |
|
212 // no more retries |
|
213 User::Leave( KErrOverflow ); |
|
214 } |
|
215 } |
|
216 |
|
217 iArray->Reset(); |
|
218 |
|
219 if ( iPckgAllocatedSize() ) |
|
220 { |
|
221 iArray->AppendFromStreamBufferL( iPtr ); |
|
222 } |
|
223 |
|
224 LOG_WRITEF( "Array count=%d startup=%d", iArray->Count(), iStartUp ); |
|
225 |
|
226 iModel->GetConnectedWlanDetails( iPckg, iConnectedWlan, iStatus ); |
|
227 iState = EGetConnectedNetwork; |
|
228 SetActive(); // Tell scheduler a request is active |
|
229 } |
|
230 else if ( iState == EGetConnectedNetwork ) |
|
231 { |
|
232 LOG_WRITEF( "request result = %d", iPckg() ); |
|
233 |
|
234 if ( !iPckg() ) |
|
235 { |
|
236 LOG_WRITE( "result is false, so wlaninfo is marked not connected" ); |
|
237 iConnectedWlan.iConnectionState = ENotConnected; |
|
238 } |
|
239 |
|
240 LOG_WRITEF( "Connected = %d", iConnectedWlan.Connected() ); |
|
241 |
|
242 LOG_WRITEF( "iConnectedWlan state = %d", |
|
243 iConnectedWlan.iConnectionState ); |
|
244 |
|
245 if ( iStartUp ) |
|
246 { |
|
247 iController->StartupRefreshDataReadyL(); |
|
248 } |
|
249 else |
|
250 { |
|
251 iController->WlanListDataReadyL(); |
|
252 } |
|
253 } |
|
254 else |
|
255 { |
|
256 LOG_WRITEF( "iState = %d", iState ); |
|
257 } |
|
258 } |
|
259 else |
|
260 { |
|
261 LOG_WRITEF( "WLANListActiveWrapper iStatus = %d", iStatus.Int() ); |
|
262 } |
|
263 } |
|
264 |
|
265 // ---------------------------------------------------------------------------- |
|
266 // CWsfWLANListActiveWrapper::RunError |
|
267 // ---------------------------------------------------------------------------- |
|
268 // |
|
269 #ifdef _DEBUG |
|
270 TInt CWsfWLANListActiveWrapper::RunError( TInt aError ) |
|
271 { |
|
272 LOG_ENTERFN( "CWsfWLANListActiveWrapper::RunError" ); |
|
273 LOG_WRITEF( "aError = %d", aError ); |
|
274 return aError; |
|
275 } |
|
276 #else |
|
277 TInt CWsfWLANListActiveWrapper::RunError( TInt /*aError*/ ) |
|
278 { |
|
279 return KErrNone; |
|
280 } |
|
281 #endif |
|