engine/src/FeedTimer.cpp
changeset 2 29cda98b007e
child 129 7ef9faf10a81
equal deleted inserted replaced
1:5f8e5adbbed9 2:29cda98b007e
       
     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 	{
       
    38 	DP("CFeedTimer::RunL");
       
    39 
       
    40 	// We need to trap this, otherwise we will not reschedule the timer
       
    41 	TRAP_IGNORE(iFeedEngine->UpdateAllFeedsL(ETrue));
       
    42 
       
    43 	// run again
       
    44 	RunPeriodically();
       
    45 	}
       
    46 
       
    47 void CFeedTimer::SetPeriod(TInt aPeriodMinutes) 
       
    48 	{
       
    49 	DP1("Setting sync period to %d", aPeriodMinutes);
       
    50 	iPeriodMinutes = aPeriodMinutes;
       
    51 	}
       
    52 
       
    53 void CFeedTimer::SetSyncTime(TTime aTime) 
       
    54 	{
       
    55 	TTime time;
       
    56 	time.HomeTime();
       
    57 
       
    58 	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());
       
    59 
       
    60 	TInt hour = aTime.DateTime().Hour();
       
    61 	TInt minute = aTime.DateTime().Minute();
       
    62 	
       
    63 	
       
    64 	TDateTime dTime;
       
    65 	
       
    66 	dTime.Set(time.DateTime().Year(), time.DateTime().Month(),
       
    67 			time.DateTime().Day(),aTime.DateTime().Hour(),
       
    68 			aTime.DateTime().Minute(), 0, 0);
       
    69 
       
    70 	TTimeIntervalMinutes tmi = 0;
       
    71 
       
    72 	// if this time already passed, add one day
       
    73 	if (time.DateTime().Hour() > hour || time.DateTime().Hour() == hour && time.DateTime().Minute() > minute) 
       
    74 		{
       
    75 		DP("Adding one day");
       
    76 		tmi = 60*24;
       
    77 		}
       
    78 	
       
    79 	TTime atTime(dTime);
       
    80 	atTime = atTime + tmi;
       
    81 	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());
       
    82 
       
    83 	// Activate the timer
       
    84 	At(atTime);
       
    85 	}
       
    86 	
       
    87 
       
    88 void CFeedTimer::RunPeriodically() 
       
    89 	{
       
    90 	DP1("RunPeriodically; thePeriod=%d", iPeriodMinutes);
       
    91 	TTime time;
       
    92 	time.UniversalTime();
       
    93 
       
    94 	TTimeIntervalMinutes tmi;
       
    95 	tmi = iPeriodMinutes;
       
    96 	time = time + tmi;
       
    97 	DP("Running timer");
       
    98 
       
    99 	AtUTC(time);
       
   100 	}