1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
void CDisplay::TimeDisplayProc(void* pThis)
{
CDisplay* pDis=(CDisplay*)pThis;
// Return code of waitformultipleobjects
DWORD l_dwWaitReturn;
// Define handle array to manage start of timer and stop of thread
HANDLE l_EventTab[3] = {0, 0, 0};
// Specifies when the state of the timer is to be set to signaled, in 100 nanosecond intervals.
LARGE_INTEGER liDueTime;
// Create a waitable timer
HANDLE l_TimerHandle = NULL;
l_TimerHandle = CreateWaitableTimer(0, FALSE, "TimeDisplayTimer");
if (!l_TimerHandle)
pDis->LogDebug(pDis->m_sPackage, pDis->m_sComponent, "TimeDisplayProc", "l_TimerHandle failed", __FILE__, __LINE__);
// Initialise event array
l_EventTab[0] = pDis->m_hStartTimer;
l_EventTab[1] = l_TimerHandle;
l_EventTab[2] = pDis->m_hEndTimeDisplayProc;
bool l_bRun = true;
while (l_bRun)
{
// Wait for the start of timer
l_dwWaitReturn = WaitForMultipleObjects(3, l_EventTab, FALSE, INFINITE);
switch(l_dwWaitReturn)
{
case WAIT_OBJECT_0:
// Start timer
{
liDueTime.QuadPart = -15000000; // =15secondes
// Set a timer to wait for N seconds.
if (!SetWaitableTimer(l_EventTab[1], &liDueTime, 0, NULL, NULL, FALSE))
pDis->LogDebug(pDis->m_sPackage, pDis->m_sComponent, "TimeDisplayProc", "SetWaitableTimer failed", __FILE__, __LINE__);
pDis->m_bDisplayInProgress = true;
}
break;
case WAIT_OBJECT_0 + 1:
// Time is done
{
EnterCriticalSection(&pPID->m_critsecDataProtection);
if (!pDis->m_DisplayList.empty())
{
std::string stext = pDis->m_DisplayList.front().text;
int minTime = pDis->m_DisplayList.front().minDuration;
pDis->m_DisplayList.pop_front();
pDis->m_bDisplayInProgress = false;
pDis->_PrintText(stext, minTime);
}
else
pDis->m_bDisplayInProgress = true;
LeaveCriticalSection(&pDis->m_critsecDataProtection);
}
break;
case WAIT_OBJECT_0 + 2:
// End requested
{
l_bRun = false;
CloseHandle(pDis->m_hStartTimer);
CloseHandle(pDis->m_hEndTimeDisplayProc);
CloseHandle(l_TimerHandle);
}
break;
case WAIT_FAILED:
{
pDis->LogDebug(pPID->m_sPackage, pPID->m_sComponent, "TimeDisplayProc", "WaitForMultipleObjects failed", __FILE__, __LINE__);
}
break;
default:
break;
}
}
} |
Partager