VMSThread.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /****************************************************************************
  2. * @source : VMSThread.h
  3. * @description : VMS Server Socket Thread header
  4. ****************************************************************************
  5. * DATE AUTHOR DESCRIPTION
  6. * --------------------------------------------------------------------------
  7. * 2012/03/09 CYM [100] First Cut
  8. *
  9. ****************************************************************************/
  10. //---------------------------------------------------------------------------
  11. #ifndef VMSThreadH
  12. #define VMSThreadH
  13. //---------------------------------------------------------------------------
  14. #include <Classes.hpp>
  15. #include <Sockets.hpp>
  16. #include "VMSProtocol.h"
  17. //---------------------------------------------------------------------------
  18. /***************************************
  19. **
  20. ** Constants
  21. **
  22. */
  23. #define SERVER_MSG_BUF_SIZE 65536 /* message buffer size */
  24. #define SERVER_MAX_PACKET_SIZE 65536 /* max packet size */
  25. #define SERVER_CONNECT_RETRY_TIME 20 /* connect retry time */
  26. enum {
  27. /* common */
  28. ST_IDLE = 1,
  29. ST_INITIATE,
  30. ST_SECTION,
  31. ST_CLOSE,
  32. /* sender */
  33. ST_LOCAL_COMMAND,
  34. ST_CLIENT_COMMAND,
  35. /* receiver */
  36. ST_LOCAL_WAIT,
  37. ST_CLIENT_WAIT
  38. };
  39. enum {
  40. SET_SERVER_SUCC,
  41. SET_SERVER_FAIL
  42. };
  43. /***************************************
  44. **
  45. ** Type definitions
  46. **
  47. */
  48. typedef struct {
  49. BOOL GeneralStatus; /* 기본상태정보 */
  50. BOOL ModuleStatus; /* 모듈상태정보 */
  51. } ACCEPT_REGISTERED;
  52. typedef union {
  53. } COMMAND_ARGUMENT;
  54. //---------------------------------------------------------------------------
  55. class TVMSThread : public TClientSocketThread
  56. {
  57. private:
  58. TCustomIpClient* pClientSocket;
  59. bool *ThreadActiveIndicator;
  60. AnsiString m_strName; /* thread name */
  61. int m_RxLen; /* received data length */
  62. int m_TxLen; /* data length to transmit */
  63. BYTE m_RxBuff[SERVER_MAX_PACKET_SIZE]; /* receive data buffer */
  64. BYTE m_TxBuff[SERVER_MAX_PACKET_SIZE]; /* transmit data buffer */
  65. TDateTime m_rTimer; /* timer for receiver */
  66. TDateTime m_WatchDogTimer; /* watchdog timer */
  67. TCOMMLOG *m_Log; /* log */
  68. SERVER_THREAD_STRUCT m_Server; /* server thread */
  69. bool m_InitFlag; /* Init Flag */
  70. DWORD m_DataPacketNumber; /* DataPacket Number */
  71. DWORD m_FrEDConfirmPacketNumber; /* FrEDConfirmPacket Number */
  72. bool m_LoginFlag; /* Login Flag */
  73. DWORD m_PublishSerialNbr; /* Publish Serial Nbr */
  74. ACCEPT_REGISTERED m_Registered; /* Accept Registered Subscription */
  75. VMS_CURRENT_STATE *m_pState; /* VMS 상태 정보 */
  76. REQ_INFO_STRUCT m_Req; /* client request */
  77. SET_INFO_STRUCT m_Set; /* client set */
  78. int __fastcall ServerInitMem(void);
  79. void __fastcall ServerInitInfo(void);
  80. void __fastcall ServerTerminate(void);
  81. void ProcLog(BYTE bKind, char *fmt, ...);
  82. void __fastcall LOG_WriteTime(Time_t *pTime);
  83. int __fastcall SaveStateData(void *pData);
  84. void __fastcall ClientResponse(int error);
  85. int __fastcall SendCommMessage(UINT Msg, int wParam, int lParam);
  86. int __fastcall SendCommDataMessage(UINT Msg, void *pData, int iLen);
  87. int __fastcall RecvPacket(void *Data, int Len);
  88. int __fastcall ProcessPacket(BYTE *pBuffer, int Len);
  89. int __fastcall SendPacket(void *Data, int Len);
  90. int __fastcall ProcessCommand(BYTE cmd, COMMAND_ARGUMENT *pArg);
  91. void __fastcall ServerStateMachine(void);
  92. void __fastcall ProcErrorState(bool flag, int result);
  93. void __fastcall SetServerState(int Case);
  94. int __fastcall CheckRegistered();
  95. int __fastcall CheckLocalData(bool *pflag);
  96. int __fastcall CheckClientData(bool *pflag);
  97. protected:
  98. void __fastcall Execute();
  99. void __fastcall TcpServerClientError(TObject *Sender, int SocketError);
  100. bool __fastcall SocketActivity(void);
  101. public:
  102. __fastcall TVMSThread(TServerSocketThread* ServerSocketThread, TCustomIpClient* ClientSocket, int Tag, bool *ActiveIndicator);
  103. __fastcall ~TVMSThread();
  104. };
  105. //---------------------------------------------------------------------------
  106. #endif