@@ -15,7 +15,10 @@ namespace gfx {
|
||||
// of readStillImage.
|
||||
class HeadlessBackend : public gfx::Renderable {
|
||||
public:
|
||||
enum class SwapBehaviour { NoFlush, Flush };
|
||||
enum class SwapBehaviour {
|
||||
NoFlush,
|
||||
Flush
|
||||
};
|
||||
|
||||
// Factory.
|
||||
static std::unique_ptr<HeadlessBackend> Create(const Size size = {256, 256},
|
||||
|
||||
@@ -63,10 +63,10 @@ public:
|
||||
style::Style& getStyle();
|
||||
const style::Style& getStyle() const;
|
||||
|
||||
using PointForFn = std::function<ScreenCoordinate (const LatLng&)>;
|
||||
using LatLngForFn = std::function<LatLng (const ScreenCoordinate&)>;
|
||||
using PointForFn = std::function<ScreenCoordinate(const LatLng&)>;
|
||||
using LatLngForFn = std::function<LatLng(const ScreenCoordinate&)>;
|
||||
using Attributions = std::vector<std::string>;
|
||||
using Callback = std::function<void (std::exception_ptr, PremultipliedImage, Attributions, PointForFn, LatLngForFn)>;
|
||||
using Callback = std::function<void(std::exception_ptr, PremultipliedImage, Attributions, PointForFn, LatLngForFn)>;
|
||||
void snapshot(Callback);
|
||||
void cancel();
|
||||
|
||||
|
||||
@@ -6,48 +6,57 @@
|
||||
namespace mbgl {
|
||||
|
||||
static constexpr const char* mergeSideloadedDatabaseSQL =
|
||||
"INSERT INTO regions\n"
|
||||
" SELECT DISTINCT NULL, sr.definition, sr.description\n"
|
||||
" FROM side.regions sr \n"
|
||||
" LEFT JOIN regions r ON sr.definition = r.definition AND sr.description IS r.description\n"
|
||||
" WHERE r.definition IS NULL;\n"
|
||||
"CREATE TEMPORARY TABLE region_mapping AS\n"
|
||||
" SELECT sr.id AS side_region_id,\n"
|
||||
" r.id AS main_region_id\n"
|
||||
" FROM side.regions sr\n"
|
||||
" JOIN regions r ON sr.definition = r.definition AND sr.description IS r.description;\n"
|
||||
"REPLACE INTO tiles\n"
|
||||
" SELECT t.id,\n"
|
||||
" st.url_template, st.pixel_ratio, st.z, st.x, st.y,\n"
|
||||
" st.expires, st.modified, st.etag, st.data, st.compressed, st.accessed, st.must_revalidate\n"
|
||||
" FROM (SELECT DISTINCT sti.* FROM side.region_tiles srt JOIN side.tiles sti ON srt.tile_id = sti.id)\n"
|
||||
" AS st\n"
|
||||
" LEFT JOIN tiles t ON st.url_template = t.url_template AND st.pixel_ratio = t.pixel_ratio AND st.z = t.z AND st.x = t.x AND st.y = t.y\n"
|
||||
" WHERE t.id IS NULL\n"
|
||||
" OR st.modified > t.modified;\n"
|
||||
"INSERT OR IGNORE INTO region_tiles\n"
|
||||
" SELECT rm.main_region_id, sti.id\n"
|
||||
" FROM side.region_tiles srt\n"
|
||||
" JOIN region_mapping rm ON srt.region_id = rm.side_region_id\n"
|
||||
" JOIN (SELECT t.id, st.id AS side_tile_id FROM side.tiles st\n"
|
||||
" JOIN tiles t ON st.url_template = t.url_template AND st.pixel_ratio = t.pixel_ratio AND st.z = t.z AND st.x = t.x AND st.y = t.y\n"
|
||||
" ) AS sti ON srt.tile_id = sti.side_tile_id;\n"
|
||||
"REPLACE INTO resources\n"
|
||||
" SELECT r.id, \n"
|
||||
" sr.url, sr.kind, sr.expires, sr.modified, sr.etag,\n"
|
||||
" sr.data, sr.compressed, sr.accessed, sr.must_revalidate\n"
|
||||
" FROM side.region_resources srr JOIN side.resources sr ON srr.resource_id = sr.id\n"
|
||||
" LEFT JOIN resources r ON sr.url = r.url\n"
|
||||
" WHERE r.id IS NULL\n"
|
||||
" OR sr.modified > r.modified;\n"
|
||||
"INSERT OR IGNORE INTO region_resources\n"
|
||||
" SELECT rm.main_region_id, sri.id\n"
|
||||
" FROM side.region_resources srr\n"
|
||||
" JOIN region_mapping rm ON srr.region_id = rm.side_region_id\n"
|
||||
" JOIN (SELECT r.id, sr.id AS side_resource_id FROM side.resources sr\n"
|
||||
" JOIN resources r ON sr.url = r.url) AS sri ON srr.resource_id = sri.side_resource_id;\n"
|
||||
" \n"
|
||||
"DROP TABLE region_mapping;\n"
|
||||
;
|
||||
"INSERT INTO regions\n"
|
||||
" SELECT DISTINCT NULL, sr.definition, sr.description\n"
|
||||
" FROM side.regions sr \n"
|
||||
" LEFT JOIN regions r ON sr.definition = r.definition AND "
|
||||
"sr.description IS r.description\n"
|
||||
" WHERE r.definition IS NULL;\n"
|
||||
"CREATE TEMPORARY TABLE region_mapping AS\n"
|
||||
" SELECT sr.id AS side_region_id,\n"
|
||||
" r.id AS main_region_id\n"
|
||||
" FROM side.regions sr\n"
|
||||
" JOIN regions r ON sr.definition = r.definition AND sr.description IS "
|
||||
"r.description;\n"
|
||||
"REPLACE INTO tiles\n"
|
||||
" SELECT t.id,\n"
|
||||
" st.url_template, st.pixel_ratio, st.z, st.x, st.y,\n"
|
||||
" st.expires, st.modified, st.etag, st.data, st.compressed, "
|
||||
"st.accessed, st.must_revalidate\n"
|
||||
" FROM (SELECT DISTINCT sti.* FROM side.region_tiles srt JOIN "
|
||||
"side.tiles sti ON srt.tile_id = sti.id)\n"
|
||||
" AS st\n"
|
||||
" LEFT JOIN tiles t ON st.url_template = t.url_template AND "
|
||||
"st.pixel_ratio = t.pixel_ratio AND st.z = t.z AND "
|
||||
"st.x = t.x AND st.y = t.y\n"
|
||||
" WHERE t.id IS NULL\n"
|
||||
" OR st.modified > t.modified;\n"
|
||||
"INSERT OR IGNORE INTO region_tiles\n"
|
||||
" SELECT rm.main_region_id, sti.id\n"
|
||||
" FROM side.region_tiles srt\n"
|
||||
" JOIN region_mapping rm ON srt.region_id = rm.side_region_id\n"
|
||||
" JOIN (SELECT t.id, st.id AS side_tile_id FROM side.tiles st\n"
|
||||
" JOIN tiles t ON st.url_template = t.url_template AND "
|
||||
"st.pixel_ratio = t.pixel_ratio AND st.z = t.z "
|
||||
"AND st.x = t.x AND st.y = t.y\n"
|
||||
" ) AS sti ON srt.tile_id = sti.side_tile_id;\n"
|
||||
"REPLACE INTO resources\n"
|
||||
" SELECT r.id, \n"
|
||||
" sr.url, sr.kind, sr.expires, sr.modified, sr.etag,\n"
|
||||
" sr.data, sr.compressed, sr.accessed, sr.must_revalidate\n"
|
||||
" FROM side.region_resources srr JOIN side.resources sr ON "
|
||||
"srr.resource_id = sr.id\n"
|
||||
" LEFT JOIN resources r ON sr.url = r.url\n"
|
||||
" WHERE r.id IS NULL\n"
|
||||
" OR sr.modified > r.modified;\n"
|
||||
"INSERT OR IGNORE INTO region_resources\n"
|
||||
" SELECT rm.main_region_id, sri.id\n"
|
||||
" FROM side.region_resources srr\n"
|
||||
" JOIN region_mapping rm ON srr.region_id = rm.side_region_id\n"
|
||||
" JOIN (SELECT r.id, sr.id AS side_resource_id FROM side.resources sr\n"
|
||||
" JOIN resources r ON sr.url = r.url) AS sri ON srr.resource_id "
|
||||
"= sri.side_resource_id;\n"
|
||||
" \n"
|
||||
"DROP TABLE region_mapping;\n";
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -32,8 +32,9 @@ namespace util {
|
||||
struct IOException;
|
||||
} // namespace util
|
||||
|
||||
struct MapboxTileLimitExceededException : util::Exception {
|
||||
MapboxTileLimitExceededException() : util::Exception("Mapbox tile limit exceeded") {}
|
||||
struct MapboxTileLimitExceededException : util::Exception {
|
||||
MapboxTileLimitExceededException()
|
||||
: util::Exception("Mapbox tile limit exceeded") {}
|
||||
};
|
||||
|
||||
class OfflineDatabase {
|
||||
@@ -66,8 +67,7 @@ public:
|
||||
expected<OfflineRegion, std::exception_ptr> createRegion(const OfflineRegionDefinition&,
|
||||
const OfflineRegionMetadata&);
|
||||
|
||||
expected<OfflineRegions, std::exception_ptr>
|
||||
mergeDatabase(const std::string& sideDatabasePath);
|
||||
expected<OfflineRegions, std::exception_ptr> mergeDatabase(const std::string& sideDatabasePath);
|
||||
|
||||
expected<OfflineRegionMetadata, std::exception_ptr> updateMetadata(int64_t regionID, const OfflineRegionMetadata&);
|
||||
|
||||
@@ -115,17 +115,15 @@ private:
|
||||
void vacuum();
|
||||
void checkFlags();
|
||||
|
||||
mapbox::sqlite::Statement& getStatement(const char *);
|
||||
mapbox::sqlite::Statement& getStatement(const char*);
|
||||
|
||||
std::optional<std::pair<Response, uint64_t>> getTile(const Resource::TileData&);
|
||||
std::optional<int64_t> hasTile(const Resource::TileData&);
|
||||
bool putTile(const Resource::TileData&, const Response&,
|
||||
const std::string&, bool compressed);
|
||||
bool putTile(const Resource::TileData&, const Response&, const std::string&, bool compressed);
|
||||
|
||||
std::optional<std::pair<Response, uint64_t>> getResource(const Resource&);
|
||||
std::optional<int64_t> hasResource(const Resource&);
|
||||
bool putResource(const Resource&, const Response&,
|
||||
const std::string&, bool compressed);
|
||||
bool putResource(const Resource&, const Response&, const std::string&, bool compressed);
|
||||
|
||||
uint64_t putRegionResourceInternal(int64_t regionID, const Resource&, const Response&);
|
||||
|
||||
@@ -144,7 +142,7 @@ private:
|
||||
std::map<const char*, const std::unique_ptr<mapbox::sqlite::Statement>> statements;
|
||||
|
||||
template <class T>
|
||||
T getPragma(const char *);
|
||||
T getPragma(const char*);
|
||||
|
||||
uint64_t maximumAmbientCacheSize = util::DEFAULT_MAX_CACHE_SIZE;
|
||||
uint64_t offlineMapboxTileCountLimit = util::mapbox::DEFAULT_OFFLINE_TILE_COUNT_LIMIT;
|
||||
|
||||
@@ -47,7 +47,7 @@ private:
|
||||
* While the request is in progress, it is recorded in `requests`. If the download
|
||||
* is deactivated, all in progress requests are cancelled.
|
||||
*/
|
||||
void ensureResource(Resource&&, std::function<void (Response)> = {});
|
||||
void ensureResource(Resource&&, std::function<void(Response)> = {});
|
||||
|
||||
void onMapboxTileCountLimitExceeded();
|
||||
|
||||
|
||||
@@ -6,58 +6,57 @@
|
||||
namespace mbgl {
|
||||
|
||||
static constexpr const char* offlineDatabaseSchema =
|
||||
"CREATE TABLE resources (\n"
|
||||
" id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n"
|
||||
" url TEXT NOT NULL,\n"
|
||||
" kind INTEGER NOT NULL,\n"
|
||||
" expires INTEGER,\n"
|
||||
" modified INTEGER,\n"
|
||||
" etag TEXT,\n"
|
||||
" data BLOB,\n"
|
||||
" compressed INTEGER NOT NULL DEFAULT 0,\n"
|
||||
" accessed INTEGER NOT NULL,\n"
|
||||
" must_revalidate INTEGER NOT NULL DEFAULT 0,\n"
|
||||
" UNIQUE (url)\n"
|
||||
");\n"
|
||||
"CREATE TABLE tiles (\n"
|
||||
" id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n"
|
||||
" url_template TEXT NOT NULL,\n"
|
||||
" pixel_ratio INTEGER NOT NULL,\n"
|
||||
" z INTEGER NOT NULL,\n"
|
||||
" x INTEGER NOT NULL,\n"
|
||||
" y INTEGER NOT NULL,\n"
|
||||
" expires INTEGER,\n"
|
||||
" modified INTEGER,\n"
|
||||
" etag TEXT,\n"
|
||||
" data BLOB,\n"
|
||||
" compressed INTEGER NOT NULL DEFAULT 0,\n"
|
||||
" accessed INTEGER NOT NULL,\n"
|
||||
" must_revalidate INTEGER NOT NULL DEFAULT 0,\n"
|
||||
" UNIQUE (url_template, pixel_ratio, z, x, y)\n"
|
||||
");\n"
|
||||
"CREATE TABLE regions (\n"
|
||||
" id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n"
|
||||
" definition TEXT NOT NULL,\n"
|
||||
" description BLOB\n"
|
||||
");\n"
|
||||
"CREATE TABLE region_resources (\n"
|
||||
" region_id INTEGER NOT NULL REFERENCES regions(id) ON DELETE CASCADE,\n"
|
||||
" resource_id INTEGER NOT NULL REFERENCES resources(id),\n"
|
||||
" UNIQUE (region_id, resource_id)\n"
|
||||
");\n"
|
||||
"CREATE TABLE region_tiles (\n"
|
||||
" region_id INTEGER NOT NULL REFERENCES regions(id) ON DELETE CASCADE,\n"
|
||||
" tile_id INTEGER NOT NULL REFERENCES tiles(id),\n"
|
||||
" UNIQUE (region_id, tile_id)\n"
|
||||
");\n"
|
||||
"CREATE INDEX resources_accessed\n"
|
||||
"ON resources (accessed);\n"
|
||||
"CREATE INDEX tiles_accessed\n"
|
||||
"ON tiles (accessed);\n"
|
||||
"CREATE INDEX region_resources_resource_id\n"
|
||||
"ON region_resources (resource_id);\n"
|
||||
"CREATE INDEX region_tiles_tile_id\n"
|
||||
"ON region_tiles (tile_id);\n"
|
||||
;
|
||||
"CREATE TABLE resources (\n"
|
||||
" id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n"
|
||||
" url TEXT NOT NULL,\n"
|
||||
" kind INTEGER NOT NULL,\n"
|
||||
" expires INTEGER,\n"
|
||||
" modified INTEGER,\n"
|
||||
" etag TEXT,\n"
|
||||
" data BLOB,\n"
|
||||
" compressed INTEGER NOT NULL DEFAULT 0,\n"
|
||||
" accessed INTEGER NOT NULL,\n"
|
||||
" must_revalidate INTEGER NOT NULL DEFAULT 0,\n"
|
||||
" UNIQUE (url)\n"
|
||||
");\n"
|
||||
"CREATE TABLE tiles (\n"
|
||||
" id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n"
|
||||
" url_template TEXT NOT NULL,\n"
|
||||
" pixel_ratio INTEGER NOT NULL,\n"
|
||||
" z INTEGER NOT NULL,\n"
|
||||
" x INTEGER NOT NULL,\n"
|
||||
" y INTEGER NOT NULL,\n"
|
||||
" expires INTEGER,\n"
|
||||
" modified INTEGER,\n"
|
||||
" etag TEXT,\n"
|
||||
" data BLOB,\n"
|
||||
" compressed INTEGER NOT NULL DEFAULT 0,\n"
|
||||
" accessed INTEGER NOT NULL,\n"
|
||||
" must_revalidate INTEGER NOT NULL DEFAULT 0,\n"
|
||||
" UNIQUE (url_template, pixel_ratio, z, x, y)\n"
|
||||
");\n"
|
||||
"CREATE TABLE regions (\n"
|
||||
" id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n"
|
||||
" definition TEXT NOT NULL,\n"
|
||||
" description BLOB\n"
|
||||
");\n"
|
||||
"CREATE TABLE region_resources (\n"
|
||||
" region_id INTEGER NOT NULL REFERENCES regions(id) ON DELETE CASCADE,\n"
|
||||
" resource_id INTEGER NOT NULL REFERENCES resources(id),\n"
|
||||
" UNIQUE (region_id, resource_id)\n"
|
||||
");\n"
|
||||
"CREATE TABLE region_tiles (\n"
|
||||
" region_id INTEGER NOT NULL REFERENCES regions(id) ON DELETE CASCADE,\n"
|
||||
" tile_id INTEGER NOT NULL REFERENCES tiles(id),\n"
|
||||
" UNIQUE (region_id, tile_id)\n"
|
||||
");\n"
|
||||
"CREATE INDEX resources_accessed\n"
|
||||
"ON resources (accessed);\n"
|
||||
"CREATE INDEX tiles_accessed\n"
|
||||
"ON tiles (accessed);\n"
|
||||
"CREATE INDEX region_resources_resource_id\n"
|
||||
"ON region_resources (resource_id);\n"
|
||||
"CREATE INDEX region_tiles_tile_id\n"
|
||||
"ON region_tiles (tile_id);\n";
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace mapbox {
|
||||
namespace sqlite {
|
||||
|
||||
enum OpenFlag : int {
|
||||
ReadOnly = 0b001,
|
||||
ReadOnly = 0b001,
|
||||
ReadWriteCreate = 0b110,
|
||||
};
|
||||
|
||||
@@ -50,13 +50,14 @@ enum class ExtendedResultCode : uint8_t {
|
||||
|
||||
class Exception : public std::runtime_error {
|
||||
public:
|
||||
Exception(ResultCode err, const char* msg) : Exception(static_cast<int>(err), msg) {}
|
||||
Exception(int err, const char* msg) : Exception(err, std::string{ msg }) {}
|
||||
Exception(ResultCode err, const char* msg)
|
||||
: Exception(static_cast<int>(err), msg) {}
|
||||
Exception(int err, const char* msg)
|
||||
: Exception(err, std::string{msg}) {}
|
||||
Exception(int err, const std::string& msg)
|
||||
: std::runtime_error(msg),
|
||||
code(static_cast<ResultCode>(err)),
|
||||
extendedCode(static_cast<ExtendedResultCode>(err >> 8)) {
|
||||
}
|
||||
extendedCode(static_cast<ExtendedResultCode>(err >> 8)) {}
|
||||
const ResultCode code = ResultCode::OK;
|
||||
const ExtendedResultCode extendedCode = ExtendedResultCode::Unknown;
|
||||
};
|
||||
@@ -74,17 +75,17 @@ private:
|
||||
Database(std::unique_ptr<DatabaseImpl>);
|
||||
|
||||
public:
|
||||
Database(const Database &) = delete;
|
||||
Database &operator=(const Database &) = delete;
|
||||
static mapbox::util::variant<Database, Exception> tryOpen(const std::string &filename, int flags = 0);
|
||||
static Database open(const std::string &filename, int flags = 0);
|
||||
Database(const Database&) = delete;
|
||||
Database& operator=(const Database&) = delete;
|
||||
static mapbox::util::variant<Database, Exception> tryOpen(const std::string& filename, int flags = 0);
|
||||
static Database open(const std::string& filename, int flags = 0);
|
||||
|
||||
Database(Database&&) noexcept;
|
||||
~Database();
|
||||
Database& operator=(Database&&) noexcept;
|
||||
|
||||
void setBusyTimeout(std::chrono::milliseconds);
|
||||
void exec(const std::string &sql);
|
||||
void exec(const std::string& sql);
|
||||
|
||||
private:
|
||||
std::unique_ptr<DatabaseImpl> impl;
|
||||
@@ -109,16 +110,18 @@ private:
|
||||
std::unique_ptr<StatementImpl> impl;
|
||||
|
||||
#ifndef NDEBUG
|
||||
// This flag stores whether there exists a Query object that uses this prepared statement.
|
||||
// There may only be one Query object at a time. Statement objects must outlive Query objects.
|
||||
// While a Query object exists, a Statement object may not be moved or deleted.
|
||||
// This flag stores whether there exists a Query object that uses this
|
||||
// prepared statement. There may only be one Query object at a time.
|
||||
// Statement objects must outlive Query objects. While a Query object
|
||||
// exists, a Statement object may not be moved or deleted.
|
||||
bool used = false;
|
||||
#endif
|
||||
};
|
||||
|
||||
// A Query object is used to run a database query with a prepared statement (stored in a Statement
|
||||
// object). There may only exist one Query object per Statement object. Query objects are designed
|
||||
// to be constructed and destroyed frequently.
|
||||
// A Query object is used to run a database query with a prepared statement
|
||||
// (stored in a Statement object). There may only exist one Query object per
|
||||
// Statement object. Query objects are designed to be constructed and destroyed
|
||||
// frequently.
|
||||
class Query {
|
||||
public:
|
||||
Query(Statement&);
|
||||
|
||||
Reference in New Issue
Block a user