1 /*
2     SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 #ifndef DHTTASKMANAGER_H
7 #define DHTTASKMANAGER_H
8 
9 #include "task.h"
10 #include <QList>
11 #include <QPointer>
12 #include <util/constants.h>
13 
14 namespace dht
15 {
16 class DHT;
17 
18 /**
19  * @author Joris Guisson <joris.guisson@gmail.com>
20  *
21  * Manages all dht tasks.
22  */
23 class TaskManager : public QObject
24 {
25 public:
26     TaskManager(const DHT *dh_table);
27     ~TaskManager() override;
28 
29     /**
30      * Add a task to manage.
31      * @param task
32      */
33     void addTask(Task *task);
34 
35     /// Get the number of running tasks
getNumTasks()36     bt::Uint32 getNumTasks() const
37     {
38         return num_active;
39     }
40 
41     /// Get the number of queued tasks
getNumQueuedTasks()42     bt::Uint32 getNumQueuedTasks() const
43     {
44         return queued.count();
45     }
46 
47 private:
48     void taskFinished(Task *task);
49 
50     const DHT *dh_table;
51     QList<QPointer<Task>> queued;
52     bt::Uint32 num_active;
53 };
54 
55 }
56 
57 #endif
58