SupportedMessages.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 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 PROTOCOLS__GNUTELLA__PACKETS__VENDOR_MESSAGE__SUPPORTED_MESSAGES_H
00024 #define PROTOCOLS__GNUTELLA__PACKETS__VENDOR_MESSAGE__SUPPORTED_MESSAGES_H
00025 
00026 #include "Imports.h"
00027 
00028 #include "VendorMessage.h"
00029 
00030 namespace Gnutella {
00031 namespace Packets {
00032 namespace VendorMessages {
00033 
00035 
00045 class SupportedMessages : public VendorMessage
00046 {
00047 public:
00048     static SupportedMessages &          castFrom (Packet & packet)              { return dynamic_cast <SupportedMessages &> (packet); }
00049     static const SupportedMessages &    castFrom (const Packet & packet)        { return dynamic_cast <const SupportedMessages &> (packet); }
00050 
00051     SupportedMessages *                 copy() const                            { return new SupportedMessages (*this); }
00052     QString                             name() const                            { return "SupportedMessages"; }
00053                     SupportedMessages();
00054                     SupportedMessages (const QByteArray &rawHeader,
00055                                        const QByteArray &rawPayload);
00056                     ~SupportedMessages();
00057 
00058     void            addMessage (const VendorCode &, quint16 messageType,
00059                                 quint16 versionNumber);
00060 
00061 protected:
00062     virtual bool    prepareReadPayload (const QByteArray &rawPayload);
00063     virtual void    readPayload (QDataStream &stream);
00064     virtual int     prepareWritePayload() const;
00065     virtual void    writePayload (QDataStream &stream) const;
00066 
00067 private:
00068     struct Message {
00069         VendorCode      vendorCode;
00070         quint16         messageType;
00071         quint16         versionNumber;
00072     };
00073 
00074     struct Data {
00075         QList <Message>     messages;
00076     } p;
00077 };
00078 
00079 } // namespace VendorMessages
00080 } // namespace Packets
00081 } // namespace Gnutella
00082 
00083 #endif // PROTOCOLS__GNUTELLA__PACKETS__VENDOR_MESSAGE__SUPPORTED_MESSAGES_H