upnp/upnpstack/upnputils/src/upnpnotifytimer.cpp
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 /** @file
       
     2 * Copyright (c) 2005-2006 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:  CUpnpNotifyTimer
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "upnpnotifytimer.h"
       
    22 #define KLogFile _L("DLNAWebServer.txt")
       
    23 #include "upnpcustomlog.h"
       
    24 
       
    25 // ============================ MEMBER FUNCTIONS ===============================
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CUpnpNotifyTimer::CUpnpNotifyTimer
       
    29 // C++ default constructor
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 EXPORT_C CUpnpNotifyTimer::CUpnpNotifyTimer(MUpnpNotifyTimerObserver* aObserver)
       
    33 	: CActive(EPriorityStandard)
       
    34     {
       
    35     CActiveScheduler::Add(this);
       
    36     iObserver = aObserver;
       
    37     }
       
    38 
       
    39 // ----------------------------------------------------------------------------
       
    40 // CUpnpNotifyTimer::NewL
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 EXPORT_C CUpnpNotifyTimer* CUpnpNotifyTimer::NewL(MUpnpNotifyTimerObserver* aObserver)
       
    44     {
       
    45     CUpnpNotifyTimer* self  = new (ELeave) CUpnpNotifyTimer(aObserver);
       
    46     CleanupStack::PushL( self );
       
    47     self->ConstructL();
       
    48     CleanupStack::Pop( self );
       
    49     return self;
       
    50     }
       
    51 
       
    52 // ----------------------------------------------------------------------------
       
    53 // CUpnpNotifyTimer::ConstructL
       
    54 // Two-phased constructor.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 void CUpnpNotifyTimer::ConstructL()
       
    58     {
       
    59     TInt err = iTimer.CreateLocal();
       
    60     if ( KErrNone != err )
       
    61         {
       
    62         LOGS1("CUpnpNotifyTimer::CUpnpNotifyTimer() CreateLocal FAILED: %d", err );
       
    63         User::Leave( err );
       
    64         }
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CUpnpNotifyTimer::~CUpnpNotifyTimer
       
    69 // C++ default destructor
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CUpnpNotifyTimer::~CUpnpNotifyTimer()
       
    73     {
       
    74     iObserver=NULL;
       
    75     Cancel();
       
    76     iTimer.Close();
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CUpnpNotifyTimer::After
       
    81 // Starts timer
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 EXPORT_C void CUpnpNotifyTimer::After( TInt aInterval, TBool /*aUnused*/ )
       
    85     {
       
    86     Start( TTimeIntervalMicroSeconds32( aInterval ) );
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CUpnpNotifyTimer::After
       
    91 // Starts timer
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 EXPORT_C void CUpnpNotifyTimer::After( TTimeIntervalMicroSeconds32 aInterval,
       
    95                                   TBool /*aUnused*/ )
       
    96     {
       
    97     Start( aInterval );
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CUpnpNotifyTimer::AfterSeconds
       
   102 // Start timer
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 EXPORT_C void CUpnpNotifyTimer::AfterSeconds( TInt aIntervalInSeconds )
       
   106     {
       
   107     if( !IsActive() )
       
   108         {
       
   109         ASSERT( 0 == iIterationsToRun );
       
   110         TInt secondsToWait = aIntervalInSeconds;
       
   111         if ( aIntervalInSeconds > KOneIterationSeconds )
       
   112             {
       
   113             iIterationsToRun = aIntervalInSeconds / KOneIterationSeconds;
       
   114             secondsToWait = aIntervalInSeconds % KOneIterationSeconds;
       
   115             }
       
   116         iTimer.After(  iStatus, TTimeIntervalMicroSeconds32( secondsToWait * KSecond ) );
       
   117         SetActive();
       
   118         }
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CUpnpNotifyTimer::Start
       
   123 // Start timer
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 EXPORT_C void CUpnpNotifyTimer::Start( TTimeIntervalMicroSeconds32 aInterval,
       
   127                                   TBool /*aUnused*/ )
       
   128     {
       
   129     if ( !IsActive() )
       
   130         {
       
   131         ASSERT( 0 == iIterationsToRun );
       
   132         iTimer.After( iStatus, aInterval );
       
   133         SetActive();
       
   134         }
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CUpnpNotifyTimer::RunL
       
   139 // Timer RunL
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 void CUpnpNotifyTimer::RunL()
       
   143     {
       
   144     LOGS1( "CUpnpNotifyTimer::RunL() iStatus: %d", iStatus.Int() );
       
   145 	User::LeaveIfError(iStatus.Int());
       
   146 
       
   147     if ( iIterationsToRun > 0 )
       
   148         {
       
   149         StartNextIteration();
       
   150         }
       
   151     else
       
   152         {
       
   153         if ( iObserver )
       
   154             {
       
   155         	iObserver->TimerEventL( this );
       
   156             }
       
   157         }
       
   158     }
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CUpnpNotifyTimer::StartNextIteration
       
   162 // only for internal use decrease repeat counter and
       
   163 // waits for KOneIterationSeconds seconds
       
   164 // This function should be run when object isn't active.
       
   165 // --------------------------------------------------------------------- --------
       
   166 //
       
   167 void CUpnpNotifyTimer::StartNextIteration()
       
   168     {
       
   169     ASSERT( !IsActive() );
       
   170     iIterationsToRun--;
       
   171     iTimer.After( iStatus,
       
   172     TTimeIntervalMicroSeconds32( KOneIterationSeconds * KSecond ) );
       
   173     SetActive();
       
   174     }
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // CUpnpNotifyTimer::RunError
       
   178 // RunError in case RunL leaves.
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 TInt CUpnpNotifyTimer::RunError( TInt aError )
       
   182     {
       
   183     LOGS1("CUpnpNotifyTimer::RunError, error %d", aError);
       
   184     iObserver->TimerEventError( this, aError );
       
   185     iIterationsToRun = 0;
       
   186     return KErrNone;
       
   187     }
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CUpnpNotifyTimer::DoCancel
       
   191 // Timer DoCanel for active timers
       
   192 // -----------------------------------------------------------------------------
       
   193 //
       
   194 EXPORT_C void CUpnpNotifyTimer::DoCancel()
       
   195     {
       
   196     iIterationsToRun = 0;
       
   197     iTimer.Cancel();
       
   198     }
       
   199 
       
   200 // -----------------------------------------------------------------------------
       
   201 // CUpnpNotifyTimer::CompleteOneselfImmediate
       
   202 //
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 EXPORT_C void CUpnpNotifyTimer::CompleteOneselfImmediate()
       
   206     {
       
   207     if ( !IsActive() )
       
   208         {
       
   209         TRequestStatus* status = &iStatus;
       
   210         User::RequestComplete( status, KErrNone );
       
   211         SetActive();
       
   212         }
       
   213     }
       
   214 
       
   215 
       
   216 // End Of File