00001 /* 00002 00003 Copyright (C) 2005-2007 by Peter Dimov. 00004 00005 This file is part of Calitko (http://www.calitko.org). 00006 00007 Calitko is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 00012 Calitko 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 Calitko; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 00021 */ 00022 00023 #ifndef PACKETREADER_H 00024 #define PACKETREADER_H 00025 00026 #include "Gnutella/Packets/Packet.h" 00027 // breaks MOC FORWARD_DECLARE2 (Protocols, Transports, class Connection) 00028 namespace Protocols { namespace Transports { class Connection; }} 00029 00030 // Open containing namespaces: 00031 namespace Gnutella { 00032 namespace PacketProcessing { 00034 00035 using Protocols::Transports::Connection; 00036 using Gnutella::Packets::Packet; 00037 00038 class PacketReader : public QObject 00039 { 00040 Q_OBJECT 00041 00042 public: 00043 PacketReader (Connection *connection); 00044 ~PacketReader(); 00045 00046 void startReading(); 00047 const Packet * packet() const; 00048 00049 signals: 00050 void packetRead(); 00051 void readError(); 00052 00053 private slots: 00054 void readyRead (); 00055 00056 private: 00057 00058 struct Private 00059 { 00060 Connection *connection; 00061 char rawHeader[Gnutella::Packets::HeaderLength]; 00062 char rawPayload[Gnutella::Packets::MaximalPayloadLength]; 00063 quint32 payloadLength; 00064 quint32 headerBytesRead; 00065 quint32 payloadBytesRead; 00066 Packet *packet; 00067 bool done; 00068 00069 Private() : connection (0), payloadLength(0), headerBytesRead (0), 00070 payloadBytesRead (0), packet (0), done (false) 00071 {} 00072 00073 private: 00074 REFERENCE_OBJECT (Private) 00075 } p; 00076 }; 00077 00078 // Close containing namespaces: 00079 } // namespace PacketProcessing 00080 } // namespace Gnutella 00082 00083 #endif // PACKETREADER_H