videoutils_plat/videoconnutility_api/tsrc/VCXTestCommon/src/CIptvTestTimer.cpp
branchRCL_3
changeset 47 826cea16efd9
parent 45 798ee5f1972c
child 48 13a33d82ad98
equal deleted inserted replaced
45:798ee5f1972c 47:826cea16efd9
     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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CIptvTestTimer.h"
       
    22 #include "MIptvTestTimerObserver.h"
       
    23 #include "VCXTestLog.h"
       
    24 
       
    25 // EXTERNAL DATA STRUCTURES
       
    26 
       
    27 // EXTERNAL FUNCTION PROTOTYPES
       
    28 
       
    29 // CONSTANTS
       
    30 
       
    31 // MACROS
       
    32 
       
    33 // LOCAL CONSTANTS AND MACROS
       
    34 
       
    35 // MODULE DATA STRUCTURES
       
    36 
       
    37 // LOCAL FUNCTION PROTOTYPES
       
    38 
       
    39 // FORWARD DECLARATIONS
       
    40 
       
    41 // ============================= LOCAL FUNCTIONS ===============================
       
    42 
       
    43 // ============================ MEMBER FUNCTIONS ===============================
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CIptvTestTimer::
       
    47 // C++ default constructor can NOT contain any code, that
       
    48 // might leave.
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 EXPORT_C CIptvTestTimer* CIptvTestTimer::NewL(MIptvTestTimerObserver& aObserver, TInt aId)
       
    52     {
       
    53     VCXLOGLO1(">>>CIptvTestTimer::NewL");
       
    54     CIptvTestTimer* self = new (ELeave) CIptvTestTimer(aObserver, aId);
       
    55     CleanupStack::PushL(self);
       
    56     self->ConstructL();
       
    57     CleanupStack::Pop();
       
    58     VCXLOGLO1("<<<CIptvTestTimer::NewL");
       
    59     return self;
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CIptvTestTimer::~CIptvTestTimer
       
    64 // destructor
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 EXPORT_C CIptvTestTimer::~CIptvTestTimer()
       
    68     {
       
    69     VCXLOGLO1(">>>CIptvTestTimer::~CIptvTestTimer");
       
    70     iRestartAfterCancel = EFalse;
       
    71     Cancel();
       
    72     iTimer.Close();
       
    73 
       
    74    	if( IsAdded() )
       
    75         {
       
    76         Deque(); // calls also Cancel()
       
    77         }
       
    78 
       
    79     VCXLOGLO1("<<<CIptvTestTimer::~CIptvTestTimer");
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CIptvTestTimer::~CIptvTestTimer
       
    84 // destructor
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 EXPORT_C void CIptvTestTimer::CancelTimer()
       
    88     {
       
    89     VCXLOGLO1(">>>CIptvTestTimer::CancelTimer");
       
    90     if( IsActive() )
       
    91     	{
       
    92     	iRestartAfterCancel = EFalse;
       
    93     	Cancel();
       
    94     	}
       
    95     VCXLOGLO1("<<<CIptvTestTimer::CancelTimer");
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CIptvTestTimer::CIptvTestTimer
       
   100 //
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 CIptvTestTimer::CIptvTestTimer(MIptvTestTimerObserver& aObserver, TInt aId) : CActive(EPriorityStandard), iObserver(aObserver),
       
   104 	iId(aId)
       
   105     {
       
   106     VCXLOGLO1(">>>CIptvTestTimer::CIptvTestTimer");
       
   107     CActiveScheduler::Add(this);
       
   108     VCXLOGLO1("<<<CIptvTestTimer::CIptvTestTimer");
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CIptvTestTimer::ConstructL
       
   113 //
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 void CIptvTestTimer::ConstructL()
       
   117     {
       
   118     VCXLOGLO1(">>>CIptvTestTimer::ConstructL");
       
   119     User::LeaveIfError(iTimer.CreateLocal());
       
   120     VCXLOGLO1("<<<CIptvTestTimer::ConstructL");
       
   121     }
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CIptvTestTimer::After
       
   125 //
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 EXPORT_C void CIptvTestTimer::After(TTimeIntervalMicroSeconds32 aInterval)
       
   129     {
       
   130 
       
   131     iInterval = aInterval;
       
   132 
       
   133     if( !IsActive() )
       
   134     	{
       
   135 	    VCXLOGLO2("CIptvTestTimer::After: Setting active. (%d)", this);
       
   136     	iTimer.After( iStatus, aInterval );
       
   137 	    SetActive();
       
   138 	    iRestartAfterCancel = EFalse; 
       
   139     	}
       
   140 	else
       
   141 		{
       
   142 		// Cancel and start again when cancel is done.
       
   143 		VCXLOGLO2("CIptvTestTimer::After: Restarting! (%d)", this);
       
   144 		iRestartAfterCancel = ETrue;
       
   145 		iTimer.Cancel();
       
   146 		}
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CIptvTestTimer::RunL
       
   151 //
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 void CIptvTestTimer::RunL()
       
   155     {
       
   156     TInt status = iStatus.Int();
       
   157 
       
   158     if( status == KErrNone )
       
   159         {
       
   160         iObserver.TimerComplete( iId, iStatus.Int() );
       
   161         }
       
   162     else
       
   163     if( status == KErrCancel && iRestartAfterCancel )
       
   164         {
       
   165         iRestartAfterCancel = EFalse;
       
   166         iTimer.After( iStatus, iInterval );
       
   167         SetActive();
       
   168         VCXLOGLO2("CIptvTestTimer::RunL: Restarted! (%d)", this);
       
   169         }
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CIptvTestTimer::DoCancel
       
   174 //
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 void CIptvTestTimer::DoCancel()
       
   178     {
       
   179     VCXLOGLO1(">>>CIptvTestTimer::DoCancel");
       
   180     iTimer.Cancel();
       
   181     VCXLOGLO1("<<<CIptvTestTimer::DoCancel");
       
   182     }
       
   183 
       
   184 //  End of File