mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Switch from using a oneof to an explicit enum for the flux source/sink
configurations, as this allows default options for multiple source/sink types.
This commit is contained in:
@@ -17,93 +17,128 @@ static bool ends_with(const std::string& value, const std::string& ending)
|
||||
|
||||
std::unique_ptr<FluxSource> FluxSource::create(const FluxSourceProto& config)
|
||||
{
|
||||
switch (config.source_case())
|
||||
{
|
||||
case FluxSourceProto::kDrive:
|
||||
return createHardwareFluxSource(config.drive());
|
||||
switch (config.type())
|
||||
{
|
||||
case FluxSourceProto::DRIVE:
|
||||
return createHardwareFluxSource(config.drive());
|
||||
|
||||
case FluxSourceProto::kErase:
|
||||
return createEraseFluxSource(config.erase());
|
||||
case FluxSourceProto::ERASE:
|
||||
return createEraseFluxSource(config.erase());
|
||||
|
||||
case FluxSourceProto::kKryoflux:
|
||||
return createKryofluxFluxSource(config.kryoflux());
|
||||
case FluxSourceProto::KRYOFLUX:
|
||||
return createKryofluxFluxSource(config.kryoflux());
|
||||
|
||||
case FluxSourceProto::kTestPattern:
|
||||
return createTestPatternFluxSource(config.test_pattern());
|
||||
case FluxSourceProto::TEST_PATTERN:
|
||||
return createTestPatternFluxSource(config.test_pattern());
|
||||
|
||||
case FluxSourceProto::kScp:
|
||||
return createScpFluxSource(config.scp());
|
||||
case FluxSourceProto::SCP:
|
||||
return createScpFluxSource(config.scp());
|
||||
|
||||
case FluxSourceProto::kCwf:
|
||||
return createCwfFluxSource(config.cwf());
|
||||
case FluxSourceProto::CWF:
|
||||
return createCwfFluxSource(config.cwf());
|
||||
|
||||
case FluxSourceProto::kFl2:
|
||||
return createFl2FluxSource(config.fl2());
|
||||
case FluxSourceProto::FLUX:
|
||||
return createFl2FluxSource(config.fl2());
|
||||
|
||||
default:
|
||||
Error() << "bad input disk configuration";
|
||||
return std::unique_ptr<FluxSource>();
|
||||
}
|
||||
default:
|
||||
Error() << "bad input disk configuration";
|
||||
return std::unique_ptr<FluxSource>();
|
||||
}
|
||||
}
|
||||
|
||||
void FluxSource::updateConfigForFilename(FluxSourceProto* proto, const std::string& filename)
|
||||
void FluxSource::updateConfigForFilename(
|
||||
FluxSourceProto* proto, const std::string& filename)
|
||||
{
|
||||
|
||||
static const std::vector<std::pair<std::regex, std::function<void(const std::string&, FluxSourceProto*)>>> formats =
|
||||
{
|
||||
{ std::regex("^(.*\\.a2r)$"), [](auto& s, auto* proto) { }},
|
||||
{ std::regex("^(.*\\.flux)$"), [](auto& s, auto* proto) { proto->mutable_fl2()->set_filename(s); }},
|
||||
{ std::regex("^(.*\\.scp)$"), [](auto& s, auto* proto) { proto->mutable_scp()->set_filename(s); }},
|
||||
{ std::regex("^(.*\\.cwf)$"), [](auto& s, auto* proto) { proto->mutable_cwf()->set_filename(s); }},
|
||||
{ std::regex("^erase:$"), [](auto& s, auto* proto) { proto->mutable_erase(); }},
|
||||
{ std::regex("^kryoflux:(.*)$"), [](auto& s, auto* proto) { proto->mutable_kryoflux()->set_directory(s); }},
|
||||
{ std::regex("^testpattern:(.*)"), [](auto& s, auto* proto) { proto->mutable_test_pattern(); }},
|
||||
{ std::regex("^drive:(.*)"), [](auto& s, auto* proto) { proto->mutable_drive(); config.mutable_drive()->set_drive(std::stoi(s)); }},
|
||||
};
|
||||
static const std::vector<std::pair<std::regex,
|
||||
std::function<void(const std::string&, FluxSourceProto*)>>>
|
||||
formats = {
|
||||
{std::regex("^(.*\\.flux)$"),
|
||||
[](auto& s, auto* proto)
|
||||
{
|
||||
proto->set_type(FluxSourceProto::FLUX);
|
||||
proto->mutable_fl2()->set_filename(s);
|
||||
}},
|
||||
{std::regex("^(.*\\.scp)$"),
|
||||
[](auto& s, auto* proto)
|
||||
{
|
||||
proto->set_type(FluxSourceProto::SCP);
|
||||
proto->mutable_scp()->set_filename(s);
|
||||
}},
|
||||
{std::regex("^(.*\\.cwf)$"),
|
||||
[](auto& s, auto* proto)
|
||||
{
|
||||
proto->set_type(FluxSourceProto::CWF);
|
||||
proto->mutable_cwf()->set_filename(s);
|
||||
}},
|
||||
{std::regex("^erase:$"),
|
||||
[](auto& s, auto* proto)
|
||||
{
|
||||
proto->set_type(FluxSourceProto::ERASE);
|
||||
}},
|
||||
{std::regex("^kryoflux:(.*)$"),
|
||||
[](auto& s, auto* proto)
|
||||
{
|
||||
proto->set_type(FluxSourceProto::KRYOFLUX);
|
||||
proto->mutable_kryoflux()->set_directory(s);
|
||||
}},
|
||||
{std::regex("^testpattern:(.*)"),
|
||||
[](auto& s, auto* proto)
|
||||
{
|
||||
proto->set_type(FluxSourceProto::TEST_PATTERN);
|
||||
}},
|
||||
{std::regex("^drive:(.*)"),
|
||||
[](auto& s, auto* proto)
|
||||
{
|
||||
proto->set_type(FluxSourceProto::DRIVE);
|
||||
config.mutable_drive()->set_drive(std::stoi(s));
|
||||
}},
|
||||
};
|
||||
|
||||
for (const auto& it : formats)
|
||||
{
|
||||
std::smatch match;
|
||||
if (std::regex_match(filename, match, it.first))
|
||||
{
|
||||
it.second(match[1], proto);
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (const auto& it : formats)
|
||||
{
|
||||
std::smatch match;
|
||||
if (std::regex_match(filename, match, it.first))
|
||||
{
|
||||
it.second(match[1], proto);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Error() << fmt::format("unrecognised flux filename '{}'", filename);
|
||||
Error() << fmt::format("unrecognised flux filename '{}'", filename);
|
||||
}
|
||||
|
||||
class TrivialFluxSourceIterator : public FluxSourceIterator
|
||||
{
|
||||
public:
|
||||
TrivialFluxSourceIterator(TrivialFluxSource* fluxSource, int track, int head):
|
||||
_fluxSource(fluxSource),
|
||||
_track(track),
|
||||
_head(head)
|
||||
{}
|
||||
TrivialFluxSourceIterator(
|
||||
TrivialFluxSource* fluxSource, int track, int head):
|
||||
_fluxSource(fluxSource),
|
||||
_track(track),
|
||||
_head(head)
|
||||
{
|
||||
}
|
||||
|
||||
bool hasNext() const override
|
||||
{
|
||||
return !!_fluxSource;
|
||||
}
|
||||
bool hasNext() const override
|
||||
{
|
||||
return !!_fluxSource;
|
||||
}
|
||||
|
||||
std::unique_ptr<const Fluxmap> next() override
|
||||
{
|
||||
auto fluxmap = _fluxSource->readSingleFlux(_track, _head);
|
||||
_fluxSource = nullptr;
|
||||
return fluxmap;
|
||||
}
|
||||
std::unique_ptr<const Fluxmap> next() override
|
||||
{
|
||||
auto fluxmap = _fluxSource->readSingleFlux(_track, _head);
|
||||
_fluxSource = nullptr;
|
||||
return fluxmap;
|
||||
}
|
||||
|
||||
private:
|
||||
TrivialFluxSource* _fluxSource;
|
||||
int _track;
|
||||
int _head;
|
||||
TrivialFluxSource* _fluxSource;
|
||||
int _track;
|
||||
int _head;
|
||||
};
|
||||
|
||||
std::unique_ptr<FluxSourceIterator> TrivialFluxSource::readFlux(int track, int head)
|
||||
std::unique_ptr<FluxSourceIterator> TrivialFluxSource::readFlux(
|
||||
int track, int head)
|
||||
{
|
||||
return std::make_unique<TrivialFluxSourceIterator>(this, track, head);
|
||||
return std::make_unique<TrivialFluxSourceIterator>(this, track, head);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user