eventqueue.cpp

来自「symbian,使用dll服务捕获按键,比设置优先级更能提高按键响应.」· C++ 代码 · 共 79 行

CPP
79
字号

#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 + =
减小字号Ctrl + -
显示快捷键?