mason/src/collection.h

76 lines
2.2 KiB
C++

#pragma once
#include <string>
#include <filesystem>
#include <map>
#include <set>
#include <exception>
#include <string_view>
#include <regex>
#include <mutex>
#include <queue>
#include "loggable.h"
#include "component.h"
#include "download.h"
#include "taskmanager.h"
#include "source.h"
class Collection : protected Loggable {
using Sources = std::set<Source>;
using SourcesQueue = std::queue<Source>;
using Downloads = std::map<Source, std::unique_ptr<Download>>;
using Components = std::map<Source, std::unique_ptr<Component>>;
public:
Collection(
const std::filesystem::path& location,
const std::filesystem::path& destination,
const std::string& target,
const std::shared_ptr<Logger>& logger,
const std::shared_ptr<TaskManager>& 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> taskManager;
std::unique_ptr<Component> root;
std::string librariesPath;
Sources knownSources;
Sources successSources;
SourcesQueue pendingSources;
Downloads downloadingSources;
Components readingSources;
Components buildingSources;
};