|
1 /* |
|
2 * Copyright (c) 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: Represents ICE valid list. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "natfwcredentials.h" |
|
22 #include "natfwcandidatepair.h" |
|
23 #include "natfwcandidate.h" |
|
24 #include "cicevalidlist.h" |
|
25 #include "icecandidatehandlerlogs.h" |
|
26 |
|
27 // ======== MEMBER FUNCTIONS ======== |
|
28 |
|
29 CIceValidList::CIceValidList( TUint aCollectionId ) |
|
30 : |
|
31 iCollectionId( aCollectionId ) |
|
32 { |
|
33 __ICEDP( "CIceValidList::CIceValidList" ) |
|
34 } |
|
35 |
|
36 |
|
37 CIceValidList* CIceValidList::NewL( TUint aCollectionId ) |
|
38 { |
|
39 __ICEDP( "CIceValidList::NewL" ) |
|
40 |
|
41 CIceValidList* self |
|
42 = CIceValidList::NewLC( aCollectionId ); |
|
43 CleanupStack::Pop( self ); |
|
44 |
|
45 return self; |
|
46 } |
|
47 |
|
48 |
|
49 CIceValidList* CIceValidList::NewLC( TUint aCollectionId ) |
|
50 { |
|
51 __ICEDP( "CIceValidList::NewLC" ) |
|
52 |
|
53 CIceValidList* self |
|
54 = new( ELeave ) CIceValidList( aCollectionId ); |
|
55 CleanupStack::PushL( self ); |
|
56 |
|
57 return self; |
|
58 } |
|
59 |
|
60 |
|
61 CIceValidList::~CIceValidList() |
|
62 { |
|
63 __ICEDP( "CIceValidList::~CIceValidList" ) |
|
64 |
|
65 iValidList.ResetAndDestroy(); |
|
66 } |
|
67 |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // CIceValidList::StreamCollectionId |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 TUint CIceValidList::StreamCollectionId() const |
|
74 { |
|
75 __ICEDP( "CIceValidList::StreamCollectionId" ) |
|
76 |
|
77 return iCollectionId; |
|
78 } |
|
79 |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // CIceValidList::AddValidPairL |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 void CIceValidList::AddValidPairL( const CNATFWCandidatePair& aPair ) |
|
86 { |
|
87 __ICEDP( "CIceValidList::AddValidPairL" ) |
|
88 |
|
89 // check if existing pair needs to be updated |
|
90 TBool existingPairFound( EFalse ); |
|
91 TInt validPairInd( iValidList.Count() - 1 ); |
|
92 while ( !existingPairFound && 0 <= validPairInd ) |
|
93 { |
|
94 if ( aPair.LocalCandidate().ComponentId() |
|
95 == iValidList[validPairInd]->LocalCandidate().ComponentId() |
|
96 && aPair.Priority() == iValidList[validPairInd]->Priority() ) |
|
97 { |
|
98 existingPairFound = ETrue; |
|
99 iValidList[ validPairInd ]->CopyL( aPair ); |
|
100 } |
|
101 |
|
102 validPairInd--; |
|
103 } |
|
104 |
|
105 if ( !existingPairFound ) |
|
106 { |
|
107 // add new pair to the valid list |
|
108 CNATFWCandidatePair* newPair = CNATFWCandidatePair::NewLC( aPair ); |
|
109 iValidList.InsertInOrderL( |
|
110 newPair, CNATFWCandidatePair::PriorityOrder ); |
|
111 CleanupStack::Pop( newPair ); |
|
112 } |
|
113 } |
|
114 |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // CIceValidList::HasPair |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 TBool CIceValidList::HasPair( const CNATFWCandidatePair& aPair ) const |
|
121 { |
|
122 __ICEDP( "CIceValidList::HasPair" ) |
|
123 |
|
124 TInt ind = iValidList.Find( &aPair, CNATFWCandidatePair::MatchAddresses ); |
|
125 return ( KErrNotFound != ind ); |
|
126 } |
|
127 |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // CIceValidList::HasPairForComponents |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 TBool CIceValidList::HasPairForComponents( |
|
134 RArray<TUint>& aComponentIds ) const |
|
135 { |
|
136 __ICEDP( "CIceValidList::HasPairForComponents" ) |
|
137 |
|
138 TInt numOfComponents( aComponentIds.Count() ); |
|
139 ASSERT( numOfComponents ); |
|
140 TInt numOfValidPairs( iValidList.Count() ); |
|
141 |
|
142 for ( TInt i( 0 ); i < numOfComponents; ++i ) |
|
143 { |
|
144 TUint compId( aComponentIds[i] ); |
|
145 |
|
146 TBool validPairExists( EFalse ); |
|
147 for ( TInt j( 0 ); j < numOfValidPairs; j++ ) |
|
148 { |
|
149 if ( iValidList[j]->LocalCandidate().ComponentId() == compId ) |
|
150 { |
|
151 validPairExists = ETrue; |
|
152 } |
|
153 } |
|
154 |
|
155 if ( !validPairExists ) |
|
156 { |
|
157 __ICEDP( "CIceValidList::HasPairForComponents, EFalse" ) |
|
158 return EFalse; |
|
159 } |
|
160 } |
|
161 |
|
162 __ICEDP( "CIceValidList::HasPairForComponents, ETrue" ) |
|
163 return ETrue; |
|
164 } |
|
165 |
|
166 |
|
167 // --------------------------------------------------------------------------- |
|
168 // CIceValidList::SetPairNominatedL |
|
169 // --------------------------------------------------------------------------- |
|
170 // |
|
171 void CIceValidList::SetPairNominatedL( const CNATFWCandidatePair& aPair ) |
|
172 { |
|
173 __ICEDP( "CIceValidList::SetPairNominatedL" ) |
|
174 |
|
175 TInt ind = iValidList.Find( &aPair, CNATFWCandidatePair::MatchAddresses ); |
|
176 User::LeaveIfError( ind ); |
|
177 |
|
178 iValidList[ind]->SetSelected( ETrue ); |
|
179 } |
|
180 |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // CIceValidList::NominatedPairsExist |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 TBool CIceValidList::NominatedPairsExist( |
|
187 RArray<TUint>& aComponentIds ) const |
|
188 { |
|
189 __ICEDP( "CIceValidList::NominatedPairsExist" ) |
|
190 |
|
191 TInt ind( aComponentIds.Count() ); |
|
192 ASSERT( aComponentIds.Count() ); |
|
193 |
|
194 while ( ind-- ) |
|
195 { |
|
196 if ( NULL == SelectedPair( aComponentIds[ind] ) ) |
|
197 { |
|
198 return EFalse; |
|
199 } |
|
200 } |
|
201 |
|
202 return ETrue; |
|
203 } |
|
204 |
|
205 |
|
206 // --------------------------------------------------------------------------- |
|
207 // CIceValidList::SelectedPair |
|
208 // --------------------------------------------------------------------------- |
|
209 // |
|
210 const CNATFWCandidatePair* |
|
211 CIceValidList::SelectedPair( TUint aComponentId ) const |
|
212 { |
|
213 __ICEDP( "CIceValidList::SelectedPair" ) |
|
214 |
|
215 TInt count( iValidList.Count() ); |
|
216 for ( TInt i( 0 ); i < count; ++i ) |
|
217 { |
|
218 CNATFWCandidatePair* item( iValidList[i] ); |
|
219 if ( item->Selected() |
|
220 && item->LocalCandidate().ComponentId() == aComponentId ) |
|
221 { |
|
222 return item; |
|
223 } |
|
224 } |
|
225 |
|
226 return NULL; |
|
227 } |
|
228 |
|
229 |
|
230 // --------------------------------------------------------------------------- |
|
231 // CIceValidList::HighestPriorityPair |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 const CNATFWCandidatePair* CIceValidList::HighestPriorityPair( |
|
235 TUint aComponentId ) const |
|
236 { |
|
237 __ICEDP( "CIceValidList::HighestPriorityPair" ) |
|
238 |
|
239 TInt count( iValidList.Count() ); |
|
240 for ( TInt i( 0 ); i < count; ++i ) |
|
241 { |
|
242 CNATFWCandidatePair* item( iValidList[i] ); |
|
243 if ( item->LocalCandidate().ComponentId() == aComponentId ) |
|
244 { |
|
245 return item; |
|
246 } |
|
247 } |
|
248 |
|
249 return NULL; |
|
250 } |
|
251 |
|
252 |
|
253 // --------------------------------------------------------------------------- |
|
254 // CIceValidList::FlushValidList |
|
255 // --------------------------------------------------------------------------- |
|
256 // |
|
257 void CIceValidList::FlushValidList() |
|
258 { |
|
259 __ICEDP( "CIceValidList::FlushValidList" ) |
|
260 |
|
261 iValidList.ResetAndDestroy(); |
|
262 } |