Upstream tarball 9962
[amule.git] / src / libs / ec / cpp / ECPacket.cpp
blob8ccfa70015a30f0250af4ba2edf432704d6cda8a
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2004-2008 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.
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
25 #include "ECPacket.h" // Needed for ECPacket
26 #include "ECSocket.h" // Needed for CECSocket
28 /**********************************************************
29 * *
30 * CECPacket class *
31 * *
32 **********************************************************/
34 bool CECPacket::ReadFromSocket(CECSocket& socket)
36 if (m_state == bsName) {
37 if (!socket.ReadNumber(&m_opCode, sizeof(ec_opcode_t))) {
38 return false;
39 } else {
40 m_state = bsChildCnt;
43 if (m_state == bsChildCnt || m_state == bsChildren) {
44 if (!ReadChildren(socket)) {
45 return false;
48 m_state = bsFinished;
49 return true;
53 bool CECPacket::WritePacket(CECSocket& socket) const
55 if (!socket.WriteNumber(&m_opCode, sizeof(ec_opcode_t))) return false;
56 if (!WriteChildren(socket)) return false;
57 return true;
60 #ifdef __DEBUG__
61 #include <common/Format.h> // Needed for CFormat
62 void CECPacket::DebugPrint(bool incoming) const
64 wxString GetDebugNameECOpCodes(uint8 arg);
66 if (ECLogIsEnabled()) {
67 DoECLogLine(CFormat(wxT("%s %s %d")) % (incoming ? wxT("<") : wxT(">"))
68 % GetDebugNameECOpCodes(m_opCode) % GetPacketLength());
69 CECTag::DebugPrint(1, false);
72 #else
73 void CECPacket::DebugPrint(bool) const {}
74 #endif
76 /*!
77 * \fn CECPacket::CECPacket(ec_opcode_t opCode, EC_DETAIL_LEVEL detail_level)
79 * \brief Creates a new packet with given OPCODE.
82 /*!
83 * \fn ec_opcode_t CECPacket::GetOpCode(void) const
85 * \brief Returns OPCODE.
87 * \return The OpCode of the packet.
90 /*!
91 * \fn uint32 CECPacket::GetPacketLength(void) const
93 * \brief Returns the length of the packet.
95 * \return The length of the packet.
97 // File_checked_for_headers