- #ifndef _ACCEPTOR_THREAD_H
- #define _ACCEPTOR_THREAD_H
- #include "thread.h"
- #include "socket.h"
- #include "mutex.h"
- #include "xfile.h"
- #include "package.h"
- #include "safeVector.h"
- #include "ThreadStorage.h"
- class CFileReceiver;
- //class CFileReceiverThread :: server socket listening thread.
- // it inherited from CThread class.
- class NETLIBDLLEXPORT CFileReceiverThread : public CThread
- {
- public:
- CFileReceiverThread();
- virtual ~CFileReceiverThread();
- //create the acceptor socket listening thread.
- bool Create( bool bCreateAndSuspended = false,
- const uint unSvrPort = 8989,
- const HWND hNotifyWnd = NULL);
- //set or get received files save root directory.
- void SetRecedFileSaveDir(const char *strRecvedFleSaveDir);
- const char* GetRecedFileSaveDir();
- protected:
- //overrides execute function.
- virtual void Execute();
- //start, stop, pause and resume event process functions.
- virtual void OnStart();
- virtual void OnStop();
- virtual void OnSuspend();
- virtual void OnResume();
- private:
- //server socket object.
- CFileReceiver *m_pWinSvrSocket;
- //notify window's handle.
- HWND m_hNotifyWNd;
- //server socket listening port.
- uint m_unSvrPort;
- //client's file save root directory.
- string m_strCltFleSaveRootDir;
- };
- //class CFileReceiver :: file receiver server socket class.
- // it workes with CFileReceiverThread class.
- class NETLIBDLLEXPORT CFileRecvorClientThread : public CThread
- {
- public:
- CFileRecvorClientThread();
- virtual ~CFileRecvorClientThread();
- protected:
- //overrides execute function.
- virtual void Execute();
- //start, stop, pause and resume event process functions.
- virtual void OnStart(){}
- virtual void OnStop();
- virtual void OnSuspend(){}
- virtual void OnResume(){}
- public:
- //Notify window's handle.
- HWND m_hNotifyWnd;
- //file save root directory.
- string m_strFleSaveRootDir;
- //communication socket.
- CXWinSocket *m_pClientSocket;
- private:
- //parse the file package.
- int Parse_Pack_FileHeader();
- int Parse_Pack_FileBody();
- //construct only one full file name string(include file path info);
- string MakeOnlyOneFileName(const char *lpszfilename);
- private:
- LPNETFILEHDR m_lpfilehdr; //file header struct.
- CXFile m_xfile; //current opened file handle.
- UINT m_nIdentity; //current sending file identity.
- };
- //class CFileReceiver :: file receiver server socket class.
- // it workes with CFileReceiverThread class.
- class NETLIBDLLEXPORT CFileReceiver : public CXWinServerSocket
- {
- public:
- CFileReceiver();
- virtual ~CFileReceiver();
- //suspend or resume the listening client connections.
- void Suspend_Accepting();
- void Resume_Accepting();
- //set the notify message window's handle.
- void SetNotifyWnd(const HWND hNotifyWnd);
- //set or get received files save root directory.
- void SetRecedFileSaveDir(const char *strRecvedFleSaveDir);
- const char* GetRecedFileSaveDir();
- //create or destroy client thread.
- CThread *New_Client_Thread(CXWinSocket *pClientSocket);
- void Delete_Client_Thread(CXWinSocket *pClientSocket);
- //find the client thread object pointer from it's clsid string.
- CThread *FindClientThread(const char *lpCltCLSID);
- protected:
- //self event do here.
- virtual bool OnAcceptVerify(CXWinSocket *pClientSocket);
- virtual void OnClientConnect(CXWinSocket *pClientSocket);
- virtual void OnClientClose(CXWinSocket *pClientSocket);
- private:
- //notify window's handle.
- HWND m_hNotifyWNd;
- bool m_bPauseState;
- string m_strCltFleSaveRootDir; //client's file save root directory.
- CThreadStorage m_tsCltThreads;
- };
- #endif //_ACCEPTOR_THREAD_H