#ifndef __TIMERCYCLE_H
#define __TIMERCYCLE_H
#pragma once
#include " .EventDefine.h "
class __declspec(dllexport) CTimerCycle
... {
public:
CTimerCycle(void);
~CTimerCycle(void);
void Initial(OBJECT);
void StartTimerCycle(void);
void StopTimerCycle(void);
protected:
static void CALLBACK OnTimeProc(UINT, UINT, DWORD, DWORD, DWORD);
void SetTimerCyclicHandler(void);
private:
UINT m_TimerID;
UINT m_TimerRes;
static OBJECT eventpf_p;
} ;
#endif
#define __TIMERCYCLE_H
#pragma once
#include " .EventDefine.h "
class __declspec(dllexport) CTimerCycle
... {
public:
CTimerCycle(void);
~CTimerCycle(void);
void Initial(OBJECT);
void StartTimerCycle(void);
void StopTimerCycle(void);
protected:
static void CALLBACK OnTimeProc(UINT, UINT, DWORD, DWORD, DWORD);
void SetTimerCyclicHandler(void);
private:
UINT m_TimerID;
UINT m_TimerRes;
static OBJECT eventpf_p;
} ;
#endif
#include
"
StdAfx.h
"
#include < mmsystem.h >
#include " .TimerCycle.h "
#include " .EventPF.h "
OBJECT CTimerCycle::eventpf_p = NULL;
CTimerCycle::CTimerCycle( void )
: m_TimerID(NULL)
, m_TimerRes(NULL)
... {
}
CTimerCycle:: ~ CTimerCycle( void )
... {
StopTimerCycle();
m_TimerID = 0;
m_TimerRes = 0;
}
void CTimerCycle::Initial(OBJECT evpf_p)
... {
eventpf_p = evpf_p;
StartTimerCycle();
}
void CTimerCycle::StartTimerCycle( void )
... {
TIMECAPS tc;
if(timeGetDevCaps(&tc,sizeof(TIMECAPS))==TIMERR_NOERROR)...{
m_TimerID = min(max(tc.wPeriodMin,m_TimerID),tc.wPeriodMax);
timeBeginPeriod(m_TimerID);
SetTimerCyclicHandler();
}
}
void CTimerCycle::StopTimerCycle( void )
... {
timeKillEvent(m_TimerRes);
timeEndPeriod(m_TimerID);
}
void CALLBACK CTimerCycle::OnTimeProc(UINT uTimerID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
... {
if (NULL != eventpf_p)...{
((CEventPF*)eventpf_p)->Clock();
}
}
void CTimerCycle::SetTimerCyclicHandler( void )
... {
m_TimerRes = timeSetEvent(TICKBASETIME, m_TimerID, (LPTIMECALLBACK)OnTimeProc, (DWORD)0,TIME_PERIODIC);
}
#include < mmsystem.h >
#include " .TimerCycle.h "
#include " .EventPF.h "
OBJECT CTimerCycle::eventpf_p = NULL;
CTimerCycle::CTimerCycle( void )
: m_TimerID(NULL)
, m_TimerRes(NULL)
... {
}
CTimerCycle:: ~ CTimerCycle( void )
... {
StopTimerCycle();
m_TimerID = 0;
m_TimerRes = 0;
}
void CTimerCycle::Initial(OBJECT evpf_p)
... {
eventpf_p = evpf_p;
StartTimerCycle();
}
void CTimerCycle::StartTimerCycle( void )
... {
TIMECAPS tc;
if(timeGetDevCaps(&tc,sizeof(TIMECAPS))==TIMERR_NOERROR)...{
m_TimerID = min(max(tc.wPeriodMin,m_TimerID),tc.wPeriodMax);
timeBeginPeriod(m_TimerID);
SetTimerCyclicHandler();
}
}
void CTimerCycle::StopTimerCycle( void )
... {
timeKillEvent(m_TimerRes);
timeEndPeriod(m_TimerID);
}
void CALLBACK CTimerCycle::OnTimeProc(UINT uTimerID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
... {
if (NULL != eventpf_p)...{
((CEventPF*)eventpf_p)->Clock();
}
}
void CTimerCycle::SetTimerCyclicHandler( void )
... {
m_TimerRes = timeSetEvent(TICKBASETIME, m_TimerID, (LPTIMECALLBACK)OnTimeProc, (DWORD)0,TIME_PERIODIC);
}
#ifndef _TIMEUPEVENTPOOL_H
#define _TIMEUPEVENTPOOL_H
#pragma once
#include " .EventPool.h "
class __declspec(dllexport) CTimeUpEventPool
... {
public:
CTimeUpEventPool(void);
~CTimeUpEventPool(void);
void Initial(CEventPool*);
US GetUniqueId(US);
void RaiseEvent(UL, US, US, CEventPara*);
void ClockTimeUpEventList(void);
void Free(void);
private:
static US m_UniqueId;
CEventPool* eventpool_p;
CCircularLinkList m_TimeUpEventList;
CCriticalSection m_CriticalSection;
} ;
#endif /* _TIMEUPEVENTPOOL_H */
#define _TIMEUPEVENTPOOL_H
#pragma once
#include " .EventPool.h "
class __declspec(dllexport) CTimeUpEventPool
... {
public:
CTimeUpEventPool(void);
~CTimeUpEventPool(void);
void Initial(CEventPool*);
US GetUniqueId(US);
void RaiseEvent(UL, US, US, CEventPara*);
void ClockTimeUpEventList(void);
void Free(void);
private:
static US m_UniqueId;
CEventPool* eventpool_p;
CCircularLinkList m_TimeUpEventList;
CCriticalSection m_CriticalSection;
} ;
#endif /* _TIMEUPEVENTPOOL_H */
#include
"
StdAfx.h
"
#include " .TimeUpEventPool.h "
#define Msec_to_Ticks(n) (UL)(n < TICKBASETIME ? 1 : (n / TICKBASETIME + 1))
US CTimeUpEventPool::m_UniqueId = 0 ;
CTimeUpEventPool::CTimeUpEventPool( void )
: eventpool_p(NULL)
... {
}
CTimeUpEventPool:: ~ CTimeUpEventPool( void )
... {
}
void CTimeUpEventPool::Initial(CEventPool * obj)
... {
m_CriticalSection.Lock();
eventpool_p = obj;
m_UniqueId = 0;
m_CriticalSection.Unlock();
}
US CTimeUpEventPool::GetUniqueId(US size)
... {
US result;
m_CriticalSection.Lock();
result = ( ++m_UniqueId % (US_MAX - size) ) + size;
m_CriticalSection.Unlock();
return result;
}
void CTimeUpEventPool::RaiseEvent(UL time, US size, US trig, CEventPara * para_p)
... {
CMyEvent* myEvent_p;
CEventElement* element_p;
m_CriticalSection.Lock();
myEvent_p = new CMyEvent();
element_p = new CEventElement();
myEvent_p->m_InitialTick = Msec_to_Ticks(time);
myEvent_p->m_NowTick = Msec_to_Ticks(time);
myEvent_p->m_TrigMax = size;
myEvent_p->m_Trigger = trig;
myEvent_p->parameter_p = para_p;
element_p->Set(myEvent_p);
m_TimeUpEventList.AppendTail(element_p);
m_CriticalSection.Unlock();
}
void CTimeUpEventPool::ClockTimeUpEventList( void )
... {
CNote* rootnode_p;
CNote* node_p;
CMyEvent* myEvent_p;
CEventPara* eventPara_p;
m_CriticalSection.Lock();
if (m_TimeUpEventList.GetHeader(&rootnode_p))...{
while( NULL != rootnode_p ) ...{
myEvent_p = (CMyEvent*)rootnode_p->element_p->Get();
myEvent_p->m_NowTick--;
if (0 >= myEvent_p->m_NowTick)...{
/**//*Copy the Parm*/
myEvent_p->parameter_p->Copy(&eventPara_p);
/**//*On The Time, Raise Event*/
this->eventpool_p->RaiseEvent(TASK_RANK_HIGH,myEvent_p->m_Trigger,eventPara_p);
node_p = rootnode_p;
/**//*next node*/
rootnode_p = m_TimeUpEventList.GetNext(rootnode_p);
/**//*delete the node*/
m_TimeUpEventList.Remove(node_p);
}
else...{
rootnode_p = m_TimeUpEventList.GetNext(rootnode_p);
}
}
}
m_CriticalSection.Unlock();
}
void CTimeUpEventPool::Free( void )
... {
m_CriticalSection.Lock();
m_TimeUpEventList.Free();
m_UniqueId = 0;
m_CriticalSection.Unlock();
}
#include " .TimeUpEventPool.h "
#define Msec_to_Ticks(n) (UL)(n < TICKBASETIME ? 1 : (n / TICKBASETIME + 1))
US CTimeUpEventPool::m_UniqueId = 0 ;
CTimeUpEventPool::CTimeUpEventPool( void )
: eventpool_p(NULL)
... {
}
CTimeUpEventPool:: ~ CTimeUpEventPool( void )
... {
}
void CTimeUpEventPool::Initial(CEventPool * obj)
... {
m_CriticalSection.Lock();
eventpool_p = obj;
m_UniqueId = 0;
m_CriticalSection.Unlock();
}
US CTimeUpEventPool::GetUniqueId(US size)
... {
US result;
m_CriticalSection.Lock();
result = ( ++m_UniqueId % (US_MAX - size) ) + size;
m_CriticalSection.Unlock();
return result;
}
void CTimeUpEventPool::RaiseEvent(UL time, US size, US trig, CEventPara * para_p)
... {
CMyEvent* myEvent_p;
CEventElement* element_p;
m_CriticalSection.Lock();
myEvent_p = new CMyEvent();
element_p = new CEventElement();
myEvent_p->m_InitialTick = Msec_to_Ticks(time);
myEvent_p->m_NowTick = Msec_to_Ticks(time);
myEvent_p->m_TrigMax = size;
myEvent_p->m_Trigger = trig;
myEvent_p->parameter_p = para_p;
element_p->Set(myEvent_p);
m_TimeUpEventList.AppendTail(element_p);
m_CriticalSection.Unlock();
}
void CTimeUpEventPool::ClockTimeUpEventList( void )
... {
CNote* rootnode_p;
CNote* node_p;
CMyEvent* myEvent_p;
CEventPara* eventPara_p;
m_CriticalSection.Lock();
if (m_TimeUpEventList.GetHeader(&rootnode_p))...{
while( NULL != rootnode_p ) ...{
myEvent_p = (CMyEvent*)rootnode_p->element_p->Get();
myEvent_p->m_NowTick--;
if (0 >= myEvent_p->m_NowTick)...{
/**//*Copy the Parm*/
myEvent_p->parameter_p->Copy(&eventPara_p);
/**//*On The Time, Raise Event*/
this->eventpool_p->RaiseEvent(TASK_RANK_HIGH,myEvent_p->m_Trigger,eventPara_p);
node_p = rootnode_p;
/**//*next node*/
rootnode_p = m_TimeUpEventList.GetNext(rootnode_p);
/**//*delete the node*/
m_TimeUpEventList.Remove(node_p);
}
else...{
rootnode_p = m_TimeUpEventList.GetNext(rootnode_p);
}
}
}
m_CriticalSection.Unlock();
}
void CTimeUpEventPool::Free( void )
... {
m_CriticalSection.Lock();
m_TimeUpEventList.Free();
m_UniqueId = 0;
m_CriticalSection.Unlock();
}