splited ASyncEvent
This commit is contained in:
74
inc/hgl/event/EventProc.h
Normal file
74
inc/hgl/event/EventProc.h
Normal file
@@ -0,0 +1,74 @@
|
||||
#ifndef HGL_EVENT_PROC_INCLUDE
|
||||
#define HGL_EVENT_PROC_INCLUDE
|
||||
|
||||
#include<hgl/type/Queue.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
/**
|
||||
* <20>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
class EventProc
|
||||
{
|
||||
public:
|
||||
|
||||
EventProc()=default;
|
||||
virtual ~EventProc()=default;
|
||||
|
||||
virtual bool Proc()=0;
|
||||
};//class EventProc
|
||||
|
||||
using EventProcQueue=Queue<EventProc *>;
|
||||
|
||||
/**
|
||||
* ִ<><D6B4>һ<EFBFBD><D2BB><EFBFBD>¼<EFBFBD>
|
||||
*/
|
||||
inline bool UpdateEvent(EventProcQueue *epq)
|
||||
{
|
||||
if(!epq||epq->GetCount()<=0)
|
||||
return(false);
|
||||
|
||||
EventProc *e;
|
||||
|
||||
if(epq->Pop(e))
|
||||
{
|
||||
e->Proc();
|
||||
delete e;
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* ˢ<><CBA2>ִ<EFBFBD><D6B4><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param epq <20>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param max_count <20><><EFBFBD><EFBFBD>ˢ<EFBFBD>¸<EFBFBD><C2B8><EFBFBD>(-1<><31>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
||||
*/
|
||||
inline int UpdateEventQueue(EventProcQueue *epq,int max_count=-1)
|
||||
{
|
||||
if(!epq||epq->GetCount()<=0||max_count==0)
|
||||
return(0);
|
||||
|
||||
int count=0;
|
||||
EventProc *e;
|
||||
|
||||
while(epq->Pop(e))
|
||||
{
|
||||
if(e)
|
||||
{
|
||||
e->Proc();
|
||||
delete e;
|
||||
}
|
||||
|
||||
++count;
|
||||
|
||||
if(--max_count==0)
|
||||
break;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}//namespace hgl
|
||||
#endif//HGL_EVENT_PROC_INCLUDE
|
Reference in New Issue
Block a user