|
1 /* |
|
2 * Copyright (c) 2009-2010 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: |
|
15 * Cache side object representing a destination. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <datamobilitycommsdattypes.h> |
|
21 #include <cmpluginembdestinationdef.h> |
|
22 #include <in_sock.h> // KAfInet |
|
23 |
|
24 #include "cmmdestinationstruct.h" |
|
25 #include "cmmtransactionhandler.h" |
|
26 #include "cmmdestinationinstance.h" |
|
27 #include "cmmcache.h" |
|
28 |
|
29 #include "OstTraceDefinitions.h" |
|
30 #ifdef OST_TRACE_COMPILER_IN_USE |
|
31 #include "cmmdestinationstructTraces.h" |
|
32 #endif |
|
33 |
|
34 const TUint KDefaultTierManagerTagId = KAfInet; |
|
35 |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // Two phased construction. |
|
39 // Opens a destination from database based on ID. |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 CCmmDestinationStruct* CCmmDestinationStruct::NewL( |
|
43 CCmmCache* aCache, |
|
44 CCmmTransactionHandler* aTransactionHandler, |
|
45 const TUint32& aDestinationId ) |
|
46 { |
|
47 OstTraceFunctionEntry0( CCMMDESTINATIONSTRUCT_NEWL_ENTRY ); |
|
48 |
|
49 CCmmDestinationStruct* self = CCmmDestinationStruct::NewLC( aCache, aTransactionHandler, aDestinationId ); |
|
50 CleanupStack::Pop( self ); |
|
51 |
|
52 OstTraceFunctionExit0( CCMMDESTINATIONSTRUCT_NEWL_EXIT ); |
|
53 return self; |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // Two phased construction. |
|
58 // Creates a new destination with name and ID (optional). |
|
59 // If ID is 0, a free ID will be used when destination is saved to database. |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 CCmmDestinationStruct* CCmmDestinationStruct::NewL( |
|
63 CCmmCache* aCache, |
|
64 CCmmTransactionHandler* aTransactionHandler, |
|
65 const TDesC& aName, |
|
66 const TUint32& aDestinationId ) |
|
67 { |
|
68 OstTraceFunctionEntry0( DUP1_CCMMDESTINATIONSTRUCT_NEWL_ENTRY ); |
|
69 |
|
70 CCmmDestinationStruct* self = CCmmDestinationStruct::NewLC( aCache, aTransactionHandler, aName, aDestinationId ); |
|
71 CleanupStack::Pop( self ); |
|
72 |
|
73 OstTraceFunctionExit0( DUP1_CCMMDESTINATIONSTRUCT_NEWL_EXIT ); |
|
74 return self; |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // Two phased construction. |
|
79 // Opens a destination from database based on ID. |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 CCmmDestinationStruct* CCmmDestinationStruct::NewLC( |
|
83 CCmmCache* aCache, |
|
84 CCmmTransactionHandler* aTransactionHandler, |
|
85 const TUint32& aDestinationId ) |
|
86 { |
|
87 OstTraceFunctionEntry0( CCMMDESTINATIONSTRUCT_NEWLC_ENTRY ); |
|
88 |
|
89 CCmmDestinationStruct* self = new( ELeave ) CCmmDestinationStruct( aCache, aTransactionHandler ); |
|
90 CleanupStack::PushL( self ); |
|
91 self->ConstructL( aDestinationId ); |
|
92 |
|
93 OstTraceFunctionExit0( CCMMDESTINATIONSTRUCT_NEWLC_EXIT ); |
|
94 return self; |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // Two phased construction. |
|
99 // Creates a new destination with name and ID (optional). |
|
100 // If ID is 0, a free ID will be used when destination is saved to database. |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 CCmmDestinationStruct* CCmmDestinationStruct::NewLC( |
|
104 CCmmCache* aCache, |
|
105 CCmmTransactionHandler* aTransactionHandler, |
|
106 const TDesC& aName, |
|
107 const TUint32& aDestinationId ) |
|
108 { |
|
109 OstTraceFunctionEntry0( DUP1_CCMMDESTINATIONSTRUCT_NEWLC_ENTRY ); |
|
110 |
|
111 CCmmDestinationStruct* self = new( ELeave ) CCmmDestinationStruct( aCache, aTransactionHandler ); |
|
112 CleanupStack::PushL( self ); |
|
113 self->ConstructL( aName, aDestinationId ); |
|
114 |
|
115 OstTraceFunctionExit0( DUP1_CCMMDESTINATIONSTRUCT_NEWLC_EXIT ); |
|
116 return self; |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // Destructor. |
|
121 // Cancels any active requests. |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 CCmmDestinationStruct::~CCmmDestinationStruct() |
|
125 { |
|
126 OstTraceFunctionEntry0( CCMMDESTINATIONSTRUCT_CCMMDESTINATIONSTRUCT_ENTRY ); |
|
127 |
|
128 if ( iReferenceCounter != 0 ) |
|
129 { |
|
130 ASSERT(0); // Error. |
|
131 } |
|
132 delete iNetworkRecord; |
|
133 delete iDestApRecord; |
|
134 delete iMetadataRecord; |
|
135 delete iName; |
|
136 |
|
137 OstTraceFunctionExit0( CCMMDESTINATIONSTRUCT_CCMMDESTINATIONSTRUCT_EXIT ); |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // Constructor. |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 CCmmDestinationStruct::CCmmDestinationStruct( |
|
145 CCmmCache* aCache, |
|
146 CCmmTransactionHandler* aTransactionHandler ) |
|
147 : |
|
148 iCache( aCache ), |
|
149 iTransactionHandler( aTransactionHandler ) |
|
150 { |
|
151 OstTraceFunctionEntry0( DUP1_CCMMDESTINATIONSTRUCT_CCMMDESTINATIONSTRUCT_ENTRY ); |
|
152 |
|
153 iDestApRecord = NULL; |
|
154 iNetworkRecord = NULL; |
|
155 iMetadataRecord = NULL; |
|
156 iDestApRecordStatus = ECmmRecordStatusBlank; |
|
157 iNetworkRecordStatus = ECmmRecordStatusBlank; |
|
158 iMetadataRecordStatus = ECmmRecordStatusBlank; |
|
159 iReferenceCounter = 0; |
|
160 iStatus = ECmmDestinationStatusNotSaved; |
|
161 iId = 0; |
|
162 iName = NULL; |
|
163 |
|
164 OstTraceFunctionExit0( DUP1_CCMMDESTINATIONSTRUCT_CCMMDESTINATIONSTRUCT_EXIT ); |
|
165 } |
|
166 |
|
167 // --------------------------------------------------------------------------- |
|
168 // Second phase constructor. |
|
169 // Opens an existing destination based on ID. |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 void CCmmDestinationStruct::ConstructL( const TUint32& aDestinationId ) |
|
173 { |
|
174 OstTraceFunctionEntry0( CCMMDESTINATIONSTRUCT_CONSTRUCTL_ENTRY ); |
|
175 |
|
176 // Check ID is in valid range. |
|
177 if ( aDestinationId <= KCmDefaultDestinationAPTagId || aDestinationId >= KCmMaxDestinationAPTagId ) |
|
178 { |
|
179 User::Leave( KErrArgument ); |
|
180 } |
|
181 iId = aDestinationId; |
|
182 |
|
183 iDestApRecord = static_cast<CommsDat::CCDAccessPointRecord*>( |
|
184 CommsDat::CCDRecordBase::RecordFactoryL( CommsDat::KCDTIdAccessPointRecord ) ); |
|
185 iNetworkRecord = static_cast<CommsDat::CCDNetworkRecord*>( |
|
186 CommsDat::CCDRecordBase::RecordFactoryL( CommsDat::KCDTIdNetworkRecord ) ); |
|
187 iMetadataRecord = new( ELeave ) CCDSNAPMetadataRecord( |
|
188 iCache->TableId( ECmmDestMetadataRecord ) ); |
|
189 |
|
190 // Load access point record. |
|
191 iDestApRecord->iRecordTag = iId; |
|
192 if ( iDestApRecord->FindL( iTransactionHandler->Session() ) ) |
|
193 { |
|
194 iDestApRecord->LoadL( iTransactionHandler->Session() ); |
|
195 } |
|
196 else |
|
197 { |
|
198 User::Leave( KErrNotFound ); |
|
199 } |
|
200 iDestApRecordStatus = ECmmRecordStatusLoaded; |
|
201 |
|
202 // Load network record. |
|
203 iNetworkRecord->SetRecordId( iDestApRecord->iCustomSelectionPolicy ); |
|
204 iNetworkRecord->LoadL( iTransactionHandler->Session() ); |
|
205 iNetworkRecordStatus = ECmmRecordStatusLoaded; |
|
206 |
|
207 // Load metadata record. |
|
208 iMetadataRecord->iSNAP = iId; |
|
209 if ( !iMetadataRecord->FindL( iTransactionHandler->Session() ) ) |
|
210 { |
|
211 // Not found -> fill in with default values. |
|
212 iMetadataRecord->iSNAP = iId; |
|
213 iMetadataRecord->iMetadata = 0; |
|
214 iMetadataRecord->iIcon = 0; |
|
215 iMetadataRecord->SetRecordId( KCDNewRecordRequest ); |
|
216 iMetadataRecordStatus = ECmmRecordStatusUnsaved; |
|
217 } |
|
218 else |
|
219 { |
|
220 iMetadataRecord->LoadL( iTransactionHandler->Session() ); |
|
221 iMetadataRecordStatus = ECmmRecordStatusLoaded; |
|
222 } |
|
223 |
|
224 SetStatus( ECmmDestinationStatusValid ); |
|
225 |
|
226 OstTraceFunctionExit0( CCMMDESTINATIONSTRUCT_CONSTRUCTL_EXIT ); |
|
227 } |
|
228 |
|
229 // --------------------------------------------------------------------------- |
|
230 // Second phase constructor. |
|
231 // Creates a new destination. With name and optionally also with ID. |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 void CCmmDestinationStruct::ConstructL( const TDesC& aName, const TUint32& aDestinationId ) |
|
235 { |
|
236 OstTraceFunctionEntry0( DUP1_CCMMDESTINATIONSTRUCT_CONSTRUCTL_ENTRY ); |
|
237 |
|
238 SetStatus( ECmmDestinationStatusNotSaved ); |
|
239 iId = aDestinationId; |
|
240 iName = aName.AllocL(); |
|
241 |
|
242 iDestApRecord = static_cast<CommsDat::CCDAccessPointRecord*>( |
|
243 CommsDat::CCDRecordBase::RecordFactoryL( CommsDat::KCDTIdAccessPointRecord ) ); |
|
244 iNetworkRecord = static_cast<CommsDat::CCDNetworkRecord*>( |
|
245 CommsDat::CCDRecordBase::RecordFactoryL( CommsDat::KCDTIdNetworkRecord ) ); |
|
246 iMetadataRecord = new( ELeave ) CCDSNAPMetadataRecord( |
|
247 iCache->TableId( ECmmDestMetadataRecord ) ); |
|
248 |
|
249 if ( aDestinationId >= KTemporaryIdCounterStart ) |
|
250 { |
|
251 // Get a real ID from database during UpdateL(). |
|
252 iNetworkRecord->SetRecordId( KCDNewRecordRequest ); |
|
253 iDestApRecord->iRecordTag = 0; |
|
254 iDestApRecord->iCustomSelectionPolicy = 0; |
|
255 // Access Point record tag ID and custom selection policy value need to |
|
256 // be set during UpdateL(), when network record's record ID is known. |
|
257 // Also metadata record SNAP ID needs to be set. |
|
258 iMetadataRecord->iSNAP = 0; |
|
259 } |
|
260 else |
|
261 { |
|
262 // Client provided an actual ID. |
|
263 iNetworkRecord->SetRecordId( aDestinationId - KCmDefaultDestinationAPTagId ); |
|
264 iDestApRecord->iRecordTag = aDestinationId; |
|
265 iDestApRecord->iCustomSelectionPolicy = ( aDestinationId - KCmDefaultDestinationAPTagId ); |
|
266 iMetadataRecord->iSNAP = aDestinationId; |
|
267 } |
|
268 iDestApRecord->SetRecordId( KCDNewRecordRequest ); |
|
269 |
|
270 iMetadataRecord->iMetadata = 0; |
|
271 iMetadataRecord->SetRecordId( KCDNewRecordRequest ); |
|
272 |
|
273 iNetworkRecord->iRecordName.SetL( aName ); |
|
274 iDestApRecord->iRecordName.SetL( aName ); |
|
275 |
|
276 InitializeDestApRecordL(); |
|
277 |
|
278 iDestApRecordStatus = ECmmRecordStatusUnsaved; |
|
279 iNetworkRecordStatus = ECmmRecordStatusUnsaved; |
|
280 iMetadataRecordStatus = ECmmRecordStatusUnsaved; |
|
281 |
|
282 OstTraceFunctionExit0( DUP1_CCMMDESTINATIONSTRUCT_CONSTRUCTL_EXIT ); |
|
283 } |
|
284 |
|
285 // --------------------------------------------------------------------------- |
|
286 // Set the destination ID. |
|
287 // --------------------------------------------------------------------------- |
|
288 // |
|
289 void CCmmDestinationStruct::SetId( const TUint32& aId ) |
|
290 { |
|
291 iId = aId; |
|
292 } |
|
293 |
|
294 // --------------------------------------------------------------------------- |
|
295 // Get the destination ID. |
|
296 // --------------------------------------------------------------------------- |
|
297 // |
|
298 TUint32 CCmmDestinationStruct::GetId() const |
|
299 { |
|
300 return iId; |
|
301 } |
|
302 |
|
303 // --------------------------------------------------------------------------- |
|
304 // Get the destination ID from network record. To get a valid ID, this must be |
|
305 // called only during or after a call to UpdateL(). |
|
306 // --------------------------------------------------------------------------- |
|
307 // |
|
308 TUint32 CCmmDestinationStruct::GetRealId() const |
|
309 { |
|
310 TUint32 id( iId ); |
|
311 if ( iNetworkRecord ) |
|
312 { |
|
313 id = ( TUint32 )iNetworkRecord->RecordId() + KCmDefaultDestinationAPTagId; |
|
314 } |
|
315 return id; |
|
316 } |
|
317 |
|
318 // --------------------------------------------------------------------------- |
|
319 // Get the destination name. |
|
320 // --------------------------------------------------------------------------- |
|
321 // |
|
322 TDesC& CCmmDestinationStruct::GetDestinationNameL() |
|
323 { |
|
324 OstTraceFunctionEntry0( CCMMDESTINATIONSTRUCT_GETDESTINATIONNAMEL_ENTRY ); |
|
325 |
|
326 // No network record exists if destination has not been saved yet. |
|
327 if ( iStatus == ECmmDestinationStatusNotSaved && iName ) |
|
328 { |
|
329 OstTraceFunctionExit0( CCMMDESTINATIONSTRUCT_GETDESTINATIONNAMEL_EXIT ); |
|
330 return *iName; |
|
331 } |
|
332 |
|
333 if ( iNetworkRecord ) |
|
334 { |
|
335 return iNetworkRecord->iRecordName.GetL(); |
|
336 } |
|
337 |
|
338 User::Leave( KErrCorrupt ); |
|
339 |
|
340 OstTraceFunctionExit0( DUP1_CCMMDESTINATIONSTRUCT_GETDESTINATIONNAMEL_EXIT ); |
|
341 return *iName; |
|
342 } |
|
343 |
|
344 // --------------------------------------------------------------------------- |
|
345 // Gets the current status of this destination struct. |
|
346 // --------------------------------------------------------------------------- |
|
347 // |
|
348 TCmmDestinationStatus CCmmDestinationStruct::GetStatus() const |
|
349 { |
|
350 return iStatus; |
|
351 } |
|
352 |
|
353 // --------------------------------------------------------------------------- |
|
354 // Get the current reference count. |
|
355 // --------------------------------------------------------------------------- |
|
356 // |
|
357 TInt CCmmDestinationStruct::GetReferenceCount() const |
|
358 { |
|
359 return iReferenceCounter; |
|
360 } |
|
361 |
|
362 // --------------------------------------------------------------------------- |
|
363 // Set the current status of this destination. |
|
364 // ECmmDestinationStatusValid: Destination exists in database. |
|
365 // ECmmDestinationStatusNotSaved: Destination does NOT exist in database yet. |
|
366 // --------------------------------------------------------------------------- |
|
367 // |
|
368 void CCmmDestinationStruct::SetStatus( const TCmmDestinationStatus& aStatus ) |
|
369 { |
|
370 OstTraceFunctionEntry0( CCMMDESTINATIONSTRUCT_SETSTATUS_ENTRY ); |
|
371 |
|
372 switch ( aStatus ) |
|
373 { |
|
374 case ECmmDestinationStatusValid: |
|
375 { |
|
376 if ( iStatus == ECmmDestinationStatusNotSaved ) |
|
377 { |
|
378 delete iName; |
|
379 iName = NULL; |
|
380 } |
|
381 } |
|
382 // Fallthrough intended. |
|
383 case ECmmDestinationStatusNotSaved: |
|
384 case ECmmDestinationStatusToBeDeleted: |
|
385 { |
|
386 // Set the status. |
|
387 iStatus = aStatus; |
|
388 } |
|
389 break; |
|
390 default: |
|
391 ASSERT( 0 ); // Error, invalid status. |
|
392 break; |
|
393 } |
|
394 |
|
395 OstTraceFunctionExit0( CCMMDESTINATIONSTRUCT_SETSTATUS_EXIT ); |
|
396 } |
|
397 |
|
398 // --------------------------------------------------------------------------- |
|
399 // Set the record status for all records. |
|
400 // --------------------------------------------------------------------------- |
|
401 // |
|
402 void CCmmDestinationStruct::SetStatusForAllRecords( const TCmmRecordStatus& aStatus ) |
|
403 { |
|
404 OstTraceFunctionEntry0( CCMMDESTINATIONSTRUCT_SETSTATUSFORALLRECORDS_ENTRY ); |
|
405 |
|
406 iDestApRecordStatus = aStatus; |
|
407 iNetworkRecordStatus = aStatus; |
|
408 iMetadataRecordStatus = aStatus; |
|
409 |
|
410 OstTraceFunctionExit0( CCMMDESTINATIONSTRUCT_SETSTATUSFORALLRECORDS_EXIT ); |
|
411 } |
|
412 |
|
413 // --------------------------------------------------------------------------- |
|
414 // Copies the data for this destination to a session instance and increments |
|
415 // the reference counter by one. |
|
416 // --------------------------------------------------------------------------- |
|
417 // |
|
418 void CCmmDestinationStruct::CreateSessionInstanceL( |
|
419 CCmmDestinationInstance& aDestinationInstance ) |
|
420 { |
|
421 OstTraceFunctionEntry0( CCMMDESTINATIONSTRUCT_CREATESESSIONINSTANCEL_ENTRY ); |
|
422 |
|
423 // This should work according to status. If status is valid, this |
|
424 // destination exists in commsdat, and other sessions can also open a handle |
|
425 // to it. Make copies of the records to give to session instance. |
|
426 // |
|
427 // If the status is unsaved, then this is a new destination that hasn't |
|
428 // been saved to commsdat yet. Thus no other session can open a handle to it |
|
429 // until it is saved with a call to UpdateL(). |
|
430 // For a non-valid destination, to save memory, transfer the ownership of |
|
431 // record pointers straight to the session and mark the cache pointers as |
|
432 // NULL. When update is called, copy the records into the cache also. |
|
433 // |
|
434 |
|
435 switch ( iStatus ) //TODO, add missing status values |
|
436 { |
|
437 case ECmmDestinationStatusNotSaved: |
|
438 { |
|
439 // Transfer ownership of table records to session. Mark local pointers to NULL. |
|
440 |
|
441 aDestinationInstance.SetRecordPointer( ECmmDestApRecord, iDestApRecord ); // iDestApRecord ownership is transfered. |
|
442 aDestinationInstance.SetRecordPointer( ECmmDestNetworkRecord, iNetworkRecord ); // iNetworkRecord ownership is transfered. |
|
443 aDestinationInstance.SetRecordPointer( ECmmDestMetadataRecord, iMetadataRecord ); // iMetadataRecord ownership is transfered. |
|
444 iDestApRecord = NULL; |
|
445 iNetworkRecord = NULL; |
|
446 iMetadataRecord = NULL; |
|
447 iDestApRecordStatus = ECmmRecordStatusBlank; |
|
448 iNetworkRecordStatus = ECmmRecordStatusBlank; |
|
449 iMetadataRecordStatus = ECmmRecordStatusBlank; |
|
450 |
|
451 aDestinationInstance.SetId( iId ); |
|
452 aDestinationInstance.SetStatus( ECmmDestinationStatusChanged ); |
|
453 } |
|
454 break; |
|
455 case ECmmDestinationStatusValid: |
|
456 { |
|
457 // Reload table records if needed, make copies and transfer those to session. |
|
458 LoadRecordL( aDestinationInstance, ECmmDestApRecord ); |
|
459 LoadRecordL( aDestinationInstance, ECmmDestNetworkRecord ); |
|
460 LoadRecordL( aDestinationInstance, ECmmDestMetadataRecord ); |
|
461 |
|
462 aDestinationInstance.SetId( iId ); |
|
463 aDestinationInstance.SetStatus( ECmmDestinationStatusValid ); |
|
464 } |
|
465 break; |
|
466 default: |
|
467 User::Leave( KErrCorrupt ); // Invalid status. |
|
468 break; |
|
469 } |
|
470 |
|
471 // A session handle has been made, increment reference counter. |
|
472 iReferenceCounter++; |
|
473 |
|
474 OstTraceFunctionExit0( CCMMDESTINATIONSTRUCT_CREATESESSIONINSTANCEL_EXIT ); |
|
475 } |
|
476 |
|
477 // --------------------------------------------------------------------------- |
|
478 // TODO |
|
479 // --------------------------------------------------------------------------- |
|
480 // |
|
481 void CCmmDestinationStruct::RefreshDestinationInstanceL( |
|
482 CCmmDestinationInstance& aDestinationInstance ) |
|
483 { |
|
484 OstTraceFunctionEntry0( CCMMDESTINATIONSTRUCT_REFRESHSESSIONINSTANCEL_ENTRY ); |
|
485 |
|
486 switch ( iStatus ) |
|
487 { |
|
488 case ECmmDestinationStatusValid: |
|
489 case ECmmDestinationStatusToBeDeleted: |
|
490 { |
|
491 // Reload table records if needed, make copies and transfer those to session. |
|
492 LoadRecordL( aDestinationInstance, ECmmDestApRecord ); |
|
493 LoadRecordL( aDestinationInstance, ECmmDestNetworkRecord ); |
|
494 LoadRecordL( aDestinationInstance, ECmmDestMetadataRecord ); |
|
495 } |
|
496 break; |
|
497 case ECmmDestinationStatusNotSaved: // This was checked before. |
|
498 case ECmmDestinationStatusChanged: |
|
499 default: |
|
500 User::Leave( KErrCorrupt ); // Invalid status. |
|
501 break; |
|
502 } |
|
503 |
|
504 // Add list of currently contained connection methods. |
|
505 iCache->GetConnMethodsFromDestinationL( |
|
506 aDestinationInstance.GetId(), |
|
507 aDestinationInstance.iConnMethodItemArray ); |
|
508 |
|
509 // Internal state need to be set to the same state as after a successfull update. |
|
510 aDestinationInstance.UpdateSuccessful(); |
|
511 |
|
512 OstTraceFunctionExit0( CCMMDESTINATIONSTRUCT_REFRESHSESSIONINSTANCEL_EXIT ); |
|
513 } |
|
514 |
|
515 // --------------------------------------------------------------------------- |
|
516 // Re-loads a destination record if needed and copies the latest version to |
|
517 // the session instance given as parameter. |
|
518 // --------------------------------------------------------------------------- |
|
519 // |
|
520 void CCmmDestinationStruct::LoadRecordL( |
|
521 CCmmDestinationInstance& aDestinationInstance, |
|
522 TCmmDbRecords aRecordType ) |
|
523 { |
|
524 OstTraceFunctionEntry0( CCMMDESTINATIONSTRUCT_LOADRECORDL_ENTRY ); |
|
525 |
|
526 if ( iStatus != ECmmDestinationStatusValid && iStatus != ECmmDestinationStatusToBeDeleted ) |
|
527 { |
|
528 // Destination must exist in database to be able to load any records. |
|
529 User::Leave( KErrCorrupt ); |
|
530 } |
|
531 |
|
532 // Record status: Action: |
|
533 // |
|
534 // ECmmRecordStatusBlank Error |
|
535 // ECmmRecordStatusLoaded Skip load, already loaded |
|
536 // ECmmRecordStatusExpired Load record from database |
|
537 // ECmmRecordStatusModified Error, session side only status |
|
538 // ECmmRecordStatusUnsaved Skip load, not in database |
|
539 |
|
540 CommsDat::CCDRecordBase* aRecordPointer; |
|
541 |
|
542 switch ( aRecordType ) |
|
543 { |
|
544 case ECmmDestNetworkRecord: |
|
545 { |
|
546 if ( iNetworkRecordStatus == ECmmRecordStatusExpired ) |
|
547 { |
|
548 iNetworkRecord->LoadL( iTransactionHandler->Session() ); |
|
549 iNetworkRecordStatus = ECmmRecordStatusLoaded; |
|
550 } |
|
551 else if ( iNetworkRecordStatus == ECmmRecordStatusBlank || |
|
552 iNetworkRecordStatus == ECmmRecordStatusModified ) |
|
553 { |
|
554 User::Leave( KErrCorrupt ); |
|
555 } |
|
556 aRecordPointer = CopyRecordL( |
|
557 ECmmDestNetworkRecord, |
|
558 static_cast<CommsDat::CCDRecordBase*>( iNetworkRecord ) ); |
|
559 aDestinationInstance.SetRecordPointer( |
|
560 ECmmDestNetworkRecord, |
|
561 aRecordPointer ); // Ownership is transfered. |
|
562 } |
|
563 break; |
|
564 case ECmmDestApRecord: |
|
565 { |
|
566 if ( iDestApRecordStatus == ECmmRecordStatusExpired ) |
|
567 { |
|
568 iDestApRecord->LoadL( iTransactionHandler->Session() ); |
|
569 iDestApRecordStatus = ECmmRecordStatusLoaded; |
|
570 } |
|
571 aRecordPointer = CopyRecordL( |
|
572 ECmmDestApRecord, |
|
573 static_cast<CommsDat::CCDRecordBase*>( iDestApRecord ) ); |
|
574 aDestinationInstance.SetRecordPointer( |
|
575 ECmmDestApRecord, |
|
576 aRecordPointer ); // Ownership is transfered. |
|
577 } |
|
578 break; |
|
579 case ECmmDestMetadataRecord: |
|
580 { |
|
581 if ( iMetadataRecordStatus == ECmmRecordStatusExpired ) |
|
582 { |
|
583 iMetadataRecord->LoadL( iTransactionHandler->Session() ); |
|
584 iMetadataRecordStatus = ECmmRecordStatusLoaded; |
|
585 } |
|
586 aRecordPointer = CopyRecordL( |
|
587 ECmmDestMetadataRecord, |
|
588 static_cast<CommsDat::CCDRecordBase*>( iMetadataRecord ) ); |
|
589 aDestinationInstance.SetRecordPointer( |
|
590 ECmmDestMetadataRecord, |
|
591 aRecordPointer ); // Ownership is transfered. |
|
592 } |
|
593 break; |
|
594 default: |
|
595 { |
|
596 User::Leave( KErrArgument ); |
|
597 } |
|
598 break; |
|
599 } |
|
600 aRecordPointer = NULL; |
|
601 |
|
602 OstTraceFunctionExit0( CCMMDESTINATIONSTRUCT_LOADRECORDL_EXIT ); |
|
603 } |
|
604 |
|
605 // --------------------------------------------------------------------------- |
|
606 // Save the contents of a session side destination handle into database. |
|
607 // --------------------------------------------------------------------------- |
|
608 // |
|
609 void CCmmDestinationStruct::UpdateL( |
|
610 CCmmDestinationInstance& aDestinationInstance, |
|
611 CCmmCache* aCache ) |
|
612 { |
|
613 OstTraceFunctionEntry0( CCMMDESTINATIONSTRUCT_UPDATEL_ENTRY ); |
|
614 |
|
615 // Structure: |
|
616 // - Use ModifyL() or StoreL() according to own status (new destination or |
|
617 // changes to existing one). |
|
618 // |
|
619 // - Update (store/modify) records to database using client copies. |
|
620 // - Free local record tables. |
|
621 // - Copy record tables from client instance into cache. |
|
622 // - Update DataMobilitySelectionPolicy-records. |
|
623 // |
|
624 |
|
625 TInt id( iId ); |
|
626 switch ( aDestinationInstance.GetStatus() ) |
|
627 { |
|
628 case ECmmDestinationStatusValid: |
|
629 { |
|
630 if ( iStatus != ECmmDestinationStatusValid ) //TODO, how will external db changes affect this? |
|
631 { |
|
632 // Error, a 'valid'-status on session side implies a 'valid'-status on cache side. |
|
633 User::Leave( KErrCorrupt ); |
|
634 } |
|
635 } |
|
636 // Fallthrough intended. |
|
637 case ECmmDestinationStatusChanged: |
|
638 { |
|
639 CommsDat::CCDRecordBase* recordPointer; |
|
640 |
|
641 // Get pointers to destination records in client instance. |
|
642 aDestinationInstance.GetRecordPointer( ECmmDestApRecord, recordPointer ); |
|
643 CommsDat::CCDAccessPointRecord* instanceDestApRecord = |
|
644 static_cast<CommsDat::CCDAccessPointRecord*>( recordPointer ); |
|
645 aDestinationInstance.GetRecordPointer( ECmmDestNetworkRecord, recordPointer ); |
|
646 CommsDat::CCDNetworkRecord* instanceNetworkRecord = |
|
647 static_cast<CommsDat::CCDNetworkRecord*>( recordPointer ); |
|
648 aDestinationInstance.GetRecordPointer( ECmmDestMetadataRecord, recordPointer ); |
|
649 CCDSNAPMetadataRecord* instanceMetadataRecord = |
|
650 static_cast<CCDSNAPMetadataRecord*>( recordPointer ); |
|
651 |
|
652 recordPointer = NULL; |
|
653 |
|
654 switch ( iStatus ) |
|
655 { |
|
656 case ECmmDestinationStatusNotSaved: |
|
657 { |
|
658 // This is a new destination that doesn't exist in database yet. |
|
659 |
|
660 // Store network record first, the record ID is needed for |
|
661 // destination access point record. |
|
662 // Record ID for network record is set during construction. |
|
663 |
|
664 //TODO, Check method call from old CmManager: |
|
665 //TODO, SetAttribute( iData->iNetworkRecord, ECDProtectedWrite, ProtectionLevel() == EProtLevel1 ); |
|
666 instanceNetworkRecord->StoreL( iTransactionHandler->Session() ); |
|
667 |
|
668 // If ID is out of valid range, it means this destination was created |
|
669 // without a specific ID. It is a temporary ID and can now be replaced |
|
670 // with the real database ID. This also enables this destination to be |
|
671 // opened by other clients. |
|
672 // Record ID from network record must be used as real ID. |
|
673 if ( iId >= KTemporaryIdCounterStart ) |
|
674 { |
|
675 id = instanceNetworkRecord->RecordId() + KCmDefaultDestinationAPTagId; |
|
676 instanceDestApRecord->iRecordTag = id; |
|
677 instanceDestApRecord->iCustomSelectionPolicy = ( id - KCmDefaultDestinationAPTagId ); |
|
678 instanceMetadataRecord->iSNAP = id; |
|
679 } |
|
680 instanceDestApRecord->StoreL( iTransactionHandler->Session() ); |
|
681 instanceMetadataRecord->StoreL( iTransactionHandler->Session() ); |
|
682 } |
|
683 break; |
|
684 |
|
685 case ECmmDestinationStatusValid: |
|
686 case ECmmDestinationStatusToBeDeleted: |
|
687 { |
|
688 // This destination already exists in database and is beeing modified. |
|
689 |
|
690 //TODO, Check method call from old CmManager: |
|
691 //TODO, SetAttribute( iData->iNetworkRecord, ECDProtectedWrite, ProtectionLevel() == EProtLevel1 ); |
|
692 instanceNetworkRecord->ModifyL( iTransactionHandler->Session() ); |
|
693 instanceDestApRecord->ModifyL( iTransactionHandler->Session() ); |
|
694 if ( iMetadataRecordStatus == ECmmRecordStatusUnsaved ) |
|
695 { |
|
696 instanceMetadataRecord->StoreL( iTransactionHandler->Session() ); |
|
697 } |
|
698 else |
|
699 { |
|
700 instanceMetadataRecord->ModifyL( iTransactionHandler->Session() ); |
|
701 } |
|
702 } |
|
703 break; |
|
704 case ECmmDestinationStatusChanged: |
|
705 default: |
|
706 User::Leave( KErrCorrupt ); // Error, invalid status. |
|
707 break; |
|
708 } |
|
709 |
|
710 // Copy destination records from client instance into cache. |
|
711 delete iDestApRecord; |
|
712 delete iNetworkRecord; |
|
713 delete iMetadataRecord; |
|
714 iDestApRecord = NULL; |
|
715 iNetworkRecord = NULL; |
|
716 iMetadataRecord = NULL; |
|
717 iDestApRecordStatus = ECmmRecordStatusBlank; |
|
718 iNetworkRecordStatus = ECmmRecordStatusBlank; |
|
719 iMetadataRecordStatus = ECmmRecordStatusBlank; |
|
720 iDestApRecord = static_cast<CommsDat::CCDAccessPointRecord*>( CopyRecordL( ECmmDestApRecord, instanceDestApRecord ) ); |
|
721 iNetworkRecord = static_cast<CommsDat::CCDNetworkRecord*>( CopyRecordL( ECmmDestNetworkRecord, instanceNetworkRecord ) ); |
|
722 iMetadataRecord = static_cast<CCDSNAPMetadataRecord*>( CopyRecordL( ECmmDestMetadataRecord, instanceMetadataRecord ) ); |
|
723 |
|
724 instanceDestApRecord = NULL; |
|
725 instanceNetworkRecord = NULL; |
|
726 instanceMetadataRecord = NULL; |
|
727 |
|
728 |
|
729 |
|
730 // Write DataMobilitySelectionPolicy-records into database. |
|
731 TInt neededRecordCount( aDestinationInstance.iConnMethodItemArray.Count() ); // +1 for destination itself. |
|
732 TInt existingRecordCount( 0 ); |
|
733 |
|
734 // Create DataMobilitySelectionPolicy-record set. |
|
735 CommsDat::CMDBRecordSet<CCDDataMobilitySelectionPolicyRecord>* snapRecordSet = |
|
736 new( ELeave ) CommsDat::CMDBRecordSet<CCDDataMobilitySelectionPolicyRecord>( |
|
737 iCache->TableId( ECmmDbSnapRecord ) ); |
|
738 CleanupStack::PushL( snapRecordSet ); |
|
739 |
|
740 // Create a DataMobilitySelectionPolicy-record to prime the set. |
|
741 CCDDataMobilitySelectionPolicyRecord* snapRecordPrime = |
|
742 new( ELeave ) CCDDataMobilitySelectionPolicyRecord( |
|
743 iCache->TableId( ECmmDbSnapRecord ) ); |
|
744 CleanupStack::PushL( snapRecordPrime ); |
|
745 |
|
746 snapRecordPrime->iSNAP = id; |
|
747 snapRecordSet->iRecords.AppendL( snapRecordPrime ); |
|
748 CleanupStack::Pop( snapRecordPrime ); // Ownership moved. |
|
749 |
|
750 // Find matching DataMobilitySelectionPolicy-records. |
|
751 if ( snapRecordSet->FindL( iTransactionHandler->Session() ) ) |
|
752 { |
|
753 existingRecordCount = snapRecordSet->iRecords.Count(); |
|
754 } |
|
755 |
|
756 CCDDataMobilitySelectionPolicyRecord* snapRecord1 = |
|
757 new( ELeave ) CCDDataMobilitySelectionPolicyRecord( |
|
758 iCache->TableId( ECmmDbSnapRecord ) ); |
|
759 CleanupStack::PushL( snapRecord1 ); |
|
760 |
|
761 // Current index in snapRecordSet. |
|
762 TInt index( 0 ); |
|
763 |
|
764 // Initial record for destination itself. |
|
765 snapRecord1->iSNAP = id; |
|
766 snapRecord1->iRecordName.SetL( iNetworkRecord->iRecordName.GetL() ); |
|
767 if ( existingRecordCount > index ) |
|
768 { |
|
769 snapRecord1->SetElementId( snapRecordSet->iRecords[index]->ElementId() ); |
|
770 snapRecord1->iEmbeddedSNAP = 0; |
|
771 snapRecord1->iIAP = 0; |
|
772 snapRecord1->iPriority = 0; |
|
773 snapRecord1->ModifyL( iTransactionHandler->Session() ); |
|
774 index++; |
|
775 } |
|
776 else |
|
777 { |
|
778 snapRecord1->SetRecordId( KCDNewRecordRequest ); |
|
779 snapRecord1->StoreL( iTransactionHandler->Session() ); |
|
780 } |
|
781 CleanupStack::PopAndDestroy( snapRecord1 ); |
|
782 |
|
783 // Records for destination contents. |
|
784 for ( TInt i = 0; i < neededRecordCount; i++ ) |
|
785 { |
|
786 // Weird stuff starts to happen in commsdat side if we try to |
|
787 // reuse a snap-record, so create new record for each entry. |
|
788 CCDDataMobilitySelectionPolicyRecord* snapRecord2 = |
|
789 new( ELeave ) CCDDataMobilitySelectionPolicyRecord( |
|
790 iCache->TableId( ECmmDbSnapRecord ) ); |
|
791 CleanupStack::PushL( snapRecord2 ); |
|
792 |
|
793 snapRecord2->iSNAP = id; |
|
794 snapRecord2->iRecordName.SetL( iNetworkRecord->iRecordName.GetL() ); |
|
795 |
|
796 // If the connection method was added to destination while |
|
797 // still having a temporary ID, update the ID to real ID. |
|
798 TUint32 connMethodRealId( aDestinationInstance.iConnMethodItemArray[i].iId ); |
|
799 if ( connMethodRealId >= KTemporaryIdCounterStart ) |
|
800 { |
|
801 aCache->TranslateTemporaryId( |
|
802 aDestinationInstance.iConnMethodItemArray[i].iId, |
|
803 connMethodRealId ); |
|
804 } |
|
805 |
|
806 //TODO, if protection level is 1 (dest AND CMs), set ECDProtectedWrite. See oldimplementation. |
|
807 |
|
808 if ( aDestinationInstance.iConnMethodItemArray[i].iBearerType == KUidEmbeddedDestination ) |
|
809 { |
|
810 // Embedded destination. |
|
811 snapRecord2->iEmbeddedSNAP = ( TInt )connMethodRealId; |
|
812 snapRecord2->iIAP = 0; |
|
813 snapRecord2->iPriority = |
|
814 CMManager::KDataMobilitySelectionPolicyPriorityWildCard; |
|
815 aDestinationInstance.iConnMethodItemArray[i].iPriority = |
|
816 CMManager::KDataMobilitySelectionPolicyPriorityWildCard; // Update this just in case. |
|
817 } |
|
818 else |
|
819 { |
|
820 // Normal connection method. |
|
821 snapRecord2->iEmbeddedSNAP = 0; |
|
822 snapRecord2->iIAP = ( KCDMaskShowField & CommsDat::KCDTIdIAPRecord ) | ( connMethodRealId << 8 ); |
|
823 snapRecord2->iPriority = i + 1; // Priority values start from 1. |
|
824 aDestinationInstance.iConnMethodItemArray[i].iPriority = i + 1; // Update this just in case. |
|
825 } |
|
826 |
|
827 if ( existingRecordCount > index ) |
|
828 { |
|
829 // An old record can be reused. |
|
830 snapRecord2->SetElementId( snapRecordSet->iRecords[index]->ElementId() ); |
|
831 snapRecord2->ModifyL( iTransactionHandler->Session() ); |
|
832 index++; |
|
833 } |
|
834 else |
|
835 { |
|
836 // A new record must be created. |
|
837 snapRecord2->SetRecordId( KCDNewRecordRequest ); |
|
838 snapRecord2->StoreL( iTransactionHandler->Session() ); |
|
839 } |
|
840 CleanupStack::PopAndDestroy( snapRecord2 ); |
|
841 } |
|
842 |
|
843 // Delete any extra records. |
|
844 while ( existingRecordCount > index ) |
|
845 { |
|
846 CCDDataMobilitySelectionPolicyRecord* snapRecord3 = |
|
847 new( ELeave ) CCDDataMobilitySelectionPolicyRecord( |
|
848 iCache->TableId( ECmmDbSnapRecord ) ); |
|
849 CleanupStack::PushL( snapRecord3 ); |
|
850 snapRecord3->SetElementId( snapRecordSet->iRecords[index]->ElementId() ); |
|
851 snapRecord3->DeleteL( iTransactionHandler->Session() ); |
|
852 CleanupStack::PopAndDestroy( snapRecord3 ); |
|
853 index++; |
|
854 } |
|
855 |
|
856 |
|
857 CleanupStack::PopAndDestroy( snapRecordSet ); |
|
858 } |
|
859 break; |
|
860 case ECmmDestinationStatusNotSaved: |
|
861 case ECmmDestinationStatusToBeDeleted: |
|
862 default: |
|
863 User::Leave( KErrCorrupt ); // Error, invalid status. |
|
864 break; |
|
865 } |
|
866 |
|
867 // Do not update destination status or record status values yet. Cache |
|
868 // will set them after successfully commiting transaction to database. |
|
869 |
|
870 OstTraceFunctionExit0( CCMMDESTINATIONSTRUCT_UPDATEL_EXIT ); |
|
871 } |
|
872 |
|
873 // --------------------------------------------------------------------------- |
|
874 // Delete all database records of this destination. Also removes any records |
|
875 // making this destination an embedded destination in another destination. |
|
876 // --------------------------------------------------------------------------- |
|
877 // |
|
878 void CCmmDestinationStruct::DeleteL() |
|
879 { |
|
880 OstTraceFunctionEntry0( CCMMDESTINATIONSTRUCT_DELETEL_ENTRY ); |
|
881 |
|
882 // Check general status. |
|
883 /*switch ( iStatus ) //TODO, already done? yes, cleanup |
|
884 { |
|
885 case ECmmDestinationStatusNotSaved: |
|
886 { |
|
887 // Doesn'texist in database. |
|
888 User::Leave( KErrNotFound ); |
|
889 } |
|
890 break; |
|
891 case ECmmDestinationStatusValid: |
|
892 // Proceed. |
|
893 break; |
|
894 case ECmmDestinationStatusToBeDeleted: |
|
895 { |
|
896 // Already deleted, nothing to do. |
|
897 return; |
|
898 } |
|
899 case ECmmDestinationStatusChanged: |
|
900 default: |
|
901 ASSERT( 0 ); // Error, invalid argument. |
|
902 User::Leave( KErrCorrupt ); |
|
903 break; |
|
904 }*/ |
|
905 |
|
906 // Check status for records. |
|
907 switch ( iNetworkRecordStatus ) |
|
908 { |
|
909 case ECmmRecordStatusLoaded: |
|
910 case ECmmRecordStatusExpired: |
|
911 { |
|
912 iNetworkRecord->DeleteL( iTransactionHandler->Session() ); |
|
913 } |
|
914 break; |
|
915 case ECmmRecordStatusUnsaved: |
|
916 // Skip. |
|
917 break; |
|
918 case ECmmRecordStatusBlank: |
|
919 case ECmmRecordStatusModified: |
|
920 default: |
|
921 ASSERT( 0 ); // Error, invalid status. |
|
922 User::Leave( KErrCorrupt ); |
|
923 break; |
|
924 } |
|
925 switch ( iDestApRecordStatus ) |
|
926 { |
|
927 case ECmmRecordStatusLoaded: |
|
928 case ECmmRecordStatusExpired: |
|
929 { |
|
930 iDestApRecord->DeleteL( iTransactionHandler->Session() ); |
|
931 } |
|
932 break; |
|
933 case ECmmRecordStatusUnsaved: |
|
934 // Skip. |
|
935 break; |
|
936 case ECmmRecordStatusBlank: |
|
937 case ECmmRecordStatusModified: |
|
938 default: |
|
939 ASSERT( 0 ); // Error, invalid status. |
|
940 User::Leave( KErrCorrupt ); |
|
941 break; |
|
942 } |
|
943 switch ( iMetadataRecordStatus ) |
|
944 { |
|
945 case ECmmRecordStatusLoaded: |
|
946 case ECmmRecordStatusExpired: |
|
947 { |
|
948 iMetadataRecord->DeleteL( iTransactionHandler->Session() ); |
|
949 } |
|
950 break; |
|
951 case ECmmRecordStatusUnsaved: |
|
952 // Skip. |
|
953 break; |
|
954 case ECmmRecordStatusBlank: |
|
955 case ECmmRecordStatusModified: |
|
956 default: |
|
957 ASSERT( 0 ); // Error, invalid status. |
|
958 User::Leave( KErrCorrupt ); |
|
959 break; |
|
960 } |
|
961 |
|
962 // Delete all datamobility selection policy records related to this destination. |
|
963 |
|
964 // Create DataMobilitySelectionPolicy-record set. |
|
965 CommsDat::CMDBRecordSet<CCDDataMobilitySelectionPolicyRecord>* snapRecordSet = |
|
966 new( ELeave ) CommsDat::CMDBRecordSet<CCDDataMobilitySelectionPolicyRecord>( |
|
967 iCache->TableId( ECmmDbSnapRecord ) ); |
|
968 CleanupStack::PushL( snapRecordSet ); |
|
969 |
|
970 // Create a DataMobilitySelectionPolicy-record. |
|
971 CCDDataMobilitySelectionPolicyRecord* snapRecord = |
|
972 new( ELeave ) CCDDataMobilitySelectionPolicyRecord( |
|
973 iCache->TableId( ECmmDbSnapRecord ) ); |
|
974 CleanupStack::PushL( snapRecord ); |
|
975 |
|
976 TRAP_IGNORE( snapRecordSet->LoadL( iTransactionHandler->Session() ) ); |
|
977 |
|
978 // Loop through all datamobility selection policy records. |
|
979 TInt snapRecordCount( snapRecordSet->iRecords.Count() ); |
|
980 for ( TInt i = 0; i < snapRecordCount; i++ ) |
|
981 { |
|
982 snapRecord->SetElementId( snapRecordSet->iRecords[i]->ElementId() ); |
|
983 snapRecord->LoadL( iTransactionHandler->Session() ); |
|
984 |
|
985 TInt snap = snapRecord->iSNAP; |
|
986 TInt embeddedSnap = snapRecord->iEmbeddedSNAP; |
|
987 if ( snap == iId || embeddedSnap == iId ) |
|
988 { |
|
989 snapRecord->DeleteL( iTransactionHandler->Session() ); |
|
990 } |
|
991 } |
|
992 CleanupStack::PopAndDestroy( snapRecord ); |
|
993 CleanupStack::PopAndDestroy( snapRecordSet ); |
|
994 |
|
995 OstTraceFunctionExit0( DUP1_CCMMDESTINATIONSTRUCT_DELETEL_EXIT ); |
|
996 } |
|
997 |
|
998 // --------------------------------------------------------------------------- |
|
999 // This should be called when a client session closes a destination handle. |
|
1000 // Reference counter is decremented by one and the remaining number of |
|
1001 // references is returned. |
|
1002 // --------------------------------------------------------------------------- |
|
1003 // |
|
1004 TInt CCmmDestinationStruct::SessionInstanceClosed() |
|
1005 { |
|
1006 OstTraceFunctionEntry0( CCMMDESTINATIONSTRUCT_SESSIONINSTANCECLOSED_ENTRY ); |
|
1007 |
|
1008 iReferenceCounter--; |
|
1009 if ( iReferenceCounter < 0 ) |
|
1010 { |
|
1011 // Error, reference counter shouldn't be able to go negative. |
|
1012 ASSERT( 0 ); |
|
1013 iReferenceCounter = 0; |
|
1014 } |
|
1015 |
|
1016 OstTraceFunctionExit0( CCMMDESTINATIONSTRUCT_SESSIONINSTANCECLOSED_EXIT ); |
|
1017 return iReferenceCounter; |
|
1018 } |
|
1019 |
|
1020 // ----------------------------------------------------------------------------- |
|
1021 // Called after this destination has been updated and database transaction has |
|
1022 // completed successfully. Sets the internal state of this destination |
|
1023 // structure to reflect the new valid state. |
|
1024 // ----------------------------------------------------------------------------- |
|
1025 // |
|
1026 void CCmmDestinationStruct::UpdateSuccessful() |
|
1027 { |
|
1028 OstTraceFunctionEntry0( CCMMDESTINATIONSTRUCT_UPDATESUCCESSFUL_ENTRY ); |
|
1029 |
|
1030 SetStatus( ECmmDestinationStatusValid ); |
|
1031 SetStatusForAllRecords( ECmmRecordStatusLoaded ); |
|
1032 |
|
1033 OstTraceFunctionExit0( CCMMDESTINATIONSTRUCT_UPDATESUCCESSFUL_EXIT ); |
|
1034 } |
|
1035 |
|
1036 // ----------------------------------------------------------------------------- |
|
1037 // CCmmDestinationStruct::InitializeDestApRecordL |
|
1038 // Set default values to a new destination access point record. |
|
1039 // ----------------------------------------------------------------------------- |
|
1040 // |
|
1041 void CCmmDestinationStruct::InitializeDestApRecordL() |
|
1042 { |
|
1043 OstTraceFunctionEntry0( CCMMDESTINATIONSTRUCT_INITIALIZEDESTAPRECORDL_ENTRY ); |
|
1044 |
|
1045 SetDefaultTierManagerL(); |
|
1046 SetDefaultMCprL(); |
|
1047 SetDefaultCprL(); |
|
1048 SetDefaultSCprL(); |
|
1049 SetDefaultProtocolL(); |
|
1050 |
|
1051 OstTraceFunctionExit0( CCMMDESTINATIONSTRUCT_INITIALIZEDESTAPRECORDL_EXIT ); |
|
1052 } |
|
1053 |
|
1054 // ----------------------------------------------------------------------------- |
|
1055 // CCmmDestinationStruct::SetDefaultTierManagerL |
|
1056 // Sets the default tier manager to destination access point record. |
|
1057 // ----------------------------------------------------------------------------- |
|
1058 void CCmmDestinationStruct::SetDefaultTierManagerL() |
|
1059 { |
|
1060 OstTraceFunctionEntry0( CCMMDESTINATIONSTRUCT_SETDEFAULTTIERMANAGERL_ENTRY ); |
|
1061 |
|
1062 CommsDat::CCDTierRecord* tierRecord = |
|
1063 static_cast<CommsDat::CCDTierRecord*>( |
|
1064 CommsDat::CCDRecordBase::RecordFactoryL( CommsDat::KCDTIdTierRecord ) ); |
|
1065 CleanupStack::PushL( tierRecord ); |
|
1066 |
|
1067 tierRecord->iRecordTag = KDefaultTierManagerTagId; |
|
1068 |
|
1069 if ( tierRecord->FindL( iTransactionHandler->Session() ) ) |
|
1070 { |
|
1071 iDestApRecord->iTier = tierRecord->ElementId(); |
|
1072 } |
|
1073 else |
|
1074 { |
|
1075 User::Leave( KErrNotFound ); |
|
1076 } |
|
1077 CleanupStack::PopAndDestroy( tierRecord ); |
|
1078 |
|
1079 OstTraceFunctionExit0( CCMMDESTINATIONSTRUCT_SETDEFAULTTIERMANAGERL_EXIT ); |
|
1080 } |
|
1081 |
|
1082 // ----------------------------------------------------------------------------- |
|
1083 // CCmmDestinationStruct::SetDefaultMCprL |
|
1084 // Sets the default MCpr to destination access point record. |
|
1085 // ----------------------------------------------------------------------------- |
|
1086 void CCmmDestinationStruct::SetDefaultMCprL() |
|
1087 { |
|
1088 OstTraceFunctionEntry0( CCMMDESTINATIONSTRUCT_SETDEFAULTMCPRL_ENTRY ); |
|
1089 |
|
1090 CommsDat::CCDMCprRecord* mcprRecord = |
|
1091 static_cast<CommsDat::CCDMCprRecord*>( |
|
1092 CommsDat::CCDRecordBase::RecordFactoryL( CommsDat::KCDTIdMCprRecord ) ); |
|
1093 CleanupStack::PushL( mcprRecord ); |
|
1094 |
|
1095 mcprRecord->SetRecordId( 1 ); |
|
1096 |
|
1097 mcprRecord->LoadL( iTransactionHandler->Session() ); |
|
1098 iDestApRecord->iMCpr = mcprRecord->ElementId(); |
|
1099 CleanupStack::PopAndDestroy( mcprRecord ); |
|
1100 |
|
1101 OstTraceFunctionExit0( CCMMDESTINATIONSTRUCT_SETDEFAULTMCPRL_EXIT ); |
|
1102 } |
|
1103 |
|
1104 // ----------------------------------------------------------------------------- |
|
1105 // CCmmDestinationStruct::SetDefaultCprL |
|
1106 // Sets the default Cpr to destination access point record. |
|
1107 // ----------------------------------------------------------------------------- |
|
1108 void CCmmDestinationStruct::SetDefaultCprL() |
|
1109 { |
|
1110 OstTraceFunctionEntry0( CCMMDESTINATIONSTRUCT_SETDEFAULTCPRL_ENTRY ); |
|
1111 |
|
1112 CommsDat::CCDCprRecord* cprRecord = |
|
1113 static_cast<CommsDat::CCDCprRecord*>( |
|
1114 CommsDat::CCDRecordBase::RecordFactoryL( CommsDat::KCDTIdCprRecord ) ); |
|
1115 CleanupStack::PushL( cprRecord ); |
|
1116 |
|
1117 cprRecord->SetRecordId( 1 ); |
|
1118 |
|
1119 cprRecord->LoadL( iTransactionHandler->Session() ); |
|
1120 iDestApRecord->iCpr = cprRecord->ElementId(); |
|
1121 CleanupStack::PopAndDestroy( cprRecord ); |
|
1122 |
|
1123 OstTraceFunctionExit0( CCMMDESTINATIONSTRUCT_SETDEFAULTCPRL_EXIT ); |
|
1124 } |
|
1125 |
|
1126 // ----------------------------------------------------------------------------- |
|
1127 // CCmmDestinationStruct::SetDefaultSCprL |
|
1128 // Sets the default SCpr to destination access point record. |
|
1129 // ----------------------------------------------------------------------------- |
|
1130 void CCmmDestinationStruct::SetDefaultSCprL() |
|
1131 { |
|
1132 OstTraceFunctionEntry0( CCMMDESTINATIONSTRUCT_SETDEFAULTSCPRL_ENTRY ); |
|
1133 |
|
1134 CommsDat::CCDSCprRecord* scprRecord = |
|
1135 static_cast<CommsDat::CCDSCprRecord*>( |
|
1136 CommsDat::CCDRecordBase::RecordFactoryL( CommsDat::KCDTIdSCprRecord ) ); |
|
1137 CleanupStack::PushL( scprRecord ); |
|
1138 |
|
1139 scprRecord->SetRecordId( 1 ); |
|
1140 |
|
1141 scprRecord->LoadL( iTransactionHandler->Session() ); |
|
1142 iDestApRecord->iSCpr = scprRecord->ElementId(); |
|
1143 CleanupStack::PopAndDestroy( scprRecord ); |
|
1144 |
|
1145 OstTraceFunctionExit0( CCMMDESTINATIONSTRUCT_SETDEFAULTSCPRL_EXIT ); |
|
1146 } |
|
1147 |
|
1148 // ----------------------------------------------------------------------------- |
|
1149 // CCmmDestinationStruct::SetDefaultProtocolL |
|
1150 // Sets the default protocol to destination access point record. |
|
1151 // ----------------------------------------------------------------------------- |
|
1152 void CCmmDestinationStruct::SetDefaultProtocolL() |
|
1153 { |
|
1154 OstTraceFunctionEntry0( CCMMDESTINATIONSTRUCT_SETDEFAULTPROTOCOLL_ENTRY ); |
|
1155 |
|
1156 CommsDat::CCDProtocolRecord* protocolRecord = |
|
1157 static_cast<CommsDat::CCDProtocolRecord*>( |
|
1158 CommsDat::CCDRecordBase::RecordFactoryL( CommsDat::KCDTIdProtocolRecord ) ); |
|
1159 CleanupStack::PushL( protocolRecord ); |
|
1160 |
|
1161 protocolRecord->SetRecordId( 1 ); |
|
1162 |
|
1163 protocolRecord->LoadL( iTransactionHandler->Session() ); |
|
1164 iDestApRecord->iProtocol = protocolRecord->ElementId(); |
|
1165 CleanupStack::PopAndDestroy( protocolRecord ); |
|
1166 |
|
1167 OstTraceFunctionExit0( CCMMDESTINATIONSTRUCT_SETDEFAULTPROTOCOLL_EXIT ); |
|
1168 } |
|
1169 |
|
1170 // ----------------------------------------------------------------------------- |
|
1171 // Creates a copy of a record of the given type. |
|
1172 // ----------------------------------------------------------------------------- |
|
1173 CommsDat::CCDRecordBase* CCmmDestinationStruct::CopyRecordL( |
|
1174 TCmmDbRecords aRecordType, |
|
1175 CommsDat::CCDRecordBase* aSource ) |
|
1176 { |
|
1177 OstTraceFunctionEntry0( CCMMDESTINATIONSTRUCT_COPYRECORDL_ENTRY ); |
|
1178 |
|
1179 CommsDat::CCDRecordBase* target = NULL; |
|
1180 |
|
1181 switch ( aRecordType ) |
|
1182 { |
|
1183 case ECmmDestNetworkRecord: |
|
1184 { |
|
1185 // Network record. |
|
1186 |
|
1187 CommsDat::CCDNetworkRecord* source = |
|
1188 static_cast<CommsDat::CCDNetworkRecord*>( aSource ); |
|
1189 CommsDat::CCDNetworkRecord* networkRecord = |
|
1190 static_cast<CommsDat::CCDNetworkRecord*>( |
|
1191 CommsDat::CCDRecordBase::RecordFactoryL( |
|
1192 CommsDat::KCDTIdNetworkRecord ) ); |
|
1193 CleanupStack::PushL( networkRecord ); |
|
1194 |
|
1195 if ( !source->iRecordTag.IsNull() ) |
|
1196 { |
|
1197 networkRecord->iRecordTag.SetL( source->iRecordTag ); |
|
1198 } |
|
1199 if ( !source->iRecordName.IsNull() ) |
|
1200 { |
|
1201 networkRecord->iRecordName.SetL( source->iRecordName ); |
|
1202 } |
|
1203 if ( !source->iHostName.IsNull() ) |
|
1204 { |
|
1205 networkRecord->iHostName.SetL( source->iHostName ); |
|
1206 } |
|
1207 networkRecord->SetElementId( source->ElementId() ); |
|
1208 |
|
1209 CleanupStack::Pop( networkRecord ); |
|
1210 target = static_cast<CommsDat::CCDRecordBase*>( networkRecord ); |
|
1211 } |
|
1212 break; |
|
1213 case ECmmDestApRecord: |
|
1214 { |
|
1215 // Access point record. |
|
1216 |
|
1217 CommsDat::CCDAccessPointRecord* source = |
|
1218 static_cast<CommsDat::CCDAccessPointRecord*>( aSource ); |
|
1219 CommsDat::CCDAccessPointRecord* destApRecord = |
|
1220 static_cast<CommsDat::CCDAccessPointRecord*>( |
|
1221 CommsDat::CCDRecordBase::RecordFactoryL( |
|
1222 CommsDat::KCDTIdAccessPointRecord ) ); |
|
1223 CleanupStack::PushL( destApRecord ); |
|
1224 |
|
1225 if ( !source->iRecordTag.IsNull() ) |
|
1226 { |
|
1227 destApRecord->iRecordTag.SetL( source->iRecordTag ); |
|
1228 } |
|
1229 if ( !source->iRecordName.IsNull() ) |
|
1230 { |
|
1231 destApRecord->iRecordName.SetL( source->iRecordName ); |
|
1232 } |
|
1233 if ( !source->iAccessPointGID.IsNull() ) |
|
1234 { |
|
1235 destApRecord->iAccessPointGID.SetL( source->iAccessPointGID ); |
|
1236 } |
|
1237 if ( !source->iSelectionPolicy.IsNull() ) |
|
1238 { |
|
1239 destApRecord->iSelectionPolicy.SetL( source->iSelectionPolicy ); |
|
1240 } |
|
1241 |
|
1242 if ( !source->iTier.IsNull() ) |
|
1243 { |
|
1244 destApRecord->iTier.SetL( source->iTier ); |
|
1245 } |
|
1246 if ( !source->iMCpr.IsNull() ) |
|
1247 { |
|
1248 destApRecord->iMCpr.SetL( source->iMCpr ); |
|
1249 } |
|
1250 if ( !source->iCpr.IsNull() ) |
|
1251 { |
|
1252 destApRecord->iCpr.SetL( source->iCpr ); |
|
1253 } |
|
1254 if ( !source->iSCpr.IsNull() ) |
|
1255 { |
|
1256 destApRecord->iSCpr.SetL( source->iSCpr ); |
|
1257 } |
|
1258 if ( !source->iProtocol.IsNull() ) |
|
1259 { |
|
1260 destApRecord->iProtocol.SetL( source->iProtocol ); |
|
1261 } |
|
1262 if ( !source->iCprConfig.IsNull() ) |
|
1263 { |
|
1264 destApRecord->iCprConfig.SetL( source->iCprConfig ); |
|
1265 } |
|
1266 if ( !source->iAppSID.IsNull() ) |
|
1267 { |
|
1268 destApRecord->iAppSID.SetL( source->iAppSID ); |
|
1269 } |
|
1270 if ( !source->iConfigAPIdList.IsNull() ) |
|
1271 { |
|
1272 destApRecord->iConfigAPIdList.SetL( source->iConfigAPIdList ); |
|
1273 } |
|
1274 if ( !source->iCustomSelectionPolicy.IsNull() ) |
|
1275 { |
|
1276 destApRecord->iCustomSelectionPolicy.SetL( source->iCustomSelectionPolicy ); |
|
1277 } |
|
1278 if ( !source->iPriority.IsNull() ) |
|
1279 { |
|
1280 destApRecord->iPriority.SetL( source->iPriority ); |
|
1281 } |
|
1282 |
|
1283 destApRecord->SetElementId( aSource->ElementId() ); |
|
1284 |
|
1285 CleanupStack::Pop( destApRecord ); |
|
1286 target = static_cast<CommsDat::CCDRecordBase*>( destApRecord ); |
|
1287 } |
|
1288 break; |
|
1289 case ECmmDestMetadataRecord: |
|
1290 { |
|
1291 // Metadata record. |
|
1292 CCDSNAPMetadataRecord* source = |
|
1293 static_cast<CCDSNAPMetadataRecord*>( aSource ); |
|
1294 CCDSNAPMetadataRecord* metadataRecord = |
|
1295 new( ELeave ) CCDSNAPMetadataRecord( |
|
1296 iCache->TableId( ECmmDestMetadataRecord ) ); |
|
1297 CleanupStack::PushL( metadataRecord ); |
|
1298 |
|
1299 if ( !source->iRecordTag.IsNull() ) |
|
1300 { |
|
1301 metadataRecord->iRecordTag.SetL( source->iRecordTag ); |
|
1302 } |
|
1303 if ( !source->iRecordName.IsNull() ) |
|
1304 { |
|
1305 metadataRecord->iRecordName.SetL( source->iRecordName ); |
|
1306 } |
|
1307 if ( !source->iSNAP.IsNull() ) |
|
1308 { |
|
1309 metadataRecord->iSNAP.SetL( source->iSNAP ); |
|
1310 } |
|
1311 if ( !source->iMetadata.IsNull() ) |
|
1312 { |
|
1313 metadataRecord->iMetadata.SetL( source->iMetadata ); |
|
1314 } |
|
1315 if ( !source->iIcon.IsNull() ) |
|
1316 { |
|
1317 metadataRecord->iIcon.SetL( source->iIcon ); |
|
1318 } |
|
1319 metadataRecord->SetElementId( source->ElementId() ); |
|
1320 |
|
1321 CleanupStack::Pop( metadataRecord ); |
|
1322 target = static_cast<CommsDat::CCDRecordBase*>( metadataRecord ); |
|
1323 } |
|
1324 break; |
|
1325 default: |
|
1326 { |
|
1327 User::Leave( KErrArgument ); |
|
1328 } |
|
1329 break; |
|
1330 } |
|
1331 |
|
1332 OstTraceFunctionExit0( CCMMDESTINATIONSTRUCT_COPYRECORDL_EXIT ); |
|
1333 return target; |
|
1334 } |
|
1335 |
|
1336 // End of file |