MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mbgl::DatabaseFileSource Class Reference

#include <database_file_source.hpp>

Inheritance diagram for mbgl::DatabaseFileSource:
mbgl::FileSource

Public Member Functions

 DatabaseFileSource (const ResourceOptions &resourceOptions, const ClientOptions &clientOptions)
 
 ~DatabaseFileSource () override
 
std::unique_ptr< AsyncRequestrequest (const Resource &, Callback) override
 FileSource overrides. More...
 
void forward (const Resource &, const Response &, std::function< void()> callback) override
 
bool canRequest (const Resource &) const override
 Checks whether a resource could be requested from this file source. More...
 
void setProperty (const std::string &, const mapbox::base::Value &) override
 Generic setter method. More...
 
void pause () override
 
void resume () override
 
virtual void setDatabasePath (const std::string &, std::function< void()> callback)
 
virtual void resetDatabase (std::function< void(std::exception_ptr)>)
 
virtual void packDatabase (std::function< void(std::exception_ptr)> callback)
 
virtual void runPackDatabaseAutomatically (bool)
 
virtual void put (const Resource &, const Response &)
 
virtual void invalidateAmbientCache (std::function< void(std::exception_ptr)>)
 
virtual void clearAmbientCache (std::function< void(std::exception_ptr)>)
 
virtual void setMaximumAmbientCacheSize (uint64_t size, std::function< void(std::exception_ptr)> callback)
 
virtual void listOfflineRegions (std::function< void(expected< OfflineRegions, std::exception_ptr >)>)
 
virtual void createOfflineRegion (const OfflineRegionDefinition &definition, const OfflineRegionMetadata &metadata, std::function< void(expected< OfflineRegion, std::exception_ptr >)>)
 
virtual void updateOfflineMetadata (int64_t regionID, const OfflineRegionMetadata &metadata, std::function< void(expected< OfflineRegionMetadata, std::exception_ptr >)>)
 
virtual void setOfflineRegionObserver (const OfflineRegion &, std::unique_ptr< OfflineRegionObserver >)
 
virtual void setOfflineRegionDownloadState (const OfflineRegion &, OfflineRegionDownloadState)
 
virtual void getOfflineRegionStatus (const OfflineRegion &, std::function< void(expected< OfflineRegionStatus, std::exception_ptr >)>) const
 
virtual void mergeOfflineRegions (const std::string &sideDatabasePath, std::function< void(expected< OfflineRegions, std::exception_ptr >)>)
 
virtual void deleteOfflineRegion (const OfflineRegion &, std::function< void(std::exception_ptr)>)
 
virtual void invalidateOfflineRegion (const OfflineRegion &, std::function< void(std::exception_ptr)>)
 
virtual void setOfflineMapboxTileCountLimit (uint64_t) const
 
void setResourceOptions (ResourceOptions) override
 
ResourceOptions getResourceOptions () override
 
void setClientOptions (ClientOptions) override
 
ClientOptions getClientOptions () override
 
- Public Member Functions inherited from mbgl::FileSource
FileSourceoperator= (const FileSource &)=delete
 
virtual ~FileSource ()=default
 
virtual bool supportsCacheOnlyRequests () const
 
virtual mapbox::base::Value getProperty (const std::string &) const
 Generic getter method. More...
 
virtual void setResourceTransform (ResourceTransform)
 When supported, sets the modifier of the requested resources. More...
 

Additional Inherited Members

- Public Types inherited from mbgl::FileSource
using Callback = std::function< void(Response)>
 
- Protected Member Functions inherited from mbgl::FileSource
 FileSource ()=default
 

Detailed Description

Definition at line 13 of file database_file_source.hpp.

Constructor & Destructor Documentation

◆ DatabaseFileSource()

mbgl::DatabaseFileSource::DatabaseFileSource ( const ResourceOptions resourceOptions,
const ClientOptions clientOptions 
)
explicit

◆ ~DatabaseFileSource()

mbgl::DatabaseFileSource::~DatabaseFileSource ( )
override

Member Function Documentation

◆ canRequest()

bool mbgl::DatabaseFileSource::canRequest ( const Resource ) const
overridevirtual

Checks whether a resource could be requested from this file source.

Implements mbgl::FileSource.

◆ clearAmbientCache()

virtual void mbgl::DatabaseFileSource::clearAmbientCache ( std::function< void(std::exception_ptr)>  )
virtual

Erase resources from the ambient cache, freeing storage space.

Erases the ambient cache, freeing resources.

Note that this operation can be potentially slow if packing the database occurs automatically (see runPackDatabaseAutomatically() and packDatabase()).

Resources overlapping with offline regions will not be affected by this call.

◆ createOfflineRegion()

