PacketWriter.h

Go to the documentation of this file.
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 PACKETWRITER_H
00024 #define PACKETWRITER_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 
00037 // \todo Derive from a base class DataWriter (belonging to the network package)
00038 class PacketWriter : public QObject
00039 {
00040     Q_OBJECT
00041 
00042 public:
00043                         PacketWriter (Connection *);
00044                         ~PacketWriter();
00045 
00046     void                write (const Gnutella::Packets::Packet &packet);
00047     bool                canWrite() const;
00048 
00049 signals:
00050     void                packetWritten();
00051     void                writeError();
00052 
00053 private slots:
00054     void                bytesWritten (qint64);
00055 
00056 private:
00057 
00058     struct Private
00059     {
00060         Connection      *connection;
00061         char            rawPacket [Gnutella::Packets::MaximalPacketLength];
00062         quint32         packetLength;
00063         quint32         packetBytesWritten;
00064     } p;
00065 };
00066 
00067 // Close containing namespaces:
00068 } // namespace PacketProcessing
00069 } // namespace Gnutella
00071 
00072 #endif // PACKETWRITER_H