CWin32Thread Class Reference#include <Win32Thread.h>
Inheritance diagram for CWin32Thread:
![]()
Collaboration diagram for CWin32Thread:
![]()
Detailed DescriptionDefinition at line 49 of file Win32Thread.h. Member Typedef Documentation
Definition at line 56 of file GenericThread.h.
Member Enumeration Documentation
Definition at line 68 of file GenericThread.h. 00069 { 00070 tpIdle=0, 00071 tpLowest, 00072 tpBelowNormal, 00073 tpNormal, 00074 tpAboveNormal, 00075 tpHighest, 00076 tpTimeCritical 00077 } ThreadPriority;
Definition at line 59 of file GenericThread.h. 00060 { 00061 tsSuspended, 00062 tsRunning, 00063 tsStopped, 00064 tsError 00065 } ThreadStatus;
Constructor & Destructor Documentation
Definition at line 51 of file Win32Thread.cpp. 00051 : CGenericThread(pThreadProc), 00052 m_hThread(0) 00053 { 00054 try 00055 { 00056 //Set our name 00057 SetName(CWin32Thread_Class); 00058 00059 //Create the thread 00060 if (GetThreadProc()) 00061 { 00062 //Our thread ID 00063 DWORD dwThreadID; 00064 00065 //Create the thread in suspend mode 00066 m_hThread=CreateThread(NULL, 00067 0, 00068 Win32Thread, 00069 this, 00070 CREATE_SUSPENDED, 00071 &dwThreadID); 00072 00073 //Check if created 00074 if (m_hThread) 00075 { 00076 //Set the thread ID 00077 SetThreadID(dwThreadID); 00078 00079 //Set the status 00080 SetThreadStatus(tsSuspended); 00081 } 00082 else 00083 //An error 00084 throw std::string("Failed to create thread!"); 00085 } 00086 else 00087 //Throw the error 00088 throw std::string("No thread proc!"); 00089 } 00090 ERROR_HANDLER_RETHROW("CWin32Thread") 00091 }
Definition at line 93 of file Win32Thread.cpp. 00094 { 00095 try 00096 { 00097 //Stop the thread 00098 Stop(); 00099 } 00100 ERROR_HANDLER("~CWin32Thread") 00101 }
Member Function Documentation
Definition at line 218 of file ErrorHandler.cpp. 00219 { 00220 try 00221 { 00222 //Try to look it in the errors 00223 if (!CErrorsRepository::GetInstance().GetErrorsMap().empty()) 00224 { 00225 //Search 00226 CErrorsRepository::ErrorMap::const_iterator aIterator; 00227 aIterator=CErrorsRepository::GetInstance().GetErrorsMap().find(dwErrorCode); 00228 00229 //Do we have it 00230 if (aIterator!=CErrorsRepository::GetInstance().GetErrorsMap().end()) 00231 return aIterator->second; 00232 } 00233 00234 //Get the error string 00235 LPVOID lpMsgBuf; 00236 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 00237 FORMAT_MESSAGE_FROM_SYSTEM | 00238 FORMAT_MESSAGE_IGNORE_INSERTS, 00239 NULL, 00240 dwErrorCode, 00241 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language 00242 (LPTSTR) &lpMsgBuf, 00243 0, 00244 NULL); 00245 00246 //Save it 00247 std::string sMessage; 00248 00249 //Do we have the message? 00250 if (lpMsgBuf) 00251 { 00252 //Save it 00253 sMessage=(char*)lpMsgBuf; 00254 00255 //Release the buffer 00256 LocalFree(lpMsgBuf); 00257 } 00258 else 00259 //Failed to find 00260 sMessage="No error description found!"; 00261 00262 //Done 00263 return sMessage; 00264 } 00265 catch (...) 00266 { 00267 return "Unknown"; 00268 } 00269 }
Definition at line 140 of file ErrorHandler.cpp. 00144 { 00145 //Our message 00146 std::string sMsg; 00147 00148 //Is it an error? 00149 if (bError) 00150 sMsg="*** Error *** "; 00151 else 00152 sMsg="### Msg ### "; 00153 00154 //Add the data now 00155 sMsg+="in "+rClass; 00156 sMsg+=":"+rMethod; 00157 sMsg+=" - " + rMsgOrError; 00158 00159 //Done 00160 return sMsg; 00161 }
Definition at line 572 of file ErrorHandler.cpp. 00573 { 00574 try 00575 { 00576 //Our string 00577 std::string sDate; 00578 00579 //Our tmp buf 00580 char cTmp[128]; 00581 00582 //Get date 00583 _strdate(cTmp); 00584 sDate=cTmp; 00585 sDate+=' '; 00586 00587 //Get time 00588 _strtime(cTmp); 00589 sDate+=cTmp; 00590 00591 //Done 00592 return sDate; 00593 } 00594 ERROR_HANDLER_STATIC_RETURN(CErrorHandler_Class,"GetCurrentDateTime","") 00595 }
Implements CGenericThread. Definition at line 300 of file Win32Thread.cpp. 00301 { 00302 try 00303 { 00304 //Check if we have the thread 00305 if (!m_hThread) 00306 return CGenericThread::tpNormal; 00307 00308 int iPriority; 00309 00310 //Get the priority 00311 iPriority=GetThreadPriority(m_hThread); 00312 00313 //And return the value 00314 switch (iPriority) 00315 { 00316 case THREAD_PRIORITY_ABOVE_NORMAL: 00317 return CGenericThread::tpAboveNormal; 00318 case THREAD_PRIORITY_BELOW_NORMAL: 00319 return CGenericThread::tpBelowNormal; 00320 case THREAD_PRIORITY_HIGHEST: 00321 return CGenericThread::tpHighest; 00322 case THREAD_PRIORITY_IDLE: 00323 return CGenericThread::tpIdle; 00324 case THREAD_PRIORITY_LOWEST: 00325 return CGenericThread::tpLowest; 00326 case THREAD_PRIORITY_NORMAL: 00327 return CGenericThread::tpNormal; 00328 case THREAD_PRIORITY_TIME_CRITICAL: 00329 return CGenericThread::tpTimeCritical; 00330 default: 00331 return CGenericThread::tpNormal; 00332 } 00333 } 00334 ERROR_HANDLER_RETURN("GetPriority",CGenericThread::tpNormal) 00335 }
Implements CGenericThread. Definition at line 337 of file Win32Thread.cpp. 00338 { 00339 return GetCurrentThreadId()==GetThreadID(); 00340 }
Definition at line 597 of file ErrorHandler.cpp. 00599 { 00600 try 00601 { 00602 //Add the error 00603 CErrorsRepository::GetInstance().GetErrorsMap().insert(CErrorsRepository::ErrorMap::value_type(dwErrorCode,rDescription)); 00604 } 00605 ERROR_HANDLER_STATIC(CErrorHandler_Class,"RegisterError") 00606 }
Definition at line 271 of file ErrorHandler.cpp. 00274 { 00275 if (!GetLog()) 00276 return; 00277 00278 try 00279 { 00280 //Convert the error code 00281 char aTmp[11]; 00282 sprintf(aTmp,"%d",iErrorCode); 00283 00284 //Get the string for it 00285 std::string sError; 00286 sError=rMessage; 00287 sError+=", and Socket error: "; 00288 sError+=aTmp; 00289 sError+=", "; 00290 sError+=ErrorCodeToString(iErrorCode); 00291 00292 //Report to the log 00293 WriteError(m_sClassName, 00294 rMethod, 00295 sError); 00296 } 00297 ERROR_UNKNOWN("ReportError") 00298 }
Definition at line 300 of file ErrorHandler.cpp. 00302 { 00303 if (!GetLog()) 00304 return; 00305 00306 try 00307 { 00308 //Convert the error code 00309 char aTmp[11]; 00310 sprintf(aTmp,"%d",iErrorCode); 00311 00312 //Get the string for it 00313 std::string sError; 00314 sError="Socket error: "; 00315 sError+=aTmp; 00316 sError+=", "; 00317 sError+=ErrorCodeToString(iErrorCode); 00318 00319 //Report to the log 00320 WriteError(m_sClassName, 00321 rMethod, 00322 sError); 00323 } 00324 ERROR_UNKNOWN("ReportError") 00325 }
Definition at line 416 of file ErrorHandler.cpp. 00419 { 00420 if (!GetLog()) 00421 return; 00422 00423 try 00424 { 00425 //Create the new message 00426 std::string sNewMessage(rMessage); 00427 sNewMessage+=", Additional data: "; 00428 sNewMessage+=rAdditionalData; 00429 00430 //Report to the log 00431 WriteError(m_sClassName, 00432 rMethod, 00433 sNewMessage); 00434 } 00435 ERROR_UNKNOWN("ReportError") 00436 }
Definition at line 438 of file ErrorHandler.cpp. 00441 { 00442 if (!GetLog()) 00443 return; 00444 00445 try 00446 { 00447 //Convert the number 00448 char aTmp[11]; 00449 ltoa(dwAdditionalData,aTmp,10); 00450 00451 //Create the new message 00452 std::string sNewMessage(rMessage); 00453 sNewMessage+=", Additional data: "; 00454 sNewMessage+=aTmp; 00455 00456 //Report to the log 00457 WriteError(m_sClassName, 00458 rMethod, 00459 sNewMessage); 00460 } 00461 ERROR_UNKNOWN("ReportError") 00462 }
Definition at line 327 of file ErrorHandler.cpp. 00329 { 00330 if (!GetLog()) 00331 return; 00332 00333 try 00334 { 00335 //Report to the log 00336 WriteError(m_sClassName, 00337 rMethod, 00338 rMessage); 00339 } 00340 ERROR_UNKNOWN("ReportError") 00341 }
Definition at line 470 of file ErrorHandler.cpp. 00471 { 00472 if (!GetLog()) 00473 return; 00474 00475 try 00476 { 00477 //Get the last error 00478 DWORD dwLastError; 00479 dwLastError=GetLastError(); 00480 00481 //Report the error 00482 WriteError(m_sClassName, 00483 rMethod, 00484 ErrorCodeToString(dwLastError)); 00485 } 00486 ERROR_UNKNOWN("ReportError") 00487 }
Definition at line 378 of file ErrorHandler.cpp. 00380 { 00381 if (!GetLog()) 00382 return; 00383 00384 try 00385 { 00386 //Get the last error 00387 DWORD dwLastError; 00388 dwLastError=GetLastError(); 00389 00390 //Format the message 00391 std::string sMessage; 00392 sMessage=rMessage; 00393 sMessage+=", with error code: "; 00394 00395 //Convert the error code 00396 char aTmp[11]; 00397 itoa(dwLastError,aTmp,10); 00398 00399 //Add it again 00400 sMessage+=aTmp; 00401 sMessage+=" "; 00402 sMessage+=ErrorCodeToString(dwLastError); 00403 00404 //Get the log 00405 CErrorLog* pLog; 00406 pLog=GetLog(); 00407 00408 //Report to the log 00409 WriteError(m_sClassName, 00410 rMethod, 00411 sMessage); 00412 } 00413 ERROR_UNKNOWN("ReportErrorOS") 00414 }
Definition at line 540 of file ErrorHandler.cpp. 00544 { 00545 if (!m_pLog) 00546 return; 00547 00548 try 00549 { 00550 //Convert the number 00551 char aTmp[11]; 00552 ltoa(dwAdditionalData,aTmp,10); 00553 00554 //Create the new message 00555 std::string sNewMessage(rMessage); 00556 sNewMessage+=", Additional data: "; 00557 sNewMessage+=aTmp; 00558 00559 //Report to the log 00560 WriteStaticError(rClass, 00561 rMethod, 00562 sNewMessage); 00563 } 00564 ERROR_UNKNOWN("ReportStaticError") 00565 }
Definition at line 523 of file ErrorHandler.cpp. 00526 { 00527 if (!m_pLog) 00528 return; 00529 00530 try 00531 { 00532 //Report to the log 00533 WriteStaticError(rClass, 00534 rMethod, 00535 rMessage); 00536 } 00537 ERROR_UNKNOWN("ReportStaticError") 00538 }
Definition at line 503 of file ErrorHandler.cpp. 00505 { 00506 if (!m_pLog) 00507 return; 00508 00509 try 00510 { 00511 //Get the last error 00512 DWORD dwLastError; 00513 dwLastError=GetLastError(); 00514 00515 //Report the error 00516 WriteStaticError(rClass, 00517 rMethod, 00518 ErrorCodeToString(dwLastError)); 00519 } 00520 ERROR_UNKNOWN("ReportStaticError") 00521 }
Definition at line 343 of file ErrorHandler.cpp. 00346 { 00347 if (!m_pLog) 00348 return; 00349 00350 try 00351 { 00352 //Get the last error 00353 DWORD dwLastError; 00354 dwLastError=GetLastError(); 00355 00356 //Format the message 00357 std::string sMessage; 00358 sMessage=rMessage; 00359 sMessage+=", with error code: "; 00360 00361 //Convert the error code 00362 char aTmp[11]; 00363 itoa(dwLastError,aTmp,10); 00364 00365 //Add it again 00366 sMessage+=aTmp; 00367 sMessage+=" "; 00368 sMessage+=ErrorCodeToString(dwLastError); 00369 00370 //Report to the log 00371 WriteStaticError(rClass, 00372 rMethod, 00373 sMessage); 00374 } 00375 ERROR_UNKNOWN("ReportStaticError") 00376 }
Implements CGenericThread. Definition at line 252 of file Win32Thread.cpp. 00253 { 00254 try 00255 { 00256 static const int iThreadPriority[]={THREAD_PRIORITY_IDLE, 00257 THREAD_PRIORITY_LOWEST, 00258 THREAD_PRIORITY_BELOW_NORMAL, 00259 THREAD_PRIORITY_NORMAL, 00260 THREAD_PRIORITY_ABOVE_NORMAL, 00261 THREAD_PRIORITY_HIGHEST, 00262 THREAD_PRIORITY_TIME_CRITICAL}; 00263 00264 //Do we have a thread 00265 if (GetThreadStatus()==tsStopped) 00266 { 00267 //Recreate the thread 00268 //Our thread ID 00269 DWORD dwThreadID; 00270 00271 //Create the thread in suspend mode 00272 m_hThread=CreateThread(NULL, 00273 0, 00274 Win32Thread, 00275 this, 00276 CREATE_SUSPENDED, 00277 &dwThreadID); 00278 00279 //Check if created 00280 if (m_hThread) 00281 { 00282 //Set the thread ID 00283 SetThreadID(dwThreadID); 00284 00285 //Set the status 00286 SetThreadStatus(tsSuspended); 00287 } 00288 else 00289 //Can't run 00290 return FALSE; 00291 } 00292 00293 //Now we can set the priority 00294 return SetThreadPriority(m_hThread, 00295 iThreadPriority[aPriority]); 00296 } 00297 ERROR_HANDLER_RETURN("SetPriority",FALSE) 00298 }
Definition at line 101 of file GenericThread.cpp. 00102 { 00103 try 00104 { 00105 //Enter the CS 00106 CCriticalAutoRelease aRelease(m_pCSection); 00107 00108 //Set it 00109 m_aThreadStatus=aStatus; 00110 } 00111 ERROR_HANDLER("SetThreadStatus") 00112 }
Reimplemented from CGenericThread. Definition at line 103 of file Win32Thread.cpp. 00104 { 00105 try 00106 { 00107 if (GetThreadStatus()==tsStopped) 00108 { 00109 //Recreate the thread 00110 //Our thread ID 00111 DWORD dwThreadID; 00112 00113 //Create the thread in suspend mode 00114 m_hThread=CreateThread(NULL, 00115 0, 00116 Win32Thread, 00117 this, 00118 CREATE_SUSPENDED, 00119 &dwThreadID); 00120 00121 //Check if created 00122 if (m_hThread) 00123 { 00124 //Set the thread ID 00125 SetThreadID(dwThreadID); 00126 00127 //Set the status 00128 SetThreadStatus(tsSuspended); 00129 } 00130 else 00131 //Can't run 00132 return FALSE; 00133 } 00134 else if (GetThreadStatus()!=tsSuspended) 00135 return FALSE; 00136 00137 //Start the thread 00138 CGenericThread::Start(pData); 00139 00140 //Resume the thread 00141 if (m_hThread) 00142 if (ResumeThread(m_hThread)!=-1) 00143 //We are running 00144 return TRUE; 00145 00146 return FALSE; 00147 } 00148 ERROR_HANDLER_RETURN("Start",FALSE) 00149 }
Implements CGenericThread. Definition at line 151 of file Win32Thread.cpp. 00152 { 00153 try 00154 { 00155 //Only if suspened or running 00156 //Do we have the thread ? 00157 if (m_hThread) 00158 { 00159 //What status are we 00160 if (GetThreadStatus()==tsRunning && 00161 GetBruteTermination()) 00162 //First try to close it 00163 if (!TerminateThread(m_hThread,THREAD_DO_NOTHING_EXIT_VALUE)) 00164 return FALSE; 00165 00166 if (GetThreadStatus()==tsSuspended || 00167 GetThreadStatus()==tsRunning) 00168 if (CloseHandle(m_hThread)) 00169 { 00170 //Close the handle 00171 m_hThread=NULL; 00172 00173 //Stopped 00174 SetThreadStatus(tsStopped); 00175 00176 //Exit 00177 return TRUE; 00178 } 00179 else 00180 return FALSE; 00181 else 00182 { 00183 //Just close the handle 00184 if (!CloseHandle(m_hThread)) 00185 m_hThread=NULL; 00186 00187 //Exit 00188 return FALSE; 00189 } 00190 } 00191 else 00192 return FALSE; 00193 } 00194 ERROR_HANDLER_RETURN("Stop",FALSE) 00195 }
Definition at line 163 of file ErrorHandler.cpp. 00166 { 00167 //Do we have a log? 00168 if (!GetLog()) 00169 return; 00170 00171 //Format the msg 00172 std::string sError; 00173 sError=FormatData(rClass, 00174 rMethod, 00175 rError); 00176 00177 //Write it 00178 GetLog()->WriteError(sError); 00179 }
Definition at line 199 of file ErrorHandler.cpp. 00202 { 00203 //Do we have a log? 00204 if (!GetLog()) 00205 return; 00206 00207 //Format the msg 00208 std::string sMsg; 00209 sMsg=FormatData(rClass, 00210 rMethod, 00211 rMessage, 00212 true); 00213 00214 //Write it 00215 GetLog()->WriteMessage(sMsg); 00216 }
Definition at line 181 of file ErrorHandler.cpp. 00184 { 00185 //Do we have a log? 00186 if (!m_pLog) 00187 return; 00188 00189 //Format the msg 00190 std::string sError; 00191 sError=FormatData(rClass, 00192 rMethod, 00193 rError); 00194 00195 //Write it 00196 m_pLog->WriteError(sError); 00197 }
The documentation for this class was generated from the following files: |