66 lines
1.6 KiB
C++
66 lines
1.6 KiB
C++
#include "component.h"
|
|
|
|
#include <array>
|
|
#include <string_view>
|
|
|
|
constexpr std::array<std::string_view, Component::done + 1> stringStates {
|
|
"initial",
|
|
"reading",
|
|
"ready",
|
|
"building",
|
|
"done"
|
|
};
|
|
|
|
Component::Component(
|
|
const std::filesystem::path& path,
|
|
const std::shared_ptr<Collection>& collection,
|
|
const std::shared_ptr<TaskManager>& taskManager,
|
|
const std::shared_ptr<Logger>& logger
|
|
):
|
|
Loggable(logger),
|
|
collection(collection),
|
|
taskManager(taskManager),
|
|
location(path)
|
|
{}
|
|
|
|
void Component::read() {
|
|
if (state != initial)
|
|
throw WrongState(state, "read");
|
|
|
|
try {
|
|
collection->addSource(location);
|
|
} catch (const Collection::DuplicateSource e) {
|
|
state = error;
|
|
throw e;
|
|
}
|
|
state = reading;
|
|
taskManager->queue(std::bind(&Component::performRead, this));
|
|
}
|
|
|
|
void Component::build(const std::filesystem::path& destination, const std::string& target) {
|
|
if (state != ready)
|
|
throw WrongState(state, "build");
|
|
|
|
state = building;
|
|
taskManager->queue(std::bind(&Component::performBuild, this, destination, target));
|
|
}
|
|
|
|
void Component::performRead() {
|
|
}
|
|
|
|
void Component::performBuild(std::filesystem::path destination, std::string target) {
|
|
}
|
|
|
|
Component::State Component::getState() const {
|
|
return state;
|
|
}
|
|
|
|
Component::Type Component::getType() const {
|
|
return type;
|
|
}
|
|
|
|
Component::WrongState::WrongState(State state, const std::string& action):
|
|
std::runtime_error("An attempt to perform action \"" + action
|
|
+ "\" on a wrong state \"" + stringStates[state].data() + '\"')
|
|
{}
|