JobThreadF.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. // 폼 다운로드 시작
  115. case eVmsScenarioDownload: // 개별 명령에 의한 시나리오 다운로드
  116. if (pSession->download_form_schedule(false) > 0)
  117. {
  118. pSession->SendFlush();
  119. }
  120. break;
  121. case eVmsStatusReq:
  122. if (pSession->ReqStauts())
  123. {
  124. pSession->SendFlush();
  125. }
  126. break;
  127. case eVmsPowerModuleStautsReq:
  128. if (pSession->ReqPowerModuleStatus())
  129. {
  130. pSession->SendFlush();
  131. }
  132. break;
  133. case eVmsDisplayModuleStatusReq:
  134. if (pSession->ReqDisplayModuelStatus())
  135. {
  136. pSession->SendFlush();
  137. }
  138. break;
  139. case eVmsParamReq:
  140. if (pSession->ReqParameter() > 0)
  141. {
  142. pSession->SendFlush();
  143. }
  144. break;
  145. case eVmsPixelImage:
  146. if (pSession->ReqPixelImage(pMsg->Buff) > 0)
  147. {
  148. pSession->SendFlush();
  149. }
  150. break;
  151. case eVmsUploadCurrentForm:
  152. if (pSession->ReqUploadCurrentForm() > 0)
  153. {
  154. pSession->SendFlush();
  155. }
  156. break;
  157. case eVmsDispalyDefaultForm:
  158. if (pSession->ReqDisplayDefaultForm() > 0)
  159. {
  160. pSession->SendFlush();
  161. }
  162. break;
  163. case eVmsUploadScheduleForm:
  164. if (pSession->ReqUploadScheduleForm() > 0)
  165. {
  166. pSession->SendFlush();
  167. }
  168. break;
  169. case eVmsDisplayFormId:
  170. if (pSession->ReqDisplayFormId(pMsg->Buff) > 0)
  171. {
  172. pSession->SendFlush();
  173. }
  174. break;
  175. case eVmsStatusControl:
  176. if (pSession->ReqStatusControl(pMsg->Buff, pMsg->Len) > 0)
  177. {
  178. pSession->SendFlush();
  179. }
  180. break;
  181. case eVmsSendPacket:
  182. if (pSession->ReqSendPacket(pMsg->Buff, pMsg->Len) > 0)
  183. {
  184. pSession->SendFlush();
  185. }
  186. break;
  187. }
  188. if (pSession->IsConnected)
  189. {
  190. pSession->SendFlush();
  191. }
  192. }
  193. }
  194. __finally
  195. {
  196. //SAFE_DELETE(pMsg);
  197. }
  198. }
  199. Term();
  200. return 0;
  201. }
  202. //---------------------------------------------------------------------------
  203. int __fastcall TJobThread::SendVmsFormDownload()
  204. {
  205. CtlrItr it;
  206. for(it=CDSCtlrManager->FLists.FObjects.begin(); it != CDSCtlrManager->FLists.FObjects.end(); ++it)
  207. {
  208. TCDSCtlr *pObj = (TCDSCtlr*)it->second;
  209. if (!pObj->Used) continue;
  210. if (!pObj->FProvide) continue;
  211. try
  212. {
  213. TClientSession *pSession = pObj->FSession;
  214. if (pSession)
  215. {
  216. if (pSession->download_form_schedule(true) > 0)
  217. {
  218. pSession->SendFlush();
  219. }
  220. }
  221. // 제어기로 전송 시퀀스를 호출한 후에 타임아웃을 체크하도록 한다.
  222. pObj->CTRLMODE->SaveFlag = false;
  223. pObj->CTRLMODE->pTimer = Now();
  224. }
  225. catch(Exception &e)
  226. {
  227. }
  228. }
  229. return 0;
  230. }
  231. //---------------------------------------------------------------------------
  232. int __fastcall TJobThread::SendVmsStatusReq()
  233. {
  234. CtlrItr it;
  235. for(it=CDSCtlrManager->FLists.FObjects.begin(); it != CDSCtlrManager->FLists.FObjects.end(); ++it)
  236. {
  237. TCDSCtlr *pObj = (TCDSCtlr*)it->second;
  238. if (!pObj->Used) continue;
  239. try
  240. {
  241. TClientSession *pSession = pObj->FSession;
  242. if (pSession)
  243. {
  244. if (pSession->ReqStauts() > 0)
  245. {
  246. pSession->SendFlush();
  247. }
  248. }
  249. }
  250. catch(Exception &e)
  251. {
  252. }
  253. }
  254. return 0;
  255. }
  256. //---------------------------------------------------------------------------