2023-07-21 21:32:24 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <mutex>
|
|
|
|
#include <condition_variable>
|
|
|
|
#include <thread>
|
|
|
|
#include <functional>
|
2023-10-07 22:36:20 +00:00
|
|
|
#include <filesystem>
|
2023-07-21 21:32:24 +00:00
|
|
|
#include <vector>
|
2023-07-23 12:04:26 +00:00
|
|
|
#include <list>
|
2023-07-21 21:32:24 +00:00
|
|
|
#include <queue>
|
|
|
|
#include <string>
|
|
|
|
#include <atomic>
|
2023-07-23 12:04:26 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <array>
|
2023-10-07 22:36:20 +00:00
|
|
|
#include <memory>
|
2023-07-23 12:04:26 +00:00
|
|
|
|
2023-10-07 22:36:20 +00:00
|
|
|
#include "settings.h"
|
2023-10-08 23:29:40 +00:00
|
|
|
#include "logger/printer.h"
|
2023-07-21 21:32:24 +00:00
|
|
|
|
|
|
|
class TaskManager {
|
2023-10-08 23:29:40 +00:00
|
|
|
typedef std::pair<bool, std::list<Logger::Message>> JobResult;
|
2023-07-21 21:32:24 +00:00
|
|
|
public:
|
2023-10-08 23:29:40 +00:00
|
|
|
TaskManager(const std::shared_ptr<Settings>& settings, const std::shared_ptr<Printer>& logger);
|
2023-07-21 21:32:24 +00:00
|
|
|
~TaskManager();
|
|
|
|
|
|
|
|
void start();
|
2023-10-07 22:36:20 +00:00
|
|
|
void queueJob(const std::filesystem::path& source, const std::filesystem::path& destination);
|
2023-07-21 21:32:24 +00:00
|
|
|
void stop();
|
|
|
|
bool busy() const;
|
|
|
|
void wait();
|
2023-10-08 23:29:40 +00:00
|
|
|
|
|
|
|
unsigned int getCompleteTasks() const;
|
2023-07-21 21:32:24 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void loop();
|
2023-10-08 23:29:40 +00:00
|
|
|
static JobResult mp3Job(const std::filesystem::path& source, const std::filesystem::path& destination, Logger::Severity logLevel);
|
2023-07-21 21:32:24 +00:00
|
|
|
private:
|
2023-10-07 22:36:20 +00:00
|
|
|
std::shared_ptr<Settings> settings;
|
2023-10-08 23:29:40 +00:00
|
|
|
std::shared_ptr<Printer> logger;
|
|
|
|
unsigned int busyThreads;
|
|
|
|
unsigned int maxTasks;
|
|
|
|
unsigned int completeTasks;
|
2023-07-21 21:32:24 +00:00
|
|
|
bool terminate;
|
2023-10-08 23:29:40 +00:00
|
|
|
bool running;
|
2023-07-21 21:32:24 +00:00
|
|
|
mutable std::mutex queueMutex;
|
|
|
|
std::condition_variable loopConditional;
|
|
|
|
std::condition_variable waitConditional;
|
|
|
|
std::vector<std::thread> threads;
|
2023-10-07 22:36:20 +00:00
|
|
|
std::queue<std::pair<std::filesystem::path, std::filesystem::path>> jobs;
|
2023-07-21 21:32:24 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|