00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #pragma once
00012
00013 #include "TestToolBox\IEventReceiver.h"
00014 #include "TestToolBox\PollingCheck.h"
00015 #include "TestToolBox\CommonSources\CommonDefinitions.h"
00016
00017 #include <iostream>
00018
00019
00020
00021
00022
00023
00024
00025
00026 namespace TestToolBox
00027 {
00028
00029 inline PollingCheck::PollingCheck()
00030 : m_initialSleepTimeMs (10)
00031 , m_sleepTimeMs (10)
00032 , m_timeoutMs (1000)
00033 , m_pEventReceiver (0)
00034 {
00035 TRCF("PollingCheck::PollingCheck");
00036 TRC(TL_DEBUG, "Constructor");
00037
00038 }
00039
00040
00041
00042
00043
00044
00045 inline PollingCheck::~PollingCheck()
00046 {
00047 TRCF("PollingCheck::~PollingCheck");
00048 TRC(TL_DEBUG, "Destructor");
00049
00050 }
00051
00052
00053
00054
00055
00056
00057 inline bool PollingCheck::Run (
00058 BoolFunctor in_functor,
00059 char const * in_functionName,
00060 char const * in_argValue,
00061 char const * in_file,
00062 long in_lineNum)
00063 {
00064 bool retVal = false;
00065
00066 TRCF("PollingCheck::Run");
00067 TRC(TL_DEBUG, "Begin");
00068
00069
00070 if (m_pEventReceiver && in_functionName)
00071 {
00072
00073 char const * pFunctionNameWithoutClass = strrchr(in_functionName,':');
00074 pFunctionNameWithoutClass = pFunctionNameWithoutClass
00075 ? pFunctionNameWithoutClass + 1 : in_functionName;
00076
00077 std::ostringstream oss;
00078 oss << "\n<" << pFunctionNameWithoutClass;
00079 if (in_argValue) oss << " " << in_argValue;
00080 oss << " [polling]";
00081 m_pEventReceiver->EventMsg(CTX_PROT, oss.str().c_str());
00082 }
00083
00084
00085 unsigned long startTimeMs = ::GetTickCount();
00086
00087
00088 if (m_initialSleepTimeMs >= 0)
00089 {
00090 ::Sleep (m_initialSleepTimeMs);
00091 }
00092
00093 bool timeout = false;
00094 do
00095 {
00096
00097 if (in_functor())
00098 {
00099
00100 retVal = true;
00101 break;
00102 }
00103
00104
00105 ::Sleep(m_sleepTimeMs);
00106
00107 timeout = (::GetTickCount() - startTimeMs >=
00108 static_cast<unsigned long>(m_timeoutMs));
00109
00110 } while (!timeout);
00111
00112
00113 if (timeout)
00114 {
00115 if (m_pEventReceiver)
00116 {
00117 m_pEventReceiver->Event(CTX_INFO,"Poll-Timeout after %d ms",
00118 ::GetTickCount() - startTimeMs);
00119 }
00120 }
00121 if (!retVal)
00122 {
00123 std::ostringstream oss;
00124 if (in_file)
00125 oss << in_file << " (" << in_lineNum << "): ";
00126 oss << "POLL-ERROR: verification failed";
00127 if (m_pEventReceiver)
00128 m_pEventReceiver->EventMsg(CTX_ERROR, oss.str().c_str());
00129 }
00130
00131 TRC(TL_DEBUG, "End: retVal=%d", retVal);
00132 return retVal;
00133
00134 }
00135
00136
00137
00138
00139
00140
00141
00142 }
00143
00144