📄 eventqueue.cpp
字号:
#include "EventQueue.h"
_LIT(KGLobalName, "HAnimGlobe");
CEventQueue* CEventQueue::NewL(MEventQueue& aNotify)
{
CEventQueue* queue = new ( ELeave ) CEventQueue(aNotify);
CleanupStack::PushL( queue );
queue->ConstructL();
CleanupStack::Pop();
return queue;
}
CEventQueue::CEventQueue(MEventQueue& aNotify):CActive( CActive::EPriorityStandard ), iEventNotify(aNotify)
{
CActiveScheduler::Add( this );
}
CEventQueue::~CEventQueue()
{
Cancel();
iMsgQueue.Close();
}
void CEventQueue::ConstructL()
{
TInt ret = iMsgQueue.OpenGlobal(KGLobalName);
if (ret != KErrNone)
{
iMsgQueue.CreateGlobal(KGLobalName, 5, sizeof(TInt), EOwnerProcess);
GetEvent();
}
else
{
iMsgQueue.Close();
ret = iMsgQueue.CreateGlobal(KGLobalName, 5, sizeof(TInt), EOwnerProcess);
GetEvent();
}
}
void CEventQueue::RunL()
{
if (iStatus.Int() == KErrNone)
{
TInt data;
TInt err = iMsgQueue.Receive( &data, sizeof(TInt) );
if (err == KErrNone)
iEventNotify.EventNotify(data);
GetEvent();
}
}
TInt CEventQueue::RunError()
{
GetEvent();
return -1;
}
void CEventQueue::GetEvent()
{
if (IsActive())
return;
iMsgQueue.NotifyDataAvailable( iStatus );
SetActive();
}
void CEventQueue::DoCancel()
{
iMsgQueue.CancelDataAvailable();
}
void CEventQueue::SendEvent()
{
TInt nExitNum=1;
iMsgQueue.Send(&nExitNum,sizeof(nExitNum));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -