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