三个timer相关的类之一
来源:互联网 发布:mysql增量备份脚本 编辑:程序博客网 时间:2024/06/05 09:40
- CTimer 收藏
class CTimer : public CActive;
Description:
- Base class for a timer active object.
- This is an active object that uses the asynchronous services provided by RTimer, to generate events. These events occur either at a specific time specified as a TTime, or after an interval specified in microseconds. (使用的两个API,At() or After())
- The RunL() virtual member function is called by the active scheduler after this event occurs.
- To write a class derived from CTimer, first define and implement a constructor through which the priority of the CTimer active object can be specified. Then define and implement a suitable RunL() function to handle the completion of a timer request. This function is not defined by CTimer itself and must, therefore, be provided by the derived class. (派生类在其默认构造函数的初始化列表里面调用CTimer的构造函数来初始化CTimer的优先级。而且RunL()在CTimer里没有做实现,所以派生类必须做实现,CTimer实现了DoCancel())
- Note that the CPeriodic and CHeartbeat classes are derived from CTimer, and answer most timing needs.
Construction and destruction:
protected: IMPORT_C CTimer(TInt aPriority);
- Classes derived from CTimer must define and provide a constructor through which the priority of the active object can be passed. Such a constructor can call CTimer's constructor in its constructor initialisation list.
protected: IMPORT_C void ConstructL();
- The function must be called before any timer requests (i.e. calls to RTimer::After() or RTimer::At()) can be made.
- Since it is protected, it cannot be called directly by clients of CTimer derived classes. Typically, a derived class makes a base call to this function in the second phase of two-phase construction; i.e. the derived class defines and implements its own ConstructL() function within which it makes a base call to CTimer::ConstructL().
(继续说明在派生类的默认构造函数的初始化列表里面初始化CTimer的优先级,和必须在ConstructL()里面调用CTimer的ConstructL())
Member functions:
IMPORT_C void At(const TTime &aTime);
- Requests an event at a given local time.
- Notes:
1. The CTimer' RunL() function will be run as soon as possible after the specified system time.
2. The RunL() may be delayed because the RunL() of another active object, with the deepest nesting-level active scheduler on the same thread, is running when the event occurs: this cannot be avoided, but can be minimised by making all RunL()s of short duration.
3. The RunL() may be delayed because other, higher-priority, active objects are scheduled instead. This can be avoided by making CTimers very high-priority.
4. The TTime object should be set to the home time.
IMPORT_C void After(TTimeIntervalMicroSeconds32 anInterval);
- Requests an event after an interval.
- This timer completes after the specified number of microseconds. The "after timer" counter stops during power-down. Therefore, a 5-second timer will complete late if the machine is turned off 2 seconds after the request is made.
protected: virtual IMPORT_C void DoCancel();
- Implements cancellation of an outstanding request
- This function is called as part of the active object's Cancel().
- It must call the appropriate cancel function offered by the active object's asynchronous service provider. The asynchronous service provider's cancel is expected to act immediately.
Example:
// 用CTimer实现一个定时器,结合Obsever模式,使其更common的使用
class MTimeOutTimer
{
public:
virtual void TimeExpired() = 0;
};
class CTimeOutTimer : public CTimer
{
public:
static CTimeOutTimer* NewL(MTimeOutTimer& aTimeOutTimer);
static CTimeOutTimer* NewLC(MTimeOutTimer& aTimeOutTimer);
~CTimeOutTimer();
protected:
virtual void RunL();
private:
CTimeOutTimer(MTimeOutTimer& aTimeOutTimer);
void ConstructL();
private:
MTimeOutTimer& iTimer;
};
#include "TimeOutTimer.h"
CTimeOutTimer* CTimeOutTimer::NewL(MTimeOutTimer& aTimeOutTimer)
{
CTimeOutTimer* self = CTimeOutTimer::NewLC(aTimeOutTimer);
CleanupStack::Pop(self);
return self;
}
CTimeOutTimer* CTimeOutTimer::NewLC(MTimeOutTimer& aTimeOutTimer)
{
CTimeOutTimer* self = new (ELeave) CTimeOutTimer(aTimeOutTimer);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
CTimeOutTimer::CTimeOutTimer(MTimeOutTimer& aTimeOutTimer)
: CTimer(EPriorityStandard) //初始化优先级
, iTimer(aTimeOutTimer)
{
}
CTimeOutTimer::~CTimeOutTimer()
{
Cancel();
}
void CTimeOutTimer::ConstructL()
{
CTimer::ConstructL(); // 调用基类的构造
CActiveScheduler::Add(this);
}
void CTimeOutTimer::RunL()
{
iTimer.TimeExpired(); // 和Observer模式相结合使用
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/jasonfqw/archive/2009/11/26/4875958.aspx
- 三个timer相关的类之一 - CTimer
- 三个timer相关的类之一 - CPeriodic
- 三个timer相关的类之一 - CIdle
- 三个timer相关的类之一
- 三个timer相关的类
- stm32 timer 的三个函数
- Timer 相关的资源
- C#中三个timer的区别
- 【缓存相关的三个头】
- 白话SCRUM之一:SCRUM 的三个角色
- show ip ospf里面的三个throtte timer
- IOS获得设备信息的三个相关类
- vxWorks中Timer相关的测试程序
- android Timer与TimerTask的相关操作
- android Timer与TimerTask的相关操作
- 在C#中关于定时器Timer三个类
- timer demo 之一
- __bridge相关的三个关键字的总结
- C函数调用约定
- 十个成功励志小故事
- auto_ptr作用和用法
- SQL Server导出表到EXCEL文件的存储过程
- Symbian CTimer类中继承子类使用说明
- 三个timer相关的类之一
- Ext.grid.GridPanel
- 用skycc营销软件,轻松当老板
- 使用控件的RenderControl()方法导出Excel
- 利用vs2005.net编写基于WinCE的DLL
- 【转】关于如何在类库中使用Response,Request,Server,Session!
- u-boot中mkimage工具的具体使用
- 知其所以然技术论坛VC++资源下载
- 物联网应用 -- 北京市旅游局的30万电子门票免费发放活动