Add net-limit module for limiting network bandwidth.
[tairon.git] / src / net-limit / limitmanager.h
blobbdf2b09fdd3fa48f3d37386953817d4640a69f73
1 /***************************************************************************
2 * *
3 * Copyright (C) 2006 David Brodsky *
4 * *
5 * This library is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU Library General Public *
7 * License as published by the Free Software Foundation and appearing *
8 * in the file LICENSE.LGPL included in the packaging of this file. *
9 * *
10 * This library is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13 * Library General Public License for more details. *
14 * *
15 ***************************************************************************/
17 #ifndef _tairon_net_limit_limitmanager_h
18 #define _tairon_net_limit_limitmanager_h
20 #include <list>
21 #include <set>
23 namespace Tairon
26 namespace Net
29 class Limiter;
30 class Timer;
32 /** \brief LimitManager handles list of limiters that are waiting for free
33 * bandwidth.
35 class LimitManager
37 public:
38 /** Creates a LimitManager object.
40 LimitManager();
42 /** Destroys the manager.
44 ~LimitManager();
46 /** Removes a limiter from the list.
48 void removeFromQueue(Limiter *l);
50 /** Returns pointer the instance of this class.
52 static LimitManager *self() {
53 return limitmanager;
56 /** Adds a limiter to the list.
58 void wantMore(Limiter *l);
60 private:
61 /** Called every second by a timer.
63 void timeout();
65 private:
66 /** Pointer to the instance of this class.
68 static LimitManager *limitmanager;
70 /** Obe second timer.
72 Timer *timer;
74 /** List of limiters that are about to be deleted from the queue.
76 std::list<Limiter *> toDelete;
78 /** List of waiting limiters.
80 std::set<Limiter *> waiting;
83 }; // namespace Net
85 }; // namespace Tairon
87 #endif
89 // vim: ai sw=4 ts=4 noet fdm=marker