三个timer相关的类之一 - CPeriodic
来源:互联网 发布:js与jsp数据交互 编辑:程序博客网 时间:2024/06/04 20:04
class CPeriodic : public CTimer;
Description:
- Periodic timer active object.
- This class generates regular timer events and handles them with a callback function. The callback is specified as a parameter to Start().(周期性的产生定时时间)
- The callback may not be called immediately after the signal from the timer request has been generated, for the following reasons:
1. the RunL() of another active object may be running at the time of the signal
2. other active objects may have a higher priority than the CPeriodic
- If timing accuracy is important to your application, you can minimise the first problem by ensuring all RunL()s complete quickly, and can eliminate the second by giving the CPeriodic a higher priority than any other active object. Although it is generally recommended that timer-related active objects have a high priority, this will not address the problem of CPeriodic timers running behind, because active object scheduling is not pre-emptive. (如果需要精确定时的话,需要提高CPeriodic优先级或是使得RunL()尽可能的短)
- After a timer signal generated by a CPeriodic, the next signal is requested just before running the callback, and this request can be delayed for the same reasons that running the callback can be delayed. Therefore, a large number N of periods may add up to somewhat more than N times the requested period time. If absolute precision is required in tracking time, do not rely on counting the number of times the callback is called: read the value of the system clock every time you need it.
Construction and destruction:
static IMPORT_C CPeriodic *NewL(TInt aPriority);
- Allocates and constructs a CPeriodic object - leaving.
- Specify a high priority so the callback function is scheduled as soon as possible after the timer events complete.
protected: IMPORT_C CPeriodic(TInt aPriority);
- Classes derived from CPeriodic must define and provide a constructor through which the priority of the active object can be passed. Such a constructor can call CPeriodic's constructor in its constructor initialisation list.
Member functions:
void Start(TTimeIntervalMicroSeconds32 aDelay, TTimeIntervalMicroSeconds32 anInterval, TCallBack aCallBack);
- Starts generating periodic events.
- The event calls the protected RunL() function, which in turn calls the function specified by aCallBack. The first event is generated after aDelay microseconds; subsequent events are generated regularly thereafter at intervals of anInterval microseconds.( 时间到达后,AS会调用RunL(),其又会调用这个callback函数)
- The TCallBack contains a function pointer and a TAny* pointer. The function will be repeatedly called with the pointer as a parameter.
- Once started, periodic events are generated until the CPeriodic object is destroyed.
protected: virtual IMPORT_C void RunL();
- Handles an active object's request completion event.
- A derived class must provide an implementation to handle the completed request. If appropriate, it may issue another request.
- The function is called by the active scheduler when a request completion event occurs, i.e. after the active scheduler's WaitForAnyRequest() function completes.
Example: // IMPLEMENTATION SPECIFIC CONSTANTS const TInt KPeriodicTimerInterval5Sec(5000000); class CMyClass : public CBase { .... private: // New functions /** * The call back function. * /param aAny A pointer to this class. */ static TInt PeriodicTimerCallBack(TAny* aAny); /** * Notice that this is a sample fuction. */ void SomeFunction(); private: // Member data /** * The periodic timer. * Owned by CMyClass */ CPeriodic* iPeriodicTimer; }; CMyClass::~CMyClass() { if (iPeriodicTimer) { // Calling Cancel without checking if the timer is active is safe iPeriodicTimer->Cancel(); } delete iPeriodicTimer; } void CMyClass::ConstructL() { // Initialize the periodic timer. iPeriodicTimer = CPeriodic::NewL(CActive::EPriorityIdle); // Start the periodic timer, when ever the time elapsed // the PeriodicTimerCallBack() will get called. // Notice: The timer will periodically hit the PeriodicTimerCallBack // until you cancel the timer by calling iPeriodicTimer->Cancel(). iPeriodicTimer->Start(KPeriodicTimerInterval5Sec, KPeriodicTimerInterval5Sec, TCallBack(PeriodicTimerCallBack, this)); } TInt CMyClass::PeriodicTimerCallBack(TAny* aAny) { CMyClass* self = static_cast<CMyClass*>( aAny ); // TODO: The below call is a sample function, // you may change it to your requirement. self->SomeFunction(); // Cancel the timer when the callback should not be called again. // Call: self->iPeriodicTimer->Cancel(); return KErrNone; // Return value ignored by CPeriodic } void CMyClass::SomeFunction() { // TODO: Your code! } CPeriodic 继承了CTimer所以做了一些必要的工作,比如调用基类的默认构造函数来设置优先级,调用AS的add方法等等。
- 三个timer相关的类之一 - CPeriodic
- 三个timer相关的类之一 - CTimer
- 三个timer相关的类之一 - CIdle
- 三个timer相关的类之一
- 三个timer相关的类
- CPeriodic周期类的使用
- 周期类: Cperiodic
- stm32 timer 的三个函数
- Timer 相关的资源
- C#中三个timer的区别
- 【缓存相关的三个头】
- 白话SCRUM之一:SCRUM 的三个角色
- show ip ospf里面的三个throtte timer
- IOS获得设备信息的三个相关类
- vxWorks中Timer相关的测试程序
- android Timer与TimerTask的相关操作
- android Timer与TimerTask的相关操作
- 在C#中关于定时器Timer三个类
- 利用oracle快照dblink解决数据库表同步问题
- 页面显示三纵三横
- 企业管理信息化已成大势所趋—致各中小企业
- 关于jstl表达式写法的实验
- 在不插网线情况下,虚拟机如何与本地主机相连!
- 三个timer相关的类之一 - CPeriodic
- 11.26
- 输入法对pb开发工具的影响
- 个人收藏 Action Profiles in SAP-CRM
- 为图片添加水印
- 三个timer相关的类之一 - CIdle
- WAV文件的头信息(文件头格式)
- 编写程序:从键盘上输入若干个整数(以输入-1作为结束标识),输出这些数中的最大值和最小值,要求编写一个函数实现最大值和最小值的求取。
- Struts标签checkbox使用總結(默認選擇設置)