browserutilities/feedsengine/FeedsServer/Server/src/UpdateQueue.cpp
changeset 0 dd21522fd290
child 16 a359256acfc6
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  UpdateQueue controls the feeds to be updated.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "UpdateManager.h"
       
    20 #include "UpdateQueue.h"
       
    21 #include "FeedsServer.h"
       
    22 
       
    23 // -----------------------------------------------------------------------------
       
    24 // CUpdateQueue::NewL
       
    25 //
       
    26 // Two-phased constructor.
       
    27 // -----------------------------------------------------------------------------
       
    28 CUpdateQueue* CUpdateQueue::NewL(CUpdateAllFeedsTask* aUpdateAllFeedTask,TInt aFreq)
       
    29     {
       
    30     CUpdateQueue* self = new (ELeave) CUpdateQueue( aUpdateAllFeedTask, aFreq);
       
    31     CleanupStack::PushL(self);
       
    32     self->ConstructL();
       
    33     CleanupStack::Pop();
       
    34     return self;
       
    35     }
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CUpdateQueue::ConstructL
       
    39 //
       
    40 // Symbian 2nd phase constructor can leave.
       
    41 // -----------------------------------------------------------------------------	
       
    42 void CUpdateQueue::ConstructL()
       
    43     {
       
    44     iLastAutoUpdate.HomeTime();
       
    45     TDateTime dateTime = iLastAutoUpdate.DateTime();
       
    46     TInt mins;
       
    47     switch(iFreq)
       
    48         {
       
    49         case 10080:
       
    50             mins = iLastAutoUpdate.DayNoInWeek()*60*24 + dateTime.Hour() * 60 + dateTime.Minute();
       
    51             break;
       
    52         default:
       
    53             mins = dateTime.Hour() * 60 + dateTime.Minute();
       
    54             break;
       
    55         }
       
    56     iLastAutoUpdate = iLastAutoUpdate - TTimeIntervalMinutes(mins % iFreq);
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CUpdateQueue::CUpdateQueue
       
    61 //
       
    62 // C++ default constructor can NOT contain any code, that
       
    63 // might leave.
       
    64 // -----------------------------------------------------------------------------
       
    65  CUpdateQueue::CUpdateQueue( CUpdateAllFeedsTask* aUpdateAllFeedTask, TInt aFreq ):
       
    66             iFreq( aFreq), iCurrentState( aFreq), iUpdateAllFeedsTask( aUpdateAllFeedTask)
       
    67     {
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CUpdateQueue::~CUpdateQueue
       
    72 //
       
    73 // Deconstructor.
       
    74 // ----------------------------------------------------------------------------- 
       
    75 CUpdateQueue::~CUpdateQueue()
       
    76     {
       
    77    	iFeedIds.Reset();
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CUpdateQueue::AddFeed
       
    82 // 
       
    83 // Add feed to the Update feed list
       
    84 // -----------------------------------------------------------------------------     
       
    85 TInt CUpdateQueue::AddFeed( TInt aFeedId)
       
    86     {
       
    87     return iFeedIds.Append( aFeedId);
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CUpdateQueue::RemoveFeed
       
    92 // 
       
    93 // Remove feed from list
       
    94 // ----------------------------------------------------------------------------- 
       
    95 TInt CUpdateQueue::RemoveFeed( TInt aFeedId)
       
    96     {
       
    97 	TInt found = -1;
       
    98 	if((found = iFeedIds.Find( aFeedId)) != KErrNotFound)
       
    99         {
       
   100         iFeedIds.Remove(found);
       
   101         }
       
   102 	return found;
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CUpdateQueue::UpdateL
       
   107 // 
       
   108 // Decrement the counter
       
   109 // ----------------------------------------------------------------------------- 
       
   110 TInt CUpdateQueue::UpdateL(TInt /*aMinutes*/)
       
   111     {
       
   112 
       
   113     TTime currentTime;
       
   114     currentTime.HomeTime();
       
   115     TTimeIntervalMinutes diff;
       
   116     currentTime.MinutesFrom(iLastAutoUpdate,diff);
       
   117 
       
   118     if(diff.Int() + 1 >= iFreq)
       
   119         {
       
   120         iUpdateAllFeedsTask->AddFeedL(iFeedIds);
       
   121         iLastAutoUpdate.HomeTime();
       
   122         TDateTime dateTime = iLastAutoUpdate.DateTime();
       
   123         TInt mins;
       
   124         switch(iFreq)
       
   125             {
       
   126             case 10080:
       
   127                 mins = iLastAutoUpdate.DayNoInWeek()*60*24 + dateTime.Hour() * 60 + dateTime.Minute();
       
   128                 break;
       
   129             default:
       
   130                 mins = dateTime.Hour() * 60 + dateTime.Minute();
       
   131                 break;
       
   132             }
       
   133         iLastAutoUpdate = iLastAutoUpdate - TTimeIntervalMinutes(mins % iFreq);
       
   134         }
       
   135     return KErrNone;
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // CUpdateQueue::GetFreq
       
   140 // 
       
   141 // return the frequency
       
   142 // ----------------------------------------------------------------------------- 
       
   143 TInt CUpdateQueue::GetFreq()
       
   144     {
       
   145     return iFreq;
       
   146     }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CUpdateQueue::Count
       
   150 // 
       
   151 // return the count
       
   152 // -----------------------------------------------------------------------------     
       
   153 TInt CUpdateQueue::Count()
       
   154     {
       
   155     return iFeedIds.Count();
       
   156     }