From 01517e77d3cff249f9de728209c8df599356008a Mon Sep 17 00:00:00 2001 From: Vaclav Blazek Date: Mon, 8 Apr 2019 17:52:24 +0200 Subject: [PATCH] generators report supported interfaces --- mapproxy/src/mapproxy/generator.hpp | 28 +++++++++++++------ mapproxy/src/mapproxy/generator/generator.cpp | 17 ++++++++++- mapproxy/src/mapproxy/generator/surface.cpp | 16 ++++++++++- .../mapproxy/generator/tms-raster-base.cpp | 20 +++++++++++-- .../mapproxy/generator/tms-raster-remote.cpp | 2 +- mapproxy/src/mapproxy/resource.hpp | 23 ++++++++++++++- 6 files changed, 92 insertions(+), 14 deletions(-) diff --git a/mapproxy/src/mapproxy/generator.hpp b/mapproxy/src/mapproxy/generator.hpp index b56ffd0..6026300 100644 --- a/mapproxy/src/mapproxy/generator.hpp +++ b/mapproxy/src/mapproxy/generator.hpp @@ -126,6 +126,23 @@ class Generator : boost::noncopyable { : resource(resource), system(false) {} }; + struct Properties { + GeneratorInterface::Interface supportedInterfaces; + + Properties(GeneratorInterface::Interface iface + = GeneratorInterface::Interface::vts) + : supportedInterfaces(iface) + {} + + Properties& support(GeneratorInterface::Interface iface) { + supportedInterfaces |= iface; return *this; + } + + bool isSupported(GeneratorInterface::Interface iface) const { + return (supportedInterfaces & iface) == iface; + } + }; + static Generator::pointer create(const Params ¶ms); static DefinitionBase::pointer definition(const Resource::Generator &type); @@ -171,6 +188,7 @@ class Generator : boost::noncopyable { const boost::filesystem::path& resourceRoot() const { return config_.resourceRoot; } + const Properties& properties() const { return properties_; } Changed changed(const Resource &resource) const; @@ -200,7 +218,7 @@ class Generator : boost::noncopyable { bool updatedSince(std::uint64_t timestamp) const; protected: - Generator(const Params ¶ms); + Generator(const Params ¶ms, const Properties &props = Properties()); void makeReady(); bool fresh() const { return fresh_; } @@ -254,6 +272,7 @@ class Generator : boost::noncopyable { const GeneratorFinder *generatorFinder_; Config config_; + Properties properties_; Resource resource_; Resource savedResource_; bool fresh_; @@ -354,13 +373,6 @@ inline vts::MapConfig Generator::mapConfig(ResourceRoot root) const return mapConfig_impl(root); } -inline Generator::Task Generator::generateFile(const FileInfo &fileInfo - , Sink sink) - const -{ - return generateFile_impl(fileInfo, sink); -} - inline Generator::pointer Generators::generator(const FileInfo &fileInfo) const { return generator(fileInfo.interface, fileInfo.resourceId); diff --git a/mapproxy/src/mapproxy/generator/generator.cpp b/mapproxy/src/mapproxy/generator/generator.cpp index de44dc4..08dc6b5 100644 --- a/mapproxy/src/mapproxy/generator/generator.cpp +++ b/mapproxy/src/mapproxy/generator/generator.cpp @@ -43,6 +43,7 @@ #include "utility/path.hpp" #include "utility/gccversion.hpp" #include "utility/time.hpp" +#include "utility/raise.hpp" #include "../error.hpp" #include "../generator.hpp" @@ -101,8 +102,9 @@ Generator::pointer Generator::create(const Params ¶ms) throw; } -Generator::Generator(const Params ¶ms) +Generator::Generator(const Params ¶ms, const Properties &properties) : generatorFinder_(params.generatorFinder), config_(params.config) + , properties_(properties) , resource_(params.resource), savedResource_(params.resource) , fresh_(false), system_(params.system) , changeEnforced_(false) @@ -1154,3 +1156,16 @@ void Generators::listResources(std::ostream &os) const { detail().listResources(os); } + +Generator::Task Generator::generateFile(const FileInfo &fileInfo, Sink sink) + const +{ + if (!properties_.isSupported(fileInfo.interface.interface)) { + utility::raise + ("WMTS interface disabled, no extension in " + "reference frame <%s> or not supported by <%s> driver." + , referenceFrameId(), resource().generator); + } + + return generateFile_impl(fileInfo, sink); +} diff --git a/mapproxy/src/mapproxy/generator/surface.cpp b/mapproxy/src/mapproxy/generator/surface.cpp index 1a29dd0..96a3eff 100644 --- a/mapproxy/src/mapproxy/generator/surface.cpp +++ b/mapproxy/src/mapproxy/generator/surface.cpp @@ -80,6 +80,20 @@ namespace vts = vtslibs::vts; namespace generator { +namespace { + +Generator::Properties +terrainSupport(const Generator::Params ¶ms) +{ + Generator::Properties props; + if (!params.resource.referenceFrame->findExtension()) { + return props; + } + return props.support(GeneratorInterface::Interface::terrain); +} + +} // namespace + fs::path SurfaceBase::filePath(vts::File fileType) const { switch (fileType) { @@ -94,7 +108,7 @@ fs::path SurfaceBase::filePath(vts::File fileType) const } SurfaceBase::SurfaceBase(const Params ¶ms) - : Generator(params) + : Generator(params, terrainSupport(params)) , definition_(resource().definition()) , tms_(params.resource.referenceFrame->findExtension()) {} diff --git a/mapproxy/src/mapproxy/generator/tms-raster-base.cpp b/mapproxy/src/mapproxy/generator/tms-raster-base.cpp index 0735877..1dea455 100644 --- a/mapproxy/src/mapproxy/generator/tms-raster-base.cpp +++ b/mapproxy/src/mapproxy/generator/tms-raster-base.cpp @@ -35,11 +35,27 @@ namespace uq = utility::query; namespace generator { +namespace { +Generator::Properties +wmtsSupport(const Generator::Params ¶ms + , const boost::optional &format) +{ + Generator::Properties props; + if (!format) { return props; } + if (!params.resource.referenceFrame->findExtension()) { + return props; + } + return props.support(GeneratorInterface::Interface::wmts); +} + +} // namespace + TmsRasterBase ::TmsRasterBase(const Params ¶ms , const boost::optional &format) - : Generator(params), format_(format ? *format : RasterFormat()) - , wmts_(format + : Generator(params, wmtsSupport(params, format)) + , format_(format ? *format : RasterFormat()) + , wmts_(properties().isSupported(GeneratorInterface::Interface::wmts) ? params.resource.referenceFrame->findExtension() : nullptr) {} diff --git a/mapproxy/src/mapproxy/generator/tms-raster-remote.cpp b/mapproxy/src/mapproxy/generator/tms-raster-remote.cpp index a7563ad..c94026e 100644 --- a/mapproxy/src/mapproxy/generator/tms-raster-remote.cpp +++ b/mapproxy/src/mapproxy/generator/tms-raster-remote.cpp @@ -152,7 +152,7 @@ vts::MapConfig TmsRasterRemote::mapConfig_impl(ResourceRoot root) } Generator::Task TmsRasterRemote::generateFile_impl(const FileInfo &fileInfo - , Sink &sink) const + , Sink &sink) const { TmsFileInfo fi(fileInfo); diff --git a/mapproxy/src/mapproxy/resource.hpp b/mapproxy/src/mapproxy/resource.hpp index 8581d6e..e9753cb 100644 --- a/mapproxy/src/mapproxy/resource.hpp +++ b/mapproxy/src/mapproxy/resource.hpp @@ -228,7 +228,7 @@ struct Resource { struct GeneratorInterface { typedef Resource::Generator::Type Type; - enum class Interface { vts, terrain, wmts }; + enum class Interface : std::uint8_t { vts = 1, terrain = 2, wmts = 3 }; Type type; Interface interface; @@ -486,4 +486,25 @@ inline bool GeneratorInterface::operator!=(const GeneratorInterface &o) const { return !(*this == o); } +inline GeneratorInterface::Interface +operator|(GeneratorInterface::Interface l, GeneratorInterface::Interface r) +{ + return static_cast + (static_cast(l) | static_cast(r)); +} + +inline GeneratorInterface::Interface& +operator|=(GeneratorInterface::Interface &l, GeneratorInterface::Interface r) +{ + return (l = l | r); +} + +inline GeneratorInterface::Interface +operator&(GeneratorInterface::Interface l, GeneratorInterface::Interface r) +{ + return static_cast + (static_cast(l) + & static_cast(r)); +} + #endif // mapproxy_resource_hpp_included_