1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2004-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5 //
6 // Any parts of this program derived from the xMule, lMule or eMule project,
7 // or contributed by third-party developers are copyrighted by their
8 // respective authors.
9 //
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
14 //
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
23 //
24 
25 #ifndef ECPACKET_H
26 #define ECPACKET_H
27 
28 #include "ECTag.h"
29 
30 // Define this to keep partial packets
31 // (those that had an error upon reception/creation)
32 #undef KEEP_PARTIAL_PACKETS
33 
34 class CECSocket;
35 
36 /**
37  * High level EC packet handler class
38  */
39 class CECPacket : public CECEmptyTag {
40 	friend class CECSocket;
41 	public:
42 		CECPacket(ec_opcode_t opCode, EC_DETAIL_LEVEL detail_level = EC_DETAIL_FULL)
43 		: CECEmptyTag(0), m_opCode(opCode)
44 		{
45 			// since EC_DETAIL_FULL is default - no point transmit it
46 			if ( detail_level != EC_DETAIL_FULL ) {
47 				AddTag(CECTag(EC_TAG_DETAIL_LEVEL, (uint64)detail_level));
48 			}
49 		}
50 
GetOpCode(void)51 		ec_opcode_t	GetOpCode(void) const { return m_opCode; }
GetPacketLength(void)52 		uint32_t		GetPacketLength(void) const { return CECTag::GetTagLen(); }
GetDetailLevel()53 		EC_DETAIL_LEVEL GetDetailLevel() const
54 		{
55 			const CECTag *tag = GetTagByName(EC_TAG_DETAIL_LEVEL);
56 			return (tag) ? (EC_DETAIL_LEVEL)tag->GetInt() : EC_DETAIL_FULL;
57 		}
58 		void DebugPrint(bool incoming, uint32 trueSize = 0) const;
59 
60 	private:
CECPacket()61 		CECPacket()	: CECEmptyTag() {}
62 
63 		bool ReadFromSocket(CECSocket& socket);
64 		bool WritePacket(CECSocket& socket) const;
65 		ec_opcode_t	m_opCode;
66 };
67 
68 #endif /* ECPACKET_H */
69 // File_checked_for_headers
70