//--------------------------------------------------------------------------- #include #include "WindowMsgF.h" #include "AppGlobalF.h" #include "ITSUtilF.h" #include "CDSProcessF.h" #include "CDSCctvCtlrF.h" #include "CDSIncidentF.h" #pragma hdrstop #include "TThreadPollingF.h" #pragma package(smart_init) //--------------------------------------------------------------------------- // Important: Methods and properties of objects in VCL can only be // used in a method called using Synchronize, for example: // // Synchronize(&UpdateCaption); // // where UpdateCaption could look like: // // void __fastcall TThreadPolling::UpdateCaption() // { // Form1->Caption = "Updated in a thread"; // } //--------------------------------------------------------------------------- __fastcall TThreadPolling::TThreadPolling(bool CreateSuspended) : TThread(CreateSuspended) { ::CoInitialize(NULL); try { //if (g_AppCfg.bDebug) ITSUtil_Trace("Start"); FreeOnTerminate = true; Priority = tpNormal;//tpIdle;//tpNormal g_AppCfg.thr.bRunning = true; m_lMainWinHandle = (HWND)g_AppCfg.lMainWinHandle; m_sDbConnString = ""; m_sDbConnString += "Provider=" + g_AppCfg.itsdb.sProvider; m_sDbConnString += ";Password=" + g_AppCfg.itsdb.sPassword; m_sDbConnString += ";Persist Security Info=True"; m_sDbConnString += ";User ID=" + g_AppCfg.itsdb.sUserName; m_sDbConnString += ";Data Source=" + g_AppCfg.itsdb.sServerName; m_pConnection = NULL; m_pConnection = new TADOConnection(NULL); } catch(...) { Terminate(); } } //--------------------------------------------------------------------------- __fastcall TThreadPolling::~TThreadPolling() { if (m_pConnection) { if (m_pConnection->Connected == true) { m_pConnection->Close(); } delete m_pConnection; m_pConnection = NULL; } // ::CoUninitialize(); } //--------------------------------------------------------------------------- /* * µ¥ÀÌÅͺ£À̽º ¿¬°á * arguments * * return * */ bool __fastcall TThreadPolling::DbConnect() { ::CoInitialize(NULL); try { m_pConnection->ConnectionString = m_sDbConnString; m_pConnection->KeepConnection = true; m_pConnection->LoginPrompt = false; m_pConnection->Open(); } catch(EDatabaseError &E) { return false; } catch (Exception &e) { return false; } catch (...) { return false; } return true; } //--------------------------------------------------------------------------- void __fastcall TThreadPolling::Execute() { ::CoInitialize(NULL); NameThreadForDebugging("PollingThread"); MSG Msg; int nRes; //if (g_AppCfg.bDebug) ITSUtil_Trace("Execute"); while (!Terminated) { if (DbConnect()) { break; } if (g_AppCfg.bAppClose) { return; } Sleep(1000); } while(!Terminated) { if (GetMessage(&Msg, NULL, 0, 0) == 0) { Terminate(); } else { nRes = 0; try { if (Msg.message == WM_QUIT) { nRes = -999; break; } if (Msg.message != WM_THREAD) continue; if (!IsDbOpen()) { DbConnect(); } m_lMainWinHandle = (HWND)g_AppCfg.lMainWinHandle; switch (Msg.wParam) { case WP_PING: POST_MSG(m_lMainWinHandle, WM_THREAD, WP_PING, WP_PING); break; case WP_PARAM_TRAFFIC: switch(Msg.lParam) { case LP_MSG_00: SelProcessStatusData(Msg.lParam); break; case LP_MSG_01: SelCctvStatusData(Msg.lParam); break; case LP_MSG_05: SelIncidentData(Msg.lParam); break; } break; } } catch(...) { //nRes = -999; } } if (nRes == -999) break; } // ::CoUninitialize(); } //--------------------------------------------------------------------------- bool __fastcall TThreadPolling::SelCctvStatusData(LPARAM LParam) { bool bRes = false; //½Ã¼³¹°(VMS) »óÅÂÁ¤º¸ POST_MSG(m_lMainWinHandle, WM_THREAD, WP_DB_SELECT_START, LParam); bRes = CctvCtlrManager->LoadStatusFromDb(m_pConnection); if (bRes) POST_MSG(m_lMainWinHandle, WM_THREAD, WP_DB_SELECT_OK, LParam); else POST_MSG(m_lMainWinHandle, WM_THREAD, WP_DB_SELECT_ERROR, LParam); return bRes; } //--------------------------------------------------------------------------- bool __fastcall TThreadPolling::SelProcessStatusData(LPARAM LParam) { bool bRes = false; //ÇÁ·Î¼¼½º »óÅÂÁ¤º¸ POST_MSG(m_lMainWinHandle, WM_THREAD, WP_DB_SELECT_START, LParam); bRes = ItsProcessManager->LoadProcessStatusFromDb(m_pConnection); if (bRes) POST_MSG(m_lMainWinHandle, WM_THREAD, WP_DB_SELECT_OK, LParam); else POST_MSG(m_lMainWinHandle, WM_THREAD, WP_DB_SELECT_ERROR, LParam); return bRes; } //--------------------------------------------------------------------------- bool __fastcall TThreadPolling::SelIncidentData(LPARAM LParam) { bool bRes = false; if (ItsIncidentManager) { //µ¹¹ß¹ß»ýÁ¤º¸ POST_MSG(m_lMainWinHandle, WM_THREAD, WP_DB_SELECT_START, LParam); bRes = ItsIncidentManager->LoadFromDb(m_pConnection); //bRes = ItsIncidentManager->LoadFromAutoIncident(m_pConnection); } else { bRes = true; } if (bRes) POST_MSG(m_lMainWinHandle, WM_THREAD, WP_DB_SELECT_OK, LParam); else POST_MSG(m_lMainWinHandle, WM_THREAD, WP_DB_SELECT_ERROR, LParam); return bRes; } //---------------------------------------------------------------------------