Update contrib.
1 // Copyright (c) 1995-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 the License "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\active\t_idle.cpp
16 // Test the CIdle class. A CIdle and CTimer run on the same active scheduler and
17 // the test displays how their callback function and RunL respectively are called.
21 // - Create and install active scheduler.
22 // - Create and start a timer, add this to the active scheduler, request an event
23 // after a specified interval. The timer will reschedule itself for a finite
24 // number of times, then it will cancel the CIdle object and then reschedule
25 // itself again and eventually it will stop the active scheduler.
26 // - Create a CIdle active object, start a background task that is encapsulated in
27 // callback function. The CIdle will keep reschedule itself by always returning
28 // TRUE from the callback.
29 // - Output some text from timer's RunL and CIdle's callback to show when they are
30 // called and how they interleave.
31 // Platforms/Drives/Compatibility:
33 // Assumptions/Requirement/Pre-requisites:
34 // Failures and causes:
35 // Base Port information:
41 enum {EIdlePriority=1000,EMoreIdlePriority=800};
43 class CMyRequestManager : public CActiveScheduler
46 virtual void Error(TInt anError) const;
49 class CMyTimer : public CTimer
52 static CMyTimer* New();
56 CMyTimer(TInt aPriority);
58 enum {EMaxCount=10,EStopCount=5,ETimeReq=100000};
62 LOCAL_D RTest test(_L("T_IDLE"));
63 LOCAL_D CIdle* MoreIdle;
64 LOCAL_D TInt TheCount=0;
66 void CMyRequestManager::Error(TInt anError) const
68 // Called if any Run() method leaves.
72 test.Panic(anError,_L("CMyRequestManager::Error"));
75 CMyTimer* CMyTimer::New()
77 // Create a new CMyTimer.
81 return(new CMyTimer(EIdlePriority));
84 CMyTimer::CMyTimer(TInt aPriority)
88 : CTimer(aPriority),iCount(0)
91 void CMyTimer::Start()
93 // The timer has completed.
97 TRAPD(r, ConstructL());
99 CActiveScheduler::Add(this);
103 void CMyTimer::RunL()
105 // The timer has completed.
110 test.Printf(_L("Timer %03d\n"),iCount);
111 if (iCount==EStopCount)
113 if (iCount<EMaxCount)
117 test.Printf(_L("\n"));
119 CActiveScheduler::Stop();
123 TInt IdleResponse(TAny*)
125 // Respond to the idle callback
129 test.Printf(_L("\rIdle response number : %6d "),++TheCount);
133 TInt IdleCancel(TAny*)
135 // Cancel the other idle object
147 GLDEF_C TInt E32Main()
149 // Test idle objects.
154 test.Start(_L("Testing idle object cancellation"));
156 CMyRequestManager* pR=new CMyRequestManager;
158 CActiveScheduler::Install(pR);
160 CMyTimer* pT=CMyTimer::New();
162 MoreIdle=CIdle::New(EIdlePriority);
163 MoreIdle->Start(&IdleResponse);
164 CActiveScheduler::Start();