View a printable version of the current page.
  Wiki > Symbian Developer Network Public Wiki > ... > Example source code > RTimer implementation
  RTimer implementation
Added by alie, last edited by Rodney De Gale on Feb 15, 2008  (view change)
Labels: 
(None)

Header file
#ifndef TIMERTOOL_H
#define TIMERTOOL_H

#include <E32Base.h>

class MTimerToolObserver
	{
	public :
		enum TTimerToolEventType
			{
			ETimerExpired
			};
		virtual void HandleTimerToolEventL(TTimerToolEventType aEventType)=0;
	};

class CTimerTool : public CActive
	{
	public:
	    static CTimerTool* NewL(MTimerToolObserver& aObserver);
	    CTimerTool(MTimerToolObserver& aObserver);
    	    ~CTimerTool();
	    void ConstructL();
	    void Start(TTimeIntervalMicroSeconds32 aInterval);
	    void Stop();

	protected:
	    void DoCancel();
    	void RunL();

	private:
		RTimer			 	iTimer;
 		MTimerToolObserver& iObserver;

	};

#endif
Cpp file
#include <E32Base.h
#include <E32Std.h>		//RTimer
#include "TimerTool.h"

CTimerTool* CTimerTool::NewL(MTimerToolObserver& aObserver)
	{
	CTimerTool* iSelf = new (ELeave) CTimerTool(aObserver);
	CleanupStack::PushL(iSelf);
	iSelf->ConstructL();
	CleanupStack::Pop();
	return iSelf;
	}

CTimerTool::CTimerTool(MTimerToolObserver& aObserver) : CActive(EPriorityStandard), iObserver(aObserver)
	{
	}

void CTimerTool::ConstructL()
	{
	User::LeaveIfError(iTimer.CreateLocal());
	CActiveScheduler::Add(this);
	}

CTimerTool::~CTimerTool()
	{
	Deque();
	iTimer.Close();
	}

void CTimerTool::Start(TTimeIntervalMicroSeconds32 aInterval)
	{
	iTimer.After(iStatus,aInterval);
	SetActive();
	}

void CTimerTool::Stop()
	{
	Cancel();
	}

void CTimerTool::DoCancel()
	{
	iTimer.Cancel();
	}

void CTimerTool::RunL()
	{
	iObserver.HandleTimerToolEventL(MTimerToolObserver::ETimerExpired);
	}
Interactive Services Terms & Conditions of use | Terms of use | Privacy policy | Media Center | Contact us | © 2008 Symbian