Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
generators report supported interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
vaclavblazek committed Apr 8, 2019
1 parent fda2e52 commit 01517e7
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 14 deletions.
28 changes: 20 additions & 8 deletions mapproxy/src/mapproxy/generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &params);

static DefinitionBase::pointer definition(const Resource::Generator &type);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -200,7 +218,7 @@ class Generator : boost::noncopyable {
bool updatedSince(std::uint64_t timestamp) const;

protected:
Generator(const Params &params);
Generator(const Params &params, const Properties &props = Properties());

void makeReady();
bool fresh() const { return fresh_; }
Expand Down Expand Up @@ -254,6 +272,7 @@ class Generator : boost::noncopyable {

const GeneratorFinder *generatorFinder_;
Config config_;
Properties properties_;
Resource resource_;
Resource savedResource_;
bool fresh_;
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 16 additions & 1 deletion mapproxy/src/mapproxy/generator/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -101,8 +102,9 @@ Generator::pointer Generator::create(const Params &params)
throw;
}

Generator::Generator(const Params &params)
Generator::Generator(const Params &params, const Properties &properties)
: generatorFinder_(params.generatorFinder), config_(params.config)
, properties_(properties)
, resource_(params.resource), savedResource_(params.resource)
, fresh_(false), system_(params.system)
, changeEnforced_(false)
Expand Down Expand Up @@ -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<NotFound>
("WMTS interface disabled, no <wmts> extension in "
"reference frame <%s> or not supported by <%s> driver."
, referenceFrameId(), resource().generator);
}

return generateFile_impl(fileInfo, sink);
}
16 changes: 15 additions & 1 deletion mapproxy/src/mapproxy/generator/surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ namespace vts = vtslibs::vts;

namespace generator {

namespace {

Generator::Properties
terrainSupport(const Generator::Params &params)
{
Generator::Properties props;
if (!params.resource.referenceFrame->findExtension<vre::Tms>()) {
return props;
}
return props.support(GeneratorInterface::Interface::terrain);
}

} // namespace

fs::path SurfaceBase::filePath(vts::File fileType) const
{
switch (fileType) {
Expand All @@ -94,7 +108,7 @@ fs::path SurfaceBase::filePath(vts::File fileType) const
}

SurfaceBase::SurfaceBase(const Params &params)
: Generator(params)
: Generator(params, terrainSupport(params))
, definition_(resource().definition<Definition>())
, tms_(params.resource.referenceFrame->findExtension<vre::Tms>())
{}
Expand Down
20 changes: 18 additions & 2 deletions mapproxy/src/mapproxy/generator/tms-raster-base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,27 @@ namespace uq = utility::query;

namespace generator {

namespace {
Generator::Properties
wmtsSupport(const Generator::Params &params
, const boost::optional<RasterFormat> &format)
{
Generator::Properties props;
if (!format) { return props; }
if (!params.resource.referenceFrame->findExtension<vre::Wmts>()) {
return props;
}
return props.support(GeneratorInterface::Interface::wmts);
}

} // namespace

TmsRasterBase
::TmsRasterBase(const Params &params
, const boost::optional<RasterFormat> &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<vre::Wmts>()
: nullptr)
{}
Expand Down
2 changes: 1 addition & 1 deletion mapproxy/src/mapproxy/generator/tms-raster-remote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
23 changes: 22 additions & 1 deletion mapproxy/src/mapproxy/resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<GeneratorInterface::Interface>
(static_cast<std::uint8_t>(l) | static_cast<std::uint8_t>(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<GeneratorInterface::Interface>
(static_cast<std::uint8_t>(l)
& static_cast<std::uint8_t>(r));
}

#endif // mapproxy_resource_hpp_included_

0 comments on commit 01517e7

Please sign in to comment.