📄 uitimer.c
字号:
/**************************************************************
INCLUDE FILE
***************************************************************/
#include <pr2k.h>
#include <uiwnd.h>
#include <uiTimer.h>
extern struct thread *CurrentThread;
TGuiTimer *PdaTimerTable=NULL;
DLL_EXP(HNDL) guiTimer_Allocate(void)
{
TGuiTimer *pTimer;
guiEnterWCS();
//allocate a timer;
//pTimer=(TGuiTimer *)kernelMalloc(sizeof(TGuiTimer));
pTimer=(TGuiTimer *)ap_malloc(sizeof(TGuiTimer));
if(pTimer!=NULL)
{
//initialize timer
pTimer->nEnabled=0;
pTimer->dwTickMax=0;
pTimer->dwTickRemain=0;
pTimer->pMsgQueue=NULL;
pTimer->iOwnerThreadID=CurrentThread->tid;
pTimer->pPrev=NULL;
pTimer->pNext=PdaTimerTable;
if(PdaTimerTable!=NULL)
{
PdaTimerTable->pPrev=pTimer;
}
PdaTimerTable=pTimer;
}
guiExitWCS();
return (HNDL)pTimer;
}
DLL_EXP(HNDL) guiTimer_Start(HNDL hTimer, DWORD initTick, DWORD cycleTick, HNDL hWin)
{
TGuiTimer *pTmr;
pTmr=(TGuiTimer *)hTimer;
if(pTmr==NULL)
{
pTmr=(TGuiTimer *)guiTimer_Allocate();
}
guiEnterWCS();
if(pTmr!=NULL)
{
pTmr->dwTickRemain=initTick;
pTmr->dwTickMax=cycleTick;
pTmr->pMsgQueue=((TWindow *)hWin)->messageQueue;
pTmr->nEnabled=1;
}
guiExitWCS();
return hTimer;
}
DLL_EXP(void) guiTimer_Free(HNDL hTimer)
{
TGuiTimer *pTmr;
pTmr=(TGuiTimer *)hTimer;
guiEnterWCS();
_guiTimer_Delete(pTmr);
guiExitWCS();
}
DLL_EXP(DWORD) guiTimer_GetValue(HNDL hTimer)
{
TGuiTimer *pTmr;
DWORD dwTicks=0;
pTmr=(TGuiTimer *)hTimer;
guiEnterWCS();
if(pTmr!=NULL)
{
dwTicks=pTmr->dwTickRemain;
}
guiExitWCS();
return dwTicks;
}
DLL_EXP(int) guiTimer_Stop(HNDL hTimer)
{
TGuiTimer *pTmr;
pTmr=(TGuiTimer *)hTimer;
guiEnterWCS();
if(pTmr!=NULL&&pTmr->nEnabled!=0)
{
pTmr->nEnabled=0;
guiExitWCS();
return 0;
}
guiExitWCS();
return -1;
}
DLL_EXP(void) pda_timerCount(void)
{
TGuiTimer *pTimer=PdaTimerTable;
TGuiMessage struMessage;
while(pTimer!=NULL)
{
if(pTimer->nEnabled==1)
{
if(pTimer->dwTickRemain==0)
{
struMessage.handle=(HNDL)pTimer;
struMessage.messageType=TIMER_TIMEOUT;
_guiEnqueue(pTimer->pMsgQueue,&struMessage);
if(pTimer->dwTickMax!=0)
{
pTimer->dwTickRemain=pTimer->dwTickMax;
}
else
{
// sc_logString("timer is stop",TO_MONITOR);
pTimer->nEnabled=0;
}
}
else
{
pTimer->dwTickRemain--;
}
}
pTimer=pTimer->pNext;
}
}
DLL_EXP(int) guiTimer_Restart(HNDL hTimer, DWORD initTick, DWORD cycleTick)
{
TGuiTimer *pTmr;
pTmr=(TGuiTimer *)hTimer;
if(pTmr==NULL)
{
return -1;
}
guiEnterWCS();
pTmr->dwTickRemain=initTick;
pTmr->dwTickMax=cycleTick;
pTmr->nEnabled=1;
guiExitWCS();
return 0;
}
DLL_EXP(int) guiTimer_IsRun(HNDL hTimer)
{
TGuiTimer *pTmr;
pTmr=(TGuiTimer *)hTimer;
if(pTmr==NULL)
{
return -1;
}
return (int)pTmr->nEnabled;
}
// internal function
void _guiTimer_Delete(TGuiTimer * tmpPtr)
{
TGuiTimer *pTimer=PdaTimerTable;
if(!pTimer)
{
return;
}
if(pTimer->pPrev!=NULL)
{
pTimer->pPrev->pNext=pTimer->pNext;
}
else
{
PdaTimerTable=pTimer->pNext;
}
if(pTimer->pNext!=NULL)
{
pTimer->pNext->pPrev=pTimer->pPrev;
}
//kernelFree(pTimer);
ap_free(pTimer);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -