genericservices/taskscheduler/SCHSVR/SCHENTRY.CPP
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2004-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 // User includes
       
    17 #include "SCHENTRY.H"
       
    18 #include "SchLogger.h"
       
    19 
       
    20 //	
       
    21 NONSHARABLE_CLASS(TScheduleEntryHourly) : public TScheduleEntry
       
    22 	{
       
    23 public:
       
    24 	TScheduleEntryHourly(TScheduleEntryInfo2& aInfo);
       
    25 	void CalculateNextPossibleRunDate(TTime& aTime) const;
       
    26 	};
       
    27 
       
    28 NONSHARABLE_CLASS(TScheduleEntryDaily) : public TScheduleEntry
       
    29 	{
       
    30 public:
       
    31 	TScheduleEntryDaily(TScheduleEntryInfo2& aInfo);
       
    32 	void CalculateNextPossibleRunDate(TTime& aTime) const;
       
    33 	};
       
    34 
       
    35 NONSHARABLE_CLASS(TScheduleEntryMonthly) : public TScheduleEntry
       
    36 	{
       
    37 public:
       
    38 	TScheduleEntryMonthly(TScheduleEntryInfo2& aInfo);
       
    39 	void CalculateNextPossibleRunDate(TTime& aTime) const;
       
    40 	};
       
    41 
       
    42 NONSHARABLE_CLASS(TScheduleEntryYearly) : public TScheduleEntry
       
    43 	{
       
    44 public:
       
    45 	TScheduleEntryYearly(TScheduleEntryInfo2& aInfo);
       
    46 	void CalculateNextPossibleRunDate(TTime& aTime) const;
       
    47 	};
       
    48 //	
       
    49 
       
    50 TScheduleEntry* ScheduleEntryFactory::CreateL(TScheduleEntryInfo2& aInfo)
       
    51 	{
       
    52 	switch (aInfo.IntervalType())
       
    53 		{
       
    54 		case EHourly:
       
    55 			{
       
    56 			return new(ELeave) TScheduleEntryHourly(aInfo);
       
    57 			}
       
    58 		case EDaily:
       
    59 			{
       
    60 			return new(ELeave) TScheduleEntryDaily(aInfo);
       
    61 			}
       
    62 		case EMonthly:
       
    63 			{
       
    64 			return new(ELeave) TScheduleEntryMonthly(aInfo);
       
    65 			}
       
    66 		case EYearly:
       
    67 			{
       
    68 			return new(ELeave) TScheduleEntryYearly(aInfo);
       
    69 			}
       
    70 		}
       
    71 	User::Leave(KErrArgument);
       
    72 	return NULL;//never gets to here!!
       
    73 	}
       
    74 
       
    75 //	
       
    76 //TScheduleEntry (generic code)
       
    77 TScheduleEntry::TScheduleEntry(TScheduleEntryInfo2& aInfo)
       
    78 :	iEntryInfo(aInfo)
       
    79 	{
       
    80 	TTsTime time;
       
    81 	time.SetUtcTime(Time::MaxTTime());
       
    82 	iDueTime = time;
       
    83 	}
       
    84 
       
    85 const TTsTime& TScheduleEntry::DueTime() const
       
    86 	{
       
    87 	return iDueTime;
       
    88 	}
       
    89 
       
    90 TInt TScheduleEntry::Offset()
       
    91 	{
       
    92 	return (_FOFF(TScheduleEntry, iLink));
       
    93 	}
       
    94 
       
    95 const TScheduleEntryInfo2& TScheduleEntry::Info() const
       
    96 	{
       
    97 	return iEntryInfo;
       
    98 	}
       
    99 /**
       
   100 returns the next due time for this schedule entry.  aTime is the minimum time
       
   101 for which this due time should be.*/
       
   102 const TTsTime& TScheduleEntry::NextScheduledTime(const TTsTime& aTime)
       
   103 	{
       
   104 	// update start time in case of any timezone/DST changes
       
   105 	// do this before calculating next scheduled time so that it is taken into
       
   106 	// account in the calculation
       
   107 	iEntryInfo.ProcessOffsetEvent();
       
   108 	
       
   109 	// if start time = max time then algorithm below doesnt work
       
   110 	// so we need to jump out of it here.
       
   111 	if (iEntryInfo.StartTime().GetUtcTime() == Time::MaxTTime() 
       
   112 		|| iEntryInfo.StartTime().GetLocalTime() == Time::MaxTTime() 
       
   113 		|| aTime.GetUtcTime() < (iEntryInfo.StartTime().GetUtcTime() + iEntryInfo.ValidityPeriod())) 
       
   114 		iDueTime = iEntryInfo.StartTime();
       
   115 	else
       
   116 		{
       
   117 		// Work out when this schedule entry can next run, by adding interval steps
       
   118 		// Due times should be UTC based or local time based, 
       
   119 		// in accordance with the start time set by the user
       
   120 		TTime nextDueTime;
       
   121 
       
   122 		if (iEntryInfo.StartTime().IsUtc())
       
   123 			{
       
   124 			nextDueTime = iEntryInfo.StartTime().GetUtcTime();
       
   125 			while (aTime.GetUtcTime() > (nextDueTime + iEntryInfo.ValidityPeriod()))	
       
   126 				CalculateNextPossibleRunDate(nextDueTime);
       
   127 			
       
   128 			iDueTime.SetUtcTime(nextDueTime);
       
   129 			}
       
   130 		else	//is hometime based
       
   131 			{
       
   132 			nextDueTime = iEntryInfo.StartTime().GetLocalTime();
       
   133 			while (aTime.GetLocalTime() > (nextDueTime + iEntryInfo.ValidityPeriod()))	
       
   134 				CalculateNextPossibleRunDate(nextDueTime);
       
   135 			
       
   136 			iDueTime.SetLocalTime(nextDueTime);
       
   137 			}
       
   138 		}
       
   139 	return iDueTime;	
       
   140 	}
       
   141 
       
   142 
       
   143 //subclass-specific code...
       
   144 TScheduleEntryHourly::TScheduleEntryHourly(TScheduleEntryInfo2& aInfo)
       
   145 			:TScheduleEntry(aInfo)
       
   146 	{
       
   147 	}
       
   148 
       
   149 void TScheduleEntryHourly::CalculateNextPossibleRunDate(TTime& aTime) const
       
   150 	{
       
   151 	aTime+=TTimeIntervalHours(Info().Interval());
       
   152 	}
       
   153 
       
   154 TScheduleEntryDaily::TScheduleEntryDaily(TScheduleEntryInfo2& aInfo)
       
   155 			:TScheduleEntry(aInfo)
       
   156 	{
       
   157 	}
       
   158 
       
   159 void TScheduleEntryDaily::CalculateNextPossibleRunDate(TTime& aTime) const
       
   160 	{
       
   161 	aTime+=TTimeIntervalDays(Info().Interval());
       
   162 	}
       
   163 
       
   164 TScheduleEntryMonthly::TScheduleEntryMonthly(TScheduleEntryInfo2& aInfo)
       
   165 			:TScheduleEntry(aInfo)
       
   166 	{
       
   167 	}
       
   168 
       
   169 void TScheduleEntryMonthly::CalculateNextPossibleRunDate(TTime& aTime) const
       
   170 	{
       
   171 	aTime+=TTimeIntervalMonths(Info().Interval());
       
   172 	}
       
   173 
       
   174 TScheduleEntryYearly::TScheduleEntryYearly(TScheduleEntryInfo2& aInfo)
       
   175 			:TScheduleEntry(aInfo)
       
   176 	{
       
   177 	}
       
   178 
       
   179 void TScheduleEntryYearly::CalculateNextPossibleRunDate(TTime& aTime) const
       
   180 	{
       
   181 	aTime+=TTimeIntervalYears(Info().Interval());
       
   182 	}