mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Flux sinks and image writers are routed through Config.
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user