resourcemgmt/hwresourcesmgr/test/multiclient/common/TestScheduler.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "TestScheduler.h"
       
    20 
       
    21 // EXTERNAL DATA STRUCTURES
       
    22 // None
       
    23 
       
    24 // EXTERNAL FUNCTION PROTOTYPES  
       
    25 // None
       
    26 
       
    27 // CONSTANTS
       
    28 // None
       
    29 
       
    30 // MACROS
       
    31 // None
       
    32 
       
    33 // LOCAL CONSTANTS AND MACROS
       
    34 // None
       
    35 
       
    36 // MODULE DATA STRUCTURES
       
    37 // None
       
    38 
       
    39 // LOCAL FUNCTION PROTOTYPES
       
    40 // None
       
    41 
       
    42 // FORWARD DECLARATIONS
       
    43 // None
       
    44 
       
    45 // ==================== LOCAL FUNCTIONS =======================================
       
    46 
       
    47 
       
    48 // ================= MEMBER FUNCTIONS =========================================
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CTestScheduler::CTestScheduler
       
    52 // C++ default constructor can NOT contain any code, that
       
    53 // might leave.
       
    54 // -----------------------------------------------------------------------------
       
    55 CTestScheduler::CTestScheduler()
       
    56 {
       
    57 	
       
    58 }
       
    59 
       
    60 // Destructor
       
    61 CTestScheduler::~CTestScheduler()
       
    62 {
       
    63 	delete iTimeout;
       
    64 }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CTestScheduler::NewL
       
    68 // Two-phased constructor.
       
    69 // 
       
    70 // -----------------------------------------------------------------------------
       
    71 CTestScheduler* CTestScheduler::NewL()
       
    72 {
       
    73 
       
    74 	CTestScheduler* self = new( ELeave )CTestScheduler();
       
    75 	CleanupStack::PushL( self );
       
    76 
       
    77 	if (CActiveScheduler::Current() == NULL)
       
    78 	{
       
    79 		CActiveScheduler::Install(self);
       
    80 	}
       
    81 
       
    82 	self->ConstructL();
       
    83 	CleanupStack::Pop( self );
       
    84 	
       
    85 	return self;
       
    86 	
       
    87 }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CTestScheduler::ConstructL
       
    91 // Symbian 2nd phase constructor can leave.
       
    92 // 
       
    93 // -----------------------------------------------------------------------------
       
    94 void CTestScheduler::ConstructL()
       
    95 {
       
    96 	iTimeout = new(ELeave) CTimeout;
       
    97 }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CTestScheduler::WaitForAnyRequest
       
   101 // Waits for user request.
       
   102 // (other items were commented in a header).
       
   103 // -----------------------------------------------------------------------------
       
   104 void CTestScheduler::WaitForAnyRequest()
       
   105 {
       
   106 	User::WaitForAnyRequest();
       
   107 }
       
   108 
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CTestScheduler::Error
       
   112 // Handles error cases.
       
   113 // (other items were commented in a header).
       
   114 // -----------------------------------------------------------------------------
       
   115 void CTestScheduler::Error(TInt /*anError*/) const
       
   116 {
       
   117 	Stop();
       
   118 }
       
   119 
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CTestScheduler::StartAndStopL
       
   123 // Starts and stops the timer.
       
   124 // (other items were commented in a header).
       
   125 // -----------------------------------------------------------------------------
       
   126 TBool CTestScheduler::StartAndStopL
       
   127 		(
       
   128 		TInt aMillisecs //vibra running time
       
   129 		)
       
   130 {
       
   131 	//initialize timer and start scheduler
       
   132 	CTestScheduler* self = CTestScheduler::NewL();
       
   133 
       
   134 	TBool value( ETrue );
       
   135 	self->iTimeout->Start(aMillisecs);
       
   136 
       
   137 	CActiveScheduler::Start();
       
   138 
       
   139 	// if not timed, then timer must be cancelled
       
   140 	if (!self->iTimeout->Timed())
       
   141 	{
       
   142 		self->iTimeout->Cancel();
       
   143 		value = ETrue;
       
   144 	}
       
   145 
       
   146 	delete self;
       
   147 	self = NULL;
       
   148 
       
   149 	return value;
       
   150 }
       
   151 
       
   152 //CTIMEOUT
       
   153 
       
   154 // -----------------------------------------------------------------------------
       
   155 // CTimeout::CTimeout
       
   156 // C++ default constructor can NOT contain any code, that
       
   157 // might leave.
       
   158 // -----------------------------------------------------------------------------
       
   159 CTimeout::CTimeout()
       
   160 :CActive(0)
       
   161 {
       
   162 	iTimer.CreateLocal();
       
   163 
       
   164 	CActiveScheduler::Add(this);			
       
   165 }
       
   166 
       
   167 
       
   168 // Destructor
       
   169 CTimeout::~CTimeout()
       
   170 {
       
   171 	Cancel();
       
   172 	iTimer.Close();
       
   173 }
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 // CTimeout::Start
       
   177 // Starts the timer with given time.
       
   178 // (other items were commented in a header).
       
   179 // -----------------------------------------------------------------------------
       
   180 void CTimeout::Start(TInt aTimeoutInMilliSecs)
       
   181 {
       
   182 	iTimer.After(iStatus, 1000 * aTimeoutInMilliSecs);
       
   183 	iTimed = FALSE;
       
   184 	SetActive();
       
   185 }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CTimeout::DoCancel
       
   189 // Cancels the timer.
       
   190 // (other items were commented in a header).
       
   191 // -----------------------------------------------------------------------------
       
   192 void CTimeout::DoCancel()
       
   193 {
       
   194 	iTimer.Cancel();
       
   195 }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CTimeout::RunL
       
   199 // 
       
   200 // 
       
   201 // -----------------------------------------------------------------------------
       
   202 void CTimeout::RunL()
       
   203 {
       
   204 	iTimed = TRUE;
       
   205 	CActiveScheduler::Stop();
       
   206 }
       
   207 
       
   208 
       
   209 
       
   210 
       
   211