pimappservices/calendar/shared/src/agmdebug.cpp
changeset 0 f979ecb2b13e
child 29 12af337248b1
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 // Copyright (c) 2006-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 "agmdebug.h"
       
    17 #include "agmentry.h"
       
    18 #include "agmserv.h"
       
    19 #include "agmrptdef.h"
       
    20 #include "agsalarm.h"
       
    21 #include "agmfilter.h"
       
    22 #include <utf.h>
       
    23 
       
    24 #if defined(_DEBUG)
       
    25 const TInt KMaxLogLength = 0x100;
       
    26 
       
    27 EXPORT_C void AgmDebug::DebugLog(const char* aFmt,...)
       
    28 	{
       
    29 	VA_LIST list = {NULL};
       
    30 	VA_START(list,aFmt);
       
    31 
       
    32 	TPtrC8 fmt8((const TText8*)aFmt);
       
    33 		
       
    34 	TBuf<KMaxLogLength> fmt16;
       
    35 	fmt16.Copy(fmt8);
       
    36 
       
    37 	TBuf<KMaxLogLength> logBuf16;
       
    38 	TTruncateOverflow16 overflow;
       
    39 	logBuf16.AppendFormatList(fmt16,list,&overflow);
       
    40 	
       
    41 	TBuf8<0x100> logBuf8;
       
    42 	
       
    43 	TInt err = CnvUtfConverter::ConvertFromUnicodeToUtf8(logBuf8,logBuf16);
       
    44 	if(err==KErrNone)
       
    45 		{
       
    46 		RDebug::Printf("CAL_LOG: %S", &logBuf8);
       
    47 		}
       
    48 	}
       
    49 
       
    50 EXPORT_C void AgmDebug::DebugLogTimeStampL(const char* aFmt,...)
       
    51 	{
       
    52 	VA_LIST list = {NULL};
       
    53 	VA_START(list,aFmt);
       
    54 
       
    55 	TPtrC8 fmt8((const TText8*)aFmt);
       
    56 		
       
    57 	TBuf<KMaxLogLength> fmt16;
       
    58 	fmt16.Copy(fmt8);
       
    59 
       
    60 	TBuf<KMaxLogLength> logBuf16;
       
    61 	TTruncateOverflow16 overflow;
       
    62 	logBuf16.AppendFormatList(fmt16,list,&overflow);
       
    63 	
       
    64 	TBuf8<0x100> logBuf8;
       
    65 	
       
    66 	TInt err = CnvUtfConverter::ConvertFromUnicodeToUtf8(logBuf8,logBuf16);
       
    67 	
       
    68 	TTime timeNow;
       
    69 	timeNow.HomeTime();
       
    70 	TBuf<KMinTTimeStrLength> timeNowBuf16;
       
    71 	TTimeStrL(timeNow, timeNowBuf16);
       
    72 	
       
    73 	TBuf8<0x100> timeBuf8;
       
    74 	
       
    75 	TInt timeErr = CnvUtfConverter::ConvertFromUnicodeToUtf8(timeBuf8,timeNowBuf16);
       
    76 	
       
    77 	if(err==KErrNone)
       
    78 		{
       
    79 		RDebug::Printf("CAL_LOG: %S: %S\n", &timeBuf8, &logBuf8);
       
    80 		}
       
    81 	}
       
    82 
       
    83 EXPORT_C  void AgmDebug::TTimeStrL(const TTime& aTTime, TDes& aTimeStr)
       
    84 	{
       
    85 	if(aTTime==Time::NullTTime())
       
    86 		{
       
    87 		_LIT(KNullTimeDes,"NULL");
       
    88 		aTimeStr.Copy(KNullTimeDes);
       
    89 		}
       
    90 	else
       
    91 		{
       
    92 		_LIT(KTTimeDateFormat,"Time: %H:%T:%S:%*C3 Date:%*1/%2/%3");
       
    93 		aTTime.FormatL(aTimeStr,KTTimeDateFormat);
       
    94 		}
       
    95 	}
       
    96 
       
    97 #if defined (__CAL_VERBOSE_LOGGING__) || (__CAL_ENTRY_LOGGING__)
       
    98 EXPORT_C void AgmDebug::DebugLogEntryL(CAgnEntry& aEntry, TAgmEntryDumpLevel aEntryDumpLevel)
       
    99 	{
       
   100 	const TInt KMaxEntryTimeModeStrLength = 12;
       
   101 	const TInt KMaxEntryTypeStrLength = 12;
       
   102 
       
   103 	TBuf<KMaxLogLength> logBuf;
       
   104 	TBuf<KMaxEntryTimeModeStrLength> entryModeBuf;
       
   105 	TBuf<KMaxEntryTypeStrLength> entryTypeBuf;
       
   106 
       
   107 	TBool entryTimeModeUTC;
       
   108 	
       
   109 	logBuf.Append(_L("Dumping Entry: "));
       
   110 	if(aEntryDumpLevel & EDumpEntryIDs) logBuf.Append(_L("Ids | "));
       
   111 	if(aEntryDumpLevel & EDumpEntryTimes) logBuf.Append(_L("Times | "));
       
   112 	if(aEntryDumpLevel & EDumpEntryRptInfo) logBuf.Append(_L("Repeat Info | "));
       
   113 	if(aEntryDumpLevel & EDumpEntryStrData) logBuf.Append(_L("String Info"));
       
   114 	
       
   115 	DebugLog("%S", &logBuf);
       
   116 	
       
   117 	// Entry Type
       
   118 	switch (aEntry.Type())
       
   119 		{
       
   120 		case CCalEntry::EAppt: 		entryTypeBuf.Copy(_L("Appointment")); break;
       
   121 		case CCalEntry::EReminder: 	entryTypeBuf.Copy(_L("Reminder")); break;
       
   122 		case CCalEntry::ETodo: 		entryTypeBuf.Copy(_L("Todo")); break;
       
   123 		case CCalEntry::EEvent: 		entryTypeBuf.Copy(_L("Event")); break;
       
   124 		case CCalEntry::EAnniv: 		entryTypeBuf.Copy(_L("Anniversary")); break;
       
   125 		}
       
   126 		
       
   127 	// Entry Time Mode
       
   128 	if (aEntry.TimeMode() == MAgnCalendarTimeMode::EFloating)
       
   129 		{
       
   130 		entryTimeModeUTC = ETrue;
       
   131 		_LIT(KFloatingDes, "Floating");
       
   132 		entryModeBuf.Copy(KFloatingDes());
       
   133 		}
       
   134 	else
       
   135 		{
       
   136 		entryTimeModeUTC = EFalse;
       
   137 		_LIT(KUTCDes, "UTC");
       
   138 		entryModeBuf.Copy(KUTCDes());
       
   139 		}
       
   140 	
       
   141 	// Entry IDs
       
   142 	if (aEntryDumpLevel & EDumpEntryIDs)
       
   143 		{
       
   144 		// == GUID and Local ID
       
   145 		logBuf.Copy(aEntry.Guid());
       
   146 		DebugLog("%S: Local UID=%d, GUID=%S, Mode =%S", &entryTypeBuf, aEntry.LocalUid(), &logBuf,&entryModeBuf);
       
   147 
       
   148 		// == Recurrence ID
       
   149 		TBuf<KMinTTimeStrLength> recIdTimeBuf;
       
   150 		if(entryTimeModeUTC)
       
   151 			{
       
   152 			TTimeStrL(aEntry.RecurrenceId().UtcL(), recIdTimeBuf);
       
   153 			}
       
   154 		else
       
   155 			{
       
   156 			TTimeStrL(aEntry.RecurrenceId().LocalL(), recIdTimeBuf);
       
   157 			}
       
   158 		DebugLog("%S: Recurrence ID is %S", &entryTypeBuf, &recIdTimeBuf);
       
   159 		
       
   160 		// == Recurrence Range
       
   161 		switch (aEntry.RecurrenceRange())
       
   162 			{
       
   163 			case CalCommon::EThisAndFuture:
       
   164 				logBuf.Copy(_L("This And Future"));
       
   165 				break;
       
   166 			case CalCommon::EThisAndPrior:
       
   167 				logBuf.Copy(_L("This And Prior"));
       
   168 				break;
       
   169 			default:
       
   170 				logBuf.Copy(_L("Not Valid"));
       
   171 				break;
       
   172 			}
       
   173 		DebugLog("%S: Recurrence Range - %S",&entryTypeBuf, &logBuf);
       
   174 		}
       
   175 
       
   176 	// Entry Times
       
   177 	if (aEntryDumpLevel & EDumpEntryTimes)
       
   178 		{
       
   179 		TBuf<KMinTTimeStrLength> startTimeBuf;
       
   180 		TBuf<KMinTTimeStrLength> endTimeBuf;
       
   181 		
       
   182 		if(entryTimeModeUTC)
       
   183 			{
       
   184 			TTimeStrL(aEntry.StartTime().UtcL(), startTimeBuf);
       
   185 			TTimeStrL(aEntry.EndTime().UtcL(), endTimeBuf);
       
   186 			}
       
   187 		else
       
   188 			{
       
   189 			TTimeStrL(aEntry.StartTime().LocalL(), startTimeBuf);
       
   190 			TTimeStrL(aEntry.EndTime().LocalL(), endTimeBuf);
       
   191 			}
       
   192 		DebugLog("%S: Start Time - %S %S", &entryTypeBuf, &startTimeBuf, &entryModeBuf);
       
   193 		DebugLog("%S: End Time - %S %S", &entryTypeBuf, &endTimeBuf, &entryModeBuf);
       
   194 		}
       
   195 	
       
   196 	// Entry Repeat Info
       
   197 	if (aEntryDumpLevel & EDumpEntryRptInfo)
       
   198 		{
       
   199 		if (aEntry.RptDef())
       
   200 			{
       
   201 			switch (aEntry.RptDef()->HasRepeatRule())
       
   202 				{
       
   203 				case TAgnRpt::EDaily:			logBuf.Copy(_L("Daily")); break;
       
   204 				case TAgnRpt::EWeekly:			logBuf.Copy(_L("Weekly")); break;
       
   205 				case TAgnRpt::EMonthlyByDates:
       
   206 				case TAgnRpt::EMonthlyByDays:	logBuf.Copy(_L("Monthly")); break;
       
   207 				case TAgnRpt::EYearlyByDate:
       
   208 				case TAgnRpt::EYearlyByDay:		logBuf.Copy(_L("Yearly")); break;
       
   209 				default:						logBuf.Copy(_L("Repeat Rule - NOT SET"));
       
   210 				}
       
   211 			
       
   212 			if(aEntry.RptDef()->HasRepeatRule())
       
   213 				{
       
   214 				DebugLog("%S: Repeats - %S, Interval - %d", &entryTypeBuf, &logBuf,aEntry.RptDef()->RRule()->Interval());
       
   215 						
       
   216 				TBuf<KMinTTimeStrLength> untilTimeBuf;
       
   217 				if(entryTimeModeUTC)
       
   218 					{
       
   219 					TTimeStrL(aEntry.RptDef()->RRule()->UntilTimeL().UtcL(), untilTimeBuf);
       
   220 					}
       
   221 				else
       
   222 					{
       
   223 					TTimeStrL(aEntry.RptDef()->RRule()->UntilTimeL().LocalL(), untilTimeBuf);
       
   224 					}		
       
   225 					
       
   226 				DebugLog("%S: Repeat Until Time - %S %S",&entryTypeBuf, &untilTimeBuf, &entryModeBuf);
       
   227 				}
       
   228 				
       
   229 			if (aEntry.RptDef()->HasSporadicDates())
       
   230 				{
       
   231 				TTime sporadicTTime;
       
   232 				TBuf<KMinTTimeStrLength> sopradicTimeBuf;
       
   233 				const TInt KRDateCount =aEntry.RptDef()->SporadicDateList()->Count();
       
   234 				
       
   235 				DebugLog("%S: Number of sporadic dates: %d",&entryTypeBuf,KRDateCount);
       
   236 				
       
   237 				for (TInt i = 0; i < KRDateCount; ++i)
       
   238 					{
       
   239 					if(entryTimeModeUTC)
       
   240 						{
       
   241 						sporadicTTime = (*aEntry.RptDef()->SporadicDateList())[i].UtcL();
       
   242 						}
       
   243 					else
       
   244 						{
       
   245 						sporadicTTime = (*aEntry.RptDef()->SporadicDateList())[i].LocalL();
       
   246 						}
       
   247 					TTimeStrL(sporadicTTime, sopradicTimeBuf);
       
   248 					DebugLog("%S: RDate %d %S",&entryTypeBuf, i+1,&sopradicTimeBuf);
       
   249 					}
       
   250 				}
       
   251 			else
       
   252 				{
       
   253 				DebugLog("%S: No sporadic dates", &entryTypeBuf);
       
   254 				}
       
   255 			}
       
   256 		else
       
   257 			{
       
   258 			DebugLog("%S: No repeat definition",&entryTypeBuf);
       
   259 			}
       
   260 		}
       
   261 
       
   262 	// Entry Info
       
   263 	if (aEntryDumpLevel & EDumpEntryStrData)
       
   264 		{
       
   265 		if (aEntry.Summary()!=KNullDesC && aEntry.Summary().Length())
       
   266 			{
       
   267 			DebugLog("%S: Summary='%S'",&entryTypeBuf, &aEntry.Summary());
       
   268 			}
       
   269 		if (aEntry.Description()!=KNullDesC && aEntry.Description().Length())
       
   270 			{
       
   271 			DebugLog("%S: Description='%S'", &entryTypeBuf, &aEntry.Description());
       
   272 			}
       
   273 		if (aEntry.Location()!=KNullDesC && aEntry.Location().Length())
       
   274 			{
       
   275 			DebugLog("%S: Location='%S'\n", &entryTypeBuf, &aEntry.Location());
       
   276 			}
       
   277 		}
       
   278 	}
       
   279 #else
       
   280 	EXPORT_C void AgmDebug::DebugLogEntryL(CAgnEntry& /*aEntry*/, TAgmEntryDumpLevel /*aEntryDumpLevel*/) {}
       
   281 #endif
       
   282 
       
   283 #if defined (__CAL_VERBOSE_LOGGING__) || (__CAL_IPC_LOGGING__)
       
   284 #define NM_CASE(x) case x: enumStr = _S(#x); break;
       
   285 EXPORT_C void AgmDebug::DebugLogIPCL(TInt aOpCode, TUint aSessionId, TInt aErrCode)
       
   286 	{
       
   287 	const TText* enumStr;
       
   288 
       
   289 	switch (aOpCode)
       
   290 		{//case EOpenAgenda: enumStr = _S("EOpenAgenda");
       
   291 		NM_CASE(EOpenAgenda);			
       
   292 		NM_CASE(ECloseAgenda);						
       
   293 		NM_CASE(ETransmitBuffer);					
       
   294 		NM_CASE(EGetInstanceExtractor);	
       
   295 		NM_CASE(EPreviousInstances);			
       
   296 		NM_CASE(ENextInstances);				
       
   297 		NM_CASE(ECreateEntryIterator);				
       
   298 		NM_CASE(EEntryIteratorNext);					
       
   299 		NM_CASE(EEntryIteratorPosition);		
       
   300 		NM_CASE(EGetEntryUidsSinceDate);				
       
   301 		NM_CASE(EGetFileId);							
       
   302 		NM_CASE(EGetCategoryListCount);				
       
   303 		NM_CASE(ECategoryFilter);					
       
   304 		NM_CASE(EStartBuildIndex);					
       
   305 		NM_CASE(EGetListFileNames);	
       
   306 		NM_CASE(ECancelTask);				
       
   307 		NM_CASE(EAgnResourceCount);	//	test 		
       
   308 		NM_CASE(EAgnSetHeapFailure);	//	test 
       
   309 		NM_CASE(EAgendaFileExists);
       
   310 	 	NM_CASE(EDisableChangeBroadcast);
       
   311 		NM_CASE(EEnableChangeBroadcast);
       
   312 		NM_CASE(ERequestChangeNotificationParameters);
       
   313 		NM_CASE(ERequestChangeNotification);
       
   314 		NM_CASE(ECancelChangeNotification);
       
   315 		NM_CASE(ERequestProgress);
       
   316 		NM_CASE(ESetUpdateAlarm);
       
   317 		NM_CASE(ESetEnablePubSubNotification);
       
   318 		NM_CASE(ERestoreAlarmAction);
       
   319 		NM_CASE(ETzDbChangedTime);
       
   320 		// ReadUserData required 
       
   321 		NM_CASE(EFetchEntry); 						
       
   322 		NM_CASE(EFetchSimpleEntry);	
       
   323 		NM_CASE(EFetchSimpleEntries);					
       
   324 		NM_CASE(EFetchEntryByUID);					
       
   325 		NM_CASE(ERestoreText);					
       
   326 		NM_CASE(EGetCategoryListItem);
       
   327 		NM_CASE(EGetChangesSinceLastNotification);
       
   328 		NM_CASE(EFindInstances);
       
   329 		NM_CASE(EFetchEntryByGuid);
       
   330 		NM_CASE(ETransferAttachmentFileToClient);
       
   331 		NM_CASE(EMoveFileToServer);
       
   332 		NM_CASE(EFetchSortedAttachments);
       
   333 		NM_CASE(EEntriesWithAttachment);
       
   334 		NM_CASE(EFetchAttachmentById);
       
   335 			
       
   336 		// WriteUserData required 
       
   337 		NM_CASE(EUpdateEntry);						
       
   338 		NM_CASE(EAddEntry);							
       
   339 		NM_CASE(EDeleteEntry);				
       
   340 		NM_CASE(EAddCategoryToList);					
       
   341 		NM_CASE(EDeleteAgendaFile);
       
   342 		NM_CASE(ETidyByDateReadParams);
       
   343 		NM_CASE(ETidyByDateStart);
       
   344 		NM_CASE(ECategoryStart);
       
   345 		NM_CASE(ECategoryStartAsyn);
       
   346 		NM_CASE(ECreateAgendaFile);	
       
   347 		NM_CASE(EDeleteEntriesByLocalUid);
       
   348 		NM_CASE(EDeleteEntryByGuid);
       
   349 		NM_CASE(ECommit);
       
   350 		NM_CASE(ERollback);
       
   351 		NM_CASE(ETransferAttachmentFileToServer);
       
   352 		NM_CASE(ETransferFileToClientToWrite);
       
   353 		NM_CASE(EAgnNotSupported);
       
   354 		default: enumStr = _S("UnsupportedIPC, OpCode is: %d"), aOpCode;
       
   355 		}
       
   356 
       
   357 	DebugLog("IPC: %s, Session Id: %d, ErrCode: %d", enumStr, aSessionId, aErrCode);
       
   358 	}
       
   359 #else
       
   360 	EXPORT_C void AgmDebug::DebugLogIPCL(TInt /*aOpCode*/, TUint /*aSessionId*/, TInt /*aErrCode*/) {}
       
   361 #endif
       
   362 
       
   363 #if defined (__CAL_VERBOSE_LOGGING__) || (__CAL_ALARM_LOGGING__)
       
   364 EXPORT_C void AgmDebug::DebugLogAlarmL(const TAgnAlarmEntry& aAlarmEntry)
       
   365 	{
       
   366 	DebugLog("Logging Alarm details");
       
   367 	
       
   368 	TBuf<KMinTTimeStrLength> dueDateTimeBuf;
       
   369 	AgmDebug::TTimeStrL(aAlarmEntry.iDueDateTimeLocal,dueDateTimeBuf);
       
   370 	
       
   371 	// Print instance of entry time in local time	
       
   372 	DebugLog("Entry Instance Due Date Time: %S - LOCAL", &dueDateTimeBuf );
       
   373 	
       
   374 	TBuf<KMinTTimeStrLength> alarmTimeBuf;
       
   375 	AgmDebug::TTimeStrL(aAlarmEntry.iAlarmTime.LocalL(),alarmTimeBuf);
       
   376 	
       
   377 	// Print alarm time in local time (as the instance time is in local time)
       
   378 	DebugLog("Alarm Time: %S - LOCAL", &alarmTimeBuf);
       
   379 
       
   380 	DebugLog("Alarm Message: %S", &aAlarmEntry.iMessage);
       
   381 	DebugLog("Alarm SoundName: %S", &aAlarmEntry.iSound);
       
   382 	
       
   383 	TBuf<KMinTTimeStrLength> instanceTimeBuf;
       
   384 	AgmDebug::TTimeStrL(aAlarmEntry.iInstanceId.Date().LocalL(),instanceTimeBuf);
       
   385 	
       
   386 	DebugLog("Alarm Instance EntryId: %d Instance Time: %S", aAlarmEntry.iInstanceId.Value(),&instanceTimeBuf);
       
   387 	}
       
   388 #else
       
   389 	EXPORT_C void AgmDebug::DebugLogAlarmL(const TAgnAlarmEntry& /*aAlarmEntry*/) {}
       
   390 #endif
       
   391 #else
       
   392 	// Avoid linking errors for exported APIs
       
   393 	EXPORT_C void AgmDebug::DebugLog(const char* /*aFmt*/,...){	}
       
   394 	EXPORT_C void AgmDebug::DebugLogTimeStampL(const char* /*aFmt*/,...){}
       
   395 	EXPORT_C void AgmDebug::DebugLogEntryL(CAgnEntry& /*aEntry*/, TAgmEntryDumpLevel /*aEntryDumpLevel*/) {}
       
   396 	EXPORT_C void AgmDebug::DebugLogIPCL(TInt /*aOpCode*/, TUint /*aSessionId*/, TInt /*aErrCode*/) {}
       
   397 	EXPORT_C void AgmDebug::DebugLogAlarmL(const TAgnAlarmEntry& /*aAlarmEntry*/) {}
       
   398 	EXPORT_C  void AgmDebug::TTimeStrL(const TTime& /*aTTime*/, TDes& /*aTimeStr*/) {}
       
   399 #endif
       
   400