FileRecvorThread.h
上传用户:maryhy001
上传日期:2007-05-02
资源大小:2317k
文件大小:4k
源码类别:

网格计算

开发平台:

Visual C++

  1. #ifndef _ACCEPTOR_THREAD_H
  2. #define _ACCEPTOR_THREAD_H
  3. #include "thread.h"
  4. #include "socket.h"
  5. #include "mutex.h"
  6. #include "xfile.h"
  7. #include "package.h"
  8. #include "safeVector.h"
  9. #include "ThreadStorage.h"
  10. class CFileReceiver;
  11. //class CFileReceiverThread ::  server socket listening thread.
  12. // it inherited from CThread class.
  13. class NETLIBDLLEXPORT CFileReceiverThread : public CThread
  14. {
  15. public:
  16. CFileReceiverThread();
  17. virtual ~CFileReceiverThread();
  18. //create the acceptor socket listening thread.
  19. bool Create( bool bCreateAndSuspended = false,
  20. const uint unSvrPort = 8989,
  21. const HWND hNotifyWnd = NULL);
  22. //set or get received files save root directory.
  23. void SetRecedFileSaveDir(const char *strRecvedFleSaveDir);
  24. const char* GetRecedFileSaveDir();
  25. protected:
  26. //overrides execute function.
  27. virtual void Execute();
  28. //start, stop, pause and resume event process functions.
  29. virtual void OnStart();
  30. virtual void OnStop();
  31. virtual void OnSuspend();
  32. virtual void OnResume();
  33. private:
  34. //server socket object.
  35. CFileReceiver *m_pWinSvrSocket;
  36. //notify window's handle.
  37. HWND m_hNotifyWNd;
  38. //server socket listening port.
  39. uint m_unSvrPort;
  40. //client's file save root directory.
  41. string m_strCltFleSaveRootDir;
  42. };
  43. //class CFileReceiver :: file receiver server socket class.
  44. //  it workes with CFileReceiverThread class.
  45. class NETLIBDLLEXPORT CFileRecvorClientThread : public CThread
  46. {
  47. public:
  48. CFileRecvorClientThread();
  49. virtual ~CFileRecvorClientThread();
  50. protected:
  51. //overrides execute function.
  52. virtual void Execute();
  53. //start, stop, pause and resume event process functions.
  54. virtual void OnStart(){}
  55. virtual void OnStop();
  56. virtual void OnSuspend(){}
  57. virtual void OnResume(){}
  58. public:
  59. //Notify window's handle.
  60. HWND m_hNotifyWnd;
  61. //file save root directory.
  62. string m_strFleSaveRootDir;
  63. //communication socket.
  64. CXWinSocket *m_pClientSocket;
  65. private:
  66. //parse the file package.
  67. int Parse_Pack_FileHeader();
  68. int Parse_Pack_FileBody();
  69. //construct only one full file name string(include file path info);
  70. string MakeOnlyOneFileName(const char *lpszfilename);
  71. private:
  72. LPNETFILEHDR m_lpfilehdr; //file header struct.
  73. CXFile m_xfile; //current opened file handle.
  74. UINT m_nIdentity; //current sending file identity.
  75. };
  76. //class CFileReceiver :: file receiver server socket class.
  77. //  it workes with CFileReceiverThread class.
  78. class NETLIBDLLEXPORT CFileReceiver : public CXWinServerSocket
  79. {
  80. public:
  81. CFileReceiver();
  82. virtual ~CFileReceiver();
  83. //suspend or resume the listening client connections.
  84. void Suspend_Accepting();
  85. void Resume_Accepting();
  86. //set the notify message window's handle.
  87. void SetNotifyWnd(const HWND hNotifyWnd);
  88. //set or get received files save root directory.
  89. void SetRecedFileSaveDir(const char *strRecvedFleSaveDir);
  90. const char* GetRecedFileSaveDir();
  91. //create or destroy client thread.
  92. CThread *New_Client_Thread(CXWinSocket *pClientSocket);
  93. void Delete_Client_Thread(CXWinSocket *pClientSocket);
  94. //find the client thread object pointer from it's clsid string.
  95. CThread *FindClientThread(const char *lpCltCLSID);
  96. protected:
  97. //self event do here.
  98. virtual bool OnAcceptVerify(CXWinSocket *pClientSocket);
  99. virtual void OnClientConnect(CXWinSocket *pClientSocket);
  100. virtual void OnClientClose(CXWinSocket *pClientSocket);
  101. private:
  102. //notify window's handle.
  103. HWND m_hNotifyWNd;
  104. bool m_bPauseState;
  105. string m_strCltFleSaveRootDir; //client's file save root directory.
  106. CThreadStorage m_tsCltThreads;
  107. };
  108. #endif //_ACCEPTOR_THREAD_H