📄 myactiveobject.cpp
字号:
/*
============================================================================
Name : MyActiveObject.cpp
Author :
Version : 1.0
Copyright : Your copyright notice
Description : CMyActiveObject implementation
============================================================================
*/
#include "MyActiveObject.h"
CMyActiveObject::CMyActiveObject(CConsoleBase& aConsole) :
CActive(EPriorityStandard), // Standard priority
iConsole(aConsole), iCount(0)
{
}
CMyActiveObject* CMyActiveObject::NewLC(CConsoleBase& aConsole)
{
CMyActiveObject* self = new ( ELeave ) CMyActiveObject(aConsole);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
CMyActiveObject* CMyActiveObject::NewL(CConsoleBase& aConsole)
{
CMyActiveObject* self = CMyActiveObject::NewLC(aConsole);
CleanupStack::Pop(); // self;
return self;
}
void CMyActiveObject::ConstructL()
{
User::LeaveIfError(iTimer.CreateLocal() ); // Initialize timer
CActiveScheduler::Add( this); // Add to scheduler
iWait = new (ELeave)CActiveSchedulerWait;
}
CMyActiveObject::~CMyActiveObject()
{
Cancel(); // Cancel any request, if outstanding
iTimer.Close(); // Destroy the RTimer object
// Delete instance variables if any
if (iWait->IsStarted())
{
iWait->AsyncStop();
}
delete iWait;
iWait = NULL;
}
void CMyActiveObject::StartL(TTimeIntervalMicroSeconds32 aDelay)
{
Cancel(); // Cancel any request, just to be sure
iTimer.After(iStatus, aDelay); // Set for later
SetActive(); // Tell scheduler a request is active
iWait->Start();
}
void CMyActiveObject::RunL()
{
iWait->AsyncStop();
TBuf<50> outputStr;
outputStr.AppendNum(iCount);
iConsole.Write(outputStr);
iConsole.Write(_L("\n"));
iCount++;
}
void CMyActiveObject::DoCancel()
{
iTimer.Cancel();
}
TInt CMyActiveObject::RunError(TInt aError)
{
return aError;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -