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__HANDSHAKING__SLOT_ALLOCATOR_H 00024 #define GNUTELLA__HANDSHAKING__SLOT_ALLOCATOR_H 00025 00026 #include "Imports.h" 00027 00028 // Open containing namespaces: 00029 namespace Gnutella { 00030 namespace Handshaking { 00032 00033 class HandshakeSession; 00034 class SlotAllocatorPrivate; 00035 00037 00040 class SlotAllocator : public QObject 00041 { 00042 Q_OBJECT 00043 REFERENCE_OBJECT (SlotAllocator) 00044 00045 public: 00046 SlotAllocator (LocalPeer *); 00047 ~SlotAllocator(); 00048 00049 bool isBootstrapping() const; 00050 bool isWellConnected() const; 00051 bool hasSlotFor (const NodeInfo &) const; 00052 bool allocateSlot (HandshakeSession *); 00053 bool allocateSlot (PacketSession *); 00054 00055 uint freeHandshakingSlots() const; 00056 uint freeUltrapeerSlots() const; 00057 uint freePeerSlots() const; 00058 uint freeLeafSlots() const; 00059 00060 /* 00061 uint usedHandshakingSlots() const; 00062 uint usedUltrapeerSlots() const; 00063 uint usedPeerSlots() const; 00064 uint usedLeafSlots() const; 00065 */ 00066 uint hasFreeUltrapeerSlots() const; 00067 uint hasFreePeerSlots() const; 00068 uint hasFreeLeafSlots() const; 00069 00070 signals: 00071 void handshakingSlotFreed(); 00072 void ultrapeerSlotFreed(); 00073 void peerSlotFreed(); 00074 void leafSlotFreed(); 00075 00076 private slots: 00077 void freeSlot (QObject *); 00078 00079 private: 00080 SlotAllocatorPrivate *p; 00081 }; 00082 00083 inline uint SlotAllocator::hasFreeUltrapeerSlots() const 00084 { return freeUltrapeerSlots() > 0; } 00085 00086 inline uint SlotAllocator::hasFreePeerSlots() const 00087 { return freePeerSlots() > 0; } 00088 00089 inline uint SlotAllocator::hasFreeLeafSlots() const 00090 { return freeLeafSlots() > 0; } 00091 00092 // Close containing namespaces: 00093 } // namespace Handshaking 00094 } // namespace Gnutella 00096 00097 #endif // GNUTELLA__HANDSHAKING__SLOT_ALLOCATOR_H