virtual void mbgl::DatabaseFileSource::createOfflineRegion ( const OfflineRegionDefinition definition,
const OfflineRegionMetadata metadata,
std::function< void(expected< OfflineRegion, std::exception_ptr >)>   
)
virtual

Create an offline region in the database.

When the initial database queries have completed, the provided callback will be executed on the database thread; it is the responsibility of the SDK bindings to re-execute a user-provided callback on the main thread.

Note that the resulting region will be in an inactive download state; to begin downloading resources, call setOfflineRegionDownloadState(OfflineRegionDownloadState::Active), optionally registering an OfflineRegionObserver beforehand.

◆ deleteOfflineRegion()

virtual void mbgl::DatabaseFileSource::deleteOfflineRegion ( const OfflineRegion ,
std::function< void(std::exception_ptr)>   
)
virtual

Remove an offline region from the database and perform any resources evictions necessary as a result.

Eviction works by removing the least-recently requested resources not also required by other regions, until the database shrinks below a certain size.

Note that this method takes ownership of the input, reflecting the fact that once region deletion is initiated, it is not legal to perform further actions with the region.

Note that this operation can be potentially slow if packing the database occurs automatically (see runPackDatabaseAutomatically() and packDatabase()).

When the operation is complete or encounters an error, the given callback will be executed on the database thread; it is the responsibility of the SDK bindings to re-execute a user-provided callback on the main thread.

◆ forward()

void mbgl::DatabaseFileSource::forward ( const Resource ,
const Response ,
std::function< void()>   
)
overridevirtual

Allows to forward response from one source to another. Optionally, callback can be provided to receive notification for forward operation.

Reimplemented from mbgl::FileSource.

◆ getClientOptions()

ClientOptions mbgl::DatabaseFileSource::getClientOptions ( )
overridevirtual

Implements mbgl::FileSource.

◆ getOfflineRegionStatus()

virtual void mbgl::DatabaseFileSource::getOfflineRegionStatus ( const OfflineRegion ,
std::function< void(expected< OfflineRegionStatus, std::exception_ptr >)>   
) const
virtual

Retrieve the current status of the region. The query will be executed asynchronously and the results passed to the given callback, which will be executed on the database thread; it is the responsibility of the SDK bindings to re-execute a user-provided callback on the main thread.

◆ getResourceOptions()

ResourceOptions mbgl::DatabaseFileSource::getResourceOptions ( )
overridevirtual

Implements mbgl::FileSource.

◆ invalidateAmbientCache()

virtual void mbgl::DatabaseFileSource::invalidateAmbientCache ( std::function< void(std::exception_ptr)>  )
virtual

Forces revalidation of the ambient cache.

Forces Mapbox GL Native to revalidate resources stored in the ambient cache with the tile server before using them, making sure they are the latest version. This is more efficient than cleaning the cache because if the resource is considered valid after the server lookup, it will not get downloaded again.

Resources overlapping with offline regions will not be affected by this call.

◆ invalidateOfflineRegion()

virtual void mbgl::DatabaseFileSource::invalidateOfflineRegion ( const OfflineRegion ,
std::function< void(std::exception_ptr)>   
)
virtual

Invalidate all the tiles from an offline region forcing Mapbox GL to revalidate the tiles with the server before using. This is more efficient than deleting the offline region and downloading it again because if the data on the cache matches the server, no new data gets transmitted.

◆ listOfflineRegions()

virtual void mbgl::DatabaseFileSource::listOfflineRegions ( std::function< void(expected< OfflineRegions, std::exception_ptr >)>  )
virtual

Retrieve all regions in the offline database.

The query will be executed asynchronously and the results passed to the given callback, which will be executed on the database thread; it is the responsibility of the SDK bindings to re-execute a user-provided callback on the main thread.

◆ mergeOfflineRegions()

virtual void mbgl::DatabaseFileSource::mergeOfflineRegions ( const std::string &  sideDatabasePath,
std::function< void(expected< OfflineRegions, std::exception_ptr >)>   
)
virtual

Merge offline regions from a secondary database into the main offline database.

When the database merge is completed, the provided callback will be executed on the database thread; it is the responsibility of the SDK bindings to re-execute a user-provided callback on the main thread.

The secondary database may need to be upgraded to the latest schema. This is done in-place and requires write-access to sideDatabasePath; it is the responsibility of the SDK bindings to ensure that this path is writeable.

Only resources and tiles that belong to a region will be copied over. Identical regions will be flattened into a single new region in the main database.

Invokes the callback with a MapboxOfflineTileCountExceededException error if the merge operation would result in the offline tile count limit being exceeded.

Merged regions may not be in a completed status if the secondary database does not contain all the tiles or resources required by the region definition.

◆ packDatabase()

virtual void mbgl::DatabaseFileSource::packDatabase ( std::function< void(std::exception_ptr)>  callback)
virtual

