#ifndef FLUXSOURCE_H #define FLUXSOURCE_H #include "lib/config/flags.h" #include "lib/data/locations.h" #include "lib/config/config.pb.h" class A2rFluxSourceProto; class CwfFluxSourceProto; class DiskFlux; class EraseFluxSourceProto; class Fl2FluxSourceProto; class FluxSourceProto; class FluxSpec; class Fluxmap; class HardwareFluxSourceProto; class KryofluxFluxSourceProto; class ScpFluxSourceProto; class TestPatternFluxSourceProto; class FlxFluxSourceProto; class Config; class FluxSourceIterator { public: virtual ~FluxSourceIterator() {} virtual bool hasNext() const = 0; virtual std::unique_ptr next() = 0; }; class FluxSource { public: virtual ~FluxSource() {} private: static std::unique_ptr createA2rFluxSource( const A2rFluxSourceProto& config); static std::unique_ptr createCwfFluxSource( const CwfFluxSourceProto& config); static std::unique_ptr createDmkFluxSource( const DmkFluxSourceProto& config); static std::unique_ptr createEraseFluxSource( const EraseFluxSourceProto& config); static std::unique_ptr createFl2FluxSource( const Fl2FluxSourceProto& config); static std::unique_ptr createFlxFluxSource( const FlxFluxSourceProto& config); static std::unique_ptr createHardwareFluxSource( const HardwareFluxSourceProto& config); static std::unique_ptr createKryofluxFluxSource( const KryofluxFluxSourceProto& config); static std::unique_ptr createScpFluxSource( const ScpFluxSourceProto& config); static std::unique_ptr createTestPatternFluxSource( const TestPatternFluxSourceProto& config); public: static std::unique_ptr createMemoryFluxSource( const DiskFlux& flux); static std::unique_ptr create(Config& config); static std::unique_ptr create(const FluxSourceProto& spec); public: /* Returns any configuration this flux source might be carrying (e.g. tpi * of the drive which made the capture). */ const ConfigProto& getExtraConfig() const { return _extraConfig; } /* Read flux from a given cylinder and head. */ virtual std::unique_ptr readFlux( int cylinder, int head) = 0; std::unique_ptr readFlux(const CylinderHead& location) { return readFlux(location.cylinder, location.head); } /* Recalibrates; seeks to cylinder 0 and ensures the head is in the right * place. */ virtual void recalibrate() {} /* Seeks to a given cylinder (without recalibrating). */ virtual void seek(int cylinder) {} /* Is this real hardware? If so, then flux can be read indefinitely (among * other things). */ virtual bool isHardware() { return false; } protected: ConfigProto _extraConfig; }; class EmptyFluxSourceIterator : public FluxSourceIterator { bool hasNext() const override { return false; } std::unique_ptr next() override { error("no flux to read"); } }; class TrivialFluxSource : public FluxSource { public: std::unique_ptr readFlux( int cylinder, int head) override; virtual std::unique_ptr readSingleFlux( int cylinder, int head) = 0; }; #endif