File indexing completed on 2025-01-05 04:37:12

0001 /*
0002     SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #ifndef DHTTASKMANAGER_H
0007 #define DHTTASKMANAGER_H
0008 
0009 #include "task.h"
0010 #include <QList>
0011 #include <QPointer>
0012 #include <util/constants.h>
0013 
0014 namespace dht
0015 {
0016 class DHT;
0017 
0018 /**
0019  * @author Joris Guisson <joris.guisson@gmail.com>
0020  *
0021  * Manages all dht tasks.
0022  */
0023 class TaskManager : public QObject
0024 {
0025 public:
0026     TaskManager(const DHT *dh_table);
0027     ~TaskManager() override;
0028 
0029     /**
0030      * Add a task to manage.
0031      * @param task
0032      */
0033     void addTask(Task *task);
0034 
0035     /// Get the number of running tasks
0036     bt::Uint32 getNumTasks() const
0037     {
0038         return num_active;
0039     }
0040 
0041     /// Get the number of queued tasks
0042     bt::Uint32 getNumQueuedTasks() const
0043     {
0044         return queued.count();
0045     }
0046 
0047 private:
0048     void taskFinished(Task *task);
0049 
0050     const DHT *dh_table;
0051     QList<QPointer<Task>> queued;
0052     bt::Uint32 num_active;
0053 };
0054 
0055 }
0056 
0057 #endif