syncmlfw/common/historylog/src/NSmlHistoryArray.cpp
changeset 0 b497e44ab2fc
child 73 ae69c2e8bc34
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2002 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:  History entry array
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <SyncMLHistory.h>
       
    20 #include <SyncMLAlertInfo.h>
       
    21 #include "NSmlHistoryArray.h"
       
    22 
       
    23 
       
    24 
       
    25 ///////////////////////////////////////////////////////////////////////////
       
    26 
       
    27 #ifdef _DEBUG
       
    28 
       
    29 #include <flogger.h>
       
    30 
       
    31 _LIT(KLogFile,"smlsync.txt");
       
    32 //_LIT(KLogDirFullName,"c:\\logs\\");
       
    33 _LIT(KLogDir,"smlsync");
       
    34 
       
    35 // Declare the FPrint function
       
    36 inline void FPrint(const TRefByValue<const TDesC> aFmt, ...)
       
    37     {
       
    38     VA_LIST list;
       
    39     VA_START(list,aFmt);
       
    40     RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list);
       
    41     }
       
    42 
       
    43 // ===========================================================================
       
    44 #ifdef __WINS__     // File logging for WINS
       
    45 // ===========================================================================
       
    46 #define FLOG(arg...)   { FPrint(arg); }
       
    47 //#define FLOG(a) { RDebug::Print(a);  }
       
    48 // ===========================================================================
       
    49 #else               // RDebug logging for target HW
       
    50 // ===========================================================================
       
    51 #define FLOG(arg...)   { FPrint(arg); }
       
    52 #endif //__WINS__
       
    53 
       
    54 
       
    55 // ===========================================================================
       
    56 #else // // No loggings --> Reduced binary size
       
    57 // ===========================================================================
       
    58 #define FLOG(arg...)
       
    59 
       
    60 #endif // _DEBUG
       
    61 
       
    62 /////////////////////////////////////////////////////////////////////////////
       
    63 
       
    64 
       
    65 
       
    66 // ---------------------------------------------------------
       
    67 // CNSmlHistoryArray::CNSmlHistoryArray()
       
    68 // Two phase constructor
       
    69 // ---------------------------------------------------------
       
    70 EXPORT_C CNSmlHistoryArray* CNSmlHistoryArray::NewL()
       
    71 	{
       
    72 	CNSmlHistoryArray* self = new (ELeave) CNSmlHistoryArray;
       
    73 	return self;	
       
    74 	}
       
    75 	
       
    76 // ---------------------------------------------------------
       
    77 // CNSmlHistoryArray::CNSmlHistoryArray()
       
    78 // Constructor
       
    79 // ---------------------------------------------------------
       
    80 CNSmlHistoryArray::CNSmlHistoryArray()
       
    81 : iHistoryOwned(EFalse), iSortOrder(CSyncMLHistoryEntry::ESortByTime)
       
    82 	{
       
    83 	
       
    84 	}
       
    85 
       
    86 // ---------------------------------------------------------
       
    87 // CNSmlHistoryArray::CNSmlHistoryArray()
       
    88 // Destructor
       
    89 // ---------------------------------------------------------
       
    90 EXPORT_C CNSmlHistoryArray::~CNSmlHistoryArray()
       
    91 	{
       
    92 	DeleteAllEntries();
       
    93 	iHistory.Close();
       
    94 	}
       
    95 		
       
    96 // ---------------------------------------------------------
       
    97 // CNSmlHistoryArray::Count()
       
    98 // Returns the item count
       
    99 // ---------------------------------------------------------
       
   100 EXPORT_C TInt CNSmlHistoryArray::Count()
       
   101 	{
       
   102 	return iHistory.Count();
       
   103 	}
       
   104 
       
   105 // ---------------------------------------------------------
       
   106 // CNSmlHistoryArray::AppendEntryL(CSyncMLHistoryEntry* aEntry)
       
   107 // Appends new entry to history array and removes the oldest item
       
   108 // if more than five items would be in the array
       
   109 // ---------------------------------------------------------
       
   110 EXPORT_C void CNSmlHistoryArray::AppendEntryL(CSyncMLHistoryEntry* aEntry)
       
   111 	{
       
   112 	if ( aEntry )
       
   113 		{
       
   114 		ResetCorruptedHistroy () ;
       
   115 		if ( aEntry->EntryType().iUid == KSmlHistoryEntryJobTypeValue )
       
   116 			{
       
   117 			DoJobLimitCheck();
       
   118 			}
       
   119 		else
       
   120 			{
       
   121 			DoPushMsgLimitCheck();
       
   122 			}
       
   123 		
       
   124 		iHistory.AppendL( aEntry );
       
   125 		}
       
   126 	}
       
   127 
       
   128 // ---------------------------------------------------------
       
   129 // CNSmlHistoryArray::ResetCorruptedHistroy()
       
   130 // This function will reset the history if it is corrupted
       
   131 // ---------------------------------------------------------
       
   132 
       
   133 void CNSmlHistoryArray::ResetCorruptedHistroy ()
       
   134 {
       
   135 	TTime earliest;
       
   136 	earliest.UniversalTime();
       
   137 	TTime historyTime;
       
   138 	if (iHistory.Count() >= 1)
       
   139 		{
       
   140 		SortEntries(CSyncMLHistoryEntry::ESortByTime); 
       
   141 		historyTime = iHistory[iHistory.Count() - 1]->TimeStamp() ;
       
   142 		if (historyTime > earliest )
       
   143 			{
       
   144 			DeleteAllEntries() ;
       
   145 			}	
       
   146 		}
       
   147 }
       
   148 
       
   149 // ---------------------------------------------------------
       
   150 // CNSmlHistoryArray::RemoveEntry(TInt aIndex)
       
   151 // Removes entry from specified index
       
   152 // ---------------------------------------------------------
       
   153 EXPORT_C CSyncMLHistoryEntry* CNSmlHistoryArray::RemoveEntry(TInt aIndex)
       
   154 	{
       
   155 	if ( (aIndex >= 0 ) && ( aIndex < iHistory.Count() ) )
       
   156 		{
       
   157 		CSyncMLHistoryEntry* entry = iHistory[aIndex];
       
   158 		iHistory.Remove(aIndex);
       
   159 		return entry;
       
   160 		}
       
   161 	return NULL;
       
   162 	}
       
   163 
       
   164 // ---------------------------------------------------------
       
   165 // CNSmlHistoryArray::DeleteAllEntriesL()
       
   166 // Deletes all entries from the array
       
   167 // ---------------------------------------------------------
       
   168 EXPORT_C void CNSmlHistoryArray::DeleteAllEntries()
       
   169 	{
       
   170 	if (iHistoryOwned)
       
   171 		{
       
   172 		iHistory.ResetAndDestroy();		
       
   173 		}
       
   174 	else
       
   175 		{
       
   176 		iHistory.Reset();
       
   177 		}
       
   178 	}
       
   179 
       
   180 // ---------------------------------------------------------
       
   181 // CNSmlHistoryArray::DeleteAllEntriesL()
       
   182 // Returns the entry from specified index
       
   183 // ---------------------------------------------------------
       
   184 EXPORT_C CSyncMLHistoryEntry& CNSmlHistoryArray::Entry(TInt aIndex)
       
   185 	{
       
   186 	return *iHistory[aIndex];
       
   187 	}
       
   188 
       
   189 // ---------------------------------------------------------
       
   190 // CNSmlHistoryArray::SortEntries(CSyncMLHistoryEntry::TSortOrder aSortType)
       
   191 // Sorts the array using specified sort type
       
   192 // ---------------------------------------------------------
       
   193 EXPORT_C void CNSmlHistoryArray::SortEntries(CSyncMLHistoryEntry::TSortOrder aSortType)
       
   194 	{
       
   195 	if ( aSortType == CSyncMLHistoryEntry::ESortByTime )
       
   196 		{
       
   197 		TLinearOrder<CSyncMLHistoryEntry> sort( CNSmlHistoryArray::SortByTime );	
       
   198 		iHistory.Sort( sort );
       
   199 		}
       
   200 	else
       
   201 		{
       
   202 		TLinearOrder<CSyncMLHistoryEntry> sort( CNSmlHistoryArray::SortByType );	
       
   203 		iHistory.Sort( sort );
       
   204 		}
       
   205 	}
       
   206 
       
   207 // ---------------------------------------------------------
       
   208 // CNSmlHistoryArray::SetOwnerShip(TBool aOwner)
       
   209 // Changes the ownership of items. If ETrue array takes ownership.
       
   210 // ---------------------------------------------------------
       
   211 EXPORT_C void CNSmlHistoryArray::SetOwnerShip(TBool aOwner)
       
   212 	{
       
   213 	iHistoryOwned = aOwner;
       
   214 	}
       
   215 
       
   216 // ---------------------------------------------------------
       
   217 // CNSmlHistoryArray::InternalizeL(RReadStream& aStream)
       
   218 // Reads history array from given stream
       
   219 // ---------------------------------------------------------
       
   220 EXPORT_C void CNSmlHistoryArray::InternalizeL(RReadStream& aStream)
       
   221 	{
       
   222 	DeleteAllEntries();
       
   223 	TInt count = aStream.ReadInt32L();
       
   224 	
       
   225 	for (TInt i = 0; i < count; i++)
       
   226 		{
       
   227 		CSyncMLHistoryEntry* entry = CSyncMLHistoryEntry::NewL(aStream);
       
   228 		iHistory.AppendL(entry);
       
   229 		}
       
   230 	}
       
   231 
       
   232 // ---------------------------------------------------------
       
   233 // CNSmlHistoryArray::ExternalizeL(RWriteStream& aStream) const
       
   234 // Writes history array to given stream
       
   235 // ---------------------------------------------------------
       
   236 EXPORT_C void CNSmlHistoryArray::ExternalizeL(RWriteStream& aStream) const
       
   237 	{
       
   238 	TInt count = iHistory.Count();
       
   239 	aStream.WriteInt32L(count);
       
   240 	for (TInt i = 0; i < count; i++)
       
   241 		{
       
   242 		iHistory[i]->ExternalizeL(aStream);
       
   243 		}
       
   244 	}
       
   245 
       
   246 // ---------------------------------------------------------
       
   247 // CNSmlHistoryArray::DoJobLimitCheck()
       
   248 // Limits the amount of CSyncMLHistoryJobs. Oldest is removed.
       
   249 // ---------------------------------------------------------
       
   250 void CNSmlHistoryArray::DoJobLimitCheck()
       
   251 	{
       
   252 	RemoveHistoryJob();
       
   253 	
       
   254 	/*
       
   255 	TInt count(0);
       
   256 	TInt target(-1);
       
   257 	TTime earliest;
       
   258 	
       
   259 	earliest.UniversalTime();
       
   260 	
       
   261 	for (TInt index = 0; index < iHistory.Count(); index++)
       
   262 		{
       
   263 		if ( iHistory[index]->EntryType().iUid == KSmlHistoryEntryJobTypeValue )
       
   264 			{
       
   265 			if (iHistory[index]->TimeStamp() < earliest )
       
   266 				{
       
   267 				earliest = iHistory[index]->TimeStamp();
       
   268 				target = index;
       
   269 				}
       
   270 			count++;
       
   271 			}
       
   272 		}
       
   273 		
       
   274 	if (count > KNSmlMaxHistoryLogEntries)
       
   275 		{
       
   276 		delete RemoveEntry(target);
       
   277 		}
       
   278 	*/
       
   279 	}
       
   280 
       
   281 
       
   282 // ---------------------------------------------------------
       
   283 // CNSmlHistoryArray::DoPushMsgLimitCheck()
       
   284 // Limits the amount of CSyncMLHistoryPushMsg. Oldest is removed.
       
   285 // ---------------------------------------------------------
       
   286 void CNSmlHistoryArray::DoPushMsgLimitCheck()
       
   287 	{
       
   288 	TInt count(0);
       
   289 	TInt target(-1);
       
   290 	TTime earliest;
       
   291 	
       
   292 	earliest.UniversalTime();
       
   293 	
       
   294 	for (TInt index = 0; index < iHistory.Count(); index++)
       
   295 		{
       
   296 		if ( iHistory[index]->EntryType().iUid == KSmlHistoryEntryPushMsgTypeValue )
       
   297 			{
       
   298 			if (iHistory[index]->TimeStamp() < earliest )
       
   299 				{
       
   300 				earliest = iHistory[index]->TimeStamp();
       
   301 				target = index;
       
   302 				}
       
   303 			count++;
       
   304 			}
       
   305 		}
       
   306 		
       
   307 	if (count > KNSmlMaxHistoryLogEntries)
       
   308 		{
       
   309 		delete RemoveEntry(target);
       
   310 		}
       
   311 	}
       
   312 
       
   313 // ---------------------------------------------------------
       
   314 // CNSmlHistoryArray::SortByType(const CSyncMLHistoryEntry& aLeft, const CSyncMLHistoryEntry& aRight)
       
   315 // Sorts the array by entry type.
       
   316 // ---------------------------------------------------------
       
   317 TInt CNSmlHistoryArray::SortByType(const CSyncMLHistoryEntry& aLeft, const CSyncMLHistoryEntry& aRight)
       
   318 	{
       
   319 	TInt left = aLeft.EntryType().iUid;
       
   320 	TInt right = aRight.EntryType().iUid;
       
   321 	
       
   322 	if ( left < right )
       
   323 		{
       
   324 		return -1; 	// Compared entry type is smaller
       
   325 		}
       
   326 	
       
   327 	if ( left > right )
       
   328 		{
       
   329 		return 1;	// Compared entry type is bigger
       
   330 		}
       
   331 		
       
   332 	return 0;
       
   333 	}
       
   334 
       
   335 // ---------------------------------------------------------
       
   336 // CNSmlHistoryArray::SortByTime(const CSyncMLHistoryEntry& aLeft, const CSyncMLHistoryEntry& aRight)
       
   337 // Sorts the array by entrie's timestamp
       
   338 // ---------------------------------------------------------
       
   339 TInt CNSmlHistoryArray::SortByTime(const CSyncMLHistoryEntry& aLeft, const CSyncMLHistoryEntry& aRight)
       
   340 	{
       
   341 	
       
   342 	if ( aLeft.TimeStamp() < aRight.TimeStamp() )
       
   343 		{
       
   344 		return -1;	// Compared entry is earlier
       
   345 		}
       
   346 	
       
   347 	if ( aLeft.TimeStamp() > aRight.TimeStamp() )
       
   348 		{
       
   349 		return 1;	// Compared entry is later
       
   350 		}
       
   351 			
       
   352 	return 0;
       
   353 	}
       
   354 
       
   355 
       
   356 // ---------------------------------------------------------
       
   357 // CNSmlHistoryArray::RemoveHistoryJob
       
   358 // 
       
   359 // ---------------------------------------------------------
       
   360 void CNSmlHistoryArray::RemoveHistoryJob()
       
   361 	{
       
   362 	TInt err = KErrNone;
       
   363 	
       
   364 	TRAP(err, RemoveHistoryJobL());
       
   365 	
       
   366 	if (err != KErrNone)
       
   367 		{
       
   368 		FLOG( _L("### CNSmlHistoryArray::RemoveHistoryJob failed (%d) ###"), err );
       
   369 		}
       
   370 		
       
   371 #ifdef _DEBUG	
       
   372 	TRAP_IGNORE(LogHistoryArrayL());
       
   373 	CheckHistoryJobCount();
       
   374 #endif
       
   375 
       
   376 	}
       
   377 
       
   378 
       
   379 // ---------------------------------------------------------
       
   380 // CNSmlHistoryArray::RemoveHistoryJobL
       
   381 // 
       
   382 // This function removes old history job entries from history
       
   383 // array. If old history job entry contains tasks that do not
       
   384 // exist in 5 most recent entries, old entry is not removed.
       
   385 // This way sync information for a task is not lost.
       
   386 // ---------------------------------------------------------
       
   387 void CNSmlHistoryArray::RemoveHistoryJobL()
       
   388 	{
       
   389     RArray<TInt> taskList;
       
   390     CleanupClosePushL(taskList);
       
   391       
       
   392 	for (;;)
       
   393 		{
       
   394 		if (!RemoveHistoryJobL(taskList))
       
   395 			{
       
   396 			break;
       
   397 			}
       
   398 		}
       
   399 	
       
   400     CleanupStack::PopAndDestroy(&taskList);
       
   401 	}
       
   402 
       
   403 
       
   404 // ---------------------------------------------------------
       
   405 // CNSmlHistoryArray::RemoveHistoryJobL
       
   406 // 
       
   407 // ---------------------------------------------------------
       
   408 TBool CNSmlHistoryArray::RemoveHistoryJobL(RArray<TInt>& aTaskList)
       
   409 	{
       
   410 	FLOG( _L("CNSmlHistoryArray::RemoveHistoryJobL START") );
       
   411 	
       
   412 	const TInt KMaxExtraHistoryLogEntries = 5;
       
   413 	const TInt KMaxTotalCount = KNSmlMaxHistoryLogEntries +
       
   414 	                            KMaxExtraHistoryLogEntries;
       
   415 
       
   416 	SortEntries(CSyncMLHistoryEntry::ESortByTime);
       
   417 	InitializeTaskListL(aTaskList);
       
   418 
       
   419 	TInt historyJobCount = 0;
       
   420 	TInt count = iHistory.Count();
       
   421 	
       
   422     
       
   423     // first pass 5 (KNSmlMaxHistoryLogEntries) latest history
       
   424     // job entries and then check whether possible extra entries
       
   425     // can be removed
       
   426     for (TInt i=count-1; i>=0; i--)
       
   427     	{
       
   428         if (iHistory[i]->EntryType().iUid == KSmlHistoryEntryJobTypeValue)
       
   429         	{
       
   430         	historyJobCount++;
       
   431         	
       
   432         	if (historyJobCount > KNSmlMaxHistoryLogEntries)
       
   433         		{
       
   434          		const CSyncMLHistoryEntry* entry = iHistory[i];
       
   435         		const CSyncMLHistoryJob* historyJob = 
       
   436         		      CSyncMLHistoryJob::DynamicCast(entry);
       
   437 
       
   438          	    if (historyJobCount > KMaxTotalCount)
       
   439         		    {
       
   440         		    // history array is full - delete extra entry
       
   441         		    FLOG( _L("### history array overflow - delete extra entry ###") );
       
   442         		    delete RemoveEntry(i);
       
   443         		    
       
   444                   	FLOG( _L("CNSmlHistoryArray::RemoveHistoryJobL END") );
       
   445                 	return ETrue;
       
   446          		    }
       
   447                 
       
   448                 if (CanRemove(historyJob, aTaskList))
       
   449                 	{
       
   450                 	FLOG(_L("remove history job entry"));
       
   451 #ifdef _DEBUG                	
       
   452                 	LogHistoryJobL(historyJob);
       
   453 #endif                	
       
   454                 	delete RemoveEntry(i);
       
   455                 	
       
   456                 	FLOG( _L("CNSmlHistoryArray::RemoveHistoryJobL END") );
       
   457                 	return ETrue;
       
   458                 	}
       
   459                 else
       
   460                 	{
       
   461                 	FLOG(_L("leave extra history job entry"));
       
   462 #ifdef _DEBUG                	
       
   463                 	LogHistoryJobL(historyJob);
       
   464 #endif                	
       
   465                 	
       
   466                 	UpdateTaskListL(historyJob, aTaskList);
       
   467                  	}
       
   468         		}
       
   469         	}
       
   470     	}
       
   471     	
       
   472     FLOG( _L("CNSmlHistoryArray::RemoveHistoryJobL END") );
       
   473     return EFalse;
       
   474 	}
       
   475 
       
   476 
       
   477 // ---------------------------------------------------------
       
   478 // CNSmlHistoryArray::InitializeTaskListL
       
   479 // 
       
   480 // ---------------------------------------------------------
       
   481 void CNSmlHistoryArray::InitializeTaskListL(RArray<TInt>& aTaskList)
       
   482 	{
       
   483 	aTaskList.Reset();
       
   484 	TInt historyJobCount = 0;
       
   485 	TInt count = iHistory.Count();
       
   486 	
       
   487     // store sync tasks from 5 most recent history job entries
       
   488     for (TInt i=count-1; i>=0; i--)
       
   489     	{
       
   490         if (iHistory[i]->EntryType().iUid == KSmlHistoryEntryJobTypeValue)
       
   491         	{
       
   492         	historyJobCount++;
       
   493         	if (historyJobCount <= KNSmlMaxHistoryLogEntries)
       
   494         		{
       
   495         		const CSyncMLHistoryEntry* entry = iHistory[i];
       
   496         		const CSyncMLHistoryJob* historyJob = 
       
   497         		      CSyncMLHistoryJob::DynamicCast(entry);
       
   498         		
       
   499         		UpdateTaskListL(historyJob, aTaskList);
       
   500         		}
       
   501         	}
       
   502     	}
       
   503 	}
       
   504 
       
   505 
       
   506 // ---------------------------------------------------------
       
   507 // CNSmlHistoryArray::UpdateTaskListL
       
   508 // 
       
   509 // ---------------------------------------------------------
       
   510 void CNSmlHistoryArray::UpdateTaskListL(const CSyncMLHistoryJob* aHistoryJob, 
       
   511                                  RArray<TInt>& aTaskList)
       
   512 	{
       
   513 	TInt count = aHistoryJob->TaskCount();
       
   514 	for (TInt i=0; i<count; i++)
       
   515 		{
       
   516 		const CSyncMLHistoryJob::TTaskInfo& taskInfo = 
       
   517 		                         aHistoryJob->TaskAt(i);
       
   518 		if (aTaskList.Find(taskInfo.iTaskId) == KErrNotFound)
       
   519 			{
       
   520 			User::LeaveIfError(aTaskList.Append(taskInfo.iTaskId));
       
   521 			}
       
   522 		}
       
   523 	}
       
   524 
       
   525 
       
   526 // ---------------------------------------------------------
       
   527 // CNSmlHistoryArray::CanRemove
       
   528 // 
       
   529 // ---------------------------------------------------------
       
   530 TBool CNSmlHistoryArray::CanRemove(const CSyncMLHistoryJob* aHistoryJob, 
       
   531                                    RArray<TInt>& aTaskList)
       
   532 	{
       
   533 	
       
   534 	// check wheteher this history job has a task that does not 
       
   535 	// exist in aTaskList
       
   536 	TInt count = aHistoryJob->TaskCount();
       
   537 	for (TInt i=0; i<count; i++)
       
   538 		{
       
   539 		const CSyncMLHistoryJob::TTaskInfo& taskInfo = 
       
   540 		                         aHistoryJob->TaskAt(i);
       
   541 		                         
       
   542 		if (aTaskList.Find(taskInfo.iTaskId) == KErrNotFound)
       
   543 			{
       
   544 			return EFalse;
       
   545 			}
       
   546 		}
       
   547 		
       
   548 	return ETrue;
       
   549 	}
       
   550 
       
   551 
       
   552 #ifdef _DEBUG
       
   553 
       
   554 // ---------------------------------------------------------
       
   555 // CNSmlHistoryArray::CheckHistoryJobCount
       
   556 // 
       
   557 // ---------------------------------------------------------
       
   558 void CNSmlHistoryArray::CheckHistoryJobCount()
       
   559 	{
       
   560 	_LIT(KPanicCategory,"CNSmlHistoryArray");
       
   561 
       
   562 	const TInt KMaxExtraHistoryLogEntries = 5;
       
   563 	TInt limit = KNSmlMaxHistoryLogEntries + KMaxExtraHistoryLogEntries;
       
   564 	
       
   565 	TInt historyJobCount = 0;
       
   566 	TInt count = iHistory.Count();
       
   567 	
       
   568     for (TInt i=count-1; i>=0; i--)
       
   569     	{
       
   570         if (iHistory[i]->EntryType().iUid == KSmlHistoryEntryJobTypeValue)
       
   571         	{
       
   572         	historyJobCount++;
       
   573         	
       
   574         	if (historyJobCount > limit)
       
   575         		{
       
   576        			User::Panic(KPanicCategory, KErrOverflow); 
       
   577         		}
       
   578         	}
       
   579     	}
       
   580 	}
       
   581 
       
   582 
       
   583 // ---------------------------------------------------------
       
   584 // CNSmlHistoryArray::LogHistoryJobL
       
   585 // 
       
   586 // ---------------------------------------------------------
       
   587 void CNSmlHistoryArray::LogHistoryJobL(const CSyncMLHistoryJob* aHistoryJob)
       
   588 	{
       
   589 	FLOG( _L("---- CSyncMLHistoryJob ----") );
       
   590 	
       
   591 	TBuf<128> buf1; TBuf<128> buf2; TBuf<128> buf3;
       
   592 	
       
   593 	TTime time = aHistoryJob->TimeStamp();
       
   594 	GetDateTimeTextL(buf1, time);
       
   595 	buf2.Format(_L("sync time: %S"), &buf1);
       
   596 	FLOG(buf2);
       
   597 	
       
   598 	buf2 = KNullDesC;
       
   599 	TInt count = aHistoryJob->TaskCount();
       
   600 	for (TInt i=0; i<count; i++)
       
   601 		{
       
   602 		const CSyncMLHistoryJob::TTaskInfo& taskInfo = 
       
   603 		                         aHistoryJob->TaskAt(i);
       
   604         buf3.Format(_L("%d "), taskInfo.iTaskId);		                         
       
   605 		buf2.Append(buf3);
       
   606 		}
       
   607 		
       
   608 	buf1.Format(_L("sync tasks: %S"), &buf2);
       
   609 	FLOG(buf1);
       
   610 
       
   611 	
       
   612 	FLOG( _L("---- CSyncMLHistoryJob ----") );
       
   613 	}
       
   614 	
       
   615 	
       
   616 // ---------------------------------------------------------
       
   617 // CNSmlHistoryArray::LogHistoryArrayL
       
   618 // 
       
   619 // ---------------------------------------------------------
       
   620 void CNSmlHistoryArray::LogHistoryArrayL()
       
   621 	{
       
   622 	FLOG( _L("---- history array ----") );
       
   623 	
       
   624 	TInt historyJobCount = 0;
       
   625 	TInt count = iHistory.Count();
       
   626 	
       
   627 	SortEntries(CSyncMLHistoryEntry::ESortByTime);
       
   628     
       
   629     for (TInt i=count-1; i>=0; i--)
       
   630     	{
       
   631         if (iHistory[i]->EntryType().iUid == KSmlHistoryEntryJobTypeValue)
       
   632         	{
       
   633         	historyJobCount++;
       
   634         	
       
   635        		const CSyncMLHistoryEntry* entry = iHistory[i];
       
   636        		const CSyncMLHistoryJob* historyJob = 
       
   637         		      CSyncMLHistoryJob::DynamicCast(entry);
       
   638           	LogHistoryJobL(historyJob);
       
   639          	}
       
   640     	}
       
   641     	
       
   642     FLOG( _L("---- history array ----") );
       
   643 	}
       
   644 
       
   645 
       
   646 // ---------------------------------------------------------
       
   647 // CNSmlHistoryArray::GetDateTimeTextL
       
   648 // 
       
   649 // ---------------------------------------------------------
       
   650 void CNSmlHistoryArray::GetDateTimeTextL(TDes& aText, TTime aDateTime)
       
   651 	{
       
   652 	TDateTime dt = aDateTime.DateTime();
       
   653 	aText.Format(_L("%02d.%02d.%04d %02d:%02d:%02d"), dt.Day()+1, dt.Month()+1, dt.Year(),  dt.Hour(), dt.Minute(), dt.Second());
       
   654 	}
       
   655 
       
   656 #endif
       
   657 
       
   658