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:
@@ -9,24 +9,24 @@
|
||||
|
||||
std::unique_ptr<FluxSink> FluxSink::create(const FluxSinkProto& config)
|
||||
{
|
||||
switch (config.dest_case())
|
||||
switch (config.type())
|
||||
{
|
||||
case FluxSinkProto::kDrive:
|
||||
case FluxSinkProto::DRIVE:
|
||||
return createHardwareFluxSink(config.drive());
|
||||
|
||||
case FluxSinkProto::kA2R:
|
||||
case FluxSinkProto::A2R:
|
||||
return createA2RFluxSink(config.a2r());
|
||||
|
||||
case FluxSinkProto::kAu:
|
||||
case FluxSinkProto::AU:
|
||||
return createAuFluxSink(config.au());
|
||||
|
||||
case FluxSinkProto::kVcd:
|
||||
case FluxSinkProto::VCD:
|
||||
return createVcdFluxSink(config.vcd());
|
||||
|
||||
case FluxSinkProto::kScp:
|
||||
case FluxSinkProto::SCP:
|
||||
return createScpFluxSink(config.scp());
|
||||
|
||||
case FluxSinkProto::kFl2:
|
||||
case FluxSinkProto::FLUX:
|
||||
return createFl2FluxSink(config.fl2());
|
||||
|
||||
default:
|
||||
@@ -35,16 +35,48 @@ std::unique_ptr<FluxSink> FluxSink::create(const FluxSinkProto& config)
|
||||
}
|
||||
}
|
||||
|
||||
void FluxSink::updateConfigForFilename(FluxSinkProto* proto, const std::string& filename)
|
||||
void FluxSink::updateConfigForFilename(
|
||||
FluxSinkProto* proto, const std::string& filename)
|
||||
{
|
||||
static const std::vector<std::pair<std::regex, std::function<void(const std::string&, FluxSinkProto*)>>> formats =
|
||||
static const std::vector<std::pair<std::regex,
|
||||
std::function<void(const std::string&, FluxSinkProto*)>>>
|
||||
formats = {
|
||||
{std::regex("^(.*\\.a2r)$"),
|
||||
[](auto& s, auto* proto)
|
||||
{
|
||||
{ std::regex("^(.*\\.a2r)$"), [](auto& s, auto* proto) { proto->mutable_a2r()->set_filename(s); }},
|
||||
{ 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("^vcd:(.*)$"), [](auto& s, auto* proto) { proto->mutable_vcd()->set_directory(s); }},
|
||||
{ std::regex("^au:(.*)$"), [](auto& s, auto* proto) { proto->mutable_au()->set_directory(s); }},
|
||||
{ std::regex("^drive:(.*)"), [](auto& s, auto* proto) { proto->mutable_drive(); config.mutable_drive()->set_drive(std::stoi(s)); }},
|
||||
proto->set_type(FluxSinkProto::A2R);
|
||||
proto->mutable_a2r()->set_filename(s);
|
||||
}},
|
||||
{std::regex("^(.*\\.flux)$"),
|
||||
[](auto& s, auto* proto)
|
||||
{
|
||||
proto->set_type(FluxSinkProto::FLUX);
|
||||
proto->mutable_fl2()->set_filename(s);
|
||||
}},
|
||||
{std::regex("^(.*\\.scp)$"),
|
||||
[](auto& s, auto* proto)
|
||||
{
|
||||
proto->set_type(FluxSinkProto::SCP);
|
||||
proto->mutable_scp()->set_filename(s);
|
||||
}},
|
||||
{std::regex("^vcd:(.*)$"),
|
||||
[](auto& s, auto* proto)
|
||||
{
|
||||
proto->set_type(FluxSinkProto::VCD);
|
||||
proto->mutable_vcd()->set_directory(s);
|
||||
}},
|
||||
{std::regex("^au:(.*)$"),
|
||||
[](auto& s, auto* proto)
|
||||
{
|
||||
proto->set_type(FluxSinkProto::AU);
|
||||
proto->mutable_au()->set_directory(s);
|
||||
}},
|
||||
{std::regex("^drive:(.*)"),
|
||||
[](auto& s, auto* proto)
|
||||
{
|
||||
proto->set_type(FluxSinkProto::DRIVE);
|
||||
config.mutable_drive()->set_drive(std::stoi(s));
|
||||
}},
|
||||
};
|
||||
|
||||
for (const auto& it : formats)
|
||||
@@ -59,5 +91,3 @@ void FluxSink::updateConfigForFilename(FluxSinkProto* proto, const std::string&
|
||||
|
||||
Error() << fmt::format("unrecognised flux filename '{}'", filename);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,15 +27,25 @@ message Fl2FluxSinkProto {
|
||||
optional string filename = 1 [default = "flux.fl2", (help) = ".fl2 file to write to"];
|
||||
}
|
||||
|
||||
// Next: 9
|
||||
// Next: 10
|
||||
message FluxSinkProto {
|
||||
oneof dest {
|
||||
HardwareFluxSinkProto drive = 2;
|
||||
A2RFluxSinkProto a2r = 8;
|
||||
AuFluxSinkProto au = 3;
|
||||
VcdFluxSinkProto vcd = 4;
|
||||
ScpFluxSinkProto scp = 5;
|
||||
Fl2FluxSinkProto fl2 = 6;
|
||||
}
|
||||
enum FluxSinkType {
|
||||
NOT_SET = 0;
|
||||
DRIVE = 1;
|
||||
A2R = 2;
|
||||
AU = 3;
|
||||
VCD = 4;
|
||||
SCP = 5;
|
||||
FLUX = 6;
|
||||
}
|
||||
|
||||
optional FluxSinkType type = 9 [default = NOT_SET, (help) = "flux sink type"];
|
||||
|
||||
optional HardwareFluxSinkProto drive = 2;
|
||||
optional A2RFluxSinkProto a2r = 8;
|
||||
optional AuFluxSinkProto au = 3;
|
||||
optional VcdFluxSinkProto vcd = 4;
|
||||
optional ScpFluxSinkProto scp = 5;
|
||||
optional Fl2FluxSinkProto fl2 = 6;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,27 +17,27 @@ 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())
|
||||
switch (config.type())
|
||||
{
|
||||
case FluxSourceProto::kDrive:
|
||||
case FluxSourceProto::DRIVE:
|
||||
return createHardwareFluxSource(config.drive());
|
||||
|
||||
case FluxSourceProto::kErase:
|
||||
case FluxSourceProto::ERASE:
|
||||
return createEraseFluxSource(config.erase());
|
||||
|
||||
case FluxSourceProto::kKryoflux:
|
||||
case FluxSourceProto::KRYOFLUX:
|
||||
return createKryofluxFluxSource(config.kryoflux());
|
||||
|
||||
case FluxSourceProto::kTestPattern:
|
||||
case FluxSourceProto::TEST_PATTERN:
|
||||
return createTestPatternFluxSource(config.test_pattern());
|
||||
|
||||
case FluxSourceProto::kScp:
|
||||
case FluxSourceProto::SCP:
|
||||
return createScpFluxSource(config.scp());
|
||||
|
||||
case FluxSourceProto::kCwf:
|
||||
case FluxSourceProto::CWF:
|
||||
return createCwfFluxSource(config.cwf());
|
||||
|
||||
case FluxSourceProto::kFl2:
|
||||
case FluxSourceProto::FLUX:
|
||||
return createFl2FluxSource(config.fl2());
|
||||
|
||||
default:
|
||||
@@ -46,19 +46,53 @@ std::unique_ptr<FluxSource> FluxSource::create(const FluxSourceProto& config)
|
||||
}
|
||||
}
|
||||
|
||||
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 =
|
||||
static const std::vector<std::pair<std::regex,
|
||||
std::function<void(const std::string&, FluxSourceProto*)>>>
|
||||
formats = {
|
||||
{std::regex("^(.*\\.flux)$"),
|
||||
[](auto& s, auto* proto)
|
||||
{
|
||||
{ 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)); }},
|
||||
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)
|
||||
@@ -77,11 +111,13 @@ void FluxSource::updateConfigForFilename(FluxSourceProto* proto, const std::stri
|
||||
class TrivialFluxSourceIterator : public FluxSourceIterator
|
||||
{
|
||||
public:
|
||||
TrivialFluxSourceIterator(TrivialFluxSource* fluxSource, int track, int head):
|
||||
TrivialFluxSourceIterator(
|
||||
TrivialFluxSource* fluxSource, int track, int head):
|
||||
_fluxSource(fluxSource),
|
||||
_track(track),
|
||||
_head(head)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
bool hasNext() const override
|
||||
{
|
||||
@@ -101,9 +137,8 @@ private:
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -30,15 +30,27 @@ message Fl2FluxSourceProto {
|
||||
(help) = ".fl2 file to read flux from"];
|
||||
}
|
||||
|
||||
// NEXT: 10
|
||||
message FluxSourceProto {
|
||||
oneof source {
|
||||
HardwareFluxSourceProto drive = 2;
|
||||
TestPatternFluxSourceProto test_pattern = 3;
|
||||
EraseFluxSourceProto erase = 4;
|
||||
KryofluxFluxSourceProto kryoflux = 5;
|
||||
ScpFluxSourceProto scp = 6;
|
||||
CwfFluxSourceProto cwf = 7;
|
||||
Fl2FluxSourceProto fl2 = 8;
|
||||
}
|
||||
enum FluxSourceType {
|
||||
NOT_SET = 0;
|
||||
DRIVE = 1;
|
||||
TEST_PATTERN = 2;
|
||||
ERASE = 3;
|
||||
KRYOFLUX = 4;
|
||||
SCP = 5;
|
||||
CWF = 6;
|
||||
FLUX = 7;
|
||||
}
|
||||
|
||||
optional FluxSourceType type = 9 [default = NOT_SET, (help) = "flux source type"];
|
||||
|
||||
optional HardwareFluxSourceProto drive = 2;
|
||||
optional TestPatternFluxSourceProto test_pattern = 3;
|
||||
optional EraseFluxSourceProto erase = 4;
|
||||
optional KryofluxFluxSourceProto kryoflux = 5;
|
||||
optional ScpFluxSourceProto scp = 6;
|
||||
optional CwfFluxSourceProto cwf = 7;
|
||||
optional Fl2FluxSourceProto fl2 = 8;
|
||||
}
|
||||
|
||||
|
||||
@@ -218,13 +218,13 @@ std::unique_ptr<Filesystem> Filesystem::createFilesystemFromConfig()
|
||||
std::shared_ptr<Decoder> decoder;
|
||||
std::shared_ptr<FluxSink> fluxSink;
|
||||
std::shared_ptr<Encoder> encoder;
|
||||
if (config.flux_source().source_case() !=
|
||||
FluxSourceProto::SOURCE_NOT_SET)
|
||||
if (config.flux_source().type() !=
|
||||
FluxSourceProto::NOT_SET)
|
||||
{
|
||||
fluxSource = FluxSource::create(config.flux_source());
|
||||
decoder = Decoder::create(config.decoder());
|
||||
}
|
||||
if (config.flux_sink().has_drive())
|
||||
if (config.flux_sink().type() == FluxSinkProto::DRIVE)
|
||||
{
|
||||
fluxSink = FluxSink::create(config.flux_sink());
|
||||
encoder = Encoder::create(config.encoder());
|
||||
|
||||
@@ -211,10 +211,10 @@ static void draw_x_graticules(Agg2D& painter, double x1, double y1, double x2, d
|
||||
|
||||
int mainAnalyseDriveResponse(int argc, const char* argv[])
|
||||
{
|
||||
config.mutable_flux_source()->mutable_drive();
|
||||
config.mutable_flux_source()->set_type(FluxSourceProto::DRIVE);
|
||||
flags.parseFlagsWithConfigFiles(argc, argv, {});
|
||||
|
||||
if (!config.flux_sink().has_drive())
|
||||
if (config.flux_sink().type() != FluxSinkProto::DRIVE)
|
||||
Error() << "this only makes sense with a real disk drive";
|
||||
|
||||
usbSetDrive(config.drive().drive(),
|
||||
|
||||
@@ -210,7 +210,7 @@ static nanoseconds_t guessClock(const Fluxmap& fluxmap)
|
||||
|
||||
int mainInspect(int argc, const char* argv[])
|
||||
{
|
||||
config.mutable_flux_source()->mutable_drive();
|
||||
config.mutable_flux_source()->set_type(FluxSourceProto::DRIVE);
|
||||
flags.parseFlagsWithConfigFiles(argc, argv, {});
|
||||
|
||||
std::unique_ptr<FluxSource> fluxSource(FluxSource::create(config.flux_source()));
|
||||
|
||||
@@ -61,10 +61,10 @@ int mainRawRead(int argc, const char* argv[])
|
||||
|
||||
if (argc == 1)
|
||||
showProfiles("rawread", formats);
|
||||
config.mutable_flux_source()->mutable_drive();
|
||||
config.mutable_flux_source()->set_type(FluxSourceProto::DRIVE);
|
||||
flags.parseFlagsWithConfigFiles(argc, argv, formats);
|
||||
|
||||
if (config.flux_sink().has_drive())
|
||||
if (config.flux_sink().type() == FluxSinkProto::DRIVE)
|
||||
Error() << "you can't use rawread to write to hardware";
|
||||
|
||||
std::unique_ptr<FluxSource> fluxSource(FluxSource::create(config.flux_source()));
|
||||
|
||||
@@ -54,7 +54,7 @@ static ActionFlag eraseFlag(
|
||||
"erases the destination",
|
||||
[]()
|
||||
{
|
||||
config.mutable_flux_source()->mutable_erase();
|
||||
config.mutable_flux_source()->set_type(FluxSourceProto::ERASE);
|
||||
});
|
||||
|
||||
int mainRawWrite(int argc, const char* argv[])
|
||||
@@ -64,10 +64,10 @@ int mainRawWrite(int argc, const char* argv[])
|
||||
|
||||
if (argc == 1)
|
||||
showProfiles("rawwrite", formats);
|
||||
config.mutable_flux_sink()->mutable_drive();
|
||||
config.mutable_flux_sink()->set_type(FluxSinkProto::DRIVE);
|
||||
flags.parseFlagsWithConfigFiles(argc, argv, formats);
|
||||
|
||||
if (config.flux_source().has_drive())
|
||||
if (config.flux_source().type() == FluxSourceProto::DRIVE)
|
||||
Error() << "you can't use rawwrite to read from hardware";
|
||||
|
||||
std::unique_ptr<FluxSource> fluxSource(FluxSource::create(config.flux_source()));
|
||||
|
||||
@@ -67,7 +67,7 @@ int mainRead(int argc, const char* argv[])
|
||||
{
|
||||
if (argc == 1)
|
||||
showProfiles("read", formats);
|
||||
config.mutable_flux_source()->mutable_drive();
|
||||
config.mutable_flux_source()->set_type(FluxSourceProto::DRIVE);
|
||||
flags.parseFlagsWithConfigFiles(argc, argv, formats);
|
||||
|
||||
if (config.decoder().copy_flux_to().has_drive())
|
||||
|
||||
@@ -20,7 +20,7 @@ int mainRpm(int argc, const char* argv[])
|
||||
{
|
||||
flags.parseFlagsWithConfigFiles(argc, argv, {});
|
||||
|
||||
if (!config.flux_source().has_drive())
|
||||
if (!config.flux_source().type() != FluxSourceProto::DRIVE)
|
||||
Error() << "this only makes sense with a real disk drive";
|
||||
|
||||
usbSetDrive(config.drive().drive(), false, config.drive().index_mode());
|
||||
|
||||
@@ -27,7 +27,7 @@ int mainSeek(int argc, const char* argv[])
|
||||
{
|
||||
flags.parseFlagsWithConfigFiles(argc, argv, {});
|
||||
|
||||
if (!config.flux_source().has_drive())
|
||||
if (config.flux_source().type() != FluxSourceProto::DRIVE)
|
||||
Error() << "this only makes sense with a real disk drive";
|
||||
|
||||
usbSetDrive(config.drive().drive(), false, config.drive().index_mode());
|
||||
|
||||
@@ -67,9 +67,9 @@ int mainWrite(int argc, const char* argv[])
|
||||
{
|
||||
if (argc == 1)
|
||||
showProfiles("write", formats);
|
||||
config.mutable_flux_sink()->mutable_drive();
|
||||
config.mutable_flux_sink()->set_type(FluxSinkProto::DRIVE);
|
||||
if (verify)
|
||||
config.mutable_flux_source()->mutable_drive();
|
||||
config.mutable_flux_source()->set_type(FluxSourceProto::DRIVE);
|
||||
flags.parseFlagsWithConfigFiles(argc, argv, formats);
|
||||
|
||||
std::unique_ptr<ImageReader> reader(ImageReader::create(config.image_reader()));
|
||||
@@ -83,7 +83,7 @@ int mainWrite(int argc, const char* argv[])
|
||||
decoder = Decoder::create(config.decoder());
|
||||
|
||||
std::unique_ptr<FluxSource> fluxSource;
|
||||
if (verify && config.has_flux_source() && config.flux_source().has_drive())
|
||||
if (verify && (config.flux_source().type() == FluxSourceProto::DRIVE))
|
||||
fluxSource = FluxSource::create(config.flux_source());
|
||||
|
||||
writeDiskCommand(*image, *encoder, *fluxSink, decoder.get(), fluxSource.get());
|
||||
|
||||
Reference in New Issue
Block a user