telephonyprotocols/csdagt/TS_CsdAgt/DbUndo.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     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 
       
   294 // GPRS OUTGOING TABLE access class
       
   295 CDbGPRSOutgoingTable *CDbGPRSOutgoingTable::NewL()
       
   296 	{
       
   297 	CDbGPRSOutgoingTable *gprs = new(ELeave) CDbGPRSOutgoingTable();
       
   298 	CleanupStack::PushL(gprs);
       
   299 	gprs->ConstructL();
       
   300 	CleanupStack::Pop();
       
   301 	return gprs;
       
   302 	}
       
   303 
       
   304 CDbGPRSOutgoingTable::CDbGPRSOutgoingTable()
       
   305 	{
       
   306 	}
       
   307 
       
   308 void CDbGPRSOutgoingTable::ConstructL()
       
   309 	{
       
   310 	CDbAgtBase::ConstructL();
       
   311 	iTable = new CMDBRecordSet<CCDWCDMAPacketServiceRecord>(KCDTIdWCDMAPacketServiceRecord);
       
   312 	iTable->LoadL(*iDb);
       
   313 	iCurrentRecord = 0;
       
   314 	}
       
   315 
       
   316 CDbGPRSOutgoingTable::~CDbGPRSOutgoingTable()
       
   317 	{
       
   318 	delete iTable;
       
   319 	}
       
   320 
       
   321 // CSD DIAL OUT table class
       
   322 CDbCsdTable *CDbCsdTable::NewL()
       
   323 	{
       
   324 	CDbCsdTable *csd = new(ELeave) CDbCsdTable();
       
   325 	CleanupStack::PushL(csd);
       
   326 	csd->ConstructL();
       
   327 	CleanupStack::Pop();
       
   328 	return csd;
       
   329 	}
       
   330 
       
   331 CDbCsdTable::CDbCsdTable()
       
   332 	{
       
   333 	}
       
   334 
       
   335 void CDbCsdTable::ConstructL()
       
   336 	{
       
   337 	CDbAgtBase::ConstructL();
       
   338 	iTable = new CMDBRecordSet<CCDDialOutISPRecord>(KCDTIdDialOutISPRecord);
       
   339 	iTable->LoadL(*iDb);
       
   340 	iCurrentRecord = 0;
       
   341 	}
       
   342 
       
   343 CDbCsdTable::~CDbCsdTable()
       
   344 	{
       
   345 	delete iTable;
       
   346 	}
       
   347 
       
   348 
       
   349 // MODEM table class
       
   350 CDbModemTable *CDbModemTable::NewL()
       
   351 	{
       
   352 	CDbModemTable *modem = new(ELeave) CDbModemTable();
       
   353 	CleanupStack::PushL(modem);
       
   354 	modem->ConstructL();
       
   355 	CleanupStack::Pop();
       
   356 	return modem;
       
   357 	}
       
   358 
       
   359 CDbModemTable::CDbModemTable()
       
   360 	{
       
   361 	}
       
   362 
       
   363 void CDbModemTable::ConstructL()
       
   364 	{
       
   365 	CDbAgtBase::ConstructL();
       
   366 	iTable = new CMDBRecordSet<CCDModemBearerRecord>(KCDTIdModemBearerRecord);
       
   367 	iTable->LoadL(*iDb);
       
   368 	iCurrentRecord = 0;
       
   369 	}
       
   370 
       
   371 CMDBRecordSetBase*CDbCsdTable::Table()
       
   372 	{
       
   373 	return(iTable);
       
   374 	}
       
   375 CDbModemTable::~CDbModemTable()
       
   376 	{
       
   377 	delete iTable;
       
   378 	}