Packs the existing database file into a minimal amount of disk space.

This operation has a performance impact as it will vacuum the database, forcing it to move pages on the filesystem.

When the operation is complete or encounters an error, the given callback will be executed on the database thread; it is the responsibility of the SDK bindings to re-execute a user-provided callback on the main thread.

◆ pause()

void mbgl::DatabaseFileSource::pause ( )
overridevirtual

Pause file request activity.

If pause is called then no revalidation or network request activity will occur.

Reimplemented from mbgl::FileSource.

◆ put()

virtual void mbgl::DatabaseFileSource::put ( const Resource ,
const Response  
)
virtual

Insert the provided resource into the ambient cache

Consumers of the resource will expect the uncompressed version; the OfflineDatabase will determine whether to compress the data on disk. This call is asynchronous: the data may not be immediately available for in-progress requests, although subsequent requests should have access to the cached data.

◆ request()

std::unique_ptr<AsyncRequest> mbgl::DatabaseFileSource::request ( const Resource ,
Callback   
)
overridevirtual

FileSource overrides.

Implements mbgl::FileSource.

◆ resetDatabase()

virtual void mbgl::DatabaseFileSource::resetDatabase ( std::function< void(std::exception_ptr)>  )
virtual

Delete existing database and re-initialize.

When the operation is complete or encounters an error, the given callback will be executed on the database thread; it is the responsibility of the SDK bindings to re-execute a user-provided callback on the main thread.

◆ resume()

void mbgl::DatabaseFileSource::resume ( )
overridevirtual

Resume file request activity.

Calling resume will unpause the file source and process any tasks that expired while the file source was paused.

Reimplemented from mbgl::FileSource.

◆ runPackDatabaseAutomatically()

virtual void mbgl::DatabaseFileSource::runPackDatabaseAutomatically ( bool  )
virtual

Sets whether packing the database file occurs automatically after an offline region is deleted (deleteOfflineRegion()) or the ambient cache is cleared (clearAmbientCache()).

By default, packing is enabled. If disabled, disk space will not be freed after resources are removed unless packDatabase() is explicitly called.

◆ setClientOptions()

void mbgl::DatabaseFileSource::setClientOptions ( ClientOptions  )
overridevirtual

Implements mbgl::FileSource.

◆ setDatabasePath()

virtual void mbgl::DatabaseFileSource::setDatabasePath ( const std::string &  ,
std::function< void()>  callback 
)
virtual

Sets path of a database to be used by DatabaseFileSource and invokes provided callback when a database path is set.

◆ setMaximumAmbientCacheSize()

virtual void mbgl::DatabaseFileSource::setMaximumAmbientCacheSize ( uint64_t  size,
std::function< void(std::exception_ptr)>  callback 
)
virtual

Sets the maximum size in bytes for the ambient cache.

This call is potentially expensive because it will try to trim the data in case the database is larger than the size defined. The size of offline regions are not affected by this settings, but the ambient cache will always try to not exceed the maximum size defined, taking into account the current size for the offline regions.

If the maximum size is set to 50 MB and 40 MB are already used by offline regions, the cache size will be effectively 10 MB.

Setting the size to 0 will disable the cache if there is no offline region on the database.

This method should always be called before using the database, otherwise the default maximum size will be used.

◆ setOfflineMapboxTileCountLimit()

virtual void mbgl::DatabaseFileSource::setOfflineMapboxTileCountLimit ( uint64_t  ) const
virtual

Changing or bypassing this limit without permission from Mapbox is prohibited by the Mapbox Terms of Service.

◆ setOfflineRegionDownloadState()

virtual void mbgl::DatabaseFileSource::setOfflineRegionDownloadState ( const OfflineRegion ,
OfflineRegionDownloadState   
)
virtual

Pause or resume downloading of regional resources.

◆ setOfflineRegionObserver()

virtual void mbgl::DatabaseFileSource::setOfflineRegionObserver ( const OfflineRegion ,
std::unique_ptr< OfflineRegionObserver  
)
virtual

Register an observer to be notified when the state of the region changes.

◆ setProperty()

void mbgl::DatabaseFileSource::setProperty ( const std::string &  ,
const mapbox::base::Value &   
)
overridevirtual

Generic setter method.

Reimplemented from mbgl::FileSource.

◆ setResourceOptions()

void mbgl::DatabaseFileSource::setResourceOptions ( ResourceOptions  )
overridevirtual

Implements mbgl::FileSource.

◆ updateOfflineMetadata()

virtual void mbgl::DatabaseFileSource::updateOfflineMetadata ( int64_t  regionID,
const OfflineRegionMetadata metadata,
std::function< void(expected< OfflineRegionMetadata, std::exception_ptr >)>   
)
virtual

Update an offline region metadata in the database.


The documentation for this class was generated from the following file: