Flux sinks and image writers are routed through Config.

This commit is contained in:
dg
2023-05-12 23:47:09 +00:00
parent dcfcc6271c
commit 17b29b1626
5 changed files with 42 additions and 9 deletions

View File

@@ -3,7 +3,9 @@
#include "lib/proto.h"
#include "lib/logger.h"
#include "lib/utils.h"
#include "lib/imagewriter/imagewriter.h"
#include "lib/imagereader/imagereader.h"
#include "lib/fluxsink/fluxsink.h"
#include "lib/fluxsource/fluxsource.h"
#include <fstream>
#include <google/protobuf/text_format.h>
@@ -34,6 +36,7 @@ Config::operator ConfigProto&() const
void Config::clear()
{
_fluxSource.reset();
_verificationFluxSource.reset();
_imageReader.reset();
(*this)->Clear();
}
@@ -450,3 +453,29 @@ std::shared_ptr<ImageReader>& Config::getImageReader()
}
return _imageReader;
}
bool Config::hasFluxSink() const
{
return (*this)->flux_sink().type() != FluxSinkProto::NOT_SET;
}
std::unique_ptr<FluxSink> Config::getFluxSink()
{
if (!hasFluxSink())
error("no flux sink configured");
return FluxSink::create((*this)->flux_sink());
}
bool Config::hasImageWriter() const
{
return (*this)->image_writer().type() != ImageWriterProto::NOT_SET;
}
std::unique_ptr<ImageWriter> Config::getImageWriter()
{
if (!hasImageWriter())
error("no image writer configured");
return ImageWriter::create((*this)->image_writer());
}

View File

@@ -7,7 +7,9 @@
class ConfigProto;
class OptionProto;
class FluxSource;
class FluxSink;
class ImageReader;
class ImageWriter;
class OptionException : public ErrorException
{
@@ -87,6 +89,13 @@ public:
bool hasVerificationFluxSource() const;
std::shared_ptr<FluxSource>& getVerificationFluxSource();
/* Create the sinks: these are not cached. */
bool hasFluxSink() const;
std::unique_ptr<FluxSink> getFluxSink();
bool hasImageWriter() const;
std::unique_ptr<ImageWriter> getImageWriter();
private:
std::shared_ptr<FluxSource> _fluxSource;
std::shared_ptr<ImageReader> _imageReader;

View File

@@ -70,8 +70,7 @@ int mainRead(int argc, const char* argv[])
auto& fluxSource = globalConfig().getFluxSource();
std::unique_ptr<Decoder> decoder(
Decoder::create(globalConfig()->decoder()));
std::unique_ptr<ImageWriter> writer(
ImageWriter::create(globalConfig()->image_writer()));
auto writer = globalConfig().getImageWriter();
readDiskCommand(*fluxSource, *decoder, *writer);

View File

@@ -72,8 +72,7 @@ int mainWrite(int argc, const char* argv[])
std::unique_ptr<Encoder> encoder(
Encoder::create(globalConfig()->encoder()));
std::unique_ptr<FluxSink> fluxSink(
FluxSink::create(globalConfig()->flux_sink()));
auto fluxSink = globalConfig().getFluxSink();
std::unique_ptr<Decoder> decoder;
std::shared_ptr<FluxSource> verificationFluxSource;

View File

@@ -148,8 +148,7 @@ public:
auto image =
globalConfig().getImageReader()->readMappedImage();
auto encoder = Encoder::create(globalConfig()->encoder());
auto fluxSink =
FluxSink::create(globalConfig()->flux_sink());
auto fluxSink = globalConfig().getFluxSink();
std::unique_ptr<Decoder> decoder;
std::shared_ptr<FluxSource> verificationFluxSource;
@@ -265,9 +264,7 @@ public:
QueueJob(
[image, this]()
{
auto imageWriter =
ImageWriter::create(globalConfig()->image_writer());
imageWriter->writeMappedImage(*image);
globalConfig().getImageWriter()->writeMappedImage(*image);
});
}
catch (const ErrorException& e)