libktorrent  2.1.1
resourcemanager.h
1 /***************************************************************************
2  * Copyright (C) 2010 by Joris Guisson *
3  * joris.guisson@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program 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 *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 
21 
22 #ifndef BT_TICKETMANAGER_H
23 #define BT_TICKETMANAGER_H
24 
25 #include <QList>
26 #include <QMap>
27 #include <QSet>
28 #include <QString>
29 #include <ktorrent_export.h>
30 #include "constants.h"
31 
32 namespace bt
33 {
34  class ResourceManager;
35 
40  class KTORRENT_EXPORT Resource
41  {
42  public:
43  Resource(ResourceManager* rman, const QString & group);
44  virtual ~Resource();
45 
47  QString groupName() const {return group;}
48 
50  virtual void acquired() = 0;
51 
53  void release();
54 
55  typedef QSet<Resource*> Set;
56  typedef QList<Resource*> List;
57 
58  private:
59  ResourceManager* rman;
60  QString group;
61  };
62 
67  class KTORRENT_EXPORT ResourceManager
68  {
69  public:
70  ResourceManager(Uint32 max_active_resources);
71  virtual ~ResourceManager();
72 
76  void setMaxActive(Uint32 m) {max_active_resources = m;}
77 
82  void add(Resource* r);
83 
90  bool acquire(Resource* r);
91 
96  void remove(Resource* r);
97 
101  void shutdown();
102 
103  private:
104  void update();
105 
106  private:
107  Uint32 max_active_resources;
108  Resource::Set active;
109  QMap<QString,Resource::List> pending;
110  QString current;
111  };
112 
113 }
114 
115 #endif // BT_TICKETMANAGER_H
bt::ResourceManager
Definition: resourcemanager.h:86
bt::Resource
Definition: resourcemanager.h:59