|
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: Settings item for one destination network. Also handles |
|
15 * saving destination networks to permanent storage. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include <wpdestinationnwadapter.rsg> |
|
23 #include <charconv.h> |
|
24 #include <CWPCharacteristic.h> |
|
25 #include <cmmanagerext.h> |
|
26 #include <cmdestinationext.h> |
|
27 #include <cmconnectionmethodext.h> |
|
28 #include <cmconnectionmethoddef.h> |
|
29 #include <cmpluginwlandef.h> // For WLAN plugin UID, i.e. bearer type. |
|
30 |
|
31 #include "cwpdestinationnwitem.h" |
|
32 #include "wpdestinationnwdebug.h" |
|
33 |
|
34 const TInt KMaxCharsInTUint32 = 10; |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // CWPDestinationNwItem::NewL |
|
38 // |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 CWPDestinationNwItem* CWPDestinationNwItem::NewL() |
|
42 { |
|
43 CWPDestinationNwItem* self = new ( ELeave ) CWPDestinationNwItem(); |
|
44 CleanupStack::PushL( self ); |
|
45 self->ConstructL(); |
|
46 CleanupStack::Pop( self ); |
|
47 return self; |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // CWPDestinationNwItem::CWPDestinationNwItem |
|
52 // |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CWPDestinationNwItem::CWPDestinationNwItem() |
|
56 { |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // CWPDestinationNwItem::~CWPDestinationNwItem |
|
61 // |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 CWPDestinationNwItem::~CWPDestinationNwItem() |
|
65 { |
|
66 DBG_PRINT( "CWPDestinationNwItem::~CWPDestinationNwItem - begin" ); |
|
67 delete iAppRef; |
|
68 delete iSettingsName; |
|
69 iNapDefs.Close(); |
|
70 delete iSavedProfileId; |
|
71 DBG_PRINT( "CWPDestinationNwItem::~CWPDestinationNwItem - end" ); |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // CWPDestinationNwItem::ConstructL |
|
76 // |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 void CWPDestinationNwItem::ConstructL() |
|
80 { |
|
81 DBG_PRINT( "CWPDestinationNwItem::ConstructL - begin" ); |
|
82 iAppRef = HBufC8::NewL( 0 ); |
|
83 iSettingsName = HBufC::NewL( 0 ); |
|
84 iSavedProfileId = HBufC8::NewL( KMaxCharsInTUint32 ); |
|
85 DBG_PRINT( "CWPDestinationNwItem::ConstructL - end" ); |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // CWPDestinationNwItem::SetAppRefL |
|
90 // |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 void CWPDestinationNwItem::SetAppRefL( const TDesC8& aAppRef ) |
|
94 { |
|
95 delete iAppRef; |
|
96 iAppRef = NULL; |
|
97 iAppRef = aAppRef.AllocL(); |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // CWPDestinationNwItem::SetSettingsNameL |
|
102 // |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 void CWPDestinationNwItem::SetSettingsNameL( const TDesC& aSettingsName ) |
|
106 { |
|
107 delete iSettingsName; |
|
108 iSettingsName = NULL; |
|
109 iSettingsName = aSettingsName.AllocL(); |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // CWPDestinationNwItem::AddNapDefL |
|
114 // |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 void CWPDestinationNwItem::AddNapDefL( CWPCharacteristic* aNapDef ) |
|
118 { |
|
119 iNapDefs.AppendL( aNapDef ); |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // CWPDestinationNwItem::AppRef |
|
124 // |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 const TDesC8& CWPDestinationNwItem::AppRef() const |
|
128 { |
|
129 return *iAppRef; |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // CWPDestinationNwItem::SettingsName |
|
134 // |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 const TDesC& CWPDestinationNwItem::SettingsName() const |
|
138 { |
|
139 return *iSettingsName; |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // CWPDestinationNwItem::SaveL() |
|
144 // Saves the Destination network using Extended connection settings API. |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 void CWPDestinationNwItem::SaveL() |
|
148 { |
|
149 DBG_PRINT( "CWPDestinationNwItem::SaveL - begin" ); |
|
150 // Number of IAPs that have been linked to this destination. |
|
151 const TInt iapCount( iNapDefs.Count() ); |
|
152 RCmManagerExt cmManager; |
|
153 cmManager.OpenL(); |
|
154 CleanupClosePushL( cmManager ); // CS:1 |
|
155 RCmDestinationExt destination = CreateDestinationL( cmManager ); |
|
156 CleanupClosePushL( destination ); // CS:2 |
|
157 RCmConnectionMethodExt tempconn; |
|
158 |
|
159 // Add linked IAPs to destination. |
|
160 for ( TInt counter = 0; counter < iapCount; counter++ ) |
|
161 { |
|
162 TPckgBuf<TUint32> apUid; |
|
163 apUid.Copy( iNapDefs[counter]->Data( 0 ) ); |
|
164 // The stored id is the wap id. Convert it into the iap id |
|
165 |
|
166 TUint32 iapId = IapIdFromWapIdL( apUid() ); |
|
167 |
|
168 apUid = NULL; |
|
169 RCmConnectionMethodExt connection = |
|
170 cmManager.ConnectionMethodL( iapId ); |
|
171 CleanupClosePushL( connection ); // CS:5 |
|
172 |
|
173 RArray<TUint32> destinationIds; |
|
174 cmManager.AllDestinationsL( destinationIds ); |
|
175 CleanupClosePushL( destinationIds ); |
|
176 |
|
177 TInt counter2(0); |
|
178 for ( counter2 = 0; counter2 < destinationIds.Count(); counter2++ ) |
|
179 { |
|
180 RCmDestinationExt tempdest = cmManager.DestinationL( |
|
181 destinationIds[counter2] ); |
|
182 |
|
183 TRAPD( err, tempconn = tempdest.ConnectionMethodByIDL( iapId )); |
|
184 |
|
185 tempconn.Close(); |
|
186 tempdest.Close(); |
|
187 |
|
188 if ( err != KErrNotFound ) |
|
189 { |
|
190 // Found from other destination |
|
191 break; |
|
192 } |
|
193 } |
|
194 if ( counter2 == destinationIds.Count() ) |
|
195 { |
|
196 // Not found in any other destination |
|
197 destination.AddConnectionMethodL( connection ); |
|
198 } |
|
199 else |
|
200 { |
|
201 // Found in some other destination -> create copy |
|
202 destination.AddConnectionMethodL( tempconn = connection.CreateCopyL() ); |
|
203 tempconn.Close(); |
|
204 } |
|
205 CleanupStack::PopAndDestroy( &destinationIds ); |
|
206 |
|
207 // Change seamlessness level for linked WLAN IAPs. |
|
208 TUint32 bearerType = connection.GetIntAttributeL( |
|
209 CMManager::ECmBearerType ); |
|
210 if ( KUidWlanBearerType == bearerType ) |
|
211 { |
|
212 connection.SetIntAttributeL( CMManager::ECmSeamlessnessLevel, |
|
213 CMManager::ESeamlessnessShowprogress ); |
|
214 connection.UpdateL(); |
|
215 } |
|
216 |
|
217 destination.UpdateL(); |
|
218 CleanupStack::PopAndDestroy( &connection ); // CS:4 |
|
219 } |
|
220 destination.UpdateL(); // In case there were no IAP linkages. |
|
221 // Destination ID is needed as a descriptor (used in linking settings). |
|
222 TUint32 destinationId = destination.Id(); |
|
223 iSavedProfileId->Des().Num( destinationId, EDecimal ); |
|
224 // Pop destination & cmManager. |
|
225 CleanupStack::PopAndDestroy( 2, &cmManager ); // CS:0 |
|
226 DBG_PRINT( "CWPDestinationNwItem::SaveL - end" ); |
|
227 } |
|
228 |
|
229 // --------------------------------------------------------------------------- |
|
230 // CWPDestinationNwItem::SaveData |
|
231 // |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 const TDesC8& CWPDestinationNwItem::SaveData() const |
|
235 { |
|
236 return *iSavedProfileId; |
|
237 } |
|
238 |
|
239 // --------------------------------------------------------------------------- |
|
240 // CWPDestinationNwItem::CreateDestinationL |
|
241 // Checks that settings name if unique, renames if necessary, and creates |
|
242 // a destination network. |
|
243 // --------------------------------------------------------------------------- |
|
244 // |
|
245 RCmDestinationExt CWPDestinationNwItem::CreateDestinationL( |
|
246 RCmManagerExt& aCmManager ) |
|
247 { |
|
248 DBG_PRINT( "CWPDestinationNwItem::CreateDestinationL - begin" ); |
|
249 RArray<TUint32> destinationIds; |
|
250 // Get destination ID's for checking if name to be set is reserved. |
|
251 CleanupClosePushL( destinationIds ); // CS:1 |
|
252 aCmManager.AllDestinationsL( destinationIds ); |
|
253 const TInt destinationCount = destinationIds.Count(); |
|
254 // Destination's name to actually be used. |
|
255 HBufC* newName = HBufC::NewLC( |
|
256 iSettingsName->Des().Length() + KMaxCharsInTUint32 ); // CS:2 |
|
257 newName->Des().Copy( iSettingsName->Des() ); |
|
258 |
|
259 // Check names from all existing destinations. |
|
260 for ( TInt counter = 0; counter < destinationCount; counter++ ) |
|
261 { |
|
262 RCmDestinationExt destination = aCmManager.DestinationL( |
|
263 destinationIds[counter] ); |
|
264 CleanupClosePushL( destination ); // CS:3 |
|
265 HBufC* settingsName = destination.NameLC(); // CS:4 |
|
266 // If destination exists, return it. |
|
267 if ( 0 == newName->Des().Compare( settingsName->Des() ) ) |
|
268 { |
|
269 // Pop settingsName & destination & newName |
|
270 CleanupStack::PopAndDestroy( 3, &destination ); // CS:1 |
|
271 |
|
272 RCmDestinationExt dest2 = aCmManager.DestinationL( |
|
273 destinationIds[counter] ); |
|
274 |
|
275 CleanupStack::PopAndDestroy( &destinationIds ); // CS:0 |
|
276 DBG_PRINT( "CWPDestinationNwItem::CreateDestinationL - end" ); |
|
277 return dest2; |
|
278 } |
|
279 // Pop settingsName & destination. |
|
280 CleanupStack::PopAndDestroy( 2, &destination ); // CS:2 |
|
281 } |
|
282 |
|
283 // Create new a destination and return it. |
|
284 RCmDestinationExt destination = aCmManager.CreateDestinationL( *newName ); |
|
285 // Pop newName & destinationIds |
|
286 CleanupStack::PopAndDestroy( 2, &destinationIds ); // CS:0 |
|
287 DBG_PRINT( "CWPDestinationNwItem::CreateDestinationL - end" ); |
|
288 return destination; |
|
289 } |
|
290 |
|
291 // --------------------------------------------------------------------------- |
|
292 // CWPDestinationNwItem::IapIdFromWapId |
|
293 // Returns IAP ID from WAP ID. |
|
294 // --------------------------------------------------------------------------- |
|
295 // |
|
296 TUint32 CWPDestinationNwItem::IapIdFromWapIdL( TUint32 aWapId ) |
|
297 { |
|
298 RCmManagerExt cmManager; |
|
299 cmManager.OpenLC(); // CS:1 |
|
300 RArray<TUint32> iapIds; |
|
301 TUint32 iapId( 0 ); |
|
302 |
|
303 // First get all free IAP ID's. |
|
304 cmManager.ConnectionMethodL( iapIds ); |
|
305 CleanupClosePushL( iapIds ); // CS:2 |
|
306 |
|
307 // Then get IAP ID's from all destinations. |
|
308 RArray<TUint32> destIds; |
|
309 cmManager.AllDestinationsL( destIds ); |
|
310 CleanupClosePushL( destIds ); // CS:3 |
|
311 TInt destCount = destIds.Count(); |
|
312 for ( TInt destIndex = 0; destIndex < destCount; destIndex++ ) |
|
313 { |
|
314 RCmDestinationExt dest = cmManager.DestinationL( |
|
315 destIds[destIndex] ); |
|
316 CleanupClosePushL( dest ); // CS:4 |
|
317 TInt cmCount = dest.ConnectionMethodCount(); |
|
318 for ( TInt cmIndex = 0; cmIndex < cmCount; cmIndex++ ) |
|
319 { |
|
320 TUint32 apId = dest.ConnectionMethodL( |
|
321 cmIndex ).GetIntAttributeL( CMManager::ECmIapId ); |
|
322 iapIds.AppendL( apId ); |
|
323 } |
|
324 CleanupStack::PopAndDestroy( &dest ); // CS:3 |
|
325 } |
|
326 // Finally, go through all connection methods and find correct IAP ID. |
|
327 const TInt cmCount = iapIds.Count(); |
|
328 for ( TInt counter = 0; counter < cmCount; counter++ ) |
|
329 { |
|
330 TUint32 id = cmManager.GetConnectionMethodInfoIntL( |
|
331 iapIds[counter], CMManager::ECmWapId ); |
|
332 if ( id == aWapId ) |
|
333 { |
|
334 iapId = iapIds[counter]; |
|
335 // No need to go through rest of IAPs. |
|
336 break; |
|
337 } |
|
338 } |
|
339 // PopAndDestroy destIds, iapIds, cmManager. |
|
340 CleanupStack::PopAndDestroy( 3, &cmManager ); // CS:0 |
|
341 return iapId; |
|
342 } |
|
343 |
|
344 |
|
345 // End of file. |