mason/src/collection.h

61 lines
1.8 KiB
C
Raw Normal View History

2023-09-17 19:34:00 +00:00
#pragma once
#include <string>
#include <filesystem>
#include <map>
#include <set>
#include <exception>
2023-09-25 20:15:24 +00:00
#include <string_view>
2023-09-26 17:36:40 +00:00
#include <regex>
#include <mutex>
2023-09-17 19:34:00 +00:00
#include "loggable.h"
#include "component.h"
2023-09-25 20:15:24 +00:00
#include "download.h"
#include "taskmanager.h"
2023-09-27 23:30:57 +00:00
class Collection : protected Loggable, public std::enable_shared_from_this<Collection> {
2023-09-25 20:15:24 +00:00
using Sources = std::set<std::string>;
using Downloads = std::map<std::string, std::unique_ptr<Download>>;
using Components = std::map<std::string, std::unique_ptr<Component>>;
2023-09-17 19:34:00 +00:00
2023-09-26 17:36:40 +00:00
public:
Collection(
2023-09-25 20:15:24 +00:00
const std::filesystem::path& destination,
const std::string& target,
const std::shared_ptr<Logger>& logger,
const std::shared_ptr<TaskManager>& taskManager
);
2023-09-17 19:34:00 +00:00
unsigned int sourcesTotal() const;
unsigned int sourcesPending() const;
unsigned int sourcesError() const;
unsigned int sourcesSuccess() const;
bool hasSource(const std::string& source) const;
void addSource(const std::string& source);
private:
2023-09-25 20:15:24 +00:00
void sourceDownaloded(const std::string& source, TaskManager::Error err);
void sourceRead(const std::string& source, TaskManager::Error err);
void sourceBuilt(const std::string& source, TaskManager::Error err);
2023-09-26 17:36:40 +00:00
static bool isRemote(const std::string& source);
2023-09-25 20:15:24 +00:00
void queueDownload(const std::string& source);
void queueRead(const std::string& source, const std::filesystem::path& location);
bool _hasSource(const std::string& source) const;
private:
mutable std::mutex mutex;
2023-09-25 20:15:24 +00:00
std::filesystem::path destination;
std::string target;
std::shared_ptr<TaskManager> taskManager;
2023-09-25 20:15:24 +00:00
Sources knownSources;
Sources successSources;
Downloads downloadingSources;
Components readingSources;
Components buildingSources;
2023-09-17 19:34:00 +00:00
};