CCHelper.cpp
上传用户:maryhy001
上传日期:2007-05-02
资源大小:2317k
文件大小:4k
- // CCHelper.cpp: implementation of the CCCHelper class.
- #include "stdafx.h"
- #include "Mainfrm.h"
- #include "trfAgent.h"
- #include "CCHelper.h"
- #include "register.h"
- //////////////////////////////////////////////////////////////////////
- CCCHelper::CCCHelper()
- {
- this->m_pchatSvrThread = NULL;
- m_pfileSenderSvr = NULL;
- m_pfileRecvorSvr = NULL;
- }
- CCCHelper::~CCCHelper()
- {
- this->Stop();
- }
- //start the cc helper functions.
- bool CCCHelper::Start(void)
- {
- return this->Start_FileTransSvr() &&
- this->Start_P2PChatSvr();
- }
- //stop the cc helper functions.
- void CCCHelper::Stop(void)
- {
- this->Stop_P2PChatSvr();
- this->Stop_FileTransSvr();
- }
- //start function of file sending server.
- bool CCCHelper::Start_FileSendSvr(void)
- {
- m_pfileSenderSvr = new CFileSenderThread();
- return true;
- }
- //stop function of file sending server.
- void CCCHelper::Stop_FileSendSvr(void)
- {
- if(NULL != this->m_pfileSenderSvr)
- {
- this->m_pfileSenderSvr->Stop();
-
- this->m_pfileSenderSvr->Destroy();
-
- _DELETE(this->m_pfileSenderSvr);
- }
- }
- //start function of file transfering.
- bool CCCHelper::Start_FileTransSvr(void)
- {
- //open the register for reading service's parameters.
-
- CRegister regkey;
- if(!regkey.Open(HKEY_CURRENT_USER, REG_SSYSSETTINGKEY))
- {
- return false;
- }
- CString savedir = regkey.Read_String_Value(REG_SRECVFLESDIR);
- DWORD dwport = regkey.Read_DWord_Value(REG_NTRFTRANSPORT);
- regkey.Close();
- this->Stop_FileTransSvr();
-
- this->m_pfileRecvorSvr = new CFileReceiverThread();
-
- this->m_pfileRecvorSvr->SetRecedFileSaveDir(savedir.GetBuffer(0));
- assert(NULL != theApp.GetMainWnd());
- HWND hwnd = theApp.GetMainWnd()->GetSafeHwnd();
- return this->m_pfileRecvorSvr->Create(false, dwport, hwnd);
- }
- //stop function of file transfering.
- void CCCHelper::Stop_FileTransSvr(void)
- {
- if(NULL != this->m_pfileRecvorSvr)
- {
- this->m_pfileRecvorSvr->Destroy();
- _DELETE(this->m_pfileRecvorSvr);
- }
- }
- //start function of peer to peer chating.
- bool CCCHelper::Start_P2PChatSvr(void)
- {
- CRegister regkey;
- DWORD dwUDPort,
- dwHeadportrait;
- //read the UDP server listening port.
- if(!regkey.Open(HKEY_CURRENT_USER, REG_SSYSSETTINGKEY)) return false;
- dwUDPort = regkey.Read_DWord_Value(REG_NCHATUDPPORT);
- //determine the UDP port whether is valid.
- if(dwUDPort < 1000 || dwUDPort > 65535) dwUDPort = 5558;
- dwHeadportrait = regkey.Read_DWord_Value(REG_NHEADBMPINDEX);
- regkey.Close();
- //stop the P2P chating service.
- this->Stop_P2PChatSvr();
- //create the chating service.
- CMainFrame *pMainFrm = (CMainFrame*)::AfxGetMainWnd();
- ASSERT(NULL != pMainFrm);
- //////////////////////////////////////////////////////////////////////////
-
- memset(&m_cpgResponse, 0x0, sizeof(m_cpgResponse));
- sprintf(m_cpgResponse.pktype, "%*d", SIZE_PKTYPE, CPT_RESPONSE);
- sprintf(m_cpgResponse.agentid, "%*d", SIZE_AGENTID, theApp.m_oCSHelper.GetClientID());
- sprintf(m_cpgResponse.headportrait, "%*d", SIZE_HADPTRT, dwHeadportrait);
-
- //////////////////////////////////////////////////////////////////////////
-
- this->m_pchatSvrThread = new CUDPServerThread;
- this->m_pchatSvrThread->SetMsgWnd(pMainFrm->m_wndChatBar, UWM_CHATINGMSG);
- this->m_pchatSvrThread->SetResponsePackage((char*)&m_cpgResponse, sizeof(m_cpgResponse));
- if(!this->m_pchatSvrThread->Create(dwUDPort)) return false;
- //Sleep(500);
- //::SendMessage(pMainFrm->m_wndChatBar.GetSafeHwnd(), UWM_CHATSTARTLOGON, 0, 0);
-
- return true;
- }
- //stop function of peer to peer chating.
- void CCCHelper::Stop_P2PChatSvr(void)
- {
- if(this->m_pchatSvrThread)
- {
- this->m_pchatSvrThread->Stop();
- _DELETE(this->m_pchatSvrThread);
- }
- }
- //get received file save directory.
- LPCSTR CCCHelper::GetRecvedFileSaveDir()
- {
- if(NULL == this->m_pfileRecvorSvr) return NULL;
-
- return this->m_pfileRecvorSvr->GetRecedFileSaveDir();
- }
- //get member pointer.
- CFileReceiverThread *CCCHelper::GetFileRecverThread()
- {
- return this->m_pfileRecvorSvr;
- }
- //get member pointer.
- CFileSenderThread *CCCHelper::GetFileSenderThread()
- {
- return this->m_pfileSenderSvr;
- }