|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "DbUndo.h" |
|
17 |
|
18 |
|
19 // UNDO Class for Integers |
|
20 void CDbUndoInt::ConstructL(const TDesC &aColumn, const TUint32 &aValue) |
|
21 { |
|
22 iColumn.Set(aColumn); |
|
23 iValue=aValue; |
|
24 } |
|
25 |
|
26 CDbUndoInt *CDbUndoInt::NewL(const TDesC &aColumn, const TUint32 &aValue) |
|
27 { |
|
28 CDbUndoInt *undo = new(ELeave) CDbUndoInt(); |
|
29 CleanupStack::PushL(undo); |
|
30 undo->ConstructL(aColumn, aValue); |
|
31 CleanupStack::Pop(); |
|
32 return undo; |
|
33 } |
|
34 |
|
35 void CDbUndoInt::UndoL(CDbAgtBase *aDb) |
|
36 { |
|
37 // Reset value in the table back to the values stored in this undo object |
|
38 aDb->ModifyColumnIntL(iColumn, iValue); |
|
39 } |
|
40 |
|
41 // UNDO Class for Booleans |
|
42 void CDbUndoBool::ConstructL(const TDesC &aColumn, const TBool &aValue) |
|
43 { |
|
44 iColumn.Set(aColumn); |
|
45 iValue=aValue; |
|
46 } |
|
47 |
|
48 CDbUndoBool *CDbUndoBool::NewL(const TDesC &aColumn, const TBool &aValue) |
|
49 { |
|
50 CDbUndoBool *undo = new(ELeave) CDbUndoBool(); |
|
51 CleanupStack::PushL(undo); |
|
52 undo->ConstructL(aColumn, aValue); |
|
53 CleanupStack::Pop(); |
|
54 return undo; |
|
55 } |
|
56 |
|
57 void CDbUndoBool::UndoL(CDbAgtBase *aDb) |
|
58 { |
|
59 // Reset value in the table back to the values stored in this undo object |
|
60 aDb->ModifyColumnBoolL(iColumn, iValue); |
|
61 } |
|
62 |
|
63 // UNDO Class for text |
|
64 void CDbUndoText::ConstructL(const TDesC &aColumn, const TDesC16& aValue) |
|
65 { |
|
66 iColumn.Set(aColumn); |
|
67 iText.Copy(aValue); |
|
68 } |
|
69 |
|
70 CDbUndoText *CDbUndoText::NewL(const TDesC &aColumn, const TDesC16& aValue) |
|
71 { |
|
72 CDbUndoText *undo = new(ELeave) CDbUndoText(); |
|
73 CleanupStack::PushL(undo); |
|
74 undo->ConstructL(aColumn, aValue); |
|
75 CleanupStack::Pop(); |
|
76 return undo; |
|
77 } |
|
78 |
|
79 void CDbUndoText::UndoL(CDbAgtBase *aDb) |
|
80 { |
|
81 // Reset text value in the table back to the text values stored in this undo object |
|
82 aDb->ModifyColumnTextL(iColumn, iText); |
|
83 } |
|
84 |
|
85 // UNDO Class for long text |
|
86 void CDbUndoLongText::ConstructL(const TDesC &aColumn, const HBufC* aValue) |
|
87 { |
|
88 iColumn.Set(aColumn); |
|
89 // Save the long text from CommDB, allocate it! |
|
90 iLongText = aValue->AllocL(); |
|
91 } |
|
92 |
|
93 CDbUndoLongText *CDbUndoLongText::NewL(const TDesC &aColumn, const HBufC* aValue) |
|
94 { |
|
95 CDbUndoLongText *undo = new(ELeave) CDbUndoLongText(); |
|
96 CleanupStack::PushL(undo); |
|
97 undo->ConstructL(aColumn, aValue); |
|
98 CleanupStack::Pop(); |
|
99 return undo; |
|
100 } |
|
101 |
|
102 void CDbUndoLongText::UndoL(CDbAgtBase *aDb) |
|
103 { |
|
104 // Reset text value in the table back to the text values stored in this undo object |
|
105 TPtr value(iLongText->Des()); |
|
106 aDb->ModifyColumnLongTextL(iColumn, value); |
|
107 // Allocated in ConstructL, remeber to delete! |
|
108 delete iLongText; |
|
109 } |
|
110 |
|
111 // UNDO Class for Agent Extension name |
|
112 void CDbUndoAgentExt::ConstructL(const TDesC &aService, const TDesC& aAgentExt) |
|
113 { |
|
114 iColumn.Set(aService); |
|
115 iText.Copy(aAgentExt); |
|
116 } |
|
117 |
|
118 CDbUndoAgentExt *CDbUndoAgentExt::NewL(const TDesC &aService, const TDesC& aAgentExt) |
|
119 { |
|
120 CDbUndoAgentExt *undo = new(ELeave) CDbUndoAgentExt(); |
|
121 CleanupStack::PushL(undo); |
|
122 undo->ConstructL(aService, aAgentExt); |
|
123 CleanupStack::Pop(); |
|
124 return undo; |
|
125 } |
|
126 |
|
127 void CDbUndoAgentExt::UndoL(CDbAgtBase* /*aDb*/) |
|
128 { |
|
129 } |
|
130 |
|
131 // Base class routines, used to open a CCommsDatabase and modify records |
|
132 CDbAgtBase::CDbAgtBase() : iQHeader(_FOFF(CDbUndoBase,iLink)), iQIter(iQHeader) |
|
133 { |
|
134 } |
|
135 |
|
136 void CDbAgtBase::ConstructL() |
|
137 { |
|
138 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY |
|
139 iDb = CMDBSession::NewL(KCDVersion1_2); |
|
140 #else |
|
141 iDb = CMDBSession::NewL(KCDVersion1_1); |
|
142 #endif |
|
143 } |
|
144 |
|
145 CDbAgtBase::~CDbAgtBase() |
|
146 { |
|
147 delete iDb; |
|
148 } |
|
149 |
|
150 |
|
151 void CDbAgtBase::SetColumnIntL(const TDesC &aColumn, const TUint32 &aValue) |
|
152 { |
|
153 // Used by a client to set a value in the database, also remembers the change |
|
154 // for undo purposes later |
|
155 |
|
156 TUint32 OldValue; |
|
157 CDbUndoInt *oldRecord; |
|
158 |
|
159 // Get the current value in the table |
|
160 TInt ValType; |
|
161 CMDBField<TUint>* field = static_cast<CMDBField<TUint>*>(iTable->iRecords[iCurrentRecord]->GetFieldByNameL(aColumn, ValType)); |
|
162 OldValue = *field; |
|
163 |
|
164 // Add to the undo list |
|
165 oldRecord = CDbUndoInt::NewL(aColumn, OldValue); |
|
166 iQHeader.AddLast(*oldRecord); |
|
167 |
|
168 // Change the record to the new value |
|
169 ModifyColumnIntL(aColumn, aValue); |
|
170 } |
|
171 |
|
172 |
|
173 void CDbAgtBase::ModifyColumnIntL(const TDesC &aColumn, const TUint32 &aValue) |
|
174 { |
|
175 TInt ValType; |
|
176 CMDBField<TUint>* field = static_cast<CMDBField<TUint>*>(iTable->iRecords[iCurrentRecord]->GetFieldByNameL(aColumn, ValType)); |
|
177 *field = aValue; |
|
178 field->ModifyL(*iDb); |
|
179 } |
|
180 |
|
181 void CDbAgtBase::SetColumnBoolL(const TDesC &aColumn, const TBool &aValue) |
|
182 { |
|
183 // Used by a client to set a value in the database, also remembers the change |
|
184 // for undo purposes later |
|
185 |
|
186 TBool OldValue; |
|
187 CDbUndoBool *oldRecord; |
|
188 |
|
189 // Get the current value in the table |
|
190 TInt ValType; |
|
191 CMDBField<TBool>* field = static_cast<CMDBField<TBool>*>(iTable->iRecords[iCurrentRecord]->GetFieldByNameL(aColumn, ValType)); |
|
192 OldValue = static_cast<TBool>(*field); |
|
193 |
|
194 // Add to the undo list |
|
195 oldRecord = CDbUndoBool::NewL(aColumn, OldValue); |
|
196 iQHeader.AddLast(*oldRecord); |
|
197 |
|
198 // Change the record to the new value |
|
199 ModifyColumnBoolL(aColumn, aValue); |
|
200 } |
|
201 |
|
202 |
|
203 void CDbAgtBase::ModifyColumnBoolL(const TDesC &aColumn, const TBool &aValue) |
|
204 { |
|
205 TInt ValType; |
|
206 CMDBField<TBool>* field = static_cast<CMDBField<TBool>*>(iTable->iRecords[iCurrentRecord]->GetFieldByNameL(aColumn, ValType)); |
|
207 *field = aValue; |
|
208 field->ModifyL(*iDb); |
|
209 } |
|
210 |
|
211 void CDbAgtBase::SetColumnTextL(const TDesC &aColumn, const TDesC16& aValue) |
|
212 { |
|
213 // Used by a client to set a text value in the database, also remembers the change |
|
214 // for undo purposes later |
|
215 |
|
216 TBuf16<KCommsDbSvrMaxFieldLength> OldText; |
|
217 CDbUndoText *oldRecord; |
|
218 |
|
219 // Get the current value in the table |
|
220 TInt ValType; |
|
221 CMDBField<TDesC>* field = static_cast<CMDBField<TDesC>*>(iTable->iRecords[iCurrentRecord]->GetFieldByNameL(aColumn, ValType)); |
|
222 OldText = static_cast<TDesC>(*field); |
|
223 |
|
224 // Add to the undo list |
|
225 oldRecord = CDbUndoText::NewL(aColumn, OldText); |
|
226 iQHeader.AddLast(*oldRecord); |
|
227 |
|
228 // Change the record to the new value |
|
229 ModifyColumnTextL(aColumn, aValue); |
|
230 } |
|
231 |
|
232 void CDbAgtBase::ModifyColumnTextL(const TDesC &aColumn, const TDesC16& aValue) |
|
233 { |
|
234 TInt ValType; |
|
235 CMDBField<TDesC>* field = static_cast<CMDBField<TDesC>*>(iTable->iRecords[iCurrentRecord]->GetFieldByNameL(aColumn, ValType)); |
|
236 *field = aValue; |
|
237 field->ModifyL(*iDb); |
|
238 } |
|
239 |
|
240 void CDbAgtBase::SetColumnLongTextL(const TDesC &aColumn, const TDesC16& aValue) |
|
241 { |
|
242 // Used by a client to set a long text value in the database, also remembers the change |
|
243 // for undo purposes later |
|
244 |
|
245 CDbUndoLongText *oldRecord; |
|
246 |
|
247 // Get the current long text in the table, it is allocated in CommDB in ReadLongTextLC. |
|
248 // The method returns a pointer into HBufC. |
|
249 TInt ValType; |
|
250 CMDBField<TDesC>* field = static_cast<CMDBField<TDesC>*>(iTable->iRecords[iCurrentRecord]->GetFieldByNameL(aColumn, ValType)); |
|
251 HBufC* OldLongText = HBufC::NewL(static_cast<TDesC>(*field).Length()); |
|
252 CleanupStack::PushL(OldLongText); |
|
253 *OldLongText = *field; |
|
254 |
|
255 // Add to the undo list |
|
256 oldRecord = CDbUndoLongText::NewL(aColumn, OldLongText); |
|
257 iQHeader.AddLast(*oldRecord); |
|
258 |
|
259 // Allocated into CDbUndoLongText in ConstructL, and this one was created in CommDB so delete it! |
|
260 // this is pushed above so clean up properly |
|
261 CleanupStack::PopAndDestroy(OldLongText); |
|
262 |
|
263 // Change the record to the new value |
|
264 ModifyColumnLongTextL(aColumn, aValue); |
|
265 } |
|
266 |
|
267 void CDbAgtBase::ModifyColumnLongTextL(const TDesC &aColumn, const TDesC16& aValue) |
|
268 { |
|
269 TInt ValType; |
|
270 CMDBField<TDesC>* field = static_cast<CMDBField<TDesC>*>(iTable->iRecords[iCurrentRecord]->GetFieldByNameL(aColumn, ValType)); |
|
271 field->SetMaxLengthL(aValue.Length()); |
|
272 *field = aValue; |
|
273 field->ModifyL(*iDb); |
|
274 } |
|
275 |
|
276 |
|
277 void CDbAgtBase::UndoDatabaseChangesL() |
|
278 { |
|
279 CDbUndoBase* currentitem; |
|
280 |
|
281 // Traverse back through the changes and reset database to the way it was |
|
282 iQIter.SetToLast(); |
|
283 |
|
284 while((currentitem = iQIter--) != NULL) |
|
285 { |
|
286 // reset the value of this record in the database |
|
287 currentitem->UndoL(this); |
|
288 currentitem->iLink.Deque(); |
|
289 delete currentitem; |
|
290 }; |
|
291 } |
|
292 |
|
293 // GPRS OUTGOING TABLE access class |
|
294 CDbGPRSOutgoingTable *CDbGPRSOutgoingTable::NewL() |
|
295 { |
|
296 CDbGPRSOutgoingTable *gprs = new(ELeave) CDbGPRSOutgoingTable(); |
|
297 CleanupStack::PushL(gprs); |
|
298 gprs->ConstructL(); |
|
299 CleanupStack::Pop(); |
|
300 return gprs; |
|
301 } |
|
302 |
|
303 CDbGPRSOutgoingTable::CDbGPRSOutgoingTable() |
|
304 { |
|
305 } |
|
306 |
|
307 void CDbGPRSOutgoingTable::ConstructL() |
|
308 { |
|
309 CDbAgtBase::ConstructL(); |
|
310 iTable = new CMDBRecordSet<CCDOutgoingGprsRecord>(KCDTIdOutgoingGprsRecord); |
|
311 iTable->LoadL(*iDb); |
|
312 iCurrentRecord = 0; |
|
313 } |
|
314 |
|
315 CDbGPRSOutgoingTable::~CDbGPRSOutgoingTable() |
|
316 { |
|
317 delete iTable; |
|
318 } |
|
319 |
|
320 // CSD DIAL OUT table class |
|
321 CDbCsdTable *CDbCsdTable::NewL() |
|
322 { |
|
323 CDbCsdTable *csd = new(ELeave) CDbCsdTable(); |
|
324 CleanupStack::PushL(csd); |
|
325 csd->ConstructL(); |
|
326 CleanupStack::Pop(); |
|
327 return csd; |
|
328 } |
|
329 |
|
330 CDbCsdTable::CDbCsdTable() |
|
331 { |
|
332 } |
|
333 |
|
334 void CDbCsdTable::ConstructL() |
|
335 { |
|
336 CDbAgtBase::ConstructL(); |
|
337 iTable = new CMDBRecordSet<CCDDialOutISPRecord>(KCDTIdDialOutISPRecord); |
|
338 iTable->LoadL(*iDb); |
|
339 iCurrentRecord = 0; |
|
340 } |
|
341 |
|
342 CDbCsdTable::~CDbCsdTable() |
|
343 { |
|
344 delete iTable; |
|
345 } |
|
346 |
|
347 |
|
348 // MODEM table class |
|
349 CDbModemTable *CDbModemTable::NewL() |
|
350 { |
|
351 CDbModemTable *modem = new(ELeave) CDbModemTable(); |
|
352 CleanupStack::PushL(modem); |
|
353 modem->ConstructL(); |
|
354 CleanupStack::Pop(); |
|
355 return modem; |
|
356 } |
|
357 |
|
358 CDbModemTable::CDbModemTable() |
|
359 { |
|
360 } |
|
361 |
|
362 void CDbModemTable::ConstructL() |
|
363 { |
|
364 CDbAgtBase::ConstructL(); |
|
365 iTable = new CMDBRecordSet<CCDModemBearerRecord>(KCDTIdModemBearerRecord); |
|
366 iTable->LoadL(*iDb); |
|
367 iCurrentRecord = 0; |
|
368 } |
|
369 |
|
370 CDbModemTable::~CDbModemTable() |
|
371 { |
|
372 delete iTable; |
|
373 } |
|
374 |
|
375 // Preference table class |
|
376 CDbPrefTable *CDbPrefTable::NewL( |
|
377 CMDBField<TCommDbConnectionDirection> aDirection, |
|
378 CBearerUpdate aBearerUpdate, |
|
379 TBool aReadOnly, |
|
380 TUint32 aDialogPref ) |
|
381 { |
|
382 CDbPrefTable *pref = new(ELeave) CDbPrefTable(); |
|
383 CleanupStack::PushL(pref); |
|
384 pref->iDirection = static_cast<TCommDbConnectionDirection>(aDirection); |
|
385 pref->iBearerUpdate.iBearerSet = aBearerUpdate.iBearerSet; |
|
386 pref->iBearerUpdate.iIapId = aBearerUpdate.iIapId; |
|
387 pref->iReadOnly = aReadOnly; |
|
388 pref->iDialogPref = aDialogPref; |
|
389 pref->ConstructL(); |
|
390 CleanupStack::Pop(); |
|
391 return pref; |
|
392 } |
|
393 |
|
394 CDbPrefTable::CDbPrefTable() |
|
395 { |
|
396 } |
|
397 |
|
398 void CDbPrefTable::ConstructL() |
|
399 { |
|
400 CDbAgtBase::ConstructL(); |
|
401 iPrefTable = new (ELeave) CMDBRecordSet<CCDConnectionPrefsRecord>(KCDTIdConnectionPrefsRecord); |
|
402 iPrefTable->LoadL(*iDb); |
|
403 |
|
404 iOldPrefs.iRanking = (static_cast<CCDConnectionPrefsRecord*>(iPrefTable->iRecords[iCurrentPrefRecord]))->iRanking; |
|
405 iOldPrefs.iDirection = static_cast<TCommDbConnectionDirection>((static_cast<CCDConnectionPrefsRecord*>(iPrefTable->iRecords[iCurrentPrefRecord]))->iDirection); |
|
406 iOldPrefs.iDialogPref = (static_cast<CCDConnectionPrefsRecord*>(iPrefTable->iRecords[iCurrentPrefRecord]))->iDialogPref; |
|
407 iOldPrefs.iBearer.iBearerSet = (static_cast<CCDConnectionPrefsRecord*>(iPrefTable->iRecords[iCurrentPrefRecord]))->iBearerSet; |
|
408 iOldPrefs.iBearer.iIapId = (static_cast<CCDConnectionPrefsRecord *>(iPrefTable->iRecords[iCurrentPrefRecord]))->iDefaultIAP; |
|
409 |
|
410 iCurrentPrefRecord = 0; |
|
411 ((CCDConnectionPrefsRecord *)iPrefTable->iRecords[iCurrentPrefRecord])->iDialogPref = iDialogPref; |
|
412 ((CCDConnectionPrefsRecord *)iPrefTable->iRecords[iCurrentPrefRecord])->iBearerSet = iBearerUpdate.iBearerSet; |
|
413 ((CCDConnectionPrefsRecord *)iPrefTable->iRecords[iCurrentPrefRecord])->iDefaultIAP = iBearerUpdate.iIapId; |
|
414 if(iReadOnly) |
|
415 { |
|
416 iPrefTable->iRecords[iCurrentPrefRecord]->SetAttributes(ECDProtectedWrite); |
|
417 } |
|
418 iPrefTable->iRecords[iCurrentPrefRecord]->ModifyL(*iDb); |
|
419 } |
|
420 |
|
421 CDbPrefTable::~CDbPrefTable() |
|
422 { |
|
423 if(iPrefTable) |
|
424 { |
|
425 // Don't care if this fails since we're in the destructor anyway (but need to trap any leaves as we can't leave from a destructor) |
|
426 TRAP_IGNORE(RevertPreferenceTableL()); |
|
427 } |
|
428 delete iTable; |
|
429 delete iPrefTable; |
|
430 } |
|
431 |
|
432 void CDbPrefTable::RevertPreferenceTableL() |
|
433 { |
|
434 // Revert back to old ones |
|
435 iCurrentPrefRecord = 0; |
|
436 // iOldPrefs has the old info |
|
437 ((CCDConnectionPrefsRecord *)iPrefTable->iRecords[iCurrentPrefRecord])->iDialogPref = iOldPrefs.iDialogPref; |
|
438 ((CCDConnectionPrefsRecord *)iPrefTable->iRecords[iCurrentPrefRecord])->iBearerSet = iOldPrefs.iBearer.iBearerSet; |
|
439 ((CCDConnectionPrefsRecord *)iPrefTable->iRecords[iCurrentPrefRecord])->iDefaultIAP = iOldPrefs.iBearer.iIapId; |
|
440 if(iReadOnly) |
|
441 { |
|
442 iPrefTable->iRecords[iCurrentPrefRecord]->SetAttributes(ECDProtectedWrite); |
|
443 } |
|
444 iPrefTable->iRecords[iCurrentPrefRecord]->ModifyL(*iDb); |
|
445 } |
|
446 |
|
447 // IAP table class |
|
448 CDbIapTable *CDbIapTable::NewL(const TDesC16& aIapName) |
|
449 { |
|
450 CDbIapTable *iap = new(ELeave) CDbIapTable(); |
|
451 CleanupStack::PushL(iap); |
|
452 iap->ConstructL(); |
|
453 iap->iIapName.Copy( aIapName ); |
|
454 CleanupStack::Pop(); |
|
455 return iap; |
|
456 } |
|
457 |
|
458 CDbIapTable::CDbIapTable() |
|
459 { |
|
460 } |
|
461 |
|
462 void CDbIapTable::ConstructL() |
|
463 { |
|
464 CDbAgtBase::ConstructL(); |
|
465 } |
|
466 |
|
467 void CDbIapTable::GetBearerSetIapIdL(TUint32& aIapId) |
|
468 { |
|
469 CCDIAPRecord* iRecord = static_cast<CCDIAPRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdIAPRecord)); |
|
470 iRecord->iRecordName = iIapName; |
|
471 |
|
472 //iTable = new CMDBRecordSet<CCDIAPRecord>(); |
|
473 //CleanupStack::Pop(iTable); |
|
474 iRecord->LoadL(*iDb); |
|
475 aIapId = iRecord->RecordId(); |
|
476 iCurrentRecord = 0; |
|
477 } |
|
478 |
|
479 CDbIapTable::~CDbIapTable() |
|
480 { |
|
481 delete iTable; |
|
482 } |