25
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2007 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 CWsfWlanInfoArray
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
// EXTERNAL INCLUDES
|
|
21 |
#include <s32mem.h>
|
|
22 |
|
|
23 |
|
|
24 |
// CLASS HEADER
|
|
25 |
#include "wsfwlaninfoarray.h"
|
|
26 |
|
|
27 |
|
|
28 |
// INTERNAL INCLUDES
|
|
29 |
#include "wsfwlaninfoarraysortkey.h"
|
|
30 |
#include "wsfwlaninfoarrayfiltervisitor.h"
|
|
31 |
|
|
32 |
|
|
33 |
using namespace CMManager;
|
|
34 |
|
|
35 |
// LOCAL DEFINITIONS
|
|
36 |
static const TUint KInfoArrayGranuality = 10;
|
|
37 |
|
|
38 |
|
|
39 |
// ---------------------------------------------------------------------------
|
|
40 |
// CWsfWlanInfoArray::NewL
|
|
41 |
// ---------------------------------------------------------------------------
|
|
42 |
//
|
|
43 |
EXPORT_C CWsfWlanInfoArray* CWsfWlanInfoArray::NewL()
|
|
44 |
{
|
|
45 |
CWsfWlanInfoArray* thisPtr = NewLC();
|
|
46 |
CleanupStack::Pop( thisPtr );
|
|
47 |
return thisPtr;
|
|
48 |
}
|
|
49 |
|
|
50 |
|
|
51 |
// ---------------------------------------------------------------------------
|
|
52 |
// CWsfWlanInfoArray::NewLC
|
|
53 |
// ---------------------------------------------------------------------------
|
|
54 |
//
|
|
55 |
EXPORT_C CWsfWlanInfoArray* CWsfWlanInfoArray::NewLC()
|
|
56 |
{
|
|
57 |
CWsfWlanInfoArray* thisPtr = new ( ELeave ) CWsfWlanInfoArray();
|
|
58 |
CleanupStack::PushL( thisPtr );
|
|
59 |
thisPtr->ConstructL();
|
|
60 |
return thisPtr;
|
|
61 |
}
|
|
62 |
|
|
63 |
|
|
64 |
// ---------------------------------------------------------------------------
|
|
65 |
// CWsfWlanInfoArray::~CWsfWlanInfoArray
|
|
66 |
// ---------------------------------------------------------------------------
|
|
67 |
//
|
|
68 |
CWsfWlanInfoArray::~CWsfWlanInfoArray()
|
|
69 |
{
|
|
70 |
if ( iInfoArray )
|
|
71 |
{
|
|
72 |
iInfoArray->ResetAndDestroy();
|
|
73 |
delete iInfoArray;
|
|
74 |
}
|
|
75 |
}
|
|
76 |
|
|
77 |
|
|
78 |
// ---------------------------------------------------------------------------
|
|
79 |
// CWsfWlanInfoArray::CWsfWlanInfoArray
|
|
80 |
// ---------------------------------------------------------------------------
|
|
81 |
//
|
|
82 |
CWsfWlanInfoArray::CWsfWlanInfoArray() :
|
|
83 |
iUIPrioritySort( EFalse )
|
|
84 |
{
|
|
85 |
}
|
|
86 |
|
|
87 |
|
|
88 |
// ---------------------------------------------------------------------------
|
|
89 |
// CWsfWlanInfoArray::ConstructL
|
|
90 |
// ---------------------------------------------------------------------------
|
|
91 |
//
|
|
92 |
void CWsfWlanInfoArray::ConstructL()
|
|
93 |
{
|
|
94 |
iInfoArray = new (ELeave) CArrayPtrFlat<TWsfWlanInfo>(
|
|
95 |
KInfoArrayGranuality );
|
|
96 |
}
|
|
97 |
|
|
98 |
|
|
99 |
// ---------------------------------------------------------------------------
|
|
100 |
// CWsfWlanInfoArray::Reset
|
|
101 |
// ---------------------------------------------------------------------------
|
|
102 |
//
|
|
103 |
EXPORT_C void CWsfWlanInfoArray::Reset()
|
|
104 |
{
|
|
105 |
iInfoArray->ResetAndDestroy();
|
|
106 |
}
|
|
107 |
|
|
108 |
|
|
109 |
// ---------------------------------------------------------------------------
|
|
110 |
// CWsfWlanInfoArray::Count
|
|
111 |
// ---------------------------------------------------------------------------
|
|
112 |
//
|
|
113 |
EXPORT_C TUint CWsfWlanInfoArray::Count()
|
|
114 |
{
|
|
115 |
return iInfoArray->Count();
|
|
116 |
}
|
|
117 |
|
|
118 |
|
|
119 |
// ---------------------------------------------------------------------------
|
|
120 |
// CWsfWlanInfoArray::AppendL
|
|
121 |
// ---------------------------------------------------------------------------
|
|
122 |
//
|
|
123 |
EXPORT_C void CWsfWlanInfoArray::AppendL( TWsfWlanInfo* aWlanInfo )
|
|
124 |
{
|
|
125 |
iInfoArray->AppendL( aWlanInfo );
|
|
126 |
}
|
|
127 |
|
|
128 |
|
|
129 |
// ---------------------------------------------------------------------------
|
|
130 |
// CWsfWlanInfoArray::At
|
|
131 |
// ---------------------------------------------------------------------------
|
|
132 |
//
|
|
133 |
EXPORT_C TWsfWlanInfo* CWsfWlanInfoArray::At( TInt aIndex ) const
|
|
134 |
{
|
|
135 |
TWsfWlanInfo* temp( NULL );
|
|
136 |
TInt count = iInfoArray->Count();
|
|
137 |
|
|
138 |
if ( count && ( aIndex < count ) )
|
|
139 |
{
|
|
140 |
temp = ( *iInfoArray )[aIndex];
|
|
141 |
}
|
|
142 |
return temp;
|
|
143 |
}
|
|
144 |
|
|
145 |
|
|
146 |
// ---------------------------------------------------------------------------
|
|
147 |
// CWsfWlanInfoArray::Delete
|
|
148 |
// ---------------------------------------------------------------------------
|
|
149 |
//
|
|
150 |
EXPORT_C void CWsfWlanInfoArray::Delete( TWsfWlanInfo* aWlanInfo )
|
|
151 |
{
|
|
152 |
TInt count = iInfoArray->Count();
|
|
153 |
|
|
154 |
for( TInt i = 0; i < count; ++i )
|
|
155 |
{
|
|
156 |
if ( ( *iInfoArray )[i] == aWlanInfo )
|
|
157 |
{
|
|
158 |
delete ( *iInfoArray )[i];
|
|
159 |
iInfoArray->Delete( i );
|
|
160 |
iInfoArray->Compress();
|
|
161 |
break;
|
|
162 |
}
|
|
163 |
}
|
|
164 |
|
|
165 |
}
|
|
166 |
|
|
167 |
|
|
168 |
// ---------------------------------------------------------------------------
|
|
169 |
// CWsfWlanInfoArray::GetArrayIndex
|
|
170 |
// ---------------------------------------------------------------------------
|
|
171 |
//
|
|
172 |
EXPORT_C TInt CWsfWlanInfoArray::GetArrayIndex( TWsfWlanInfo* aWlanInfo ) const
|
|
173 |
{
|
|
174 |
TBool found( EFalse );
|
|
175 |
TInt index( 0 );
|
|
176 |
TWsfWlanInfo* temp;
|
|
177 |
TInt count = iInfoArray->Count();
|
|
178 |
|
|
179 |
while( ( index < count ) && !found )
|
|
180 |
{
|
|
181 |
temp = ( *iInfoArray )[index];
|
|
182 |
if ( !temp->iSsid.Compare( aWlanInfo->iSsid ) )
|
|
183 |
{
|
|
184 |
found = ETrue;
|
|
185 |
}
|
|
186 |
else
|
|
187 |
{
|
|
188 |
++index;
|
|
189 |
}
|
|
190 |
}
|
|
191 |
return ( found ? index : KErrNotFound );
|
|
192 |
}
|
|
193 |
|
|
194 |
|
|
195 |
// ---------------------------------------------------------------------------
|
|
196 |
// CWsfWlanInfoArray::operator[]
|
|
197 |
// ---------------------------------------------------------------------------
|
|
198 |
//
|
|
199 |
EXPORT_C TWsfWlanInfo* CWsfWlanInfoArray::operator[]( TUint aIndex ) const
|
|
200 |
{
|
|
201 |
return ( *iInfoArray )[aIndex];
|
|
202 |
}
|
|
203 |
|
|
204 |
|
|
205 |
// ---------------------------------------------------------------------------
|
|
206 |
// CWsfWlanInfoArray::Match
|
|
207 |
// ---------------------------------------------------------------------------
|
|
208 |
//
|
|
209 |
EXPORT_C TWsfWlanInfo* CWsfWlanInfoArray::Match( const TDesC8& aSsid,
|
|
210 |
const TInt aPriorThis )
|
|
211 |
{
|
|
212 |
TInt count = iInfoArray->Count();
|
|
213 |
TWsfWlanInfo* ret( NULL );
|
|
214 |
|
|
215 |
count = count < aPriorThis ? count: aPriorThis;
|
|
216 |
|
|
217 |
for( TInt i = 0; i < count; i++ )
|
|
218 |
{
|
|
219 |
TWsfWlanInfo* temp = ( *iInfoArray )[i];
|
|
220 |
if ( !temp->iSsid.Compare( aSsid ) )
|
|
221 |
{
|
|
222 |
ret = temp;
|
|
223 |
break;
|
|
224 |
}
|
|
225 |
}
|
|
226 |
return ret;
|
|
227 |
}
|
|
228 |
|
|
229 |
|
|
230 |
// ---------------------------------------------------------------------------
|
|
231 |
// CWsfWlanInfoArray::Match
|
|
232 |
// ---------------------------------------------------------------------------
|
|
233 |
//
|
|
234 |
EXPORT_C TWsfWlanInfo* CWsfWlanInfoArray::Match( const TUint32 aIapID,
|
|
235 |
const TInt aPriorThis )
|
|
236 |
{
|
|
237 |
TInt count = iInfoArray->Count();
|
|
238 |
TWsfWlanInfo* ret( NULL );
|
|
239 |
|
|
240 |
count = count < aPriorThis ? count: aPriorThis;
|
|
241 |
|
|
242 |
for( TInt i = 0; i < count; i++ )
|
|
243 |
{
|
|
244 |
TWsfWlanInfo* temp = ( *iInfoArray )[i];
|
|
245 |
if ( temp->iIapId == aIapID )
|
|
246 |
{
|
|
247 |
ret = temp;
|
|
248 |
break;
|
|
249 |
}
|
|
250 |
}
|
|
251 |
return ret;
|
|
252 |
}
|
|
253 |
|
|
254 |
|
|
255 |
// ---------------------------------------------------------------------------
|
|
256 |
// CWsfWlanInfoArray::MatchWithIapIDL
|
|
257 |
// ---------------------------------------------------------------------------
|
|
258 |
//
|
|
259 |
EXPORT_C void CWsfWlanInfoArray::MatchWithIapIDL( const TUint aIapID,
|
|
260 |
const TInt aPriorThis,
|
|
261 |
RPointerArray<TWsfWlanInfo>& aMatchArray )
|
|
262 |
{
|
|
263 |
aMatchArray.Reset();
|
|
264 |
|
|
265 |
TInt count = iInfoArray->Count();
|
|
266 |
TWsfWlanInfo* temp(NULL);
|
|
267 |
|
|
268 |
count = count < aPriorThis ? count: aPriorThis;
|
|
269 |
|
|
270 |
for( TInt i = 0; i < count ; i++ )
|
|
271 |
{
|
|
272 |
temp = ( *iInfoArray )[i];
|
|
273 |
if( temp->iIapId == aIapID )
|
|
274 |
{
|
|
275 |
aMatchArray.AppendL(temp);
|
|
276 |
}
|
|
277 |
}
|
|
278 |
}
|
|
279 |
|
|
280 |
|
|
281 |
// ---------------------------------------------------------------------------
|
|
282 |
// CWsfWlanInfoArray::MatchL
|
|
283 |
// ---------------------------------------------------------------------------
|
|
284 |
//
|
|
285 |
EXPORT_C void CWsfWlanInfoArray::MatchL( const TDesC8& aSsid,
|
|
286 |
CMManager::TWlanSecMode aSecMode,
|
|
287 |
CMManager::TWlanNetMode aNetMode,
|
|
288 |
TBool aUsesPreSharedKey,
|
|
289 |
const TInt aPriorThis,
|
|
290 |
RPointerArray<TWsfWlanInfo>& aMatchArray )
|
|
291 |
{
|
|
292 |
aMatchArray.Reset();
|
|
293 |
|
|
294 |
TInt count = iInfoArray->Count();
|
|
295 |
TWsfWlanInfo* temp(NULL);
|
|
296 |
|
|
297 |
count = count < aPriorThis ? count: aPriorThis;
|
|
298 |
|
|
299 |
for( TInt i = 0; i < count ; i++ )
|
|
300 |
{
|
|
301 |
temp = ( *iInfoArray )[i];
|
|
302 |
if( !temp->iSsid.Compare( aSsid ) && temp->iSecurityMode == aSecMode
|
|
303 |
&& temp->iNetMode == aNetMode )
|
|
304 |
{
|
|
305 |
aMatchArray.AppendL(temp);
|
|
306 |
}
|
|
307 |
else if ( temp->iIapId && !temp->iSsid.Compare( aSsid )
|
|
308 |
&& temp->SecurityMode() == CMManager::EWlanSecMode802_1x
|
|
309 |
&& temp->iNetMode == aNetMode )
|
|
310 |
{
|
|
311 |
if ( aSecMode == CMManager::EWlanSecModeOpen )
|
|
312 |
{
|
|
313 |
aMatchArray.AppendL(temp);
|
|
314 |
}
|
|
315 |
else if ( aSecMode == CMManager::EWlanSecModeWep )
|
|
316 |
{
|
|
317 |
aMatchArray.AppendL(temp);
|
|
318 |
}
|
|
319 |
else if ( aSecMode == CMManager::EWlanSecModeWpa
|
|
320 |
&& !aUsesPreSharedKey )
|
|
321 |
{
|
|
322 |
aMatchArray.AppendL(temp);
|
|
323 |
}
|
|
324 |
else if ( aSecMode == CMManager::EWlanSecMode802_1x )
|
|
325 |
{
|
|
326 |
aMatchArray.AppendL(temp);
|
|
327 |
}
|
|
328 |
}
|
|
329 |
}
|
|
330 |
}
|
|
331 |
// ---------------------------------------------------------------------------
|
|
332 |
// CWsfWlanInfoArray::SerializeContentLC
|
|
333 |
// ---------------------------------------------------------------------------
|
|
334 |
//
|
|
335 |
EXPORT_C HBufC8* CWsfWlanInfoArray::SerializeContentLC()
|
|
336 |
{
|
|
337 |
HBufC8* buffer( NULL );
|
|
338 |
|
|
339 |
if ( !iInfoArray->Count() )
|
|
340 |
{
|
|
341 |
buffer = KNullDesC8().AllocLC();
|
|
342 |
}
|
|
343 |
else
|
|
344 |
{
|
|
345 |
TInt32 requiredBufferSize = sizeof( TUint32 ) +
|
|
346 |
iInfoArray->Count() * sizeof( TWsfWlanInfo );
|
|
347 |
buffer = HBufC8::NewLC( requiredBufferSize );
|
|
348 |
|
|
349 |
// create a stream..
|
|
350 |
TPtr8 bufferPtr = buffer->Des();
|
|
351 |
RDesWriteStream writeStream( bufferPtr );
|
|
352 |
writeStream.Open( bufferPtr);
|
|
353 |
CleanupClosePushL( writeStream );
|
|
354 |
writeStream.WriteInt16L( iInfoArray->Count() );
|
|
355 |
TWsfWlanInfo* infoPtr = NULL;
|
|
356 |
for ( TInt i( 0 ); i < iInfoArray->Count(); i++)
|
|
357 |
{
|
|
358 |
infoPtr = ( *iInfoArray )[i];
|
|
359 |
writeStream << *infoPtr;
|
|
360 |
}
|
|
361 |
writeStream.CommitL();
|
|
362 |
// try to realloc - save space realloc to required level..
|
|
363 |
TStreamPos position = writeStream.Sink()->TellL( MStreamBuf::EWrite );
|
|
364 |
|
|
365 |
CleanupStack::PopAndDestroy( &writeStream ); // closes the stream
|
|
366 |
CleanupStack::Pop( buffer );
|
|
367 |
HBufC8* newBuffer = buffer->ReAlloc( position.Offset() );
|
|
368 |
if ( newBuffer ) // the realloc succeeded - swap the buffer
|
|
369 |
{
|
|
370 |
buffer = newBuffer;
|
|
371 |
}
|
|
372 |
CleanupStack::PushL( buffer);
|
|
373 |
}
|
|
374 |
|
|
375 |
return buffer;
|
|
376 |
}
|
|
377 |
|
|
378 |
|
|
379 |
// ---------------------------------------------------------------------------
|
|
380 |
// CWsfWlanInfoArray::AppendFromStreamBufferL
|
|
381 |
// ---------------------------------------------------------------------------
|
|
382 |
//
|
|
383 |
EXPORT_C TInt CWsfWlanInfoArray::AppendFromStreamBufferL(
|
|
384 |
const TDesC8& aStreamBuffer )
|
|
385 |
{
|
|
386 |
RDesReadStream reader( aStreamBuffer );
|
|
387 |
reader.Open( aStreamBuffer ); // codescanner false alarm
|
|
388 |
// ignoring Open() return value.. Open returns void
|
|
389 |
CleanupClosePushL( reader );
|
|
390 |
|
|
391 |
TInt infoCount = reader.ReadInt16L();
|
|
392 |
|
|
393 |
TWsfWlanInfo *infoPtr = NULL;
|
|
394 |
for ( TInt i(0); i < infoCount; i++ )
|
|
395 |
{
|
|
396 |
infoPtr = new (ELeave)TWsfWlanInfo;
|
|
397 |
CleanupStack::PushL( infoPtr );
|
|
398 |
reader >> *infoPtr;
|
|
399 |
AppendL( infoPtr );
|
|
400 |
CleanupStack::Pop( infoPtr );
|
|
401 |
}
|
|
402 |
|
|
403 |
CleanupStack::PopAndDestroy( &reader );
|
|
404 |
return Count();
|
|
405 |
}
|
|
406 |
|
|
407 |
|
|
408 |
// ---------------------------------------------------------------------------
|
|
409 |
// CWsfWlanInfoArray::FindHiddenEntry
|
|
410 |
// ---------------------------------------------------------------------------
|
|
411 |
//
|
|
412 |
EXPORT_C TWsfWlanInfo* CWsfWlanInfoArray::FindHiddenEntry(
|
|
413 |
const TInt aPriorThis )
|
|
414 |
{
|
|
415 |
TInt count = iInfoArray->Count();
|
|
416 |
TWsfWlanInfo* ret( NULL );
|
|
417 |
count = count < aPriorThis ? count : aPriorThis;
|
|
418 |
|
|
419 |
for ( TInt i = 0; i < count; ++i )
|
|
420 |
{
|
|
421 |
TWsfWlanInfo* temp = ( *iInfoArray )[i];
|
|
422 |
if ( !temp->iVisibility )
|
|
423 |
{
|
|
424 |
ret = temp;
|
|
425 |
break;
|
|
426 |
}
|
|
427 |
}
|
|
428 |
return ret;
|
|
429 |
}
|
|
430 |
|
|
431 |
|
|
432 |
// ---------------------------------------------------------------------------
|
|
433 |
// CWsfWlanInfoArray::DeleteFromTail
|
|
434 |
// ---------------------------------------------------------------------------
|
|
435 |
//
|
|
436 |
EXPORT_C TInt CWsfWlanInfoArray::DeleteFromTail( const TInt aCount )
|
|
437 |
{
|
|
438 |
TInt arrayItemCount = iInfoArray->Count();
|
|
439 |
|
|
440 |
if ( aCount >= arrayItemCount )
|
|
441 |
{
|
|
442 |
iInfoArray->ResetAndDestroy();
|
|
443 |
}
|
|
444 |
else
|
|
445 |
{
|
|
446 |
--arrayItemCount;
|
|
447 |
for ( TInt i( 1 ) ; i <= aCount; ++i, --arrayItemCount )
|
|
448 |
{
|
|
449 |
delete ( *iInfoArray )[arrayItemCount];
|
|
450 |
iInfoArray->Delete( arrayItemCount );
|
|
451 |
}
|
|
452 |
iInfoArray->Compress();
|
|
453 |
}
|
|
454 |
|
|
455 |
return iInfoArray->Count();
|
|
456 |
}
|
|
457 |
|
|
458 |
|
|
459 |
// ---------------------------------------------------------------------------
|
|
460 |
// CWsfWlanInfoArray::SortArrayL
|
|
461 |
// ---------------------------------------------------------------------------
|
|
462 |
//
|
|
463 |
EXPORT_C void CWsfWlanInfoArray::SortArrayL()
|
|
464 |
{
|
|
465 |
if ( iInfoArray->Count() > 1 )
|
|
466 |
{
|
|
467 |
CWsfWlanInfoArraySortKey* sortKey = CWsfWlanInfoArraySortKey::NewLC(
|
|
468 |
*this );
|
|
469 |
|
|
470 |
// Sort returns KErrGeneral if stack overflow, otherwise, returns
|
|
471 |
// KErrNone. So we will Leave only if stack overflow,
|
|
472 |
// but than that really does not matter...
|
|
473 |
User::LeaveIfError( iInfoArray->Sort( *sortKey ) );
|
|
474 |
|
|
475 |
CleanupStack::PopAndDestroy( sortKey );
|
|
476 |
}
|
|
477 |
}
|
|
478 |
|
|
479 |
|
|
480 |
// ---------------------------------------------------------------------------
|
|
481 |
// CWsfWlanInfoArray::SortArrayL
|
|
482 |
// ---------------------------------------------------------------------------
|
|
483 |
//
|
|
484 |
EXPORT_C void CWsfWlanInfoArray::SortArrayL(
|
|
485 |
MWsfWlanInfoArrayFilterVisitor& aSortKey )
|
|
486 |
{
|
|
487 |
// the visitor sortkey may do some other stuff too
|
|
488 |
// so don't make any asumptions...
|
|
489 |
// just go for the sorting...
|
|
490 |
|
|
491 |
aSortKey.FilterPreSortL( this );
|
|
492 |
|
|
493 |
User::LeaveIfError( iInfoArray->Sort( aSortKey.SortingKey() ) );
|
|
494 |
|
|
495 |
aSortKey.FilterPostSortL( this );
|
|
496 |
}
|
|
497 |
|
|
498 |
|
|
499 |
// ---------------------------------------------------------------------------
|
|
500 |
// CWsfWlanInfoArray::SetUIPrioritySort
|
|
501 |
// ---------------------------------------------------------------------------
|
|
502 |
//
|
|
503 |
EXPORT_C void CWsfWlanInfoArray::SetUIPrioritySort( const TBool aUIPrioritySort )
|
|
504 |
{
|
|
505 |
iUIPrioritySort = aUIPrioritySort;
|
|
506 |
}
|
|
507 |
|
|
508 |
|
|
509 |
// ---------------------------------------------------------------------------
|
|
510 |
// CWsfWlanInfoArray::GetUIPrioritySort
|
|
511 |
// ---------------------------------------------------------------------------
|
|
512 |
//
|
|
513 |
EXPORT_C TBool CWsfWlanInfoArray::GetUIPrioritySort( )
|
|
514 |
{
|
|
515 |
return iUIPrioritySort;
|
|
516 |
}
|
|
517 |
|