1 /* |
|
2 * Copyright (c) 2004-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: MPM user dialog handling |
|
15 * |
|
16 */ |
|
17 |
|
18 /** |
|
19 @file mpmdialog.cpp |
|
20 Mobility Policy Manager user dialog initiation. |
|
21 */ |
|
22 |
|
23 // INCLUDE FILES |
|
24 #include <connpref.h> // for TConnPref |
|
25 #include <gsmerror.h> |
|
26 #include <metadatabase.h> |
|
27 #include <datamobilitycommsdattypes.h> |
|
28 #include <commdb.h> |
|
29 #include <bldvariant.hrh> // For feature flags |
|
30 #include <e32property.h> //publish and subscribe |
|
31 |
|
32 #include "mpmdialog.h" |
|
33 #include "mpmlogger.h" |
|
34 #include "mpmdefaultconnection.h" |
|
35 #include "rmpm.h" |
|
36 #include "mpmcommsdataccess.h" |
|
37 |
|
38 // ============================= LOCAL FUNCTIONS =============================== |
|
39 |
|
40 // ============================ MEMBER FUNCTIONS =============================== |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CMPMDialog::NewL |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CMPMDialog* CMPMDialog::NewL( CMPMIapSelection& aIapSelection, |
|
47 const RAvailableIAPList& aIAPList, |
|
48 TUint32 aBearerSet, |
|
49 CArrayPtrFlat<CMPMDialog>& aQueue, |
|
50 CMPMServer& aServer ) |
|
51 { |
|
52 CMPMDialog* self = new ( ELeave ) CMPMDialog( aIapSelection, |
|
53 aBearerSet, |
|
54 aQueue, |
|
55 aServer ); |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL( aIAPList ); |
|
58 CleanupStack::Pop( self ); |
|
59 return self; |
|
60 } |
|
61 |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CMPMDialog::CMPMDialog |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 CMPMDialog::CMPMDialog( CMPMIapSelection& aIapSelection, |
|
68 TUint32 aBearerSet, |
|
69 CArrayPtrFlat<CMPMDialog>& aQueue, |
|
70 CMPMServer& aServer ) |
|
71 : CMPMDialogBase( *(CArrayPtrFlat<CMPMDialogBase>*)&aQueue ), |
|
72 iIapSelection( aIapSelection ), |
|
73 iSnapOrIAPId( 0 ), |
|
74 iBearerSet( aBearerSet ), |
|
75 iServer ( aServer ) |
|
76 { |
|
77 } |
|
78 |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CMPMDialog::~CMPMDialog |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 CMPMDialog::~CMPMDialog() |
|
85 { |
|
86 Cancel(); |
|
87 MPMLOGSTRING2( "CMPMDialog::~CMPMDialog: deleted, Completing with code = %i", |
|
88 iStatus.Int() ) |
|
89 iDlgServ.Close(); |
|
90 // Clean up all other stuff |
|
91 iIAPList.Close(); |
|
92 } |
|
93 |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CMPMDialog::ConstructL |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 void CMPMDialog::ConstructL( const RAvailableIAPList& aIAPList ) |
|
100 { |
|
101 User::LeaveIfError( CopyArray( aIAPList, iIAPList ) ); |
|
102 CMPMDialogBase::ConstructL(); |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CMPMDialog::ConstructL |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 void CMPMDialog::Start( CMPMDialogBase* /*aDlg*/ ) |
|
110 { |
|
111 InitSelectConnection(); |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // CMPMDialog::IntSelectConnection |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void CMPMDialog::InitSelectConnection() |
|
119 { |
|
120 TInt err = iDlgServ.Connect(); |
|
121 // Try to publish sort snap data |
|
122 // |
|
123 if ( err == KErrNone ) |
|
124 { |
|
125 TRAP( err, PublishSortSnapInfoL() ) |
|
126 } |
|
127 if ( err != KErrNone ) |
|
128 { |
|
129 // Jump to RunL() |
|
130 TRequestStatus* status = &iStatus; |
|
131 User::RequestComplete( status, err ); |
|
132 SetActive(); |
|
133 return; |
|
134 } |
|
135 |
|
136 // Map bearer set. bearerSet variable is a combination of values |
|
137 // mapped to TCommDbBearer while iBearerSet is a combination of |
|
138 // TExtendedConnPref::TExtendedConnBearer values. |
|
139 |
|
140 TUint32 bearerSet( ECommDbBearerVirtual ); |
|
141 if ( iBearerSet == TExtendedConnPref::EExtendedConnBearerUnknown ) |
|
142 { |
|
143 bearerSet |= ECommDbBearerCSD | ECommDbBearerWcdma | |
|
144 ECommDbBearerWLAN; |
|
145 } |
|
146 else |
|
147 { |
|
148 if ( iBearerSet & TExtendedConnPref::EExtendedConnBearerWLAN ) |
|
149 { |
|
150 bearerSet |= ECommDbBearerWLAN; |
|
151 } |
|
152 if ( iBearerSet & TExtendedConnPref::EExtendedConnBearerCellular ) |
|
153 { |
|
154 bearerSet |= ECommDbBearerWcdma; |
|
155 } |
|
156 } |
|
157 |
|
158 // API definition was provided by Symbian, but we don't really need |
|
159 // these parameters with AccessPointConnection. |
|
160 // |
|
161 TUint32 unusedVariable( 0 ); |
|
162 |
|
163 /* AccessPointConnection API implements also the ChangeConnection in |
|
164 * the ALR "world", you should also be careful of the input value of |
|
165 * iSnapOrIAPId, because the Destination with the input ElementID is |
|
166 * considered the "current Destination in use", so it will not be |
|
167 * listed by the notifier. So if you really want to see the ALR |
|
168 * version of AccessPointConnection, in input iSnapOrIAPId MUST be |
|
169 * an invalid ElementID (e.g. 0), to be sure that no Destinations |
|
170 * will be removed from the list. |
|
171 */ |
|
172 iDlgServ.AccessPointConnection( unusedVariable, |
|
173 unusedVariable, |
|
174 iSnapOrIAPId, |
|
175 bearerSet, |
|
176 iStatus ); |
|
177 |
|
178 SetActive(); |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CMPMDialog::PublishSortSnapInfoL |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 void CMPMDialog::PublishSortSnapInfoL() |
|
186 { |
|
187 // allow PublishSortSnapInfoL to run only |
|
188 // if the dialog is the first one in the queue. |
|
189 // => First one is active one. |
|
190 if ( !IsFirst() ) |
|
191 { |
|
192 return; |
|
193 } |
|
194 |
|
195 MPMLOGSTRING( "CMPMDialog::PublishSortSnapInfoL" ) |
|
196 RArray<TUint> snaps; |
|
197 CleanupClosePushL( snaps ); |
|
198 |
|
199 // set first snap to 0 as ungathegorised |
|
200 // |
|
201 snaps.AppendL( KSortUncategorisedIaps ); |
|
202 |
|
203 // Find Snap ids |
|
204 // |
|
205 iServer.CommsDatAccess()->FindAllSnapsL( snaps ); |
|
206 |
|
207 // Write iaps for each snap, also 0 is |
|
208 // included for uncategorised |
|
209 // |
|
210 TMpmSnapPubSubFormat snapData; |
|
211 TInt i( 0 ), err( KErrNone ); |
|
212 for(; ( i < snaps.Count() ) && |
|
213 ( i < KMPMSortSnapMaxKey ); i++ ) |
|
214 { |
|
215 snapData.iSnap = snaps[ i ]; |
|
216 snapData.iSortedIaps.Reset(); |
|
217 // Get sorted iaps |
|
218 // |
|
219 iIapSelection.Session()->SortSnapL( snaps[ i ], snapData.iSortedIaps ); |
|
220 |
|
221 // Define pub&sub key if not already defined |
|
222 // |
|
223 err = RProperty::Define( KMPMSortSnapCategory, |
|
224 i, |
|
225 KMPMSortSnapType, |
|
226 KMPMSortSnapReadPolicy, |
|
227 KMPMSortSnapWritePolicy ); |
|
228 |
|
229 if ( err != KErrAlreadyExists && |
|
230 err != KErrNone ) |
|
231 { |
|
232 MPMLOGSTRING2( "CMPMDialog::PublishSortSnapInfoL: error in define: %d ", err ) |
|
233 } |
|
234 |
|
235 TPtrC8 dataPtr( reinterpret_cast< TUint8* >( &snapData ), sizeof( snapData ) ); |
|
236 |
|
237 err = RProperty::Set( KMPMSortSnapCategory, |
|
238 i, |
|
239 dataPtr ); |
|
240 if ( err != KErrNone ) |
|
241 { |
|
242 MPMLOGSTRING2( "CMPMDialog::PublishSortSnapInfoL: error in set: %d ", err ) |
|
243 } |
|
244 MPMLOGSTRING3( "CMPMDialog::PublishSortSnapInfoL: snap %d iap count %d", |
|
245 snapData.iSnap, snapData.iSortedIaps.Count() ) |
|
246 } |
|
247 |
|
248 // set rest of the keys to undefined |
|
249 // |
|
250 while( i < KMPMSortSnapMaxKey ) |
|
251 { |
|
252 err = RProperty::Delete( KMPMSortSnapCategory, i ); |
|
253 if ( err != KErrNotFound && |
|
254 err != KErrNone ) |
|
255 { |
|
256 MPMLOGSTRING2( "CMPMDialog::PublishSortSnapInfoL: error in delete: %d ", err ) |
|
257 } |
|
258 i++; |
|
259 } |
|
260 CleanupStack::PopAndDestroy( &snaps ); |
|
261 } |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CMPMDialog::RunL |
|
265 // ----------------------------------------------------------------------------- |
|
266 // |
|
267 void CMPMDialog::RunL() |
|
268 { |
|
269 MPMLOGSTRING2( "CMPMDialog::RunL: status = %i", |
|
270 iStatus.Int() ) |
|
271 |
|
272 TMDBElementId tableId = iSnapOrIAPId & KCDMaskShowRecordType; |
|
273 TBool isIap( EFalse ); |
|
274 if ( tableId == KCDTIdIAPRecord ) |
|
275 { |
|
276 isIap = ETrue; |
|
277 } |
|
278 |
|
279 // Clean data from publish & subscribe |
|
280 // |
|
281 CleanSortSnapInfo(); |
|
282 |
|
283 TUint32 id = ( iSnapOrIAPId & KCDMaskShowRecordId ) >> KShift8; |
|
284 iIapSelection.HandleUserSelectionL( isIap, id, iStatus.Int() ); |
|
285 } |
|
286 |
|
287 |
|
288 // ----------------------------------------------------------------------------- |
|
289 // CMPMDialog::RunError |
|
290 // ----------------------------------------------------------------------------- |
|
291 // |
|
292 TInt CMPMDialog::RunError(TInt aError) |
|
293 { |
|
294 // Handles a leave occurring in the request completion event handler |
|
295 // RunL(). The active scheduler calls this function if this active |
|
296 // object's RunL() function leaves. This gives this active object |
|
297 // the opportunity to perform any necessary cleanup. |
|
298 // |
|
299 MPMLOGSTRING2( "CMPMDialog::RunError: RunL left with error = %i", aError ) |
|
300 iIapSelection.HandleUserSelectionError( aError ); |
|
301 |
|
302 // Clean data from publish & subscribe |
|
303 // |
|
304 CleanSortSnapInfo(); |
|
305 |
|
306 // Return KErrNone to prevent panic |
|
307 // |
|
308 return KErrNone; |
|
309 } |
|
310 |
|
311 |
|
312 // ----------------------------------------------------------------------------- |
|
313 // CMPMDialog::DoCancel |
|
314 // ----------------------------------------------------------------------------- |
|
315 // |
|
316 void CMPMDialog::DoCancel() |
|
317 { |
|
318 iDlgServ.CancelAccessPointConnection(); |
|
319 // Clean data from publish & subscribe |
|
320 // |
|
321 CleanSortSnapInfo(); |
|
322 } |
|
323 |
|
324 |
|
325 // ----------------------------------------------------------------------------- |
|
326 // CMPMDialog::CopyArray |
|
327 // ----------------------------------------------------------------------------- |
|
328 // |
|
329 TInt CMPMDialog::CopyArray( const RAvailableIAPList& aOrigin, |
|
330 RAvailableIAPList& aCopy ) |
|
331 { |
|
332 TInt err( KErrNone ); |
|
333 |
|
334 // Clean array first |
|
335 // |
|
336 aCopy.Reset(); |
|
337 |
|
338 for( TInt i( 0 ); ( i < aOrigin.Count() ) && ( err == KErrNone ); ++i ) |
|
339 { |
|
340 err = aCopy.Append( aOrigin[i] ); |
|
341 if ( err != KErrNone ) |
|
342 { |
|
343 // Cleanup and return |
|
344 // |
|
345 MPMLOGSTRING2( "CMPMDialog::CopyArray: Append error = %i", err ) |
|
346 aCopy.Reset(); |
|
347 } |
|
348 } |
|
349 |
|
350 return err; |
|
351 } |
|
352 |
|
353 // ----------------------------------------------------------------------------- |
|
354 // CMPMDialog::CleanSortSnapInfoL |
|
355 // ----------------------------------------------------------------------------- |
|
356 // |
|
357 void CMPMDialog::CleanSortSnapInfo() |
|
358 { |
|
359 MPMLOGSTRING( "CMPMDialog::CleanSortSnapInfoL" ) |
|
360 |
|
361 // Clean info from all keys |
|
362 // |
|
363 for( TInt i(0); i < KMPMSortSnapMaxKey; i++ ) |
|
364 { |
|
365 TInt err = RProperty::Delete( KMPMSortSnapCategory, i ); |
|
366 if ( err != KErrNotFound && |
|
367 err != KErrNone ) |
|
368 { |
|
369 MPMLOGSTRING2( "CMPMDialog::CleanSortSnapInfoL: error in delete: %d ", err ) |
|
370 } |
|
371 } |
|
372 } |
|
373 |
|
374 // End of File |
|