Ultrapeer.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 ULTRAPEER_H
00024 #define ULTRAPEER_H
00025 
00026 #include "Gnutella/Packets/Extensions/Ggep.h"
00027 #include "Utils/Version.h"
00028 
00029 // Open containing namespaces:
00030 namespace Gnutella {
00031 namespace Packets {
00032 namespace Extensions {
00033     class GgepBlock; // Forward declaration.
00034 namespace Ggeps {
00036 
00037 using Utils::Version;
00038 
00040 class Ultrapeer : public Ggep
00041 {
00042 public:
00043     static const Ggep::GgepId Id;
00044 
00045                                     Ultrapeer (const GgepId &id, int flags, int dataSize);
00046                                     Ultrapeer (Version version, int ultrapeerSlots, int leafSlots);
00047                                     ~Ultrapeer();
00048     inline                          Ultrapeer (const Ultrapeer &other);
00049     Ultrapeer &                     operator= (const Ultrapeer &other);
00050 
00051     static const Ultrapeer *        findIn (const GgepBlock &ggepBlock);
00052     Ultrapeer *                     copy() const;
00053 
00054     inline Version                  version() const;
00055     inline int                      ultrapeerSlots() const;
00056     inline int                      leafSlots() const;
00057 
00058 protected:
00059     bool                            prepareReadData (const QByteArray &rawData);
00060     void                            readData (QDataStream &stream);
00061     int                             prepareWriteData() const;
00062     void                            writeData (QDataStream &stream) const;
00063 
00064 private:
00065 
00066     struct Data
00067     {
00068         QBasicAtomic                ref;
00069 
00070         Version                     version;
00071         uchar                       ultrapeerSlots;
00072         uchar                       leafSlots;
00073     };
00074 
00075     Data                            *d;
00076 };
00077 
00079 // inline functions
00081 
00082 Ultrapeer::Ultrapeer (const Ultrapeer &other)
00083 : Ggep (Id), d (other.d)
00084 { d->ref.ref(); }
00085 
00086 Version Ultrapeer::version() const
00087 { return d->version; }
00088 
00089 int Ultrapeer::ultrapeerSlots() const
00090 { return d->ultrapeerSlots; }
00091 
00092 int Ultrapeer::leafSlots() const
00093 { return d->leafSlots; }
00094 
00095 // Close containing namespaces:
00096 } // namespace Ggeps
00097 } // namespace Extensions
00098 } // namespace Packets
00099 } // namespace Gnutella
00101 
00102 #endif // ULTRAPPER_H