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#include "ECPacket.h"	// Needed for ECPacket
26#include "ECSocket.h"	// Needed for CECSocket
27
28/**********************************************************
29 *							  *
30 *	CECPacket class					  *
31 *							  *
32 **********************************************************/
33
34bool CECPacket::ReadFromSocket(CECSocket& socket)
35{
36	return socket.ReadNumber(&m_opCode, sizeof(ec_opcode_t))
37		&& ReadChildren(socket);
38}
39
40
41bool CECPacket::WritePacket(CECSocket& socket) const
42{
43	if (!socket.WriteNumber(&m_opCode, sizeof(ec_opcode_t))) return false;
44	if (!WriteChildren(socket)) return false;
45	return true;
46}
47
48#ifdef __DEBUG__
49#include <common/Format.h>  // Needed for CFormat
50void CECPacket::DebugPrint(bool incoming, uint32 trueSize) const
51{
52	wxString GetDebugNameECOpCodes(uint8 arg);
53
54	if (ECLogIsEnabled()) {
55		uint32 size = GetPacketLength() + sizeof(ec_opcode_t) + 2;	// full length incl. header
56
57		if (trueSize == 0 || size == trueSize) {
58			DoECLogLine(CFormat(wxT("%s %s %d")) % (incoming ? wxT("<") : wxT(">"))
59				% GetDebugNameECOpCodes(m_opCode) % size);
60		} else {
61			DoECLogLine(CFormat(wxT("%s %s %d (compressed: %d)")) % (incoming ? wxT("<") : wxT(">"))
62				% GetDebugNameECOpCodes(m_opCode) % size % trueSize);
63		}
64		CECTag::DebugPrint(1, false);
65	}
66}
67#else
68void CECPacket::DebugPrint(bool, uint32) const {}
69#endif
70
71/*!
72 * \fn CECPacket::CECPacket(ec_opcode_t opCode, EC_DETAIL_LEVEL detail_level)
73 *
74 * \brief Creates a new packet with given OPCODE.
75 */
76
77/*!
78 * \fn ec_opcode_t CECPacket::GetOpCode(void) const
79 *
80 * \brief Returns OPCODE.
81 *
82 * \return The OpCode of the packet.
83 */
84
85/*!
86 * \fn uint32 CECPacket::GetPacketLength(void) const
87 *
88 * \brief Returns the length of the packet.
89 *
90 * \return The length of the packet.
91 */
92// File_checked_for_headers
93