2
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB
|
|
3 |
*
|
|
4 |
* All rights reserved.
|
|
5 |
* This component and the accompanying materials are made available
|
|
6 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
7 |
* which accompanies this distribution, and is available
|
|
8 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
9 |
*
|
|
10 |
* Initial Contributors:
|
|
11 |
* EmbedDev AB - initial contribution.
|
|
12 |
*
|
|
13 |
* Contributors:
|
|
14 |
*
|
|
15 |
* Description:
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
#include "FeedTimer.h"
|
|
20 |
#include "FeedEngine.h"
|
|
21 |
|
|
22 |
CFeedTimer::CFeedTimer(CFeedEngine *aFeedEngine) : CTimer(EPriorityIdle), iFeedEngine(aFeedEngine)
|
|
23 |
{
|
|
24 |
CActiveScheduler::Add(this);
|
|
25 |
}
|
|
26 |
|
|
27 |
CFeedTimer::~CFeedTimer()
|
|
28 |
{
|
|
29 |
}
|
|
30 |
|
|
31 |
void CFeedTimer::ConstructL()
|
|
32 |
{
|
|
33 |
CTimer::ConstructL();
|
|
34 |
}
|
|
35 |
|
|
36 |
void CFeedTimer::RunL()
|
|
37 |
{
|
129
|
38 |
DP("CFeedTimer::RunL BEGIN");
|
|
39 |
|
|
40 |
TTime time;
|
|
41 |
time.UniversalTime();
|
2
|
42 |
|
129
|
43 |
if (time < iTriggerTime)
|
|
44 |
{
|
|
45 |
// timer was probably reset, this happens on Nokia every 30 minutes
|
|
46 |
DP("Timer reset");
|
|
47 |
AtUTC(iTriggerTime);
|
|
48 |
}
|
|
49 |
else
|
|
50 |
{
|
|
51 |
// We need to trap this, otherwise we will not reschedule the timer
|
|
52 |
TRAP_IGNORE(iFeedEngine->UpdateAllFeedsL(ETrue));
|
|
53 |
|
|
54 |
// run again
|
|
55 |
RunPeriodically();
|
|
56 |
}
|
|
57 |
DP("CFeedTimer::RunL END");
|
2
|
58 |
}
|
|
59 |
|
|
60 |
void CFeedTimer::SetPeriod(TInt aPeriodMinutes)
|
|
61 |
{
|
|
62 |
DP1("Setting sync period to %d", aPeriodMinutes);
|
|
63 |
iPeriodMinutes = aPeriodMinutes;
|
|
64 |
}
|
|
65 |
|
|
66 |
void CFeedTimer::SetSyncTime(TTime aTime)
|
|
67 |
{
|
|
68 |
TTime time;
|
|
69 |
time.HomeTime();
|
|
70 |
|
|
71 |
DP5("Now is %4d-%02d-%02d, %02d:%02d", time.DateTime().Year(), time.DateTime().Month()+1, time.DateTime().Day()+1, time.DateTime().Hour(), time.DateTime().Minute());
|
|
72 |
|
|
73 |
TInt hour = aTime.DateTime().Hour();
|
|
74 |
TInt minute = aTime.DateTime().Minute();
|
|
75 |
|
|
76 |
|
|
77 |
TDateTime dTime;
|
|
78 |
|
|
79 |
dTime.Set(time.DateTime().Year(), time.DateTime().Month(),
|
|
80 |
time.DateTime().Day(),aTime.DateTime().Hour(),
|
|
81 |
aTime.DateTime().Minute(), 0, 0);
|
|
82 |
|
|
83 |
TTimeIntervalMinutes tmi = 0;
|
|
84 |
|
|
85 |
// if this time already passed, add one day
|
|
86 |
if (time.DateTime().Hour() > hour || time.DateTime().Hour() == hour && time.DateTime().Minute() > minute)
|
|
87 |
{
|
|
88 |
DP("Adding one day");
|
|
89 |
tmi = 60*24;
|
|
90 |
}
|
|
91 |
|
|
92 |
TTime atTime(dTime);
|
|
93 |
atTime = atTime + tmi;
|
|
94 |
DP5("Setting sync timer to %4d-%02d-%02d, %02d:%02d", atTime.DateTime().Year(), atTime.DateTime().Month()+1, atTime.DateTime().Day()+1, atTime.DateTime().Hour(), atTime.DateTime().Minute());
|
|
95 |
|
|
96 |
// Activate the timer
|
|
97 |
At(atTime);
|
|
98 |
}
|
|
99 |
|
|
100 |
|
|
101 |
void CFeedTimer::RunPeriodically()
|
|
102 |
{
|
|
103 |
DP1("RunPeriodically; thePeriod=%d", iPeriodMinutes);
|
|
104 |
TTime time;
|
|
105 |
time.UniversalTime();
|
|
106 |
|
|
107 |
TTimeIntervalMinutes tmi;
|
|
108 |
tmi = iPeriodMinutes;
|
129
|
109 |
iTriggerTime = time + tmi;
|
2
|
110 |
DP("Running timer");
|
|
111 |
|
129
|
112 |
AtUTC(iTriggerTime);
|
2
|
113 |
}
|