#pragma once #include #include #include #include #include #include #include #include #include #include "loggable.h" #include "component.h" #include "download.h" #include "taskmanager.h" #include "source.h" class Collection : protected Loggable { using Sources = std::set; using SourcesQueue = std::queue; using Downloads = std::map>; using Components = std::map>; public: Collection( const std::filesystem::path& location, const std::filesystem::path& destination, const std::string& target, const std::shared_ptr& logger, const std::shared_ptr& taskManager ); bool success() const; unsigned int sourcesTotal() const; unsigned int sourcesPending() const; unsigned int sourcesError() const; unsigned int sourcesSuccess() const; bool hasSource(const Source& source) const; void addSource(const Source& source); private: void sourceDownaloded(const Source& source, TaskManager::Error err); void sourceRead(const Source& source, TaskManager::Error err); void sourceBuilt(const Source& source, TaskManager::Error err); void rootBuilt(TaskManager::Error err); static bool isRemote(const std::string& source); void processSource(const Source& source); void queueDownload(const Source& source); void queueRead(const Source& source, const std::filesystem::path& location); bool _hasSource(const Source& source) const; unsigned int _sourcesTotal() const; unsigned int _sourcesPending() const; unsigned int _sourcesError() const; unsigned int _sourcesSuccess() const; private: mutable std::mutex mutex; std::filesystem::path destination; std::string target; std::shared_ptr taskManager; std::unique_ptr root; std::string librariesPath; Sources knownSources; Sources successSources; SourcesQueue pendingSources; Downloads downloadingSources; Components readingSources; Components buildingSources; };