MainProcess.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /************************************************************************/
  2. /* Copyright (C), 2016-2020, [IT], 保留所有权利;
  3. /* 模 块 名:服务的主要处理类;
  4. /* 描 述:;
  5. /*
  6. /* 版 本:[V];
  7. /* 作 者:[IT];
  8. /* 日 期:[5/6/2016];
  9. /*
  10. /*
  11. /* 注 意:;
  12. /*
  13. /* 修改记录:[IT];
  14. /* 修改日期:;
  15. /* 修改版本:;
  16. /* 修改内容:;
  17. /************************************************************************/
  18. #ifndef __MAIN_PROCESS__
  19. #define __MAIN_PROCESS__
  20. #pragma once
  21. #include "HPSocket4C.h"
  22. #include "helper.h"
  23. class CMainProcess
  24. {
  25. CMainProcess(void);
  26. public:
  27. // 单例对象模式;
  28. static CMainProcess* GetInstance()
  29. {
  30. if (m_spThis == NULL )
  31. {
  32. m_spThis = new CMainProcess;
  33. }
  34. return m_spThis;
  35. }
  36. ~CMainProcess(void);
  37. private:
  38. static const USHORT PORT;
  39. static const LPCTSTR ADDRESS;
  40. EnAppState m_enState;
  41. CString m_strAddress;
  42. static CMainProcess* m_spThis;
  43. HP_TcpPackServer m_pServer;
  44. HP_TcpServerListener m_pListener;
  45. static En_HP_HandleResult __stdcall OnPrepareListen(SOCKET soListen);
  46. static En_HP_HandleResult __stdcall OnAccept(HP_CONNID dwConnID, SOCKET soClient);
  47. static En_HP_HandleResult __stdcall OnSend(HP_CONNID dwConnID, const BYTE* pData, int iLength);
  48. static En_HP_HandleResult __stdcall OnReceive(HP_CONNID dwConnID, const BYTE* pData, int iLength);
  49. static En_HP_HandleResult __stdcall OnClose(HP_CONNID dwConnID, En_HP_SocketOperation enOperation, int iErrorCode);
  50. static En_HP_HandleResult __stdcall OnShutdown();
  51. protected:
  52. // 线程控制句柄;
  53. HANDLE m_hEvent1;
  54. // 检查服务线程句柄;
  55. HANDLE m_hCheckServices;
  56. // 线程控制句柄;
  57. HANDLE m_hEvent2;
  58. // 备份数据库线程句柄;
  59. HANDLE m_hBackupDatabase;
  60. // 其他接口;
  61. public:
  62. // 工作开始函数;
  63. void StartWork();
  64. // 工作结束函数;
  65. void EndofWork();
  66. // 检测服务在线线程;
  67. static DWORD WINAPI CheckSvcStatusThread(LPVOID lpVoid);
  68. static DWORD WINAPI BackupDatabaseThread(LPVOID lpVoid);
  69. public:
  70. // 启动/退出;
  71. static BOOL Start();
  72. static BOOL Stop();
  73. static BOOL Disconnect(IN const DWORD& dwConnId);
  74. // 登录登出;
  75. static void Req_Login(IN HP_CONNID dwConnID, IN const BYTE* pReceiveData, IN INT nReceiveLength, IN TheProPackage &thepackage, OUT BYTE*& pSendData, OUT DWORD &dwSendLen);
  76. static void Req_LogOut(IN HP_CONNID dwConnID, IN const BYTE* pReceiveData, IN INT nReceiveLength, IN TheProPackage &thepackage, OUT BYTE*& pSendData, OUT DWORD &dwSendLen);
  77. // 部门;
  78. static void New_Department(IN HP_CONNID dwConnID, IN const BYTE* pReceiveData, IN INT nReceiveLength, IN TheProPackage &thepackage, OUT BYTE*& pSendData, OUT DWORD &dwSendLen);
  79. static void Del_Department(IN HP_CONNID dwConnID, IN const BYTE* pReceiveData, IN INT nReceiveLength, IN TheProPackage &thepackage, OUT BYTE*& pSendData, OUT DWORD &dwSendLen);
  80. static void Mod_Department(IN HP_CONNID dwConnID, IN const BYTE* pReceiveData, IN INT nReceiveLength, IN TheProPackage &thepackage, OUT BYTE*& pSendData, OUT DWORD &dwSendLen);
  81. static EnHandleResult Ask_Department(IN HP_CONNID dwConnID, IN const BYTE* pReceiveData, IN INT nReceiveLength, IN TheProPackage &thepackage, OUT BYTE*& pSendData, OUT DWORD &dwSendLen);
  82. };
  83. #endif