Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

BTPacket.h

Go to the documentation of this file.
00001 //
00002 // BTPacket.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_BTPACKET_H__F3CA41D9_F0E8_4996_A551_F7EEE8D509B3__INCLUDED_)
00023 #define AFX_BTPACKET_H__F3CA41D9_F0E8_4996_A551_F7EEE8D509B3__INCLUDED_
00024 
00025 #pragma once
00026 
00027 #include "Packet.h"
00028 
00029 //
00030 // Packet
00031 //
00032 
00033 class CBTPacket : public CPacket
00034 {
00035 // Construction
00036 protected:
00037         CBTPacket();
00038         virtual ~CBTPacket();
00039 
00040 // Attributes
00041 public:
00042         BYTE    m_nType;
00043 
00044 // Operations
00045 public:
00046         virtual void            ToBuffer(CBuffer* pBuffer) const;
00047         static  CBTPacket*      ReadBuffer(CBuffer* pBuffer);
00048 public:
00049         virtual LPCTSTR         GetType() const;
00050 
00051 // Packet Pool
00052 protected:
00053         class CBTPacketPool : public CPacketPool
00054         {
00055         public:
00056                 virtual ~CBTPacketPool() { Clear(); }
00057         protected:
00058                 virtual void NewPoolImpl(int nSize, CPacket*& pPool, int& nPitch);
00059                 virtual void FreePoolImpl(CPacket* pPool);
00060         };
00061 
00062         static CBTPacketPool POOL;
00063 
00064 // Allocation
00065 public:
00066         inline static CBTPacket* New(BYTE nType)
00067         {
00068                 CBTPacket* pPacket = (CBTPacket*)POOL.New();
00069                 pPacket->m_nType = nType;
00070                 return pPacket;
00071         }
00072 
00073         inline virtual void Delete()
00074         {
00075                 POOL.Delete( this );
00076         }
00077 
00078         friend class CBTPacket::CBTPacketPool;
00079 };
00080 
00081 inline void CBTPacket::CBTPacketPool::NewPoolImpl(int nSize, CPacket*& pPool, int& nPitch)
00082 {
00083         nPitch  = sizeof(CBTPacket);
00084         pPool   = new CBTPacket[ nSize ];
00085 }
00086 
00087 inline void CBTPacket::CBTPacketPool::FreePoolImpl(CPacket* pPacket)
00088 {
00089         delete [] (CBTPacket*)pPacket;
00090 }
00091 
00092 //
00093 // Packet Types
00094 //
00095 
00096 #define BT_PACKET_CHOKE                         0
00097 #define BT_PACKET_UNCHOKE                       1
00098 #define BT_PACKET_INTERESTED            2
00099 #define BT_PACKET_NOT_INTERESTED        3
00100 #define BT_PACKET_HAVE                          4
00101 #define BT_PACKET_BITFIELD                      5
00102 #define BT_PACKET_REQUEST                       6
00103 #define BT_PACKET_PIECE                         7
00104 #define BT_PACKET_CANCEL                        8
00105 
00106 #define BT_PACKET_HANDSHAKE                     128
00107 #define BT_PACKET_SOURCE_REQUEST        129
00108 #define BT_PACKET_SOURCE_RESPONSE       130
00109 
00110 #define BT_PACKET_KEEPALIVE                     255
00111 
00112 #pragma pack(1)
00113 
00114 typedef struct
00115 {
00116         DWORD   nLength;
00117         BYTE    nType;
00118         DWORD   nPiece;
00119         DWORD   nOffset;
00120 } BT_PIECE_HEADER;
00121 
00122 #pragma pack()
00123 
00124 #endif // !defined(AFX_BTPACKET_H__F3CA41D9_F0E8_4996_A551_F7EEE8D509B3__INCLUDED_)

Generated on Thu Dec 15 10:39:33 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2