upnpframework/upnpaiwengine/src/upnpaiwtimer.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 2005-2007 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 "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:  Implementation of the class CUPnPAiwTimer.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include "upnpaiwtimer.h"
       
    21 #include "upnpaiwtimerobserver.h"
       
    22 
       
    23 // ============================ MEMBER FUNCTIONS ============================
       
    24 
       
    25 // --------------------------------------------------------------------------
       
    26 // CUPnPAiwTimer::NewL
       
    27 // Construct the timer, add CHeartbeat to Active Scheduler and start it.
       
    28 // --------------------------------------------------------------------------
       
    29 //
       
    30 CUPnPAiwTimer* CUPnPAiwTimer::NewL( TInt aInterval,
       
    31                                     MUPnPAiwTimerObserver* aCallback 
       
    32                                 )
       
    33     {
       
    34     CUPnPAiwTimer* self = new (ELeave) CUPnPAiwTimer();
       
    35     CleanupStack::PushL( self );
       
    36     self->ConstructL( aInterval, aCallback );
       
    37     CleanupStack::Pop( self );
       
    38     return self;
       
    39     }
       
    40 
       
    41 // --------------------------------------------------------------------------
       
    42 // CUPnPAiwTimer::CUPnPAiwTimer
       
    43 // Constructor
       
    44 // --------------------------------------------------------------------------
       
    45 //
       
    46 CUPnPAiwTimer::CUPnPAiwTimer()
       
    47     {
       
    48     // No implementation
       
    49     }
       
    50 
       
    51 // --------------------------------------------------------------------------
       
    52 // CUPnPAiwTimer::ConstructL
       
    53 // Constructs the timer.
       
    54 // --------------------------------------------------------------------------
       
    55 //
       
    56 void CUPnPAiwTimer::ConstructL( TInt aInterval,
       
    57                                 MUPnPAiwTimerObserver* aCallback )
       
    58     {
       
    59 
       
    60     // Check the parameters
       
    61     if( aInterval <= 0 ||
       
    62         !aCallback )
       
    63         {
       
    64         User::Leave( KErrArgument );
       
    65         }
       
    66     else
       
    67         {
       
    68         iInterval = aInterval;
       
    69         iCallback = aCallback;
       
    70         }
       
    71 
       
    72     // Create CHeartbeat object
       
    73     iHeartbeat = CHeartbeat::NewL( EPriorityLow );
       
    74 
       
    75     iCounter = 0;
       
    76 
       
    77     // Start the heartbeat timer (beating exactly on the second)
       
    78     iHeartbeat->Start( ETwelveOClock, this );
       
    79     }
       
    80 
       
    81 // --------------------------------------------------------------------------
       
    82 // CUPnPAiwTimer::~CUPnPAiwTimer()
       
    83 // Destructor.
       
    84 // --------------------------------------------------------------------------
       
    85 //
       
    86 CUPnPAiwTimer::~CUPnPAiwTimer()
       
    87     {
       
    88     // Cancel any outstanding request
       
    89     if( iHeartbeat )
       
    90         {
       
    91         iHeartbeat->Cancel();
       
    92         delete iHeartbeat;
       
    93         }
       
    94     }
       
    95 
       
    96 // --------------------------------------------------------------------------
       
    97 // CUPnPAiwTimer::Beat()
       
    98 // Called when the beat is in sync.
       
    99 // --------------------------------------------------------------------------
       
   100 //
       
   101 void CUPnPAiwTimer::Beat()
       
   102     {
       
   103     // Increase heartbeat counter
       
   104     iCounter++;
       
   105 
       
   106     // If interval is reached, do the call back
       
   107     if( iCounter == iInterval )
       
   108         {
       
   109         if( iCallback )
       
   110             {
       
   111             iCallback->TimerCallback();
       
   112             }
       
   113         iCounter = 0;
       
   114         }
       
   115     }
       
   116 
       
   117 // --------------------------------------------------------------------------
       
   118 // CUPnPAiwTimer::Synchronize()
       
   119 // Called when the beat needs to be syncronized.
       
   120 // --------------------------------------------------------------------------
       
   121 //
       
   122 void CUPnPAiwTimer::Synchronize()
       
   123     {
       
   124     // not used
       
   125     }
       
   126 
       
   127 //  End of File