00001 // 00002 // Transfers.h 00003 // 00004 // Copyright (c) Shareaza Development Team, 2002-2005. 00005 // This file is part of SHAREAZA (www.shareaza.com) 00006 // 00007 // Shareaza is free software; you can redistribute it 00008 // and/or modify it under the terms of the GNU General Public License 00009 // as published by the Free Software Foundation; either version 2 of 00010 // the License, or (at your option) any later version. 00011 // 00012 // Shareaza is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with Shareaza; if not, write to the Free Software 00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 // 00021 00022 #if !defined(AFX_TRANSFERS_H__950AC162_FF34_4B40_8D8A_2745AA245316__INCLUDED_) 00023 #define AFX_TRANSFERS_H__950AC162_FF34_4B40_8D8A_2745AA245316__INCLUDED_ 00024 00025 #pragma once 00026 00027 class CTransfer; 00028 00029 class CTransfers; 00030 00031 extern CTransfers Transfers; 00032 00033 class CTransfers 00034 { 00035 // Construction 00036 public: 00037 CTransfers(); 00038 virtual ~CTransfers(); 00039 00040 // Attributes 00041 public: 00042 CMutex m_pSection; 00043 class Lock 00044 { 00045 public: 00046 Lock() { Transfers.m_pSection.Lock(); } 00047 ~Lock() { Transfers.m_pSection.Unlock(); } 00048 private: 00049 Lock(const Lock&); 00050 Lock& operator=(const Lock&); 00051 static void* operator new(std::size_t); 00052 static void* operator new[](std::size_t); 00053 static void operator delete(void*); 00054 static void operator delete[](void*); 00055 }; 00056 DWORD m_nBuffer; 00057 BYTE* m_pBuffer; 00058 protected: 00059 CPtrList m_pList; 00060 HANDLE m_hThread; 00061 volatile BOOL m_bThread; 00062 CEvent m_pWakeup; 00063 DWORD m_nRunCookie; 00064 00065 // Operations 00066 public: 00067 int GetActiveCount() const; 00068 BOOL IsConnectedTo(IN_ADDR* pAddress); 00069 BOOL StartThread(); 00070 void StopThread(); 00071 protected: 00072 static UINT ThreadStart(LPVOID pParam); 00073 void OnRun(); 00074 void OnRunTransfers(); 00075 void OnCheckExit(); 00076 protected: 00077 void Add(CTransfer* pTransfer); 00078 void Remove(CTransfer* pTransfer); 00079 00080 // List Access 00081 public: 00082 inline POSITION GetIterator() const 00083 { 00084 return m_pList.GetHeadPosition(); 00085 } 00086 00087 inline CTransfer* GetNext(POSITION& pos) const 00088 { 00089 return (CTransfer*)m_pList.GetNext( pos ); 00090 } 00091 00092 inline int GetCount() const 00093 { 00094 return m_pList.GetCount(); 00095 } 00096 00097 inline BOOL Check(CTransfer* pTransfer) const 00098 { 00099 return m_pList.Find( pTransfer ) != NULL; 00100 } 00101 00102 friend class CTransfer; 00103 friend class CUpload; 00104 friend class CDownloadWithTransfers; 00105 00106 }; 00107 00108 #endif // !defined(AFX_TRANSFERS_H__950AC162_FF34_4B40_8D8A_2745AA245316__INCLUDED_)