00001 /* 00002 00003 Copyright (C) 2006-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 GNUTELLA__PACKETS__BYE__H 00024 #define GNUTELLA__PACKETS__BYE__H 00025 00026 #include "Packet.h" 00027 00028 namespace Gnutella { 00029 namespace Packets { 00030 00031 class Bye : public Packet 00032 { 00033 public: 00034 static inline Bye & castFrom (Packet & packet); 00035 static inline const Bye & castFrom (const Packet & packet); 00036 00037 Bye (const QByteArray &rawHeader, const QByteArray &rawPayload); 00038 Bye (quint16 code, const QByteArray &message); 00039 inline Bye (const Bye &other); 00040 Bye & operator= (const Bye &other); 00041 ~Bye(); 00042 00043 inline Bye * copy() const; 00044 00045 QString name() const { return QString ("Bye"); } 00046 00047 inline quint16 code() const; 00048 inline QByteArray message() const; 00049 00050 inline void setCode (quint16 code); 00051 inline void setMessage (const QByteArray &message); 00052 00053 protected: 00054 00055 void invalidatePayload(); 00056 00057 bool prepareReadPayload (const QByteArray &rawPayload); 00058 void readPayload (QDataStream &stream); 00059 int prepareWritePayload() const; 00060 void writePayload (QDataStream &stream) const; 00061 00062 private: 00063 struct Data 00064 { 00065 quint16 code; 00066 QByteArray message; 00067 }; 00068 00069 Data d; 00070 }; 00071 00072 inline Bye & Bye::castFrom (Packet & packet) 00073 { return dynamic_cast <Bye &> (packet); } 00074 00075 inline const Bye & Bye::castFrom (const Packet & packet) 00076 { return dynamic_cast <const Bye &> (packet); } 00077 00078 inline Bye::Bye (const Bye &other) 00079 : Packet (other), d (other.d) 00080 {} 00081 00082 inline Bye* Bye::copy() const 00083 { return new Bye (*this); } 00084 00085 inline quint16 Bye::code() const 00086 { return d.code; } 00087 00088 inline QByteArray Bye::message() const 00089 { return d.message; } 00090 00091 inline void Bye::setCode (quint16 code) 00092 { d.code = code; } 00093 00094 inline void Bye::setMessage (const QByteArray &message) 00095 { d.message = message; } 00096 00097 } // namespace Packets 00098 } // namespace Gnutella 00099 00100 #endif // GNUTELLA__PACKETS__BYE__H