//--------------------------------------------------------------------------- #include #include "VMSCommLibF.h" #pragma hdrstop #include "JobThreadF.h" #include "ClientSessionF.h" #include "ClientSessionManagerF.h" #include "CDSCtlrF.h" #include "VmsProtocolF.h" //--------------------------------------------------------------------------- #pragma package(smart_init) TJobThread *JobThread = NULL; //--------------------------------------------------------------------------- TJobThread::TJobThread() { FPnlState = NULL; FTmrDb = NULL; } //--------------------------------------------------------------------------- TJobThread::~TJobThread() { } //--------------------------------------------------------------------------- void __fastcall TJobThread::updateLedColor(TColor AColor) { try { if (FPnlState) { PostMessage((HWND)g_AppCfg.lMainWinHandle, WM_PANEL_REFRESH, 3, (LPARAM)AColor); } } catch(Exception &e) {} } //--------------------------------------------------------------------------- DWORD __fastcall TJobThread::Process(LPVOID AParam) { TClientSession *pSession; IPC_JOB_MESSAGE *pMsg; DWORD dwJob; int nRcvSize; char *pRcvBuff; OverlappedIO overlappedIO; while(!IsTerm() && !g_AppCfg.bThrExit) { updateLedColor(clGreen); if (!g_jobQ.PopBlocking(dwJob)) { continue; } if (dwJob == Q_CLOSE) { break; } else if (dwJob == Q_TICK) { updateLedColor(clRed); ClientSessionManager->SendFlushAllClient(); ClientSessionManager->CheckCommandTimeoutSessions(); #if USE_POOL #else ClientSessionManager->CollectGarbageSessions(); #endif continue; } else if (dwJob == eTcpCloseAll) { updateLedColor(clLime); ClientSessionManager->CloseAll(); continue; } else if (dwJob == eVmsFormDownload) { // Á¤Áֱ⠽󪸮¿À ´Ù¿î·Îµå SendVmsFormDownload(); continue; } else if (dwJob == eVmsStatusReqAll) { // Á¤Áֱ⠻óÅÂÁ¤º¸ ¿äû SendVmsStatusReq(); continue; } updateLedColor(clLime); pMsg = (IPC_JOB_MESSAGE*)dwJob; try { pSession = (TClientSession*)pMsg->ObjPtr; if (pSession == NULL) { MERROR("JOBT Unknown Event Null session: %d", pMsg->Type); } else { switch(pMsg->Type) { case eTcpConnect: if (pSession->OnConnect()) { pSession->SendFlush(); } break; case eTcpErrorEvent: case eTcpErrorRecv: case eTcpErrorSend: case eTcpClose: pSession->Disconnect(); break; case eTcpRecv: nRcvSize = pSession->GetFreeSpaceSize(); pRcvBuff = pSession->GetBuffer(); if (nRcvSize >= pMsg->Len && pRcvBuff) { memcpy(pRcvBuff, pMsg->Buff, pMsg->Len); overlappedIO.FSession = pSession; RecvCompletion(0, pMsg->Len, (LPWSAOVERLAPPED)&overlappedIO, 0); } break; //TODO: 20241220, FTP DOWNLOAD case eVmsFtpFileDownload: if (pSession->download_ftp_file() > 0) { pSession->SendFlush(); } break; // Æû ´Ù¿î·Îµå ½ÃÀÛ case eVmsScenarioDownload: // °³º° ¸í·É¿¡ ÀÇÇÑ ½Ã³ª¸®¿À ´Ù¿î·Îµå if (pSession->download_form_schedule(false) > 0) { pSession->SendFlush(); } break; case eVmsStatusReq: if (pSession->ReqStauts()) { pSession->SendFlush(); } break; case eVmsPowerModuleStautsReq: if (pSession->ReqPowerModuleStatus()) { pSession->SendFlush(); } break; case eVmsDisplayModuleStatusReq: if (pSession->ReqDisplayModuelStatus()) { pSession->SendFlush(); } break; case eVmsParamReq: if (pSession->ReqParameter() > 0) { pSession->SendFlush(); } break; case eVmsPixelImage: if (pSession->ReqPixelImage(pMsg->Buff) > 0) { pSession->SendFlush(); } break; case eVmsUploadCurrentForm: if (pSession->ReqUploadCurrentForm() > 0) { pSession->SendFlush(); } break; case eVmsDispalyDefaultForm: if (pSession->ReqDisplayDefaultForm() > 0) { pSession->SendFlush(); } break; case eVmsUploadScheduleForm: if (pSession->ReqUploadScheduleForm() > 0) { pSession->SendFlush(); } break; case eVmsDisplayFormId: if (pSession->ReqDisplayFormId(pMsg->Buff) > 0) { pSession->SendFlush(); } break; case eVmsStatusControl: if (pSession->ReqStatusControl(pMsg->Buff, pMsg->Len) > 0) { pSession->SendFlush(); } break; case eVmsSendPacket: if (pSession->ReqSendPacket(pMsg->Buff, pMsg->Len) > 0) { pSession->SendFlush(); } break; } if (pSession->IsConnected) { pSession->SendFlush(); } } } __finally { //SAFE_DELETE(pMsg); } } Term(); return 0; } //--------------------------------------------------------------------------- int __fastcall TJobThread::SendVmsFormDownload() { CtlrItr it; for(it=CDSCtlrManager->FLists.FObjects.begin(); it != CDSCtlrManager->FLists.FObjects.end(); ++it) { TCDSCtlr *pObj = (TCDSCtlr*)it->second; if (!pObj->Used) continue; if (!pObj->FProvide) continue; try { TClientSession *pSession = pObj->FSession; if (pSession) { if (pSession->download_form_schedule(true) > 0) { pSession->SendFlush(); } } // Á¦¾î±â·Î Àü¼Û ½ÃÄö½º¸¦ È£ÃâÇÑ ÈÄ¿¡ ŸÀӾƿôÀ» üũÇϵµ·Ï ÇÑ´Ù. pObj->CTRLMODE->SaveFlag = false; pObj->CTRLMODE->pTimer = Now(); } catch(Exception &e) { } } return 0; } //--------------------------------------------------------------------------- int __fastcall TJobThread::SendVmsStatusReq() { CtlrItr it; for(it=CDSCtlrManager->FLists.FObjects.begin(); it != CDSCtlrManager->FLists.FObjects.end(); ++it) { TCDSCtlr *pObj = (TCDSCtlr*)it->second; if (!pObj->Used) continue; try { TClientSession *pSession = pObj->FSession; if (pSession) { if (pSession->ReqStauts() > 0) { pSession->SendFlush(); } } } catch(Exception &e) { } } return 0; } //---------------------------------------------------------------------------