syncmlfw/ds/syncagent/src/nsmldsmapcontainer.cpp
changeset 0 b497e44ab2fc
child 73 ae69c2e8bc34
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Map command buffering
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <nsmlconstants.h>
       
    21 #include "nsmldsmapcontainer.h"
       
    22 
       
    23 // <MAPINFO_RESEND_MOD_BEGIN>
       
    24 #include <nsmldebug.h>
       
    25 // <MAPINFO_RESEND_MOD_END>
       
    26 
       
    27 // ============================ MEMBER FUNCTIONS ===============================
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CNSmlDSMapContainer::CMapItem::~CMapItem
       
    31 // Destructor.
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 CNSmlDSMapContainer::CMapItem::~CMapItem()
       
    35 	{
       
    36 	delete iGlobalUid;
       
    37 	}
       
    38 	
       
    39 // -----------------------------------------------------------------------------
       
    40 // CNSmlDSMapContainer::CNSmlDSMapContainer
       
    41 // C++ default constructor.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CNSmlDSMapContainer::CNSmlDSMapContainer()
       
    45 	{
       
    46 // <MAPINFO_RESEND_MOD_BEGIN>
       
    47 	setAppendToStore( EFalse );
       
    48 	iMapRemovable = EFalse;
       
    49 // <MAPINFO_RESEND_MOD_END>
       
    50 	}
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CNSmlDSMapContainer::~CNSmlDSMapContainer
       
    54 // Destructor.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CNSmlDSMapContainer::~CNSmlDSMapContainer()
       
    58 	{
       
    59 	iMapItemList.ResetAndDestroy();
       
    60 	}
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CNSmlDSMapContainer::NewL
       
    64 // Two-phased constructor.
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CNSmlDSMapContainer* CNSmlDSMapContainer::NewL()
       
    68 	{
       
    69 	CNSmlDSMapContainer* self = new ( ELeave ) CNSmlDSMapContainer;
       
    70 	return self;
       
    71 	}
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CNSmlDSMapContainer::MapListExists
       
    75 // Checks whether the map list exists.
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 TBool CNSmlDSMapContainer::MapListExists() const
       
    79 	{
       
    80 	if ( iMapItemList.Count() == 0 )
       
    81 		{
       
    82 		return EFalse;
       
    83 		}
       
    84 		
       
    85 	for ( TInt i = 0; i < iMapItemList.Count(); i++ )
       
    86 		{
       
    87 		if ( !iMapItemList[i]->iAlreadySent )
       
    88 			{
       
    89 			return ETrue;
       
    90 			}
       
    91 		}
       
    92 		
       
    93 	return EFalse;
       
    94 	}
       
    95 	
       
    96 // -----------------------------------------------------------------------------
       
    97 // CNSmlDSMapContainer::CreateNewMapItemL
       
    98 // Creates new map item to the list.
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 void CNSmlDSMapContainer::CreateNewMapItemL( const TSmlDbItemUid aLocalUid, const TDesC8& aGlobalUid, const TInt aAtomicId )
       
   102 	{
       
   103 	CMapItem* item = new ( ELeave ) CMapItem;
       
   104 	CleanupStack::PushL( item );
       
   105 	item->iAlreadySent = EFalse;
       
   106 	item->iAtomicId = aAtomicId;
       
   107 	item->iGlobalUid = aGlobalUid.AllocL();
       
   108 	item->iLocalUid = aLocalUid;
       
   109 
       
   110 // <MAPINFO_RESEND_MOD_BEGIN>
       
   111 	if( !MapListExists() )
       
   112 		{
       
   113 		iMapRemovable = EFalse;	
       
   114 		}
       
   115 // <MAPINFO_RESEND_MOD_BEGIN>
       
   116 
       
   117 	iMapItemList.AppendL( item );
       
   118 	
       
   119 	CleanupStack::Pop(); // item
       
   120 	}
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CNSmlDSMapContainer::RemoveFailedAtomics
       
   124 // Removes those map items that were executed under a failed atomic command.
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CNSmlDSMapContainer::RemoveFailedAtomics( const TInt aAtomicId )
       
   128 	{
       
   129 	for ( TInt i = 0; i < iMapItemList.Count(); )
       
   130 		{
       
   131 		if ( iMapItemList[i]->iAtomicId == aAtomicId )
       
   132 			{
       
   133 			delete iMapItemList[i];
       
   134 			iMapItemList.Remove( i );
       
   135 			}
       
   136 		else
       
   137 			{
       
   138 			++i;
       
   139 			}
       
   140 		}
       
   141 		
       
   142 	iMapItemList.Compress();
       
   143 	}
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CNSmlDSMapContainer::MapItemList
       
   147 // Returns the map item list, ownership is changed to a caller. 
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 SmlMapItemList_t* CNSmlDSMapContainer::MapItemListL()
       
   151 	{
       
   152 	SmlMapItemList_t* mapItemList( NULL );
       
   153 	SmlMapItemList_t* mapItemListLast( NULL );
       
   154 	
       
   155 	for ( TInt i = 0; i < iMapItemList.Count(); i++ )
       
   156 		{
       
   157 		if ( iMapItemList[i]->iAlreadySent )
       
   158 			{
       
   159 			continue;
       
   160 			}
       
   161 			
       
   162 		TBuf8<16> localUid;
       
   163 		localUid.Num( iMapItemList[i]->iLocalUid );
       
   164 
       
   165 		if ( !mapItemList )	
       
   166 			{
       
   167 			mapItemList = new ( ELeave ) SmlMapItemList_t;
       
   168 			mapItemListLast = mapItemList;
       
   169 			}
       
   170 		else
       
   171 			{
       
   172 			mapItemListLast->next = new ( ELeave ) SmlMapItemList_t;
       
   173 			mapItemListLast = mapItemListLast->next;
       
   174 			}
       
   175 			
       
   176 		mapItemListLast->next = NULL;
       
   177 		mapItemListLast->mapItem = new( ELeave ) SmlMapItem_t;
       
   178 		mapItemListLast->mapItem->target = new( ELeave ) SmlTarget_t;
       
   179 		mapItemListLast->mapItem->target->locName = NULL;
       
   180 		PcdataNewL( mapItemListLast->mapItem->target->locURI, *iMapItemList[i]->iGlobalUid );
       
   181 		mapItemListLast->mapItem->source = new( ELeave ) SmlSource_t;
       
   182 		mapItemListLast->mapItem->source->locName = NULL;
       
   183 		PcdataNewL( mapItemListLast->mapItem->source->locURI, localUid );
       
   184 		}
       
   185 		
       
   186 	return mapItemList;
       
   187 	}
       
   188 	
       
   189 // -----------------------------------------------------------------------------
       
   190 // CNSmlDSMapContainer::SetMapItemList
       
   191 // Sets the map item list, ownership is changed to this class.
       
   192 // -----------------------------------------------------------------------------
       
   193 //
       
   194 void CNSmlDSMapContainer::SetMapItemList( SmlMapItemList_t* aMapItemList )
       
   195 	{
       
   196 // <MAPINFO_RESEND_MOD_BEGIN>
       
   197 	iMapRemovable = EFalse;
       
   198 // <MAPINFO_RESEND_MOD_END>
       
   199 	delete aMapItemList;
       
   200 	}
       
   201 	
       
   202 // -----------------------------------------------------------------------------
       
   203 // CNSmlDSMapContainer::PcdataNewL
       
   204 // Creates a new Pcdata element.
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 void CNSmlDSMapContainer::PcdataNewL( SmlPcdata_t*& aPcdata, const TDesC8& aContent ) const
       
   208 	{
       
   209 	aPcdata = new( ELeave ) SmlPcdata_t;
       
   210 	aPcdata->SetDataL( aContent );
       
   211 	aPcdata->contentType = SML_PCDATA_OPAQUE;   
       
   212 	aPcdata->extension = SML_EXT_UNDEFINED; 	
       
   213 	}
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // CNSmlDSMapContainer::MapSourceParent
       
   217 // Maps a SourceParent to an existing LUID.
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 TBool CNSmlDSMapContainer::MapSourceParent( const TDesC8& aSourceParent, TSmlDbItemUid& aUid ) const
       
   221 	{
       
   222 	for ( TInt i = 0; i < iMapItemList.Count(); i++ )
       
   223 		{
       
   224 		if ( *iMapItemList[i]->iGlobalUid == aSourceParent )
       
   225 			{
       
   226 			aUid = iMapItemList[i]->iLocalUid;
       
   227 			return ETrue;
       
   228 			}
       
   229 		}
       
   230 		
       
   231 	return EFalse;
       
   232 	}
       
   233 
       
   234 // -----------------------------------------------------------------------------
       
   235 // CNSmlDSMapContainer::MarkAllItemsSent
       
   236 // Marks all items as sent.
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 void CNSmlDSMapContainer::MarkAllItemsSent()
       
   240 	{
       
   241 	for ( TInt i = 0; i < iMapItemList.Count(); i++ )
       
   242 		{
       
   243 		iMapItemList[i]->iAlreadySent = ETrue;
       
   244 		}
       
   245 	}
       
   246 
       
   247 // <MAPINFO_RESEND_MOD_BEGIN>
       
   248 
       
   249 // ------------------------------------------------------------------------------------------------
       
   250 //CNSmlDSMapContainer::ExternalizeL
       
   251 ///To externalize the map information
       
   252 // ------------------------------------------------------------------------------------------------
       
   253 void CNSmlDSMapContainer::ExternalizeL( RWriteStream& aStream ) const
       
   254 	{
       
   255 	DBG_FILE(_S8("CNSmlDSMapContainer::ExternalizeL(): begin"));
       
   256 	if( !isAppendToStore() )
       
   257 		{
       
   258 		TPckgBuf<TTime> anchor( iMapAnchor );
       
   259 		aStream << anchor;
       
   260 		}
       
   261 	aStream.WriteInt8L(iMapItemList.Count());
       
   262 	for( int i = 0 ; i < iMapItemList.Count() ; i++ )
       
   263 		{
       
   264 		if( !iMapItemList[i]->iLocalUid != NULL && iMapItemList[i]->iGlobalUid != NULL )
       
   265 			{
       
   266 			break;
       
   267 			}
       
   268 		TNSmlMapInfoItem mapItem( iMapItemList[i]->iLocalUid, *iMapItemList[i]->iGlobalUid, iMapItemList[i]->iAtomicId );
       
   269 		TInt err;
       
   270 		TRAP( err, aStream << mapItem );
       
   271 		DBG_FILE_CODE( err, _S8("CNSmlDSMapContainer::ExternalizeL(): Item externalized!"));
       
   272 		}
       
   273 	DBG_FILE(_S8("CNSmlDSMapContainer::ExternalizeL(): end"));
       
   274 	}
       
   275 
       
   276 // ------------------------------------------------------------------------------------------------
       
   277 //CNSmlDSMapContainer::InternalizeL
       
   278 ///To internalize the map information
       
   279 // ------------------------------------------------------------------------------------------------
       
   280 void CNSmlDSMapContainer::InternalizeL( RReadStream& aStream )
       
   281 	{
       
   282 	DBG_FILE(_S8("CNSmlDSMapContainer::InternalizeL(): begin"));
       
   283 	TPckgBuf<TTime> lastMapAnchor;
       
   284 	TRAPD( er, aStream >> lastMapAnchor );
       
   285 	TInt count = 0;
       
   286 	TInt8 mapItemCount = 0;
       
   287 	if( er != KErrEof )
       
   288 		{		
       
   289 		TRAP( er, mapItemCount = aStream.ReadInt8L(); );
       
   290 		}
       
   291 	if( er != KErrEof )
       
   292 		{
       
   293 		setMapAnchor( lastMapAnchor() );
       
   294 		if( mapItemCount > 0 )
       
   295 			{
       
   296 			iMapRemovable = EFalse;
       
   297 			for( int i = 0; i < mapItemCount; i++ )
       
   298 				{
       
   299 				TNSmlMapInfoItem mapItem;
       
   300 				TRAPD( er1, aStream >> mapItem );
       
   301 				if( er1 == KErrEof )
       
   302 					break;
       
   303 				if( mapItem.iLUId != 0 && mapItem.iGUId.Length() != 0 )
       
   304 					{
       
   305 					CreateNewMapItemL( mapItem.iLUId, mapItem.iGUId, mapItem.iAtomicId );
       
   306 					count++;
       
   307 					}
       
   308 				}
       
   309 			}
       
   310 		}
       
   311 	DBG_FILE(_S8("CNSmlDSMapContainer::InternalizeL(): end"));
       
   312 	}
       
   313 
       
   314 // ------------------------------------------------------------------------------------------------
       
   315 //CNSmlDSMapContainer::MapItemListSize
       
   316 //To Retrieve the number of map items present in the map list
       
   317 //-------------------------------------------------------------------------------------------------
       
   318 TInt CNSmlDSMapContainer::MapItemListSize() const
       
   319 	{
       
   320 	return iMapItemList.Count();
       
   321 	}
       
   322 // ------------------------------------------------------------------------------------------------
       
   323 //CNSmlDSMapContainer::setMapAnchor
       
   324 //To set the time stamp of the map list items, for any Time comparisions required
       
   325 // ------------------------------------------------------------------------------------------------
       
   326 void CNSmlDSMapContainer::setMapAnchor(TTime aMapAnchor)
       
   327 	{
       
   328 	iMapAnchor=aMapAnchor;
       
   329 	}
       
   330 
       
   331 // ------------------------------------------------------------------------------------------------
       
   332 //CNSmlDSMapContainer::getMapAnchor
       
   333 //To get the time stamp of the last map list items externalized, for any Time comparisions required
       
   334 // ------------------------------------------------------------------------------------------------
       
   335 TTime CNSmlDSMapContainer::getMapAnchor()
       
   336 	{
       
   337 	return iMapAnchor;
       
   338 	}
       
   339 
       
   340 // ------------------------------------------------------------------------------------------------
       
   341 //CNSmlDSMapContainer::isAppendToStore
       
   342 //To check if the map store has to be overwritten or the new map items to be appended to the existing map store
       
   343 // ------------------------------------------------------------------------------------------------
       
   344 TBool CNSmlDSMapContainer::isAppendToStore() const
       
   345 	{
       
   346 	return iAppendToStore;
       
   347 	}
       
   348 // ------------------------------------------------------------------------------------------------
       
   349 //CNSmlDSMapContainer::isAppendToStore
       
   350 //To set the flag fro the map store for over writing or to appended the new map items to the existing map store
       
   351 // ------------------------------------------------------------------------------------------------
       
   352 void CNSmlDSMapContainer::setAppendToStore(TBool aAppend)
       
   353 	{
       
   354 	iAppendToStore = aAppend;
       
   355 	}
       
   356 
       
   357 // ------------------------------------------------------------------------------------------------
       
   358 //CNSmlDSMapContainer::setRemoveMap()
       
   359 // To Delay the removal of map information from the cache and to remove at a later stage by using isMapRemovable
       
   360 // ---------------------------------------------------------
       
   361 void CNSmlDSMapContainer::setRemoveMap(TBool aRemoveMap)
       
   362 	{
       
   363 	iMapRemovable = aRemoveMap;
       
   364 	}
       
   365 // ------------------------------------------------------------------------------------------------
       
   366 //CNSmlDSMapContainer::isMapRemovable()
       
   367 // To check if map information can be removed from the cache.
       
   368 // ---------------------------------------------------------
       
   369 TBool CNSmlDSMapContainer::isMapRemovable()
       
   370 	{
       
   371 	return iMapRemovable;
       
   372 	}
       
   373 
       
   374 // ------------------------------------------------------------------------------------------------
       
   375 //TNSmlMapInfoItem::ExternalizeL
       
   376 ///To externalize a map item
       
   377 // ------------------------------------------------------------------------------------------------
       
   378 void TNSmlMapInfoItem::ExternalizeL(RWriteStream& aStream) const
       
   379 	{
       
   380 	aStream.WriteInt16L(iLUId);
       
   381 	aStream << iGUId;
       
   382 	aStream.WriteInt8L(iAtomicId);
       
   383 	}
       
   384 // ------------------------------------------------------------------------------------------------
       
   385 //TNSmlMapInfoItem::InternalizeL
       
   386 ///To internalize a map item
       
   387 // ------------------------------------------------------------------------------------------------
       
   388 void TNSmlMapInfoItem::InternalizeL(RReadStream& aStream)
       
   389 	{
       
   390 	iLUId = aStream.ReadInt16L();
       
   391 	aStream >> iGUId;
       
   392 	iAtomicId = aStream.ReadInt8L();
       
   393 	}
       
   394 // ------------------------------------------------------------------------------------------------
       
   395 //TNSmlMapInfoItem::TNSmlMapInfoItem
       
   396 ///Map item constructor
       
   397 // ------------------------------------------------------------------------------------------------
       
   398 TNSmlMapInfoItem::TNSmlMapInfoItem()
       
   399 	{
       
   400 	iLUId = 0;
       
   401 	iGUId.Zero();
       
   402 	iAtomicId = 0;
       
   403 	}
       
   404 // ------------------------------------------------------------------------------------------------
       
   405 //TNSmlMapInfoItem::TNSmlMapInfoItem
       
   406 ///Map item overloaded constructor
       
   407 // ------------------------------------------------------------------------------------------------
       
   408 TNSmlMapInfoItem::TNSmlMapInfoItem( const TSmlDbItemUid aLUId, const TDesC8& aGUId, const TInt aAtomicId )
       
   409 	{
       
   410 	iLUId = aLUId;
       
   411 	iGUId = aGUId;
       
   412 	iAtomicId = aAtomicId;
       
   413 	}
       
   414 // ------------------------------------------------------------------------------------------------
       
   415 //TNSmlMapInfoItem::TNSmlMapInfoItem
       
   416 ///Map item copy constructor
       
   417 // ------------------------------------------------------------------------------------------------
       
   418 TNSmlMapInfoItem::TNSmlMapInfoItem( const TNSmlMapInfoItem& aItem )
       
   419 	{
       
   420 	iLUId = aItem.iLUId;
       
   421 	iGUId = aItem.iGUId;
       
   422 	iAtomicId = aItem.iAtomicId;
       
   423 	}
       
   424 
       
   425 // ------------------------------------------------------------------------------------------------
       
   426 
       
   427 // <MAPINFO_RESEND_MOD_END>
       
   428 	
       
   429 // End of File