Push.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 PUSH_H
00024 #define PUSH_H
00025 
00026 #include "Packet.h"
00027 #include "Extensions/GgepBlock.h"
00028 
00029 // Open containing namespaces:
00030 namespace Gnutella {
00031 namespace Packets {
00033 
00035 
00053 class Push : public Packet
00054 {
00055 public:
00056     static Push &           castFrom (Packet & packet)              { return dynamic_cast <Push &> (packet); }
00057     static const Push &     castFrom (const Packet & packet)        { return dynamic_cast <const Push &> (packet); }
00058 
00059                         Push (const QByteArray &rawHeader, const QByteArray &rawPayload);
00060                         ~Push();
00061 
00062     const QUuid &       serventId() const               { return p.serventId; }     
00063     const Extensions::GgepBlock &   ggepBlock() const               { return p.ggepBlock; }         
00064 
00065     void                setGgepBlock (const Extensions::GgepBlock &block)       { p.ggepBlock = block; invalidatePayload(); }           
00066 
00067     Push*               copy() const                    { return new Push (*this); }
00068 
00069     QString             name() const { return QString ("Push"); }
00070 
00071 protected:
00072     bool    prepareReadPayload (const QByteArray &rawPayload);
00073     void    readPayload (QDataStream &stream);
00074     int     prepareWritePayload() const;
00075     void    writePayload (QDataStream &stream) const;
00076 
00077 private:
00078 
00079     struct Data
00080     {
00081         QUuid                   serventId;      
00082         quint32                 fileIndex;      
00083         QHostAddress            ipAddress;      
00084         quint16                 port;           
00085         Extensions::GgepBlock   ggepBlock;      
00086     } p;
00087 };
00088 
00089 // Close containing namespaces:
00090 } // namespace Packets
00091 } // namespace Gnutella
00093 
00094 #endif // PUSH_H