#pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include "settings.h" #include "logger/printer.h" class TaskManager { using JobResult = std::pair>; struct Job; public: TaskManager(const std::shared_ptr& settings, const std::shared_ptr& logger); ~TaskManager(); void start(); void queueConvert(const std::filesystem::path& source, const std::filesystem::path& destination); void queueCopy(const std::filesystem::path& source, const std::filesystem::path& destination); void stop(); bool busy() const; void wait(); unsigned int getCompleteTasks() const; private: void loop(); JobResult execute(Job& job); void printResilt(const Job& job, const JobResult& result); static JobResult mp3Job(const Job& job, const std::shared_ptr& settings); static JobResult copyJob(const Job& job, const std::shared_ptr& settings); private: std::shared_ptr settings; std::shared_ptr logger; unsigned int busyThreads; unsigned int maxTasks; unsigned int completeTasks; bool terminate; bool running; mutable std::mutex queueMutex; std::condition_variable loopConditional; std::condition_variable waitConditional; std::vector threads; std::queue jobs; }; struct TaskManager::Job { enum Type { copy, convert }; Job(Type type, const std::filesystem::path& source, std::filesystem::path destination); Type type; std::filesystem::path source; std::filesystem::path destination; };