JobThreadF.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "VMSCommLibF.h"
  4. #pragma hdrstop
  5. #include "JobThreadF.h"
  6. #include "ClientSessionF.h"
  7. #include "ClientSessionManagerF.h"
  8. #include "CDSCtlrF.h"
  9. #include "VmsProtocolF.h"
  10. //---------------------------------------------------------------------------
  11. #pragma package(smart_init)
  12. TJobThread *JobThread = NULL;
  13. //---------------------------------------------------------------------------
  14. TJobThread::TJobThread()
  15. {
  16. FPnlState = NULL;
  17. FTmrDb = NULL;
  18. }
  19. //---------------------------------------------------------------------------
  20. TJobThread::~TJobThread()
  21. {
  22. }
  23. //---------------------------------------------------------------------------
  24. DWORD __fastcall TJobThread::Process(LPVOID AParam)
  25. {
  26. TClientSession *pSession;
  27. IPC_JOB_MESSAGE *pMsg;
  28. DWORD dwJob;
  29. int nRcvSize;
  30. char *pRcvBuff;
  31. OverlappedIO overlappedIO;
  32. TPanel *pState = FPnlState;
  33. while(!IsTerm() && !g_AppCfg.bThrExit)
  34. {
  35. try {
  36. if (pState) pState->Color = pState->Color == clLime ? clGreen : clRed;
  37. }catch(Exception &e) {}
  38. if (!g_jobQ.PopBlocking(dwJob))
  39. {
  40. continue;
  41. }
  42. if (dwJob == Q_CLOSE)
  43. {
  44. break;
  45. }
  46. else
  47. if (dwJob == Q_TICK)
  48. {
  49. if (pState) pState->Color = clLime;
  50. ClientSessionManager->SendFlushAllClient();
  51. ClientSessionManager->CheckCommandTimeoutSessions();
  52. #if USE_POOL
  53. #else
  54. ClientSessionManager->CollectGarbageSessions();
  55. #endif
  56. continue;
  57. }
  58. else
  59. if (dwJob == eTcpCloseAll)
  60. {
  61. if (pState) pState->Color = clLime;
  62. ClientSessionManager->CloseAll();
  63. continue;
  64. }
  65. else
  66. if (dwJob == eVmsFormDownload)
  67. {
  68. // 정주기 시나리오 다운로드
  69. SendVmsFormDownload();
  70. continue;
  71. }
  72. else
  73. if (dwJob == eVmsStatusReqAll)
  74. {
  75. // 정주기 상태정보 요청
  76. SendVmsStatusReq();
  77. continue;
  78. }
  79. if (pState) pState->Color = clLime;
  80. pMsg = (IPC_JOB_MESSAGE*)dwJob;
  81. try
  82. {
  83. pSession = (TClientSession*)pMsg->ObjPtr;
  84. if (pSession == NULL)
  85. {
  86. MERROR("JOBT Unknown Event Null session: %d", pMsg->Type);
  87. }
  88. else
  89. {
  90. switch(pMsg->Type)
  91. {
  92. case eTcpConnect:
  93. if (pSession->OnConnect())
  94. {
  95. pSession->SendFlush();
  96. }
  97. break;
  98. case eTcpErrorEvent:
  99. case eTcpErrorRecv:
  100. case eTcpErrorSend:
  101. case eTcpClose:
  102. pSession->Disconnect();
  103. break;
  104. case eTcpRecv:
  105. nRcvSize = pSession->GetFreeSpaceSize();
  106. pRcvBuff = pSession->GetBuffer();
  107. if (nRcvSize >= pMsg->Len && pRcvBuff)
  108. {
  109. memcpy(pRcvBuff, pMsg->Buff, pMsg->Len);
  110. overlappedIO.FSession = pSession;
  111. RecvCompletion(0, pMsg->Len, (LPWSAOVERLAPPED)&overlappedIO, 0);
  112. }
  113. break;
  114. //TODO: 20241220, FTP DOWNLOAD
  115. case eVmsFtpFileDownload:
  116. if (pSession->download_ftp_file() > 0)
  117. {
  118. pSession->SendFlush();
  119. }
  120. break;
  121. // 폼 다운로드 시작
  122. case eVmsScenarioDownload: // 개별 명령에 의한 시나리오 다운로드
  123. if (pSession->download_form_schedule(false) > 0)
  124. {
  125. pSession->SendFlush();
  126. }
  127. break;
  128. case eVmsStatusReq:
  129. if (pSession->ReqStauts())
  130. {
  131. pSession->SendFlush();
  132. }
  133. break;
  134. case eVmsPowerModuleStautsReq:
  135. if (pSession->ReqPowerModuleStatus())
  136. {
  137. pSession->SendFlush();
  138. }
  139. break;
  140. case eVmsDisplayModuleStatusReq:
  141. if (pSession->ReqDisplayModuelStatus())
  142. {
  143. pSession->SendFlush();
  144. }
  145. break;
  146. case eVmsParamReq:
  147. if (pSession->ReqParameter() > 0)
  148. {
  149. pSession->SendFlush();
  150. }
  151. break;
  152. case eVmsPixelImage:
  153. if (pSession->ReqPixelImage(pMsg->Buff) > 0)
  154. {
  155. pSession->SendFlush();
  156. }
  157. break;
  158. case eVmsUploadCurrentForm:
  159. if (pSession->ReqUploadCurrentForm() > 0)
  160. {
  161. pSession->SendFlush();
  162. }
  163. break;
  164. case eVmsDispalyDefaultForm:
  165. if (pSession->ReqDisplayDefaultForm() > 0)
  166. {
  167. pSession->SendFlush();
  168. }
  169. break;
  170. case eVmsUploadScheduleForm:
  171. if (pSession->ReqUploadScheduleForm() > 0)
  172. {
  173. pSession->SendFlush();
  174. }
  175. break;
  176. case eVmsDisplayFormId:
  177. if (pSession->ReqDisplayFormId(pMsg->Buff) > 0)
  178. {
  179. pSession->SendFlush();
  180. }
  181. break;
  182. case eVmsStatusControl:
  183. if (pSession->ReqStatusControl(pMsg->Buff, pMsg->Len) > 0)
  184. {
  185. pSession->SendFlush();
  186. }
  187. break;
  188. case eVmsSendPacket:
  189. if (pSession->ReqSendPacket(pMsg->Buff, pMsg->Len) > 0)
  190. {
  191. pSession->SendFlush();
  192. }
  193. break;
  194. }
  195. if (pSession->IsConnected)
  196. {
  197. pSession->SendFlush();
  198. }
  199. }
  200. }
  201. __finally
  202. {
  203. //SAFE_DELETE(pMsg);
  204. }
  205. }
  206. Term();
  207. return 0;
  208. }
  209. //---------------------------------------------------------------------------
  210. int __fastcall TJobThread::SendVmsFormDownload()
  211. {
  212. CtlrItr it;
  213. for(it=CDSCtlrManager->FLists.FObjects.begin(); it != CDSCtlrManager->FLists.FObjects.end(); ++it)
  214. {
  215. TCDSCtlr *pObj = (TCDSCtlr*)it->second;
  216. if (!pObj->Used) continue;
  217. if (!pObj->FProvide) continue;
  218. try
  219. {
  220. TClientSession *pSession = pObj->FSession;
  221. if (pSession)
  222. {
  223. if (pSession->download_form_schedule(true) > 0)
  224. {
  225. pSession->SendFlush();
  226. }
  227. }
  228. // 제어기로 전송 시퀀스를 호출한 후에 타임아웃을 체크하도록 한다.
  229. pObj->CTRLMODE->SaveFlag = false;
  230. pObj->CTRLMODE->pTimer = Now();
  231. }
  232. catch(Exception &e)
  233. {
  234. }
  235. }
  236. return 0;
  237. }
  238. //---------------------------------------------------------------------------
  239. int __fastcall TJobThread::SendVmsStatusReq()
  240. {
  241. CtlrItr it;
  242. for(it=CDSCtlrManager->FLists.FObjects.begin(); it != CDSCtlrManager->FLists.FObjects.end(); ++it)
  243. {
  244. TCDSCtlr *pObj = (TCDSCtlr*)it->second;
  245. if (!pObj->Used) continue;
  246. try
  247. {
  248. TClientSession *pSession = pObj->FSession;
  249. if (pSession)
  250. {
  251. if (pSession->ReqStauts() > 0)
  252. {
  253. pSession->SendFlush();
  254. }
  255. }
  256. }
  257. catch(Exception &e)
  258. {
  259. }
  260. }
  261. return 0;
  262. }
  263. //---------------------------------------------------------------------------