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

Commit

Permalink
Merge branch 'metadriver'
Browse files Browse the repository at this point in the history
  • Loading branch information
vaclavblazek committed Nov 27, 2019
2 parents 01a8a5d + d39bca1 commit 7b0b772
Show file tree
Hide file tree
Showing 38 changed files with 2,191 additions and 1,049 deletions.
2 changes: 1 addition & 1 deletion externals/libgeo
6 changes: 6 additions & 0 deletions mapproxy/src/mapproxy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(mapproxy-core_SOURCES
support/mmapped/memory.hpp support/mmapped/memory-impl.hpp
support/mmapped/tileflags.hpp
support/mmapped/qtree-rasterize.hpp
support/atlas.hpp support/atlas.cpp

support/mmapped/tilesetindex.hpp support/mmapped/tilesetindex.cpp
heightfunction.hpp heightfunction.cpp
Expand All @@ -47,6 +48,7 @@ set(mapproxy-core_SOURCES
definition/surface.cpp
definition/surface-spheroid.cpp
definition/surface-dem.cpp
definition/surface-meta.hpp definition/surface-meta.cpp

definition/geodata.hpp
definition/geodata.cpp
Expand Down Expand Up @@ -128,9 +130,12 @@ set(mapproxy_SOURCES

generator.hpp
generator/generator.cpp
generator/generators.hpp generator/generators.cpp
generator/registry.hpp generator/registry.cpp
generator/factory.hpp
generator/metatile.hpp generator/metatile.cpp
generator/demregistry.hpp generator/demregistry.cpp
generator/providers.hpp

# bound layers
generator/tms-raster-base.hpp generator/tms-raster-base.cpp
Expand All @@ -146,6 +151,7 @@ set(mapproxy_SOURCES
generator/surface.hpp generator/surface.cpp
generator/surface-spheroid.hpp generator/surface-spheroid.cpp
generator/surface-dem.hpp generator/surface-dem.cpp
generator/surface-meta.hpp generator/surface-meta.cpp

# free layers
generator/geodatavectorbase.hpp generator/geodatavectorbase.cpp
Expand Down
1 change: 1 addition & 0 deletions mapproxy/src/mapproxy/definition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "definition/factory.hpp"
#include "definition/tms.hpp"
#include "definition/surface.hpp"
#include "definition/surface-meta.hpp"
#include "definition/geodata.hpp"
#include "definition/geodata-semantic.hpp"

Expand Down
97 changes: 97 additions & 0 deletions mapproxy/src/mapproxy/definition/surface-meta.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* Copyright (c) 2018 Melown Technologies SE
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#include "utility/premain.hpp"

#include "jsoncpp/json.hpp"
#include "jsoncpp/as.hpp"

#include "surface-meta.hpp"
#include "factory.hpp"

namespace resource {

constexpr char SurfaceMeta::driverName[];

namespace {

utility::PreMain register_([]() { registerDefinition<SurfaceMeta>(); });

void parseDefinition(SurfaceMeta &def, const Json::Value &value)
{
const auto &rid([](const Json::Value &item) -> Resource::Id
{
Resource::Id id;
Json::get(id.group, item, "group");
Json::get(id.id, item, "id");
return id;
});

def.surface = rid(Json::check(value["surface"], Json::objectValue));
def.tms = rid(Json::check(value["tms"], Json::objectValue));
}

void buildDefinition(Json::Value &value, const SurfaceMeta &def)
{
const auto &rid([](const Resource::Id &id) -> Json::Value
{
Json::Value value;
value["group"] = id.group;
value["id"] = id.id;
return value;
});

value["surface"] = rid(def.surface);
value["tms"] = rid(def.tms);
}

} // namespace

void SurfaceMeta::from_impl(const Json::Value &value)
{
parseDefinition(*this, value);
}

void SurfaceMeta::to_impl(Json::Value &value) const
{
buildDefinition(value, *this);
}

Changed SurfaceMeta::changed_impl(const DefinitionBase &o) const
{
const auto &other(o.as<SurfaceMeta>());

if (surface != other.surface) { return Changed::yes; }
if (tms != other.tms) { return Changed::yes; }

return Changed::no;
}

Resource::Id::list SurfaceMeta::needsResources_impl() const {
return { surface, tms };
}

} // namespace resource
60 changes: 60 additions & 0 deletions mapproxy/src/mapproxy/definition/surface-meta.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Copyright (c) 2019 Melown Technologies SE
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef mapproxy_definition_surface_meta_hpp_included_
#define mapproxy_definition_surface_meta_hpp_included_

#include "../resource.hpp"

// fwd
namespace Json { class Value; }

namespace resource {

// meta surface: combines existing surface with existing TMS

class SurfaceMeta : public DefinitionBase {
public:
Resource::Id surface;
Resource::Id tms;

static constexpr Resource::Generator::Type type
= Resource::Generator::Type::surface;

static constexpr char driverName[] = "surface-meta";

protected:
virtual void from_impl(const Json::Value &value);
virtual void to_impl(Json::Value &value) const;
virtual Changed changed_impl(const DefinitionBase &other) const;
virtual Resource::Id::list needsResources_impl() const;
virtual bool needsRanges_impl() const { return false; }
};

} // namespace resource

#endif // mapproxy_definition_surface_meta_hpp_included_

3 changes: 2 additions & 1 deletion mapproxy/src/mapproxy/fileinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ Sink::FileInfo TmsFileInfo::sinkFileInfo(std::time_t lastModified) const

SurfaceFileInfo::SurfaceFileInfo(const FileInfo &fi)
: fileInfo(fi), type(Type::unknown), fileType(vs::File::config)
, tileType(vts::TileFile::meta), flavor(vts::FileFlavor::regular)
, tileType(vts::TileFile::meta), subTileIndex()
, flavor(vts::FileFlavor::regular)
, support(), registry(), serviceFile()
{
if (vts::fromFilename
Expand Down
68 changes: 61 additions & 7 deletions mapproxy/src/mapproxy/generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <boost/filesystem/path.hpp>

#include "utility/resourcefetcher.hpp"
#include "utility/format.hpp"

#include "vts-libs/storage/support.hpp"
#include "vts-libs/vts/mapconfig.hpp"
Expand Down Expand Up @@ -71,12 +72,28 @@ class GeneratorFinder {

std::shared_ptr<Generator>
findGenerator(Resource::Generator::Type generatorType
, const Resource::Id &resourceId) const;
, const Resource::Id &resourceId
, bool mustBeReady = true) const;

private:
virtual std::shared_ptr<Generator>
findGenerator_impl(Resource::Generator::Type generatorType
, const Resource::Id &resourceId) const = 0;
, const Resource::Id &resourceId
, bool mustBeReady) const = 0;
};

struct GeneratorNotFound : std::runtime_error {
GeneratorNotFound(Resource::Generator::Type generatorType
, const Resource::Id &resourceId)
: std::runtime_error
(utility::format("Cannot find <%s> generator for resource <%s>."
, generatorType, resourceId))
, generatorType(generatorType)
, resourceId(resourceId)
{}

Resource::Generator::Type generatorType;
const Resource::Id &resourceId;
};

/** Dataset generator.
Expand Down Expand Up @@ -219,6 +236,16 @@ class Generator : boost::noncopyable {
*/
bool updatedSince(std::uint64_t timestamp) const;

/** Generic type for provider handling
*/
struct Provider { virtual ~Provider() {} };

/** Returns generators provider machinery. Returns null if provider of given
* type is not available.
*/
template <typename ProviderType>
ProviderType* getProvider() const;

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

Expand Down Expand Up @@ -252,7 +279,9 @@ class Generator : boost::noncopyable {
const;

Generator::pointer otherGenerator(Resource::Generator::Type generatorType
, const Resource::Id &resourceId) const;
, const Resource::Id &resourceId
, bool mustBeReady = true
, bool mandatory = false) const;

void supportFile(const vs::SupportFile &support, Sink &sink
, const Sink::FileInfo &fileInfo) const;
Expand All @@ -265,6 +294,10 @@ class Generator : boost::noncopyable {
*/
bool changeEnforced() const { return changeEnforced_; }

/** Sets new provider. Value is stolen.
*/
void setProvider(std::unique_ptr<Provider> &&provider);

private:
virtual void prepare_impl(Arsenal &arsenal) = 0;
virtual vts::MapConfig mapConfig_impl(ResourceRoot root) const = 0;
Expand All @@ -284,6 +317,7 @@ class Generator : boost::noncopyable {
std::atomic<std::uint64_t> readySince_;
DemRegistry::pointer demRegistry_;
Generator::pointer replace_;
std::unique_ptr<Provider> provider_;
};

/** Set of dataset generators.
Expand Down Expand Up @@ -384,16 +418,36 @@ inline Generator::pointer Generators::generator(const FileInfo &fileInfo) const

std::shared_ptr<Generator>
inline GeneratorFinder::findGenerator(Resource::Generator::Type generatorType
, const Resource::Id &resourceId) const
, const Resource::Id &resourceId
, bool mustBeReady) const
{
return findGenerator_impl(generatorType, resourceId);
return findGenerator_impl(generatorType, resourceId, mustBeReady);
}

inline Generator::pointer
Generator::otherGenerator(Resource::Generator::Type generatorType
, const Resource::Id &resourceId) const
, const Resource::Id &resourceId
, bool mustBeReady, bool mandatory)
const
{
auto other(generatorFinder_->findGenerator
(generatorType, resourceId, mustBeReady));
if (!other && mandatory) {
throw GeneratorNotFound(generatorType, resourceId);
}
return other;
}

template <typename ProviderType>
ProviderType* Generator::getProvider() const
{
if (!provider_) { return nullptr; }
return dynamic_cast<ProviderType*>(provider_.get());
}

inline void Generator::setProvider(std::unique_ptr<Provider> &&provider)
{
return generatorFinder_->findGenerator(generatorType, resourceId);
provider_ = std::move(provider);
}

#endif // mapproxy_generator_hpp_included_
11 changes: 11 additions & 0 deletions mapproxy/src/mapproxy/generator/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ struct Generator::Factory {
* reference frame.
*/
virtual bool systemInstance() const { return false; }

/** Factory registry support
*/
typedef std::map<Resource::Generator, pointer> Registry;

static pointer findFactory(const Resource::Generator &type);

static void registerType(const Resource::Generator &type
, const pointer &factory);

static Registry &registry();
};

#endif // mapproxy_generator_factory_hpp_included_
Loading

0 comments on commit 7b0b772

Please sign in to comment.