Manage DataStoreServer instance

To access the OCM data from the HERE platform, you need a DataStoreServer instance.

To use the DataStoreServer instance:

  1. Create the DataStoreServer instance using the previously created Network and TaskScheduler instances, and if you plan to work with map regions, initialize the protected cache settings.

    Note: If you need to set a specific political view, specify the political_view_iso_id parameter. For more information, see the related instruction.

     #include <olp/clientmap/datastore/DataStoreServer.h>
     ...
     olp::clientmap::datastore::DataStoreServerSettings server_settings;
     server_settings.network_request_handler = network;
     server_settings.task_scheduler = task_scheduler;
     server_settings.cache_settings.disk_path_protected = "path/to/protected/cache";
    
     auto server = std::make_shared< olp::clientmap::datastore::DataStoreServer >(
     server_settings );
    
  2. Initialize the DataStoreServer instance and cache.

     auto init_result = server->Init();
    

If the operation is successful, you get the kNone error.

You can also get region-related errors.

After the initialization of the DataStoreServer instance, you can get the following errors related to the protected cache:

  • kPendingUpdate – the DataStoreServer instance was destructed during an ongoing map region update porcess, and the AbstractCacheUpdateManager::PrefetchMapRegions and AbstractCacheUpdateManager::RemoveMapRegions APIs are blocked.

    To fix the kPendingUpdate error, call the UpdateMapRegions method with the same parameters that you used during the last update. For instructions, see "Update map regions" in Manage data in protected cache.

  • kProtectedCacheCorrupted – the cache is corrupted, all the AbstractCacheUpdateManager APIs are blocked, the protected cache is not loaded, and you cannot access the data in it.

  • kMigrationRequired – you need to migrate to the journal of a new format. Until then, the CacheUpdateManager APIs are blocked.

    In version 1.3.0, OCMAM uses a new journal format. If you downloaded map regions using OCMAM version 1.2.0 or older, to work with the CacheUpdateManager APIs in OCMAM version 1.3.0 or later, migrate to the new journal.

    To fix the kMigrationRequired and kProtectedCacheCorrupted errors, call the RepairAndOpenCache method with the HRNs of the catalogs that are downloaded to the protected cache.

      auto& update_manager = server->GetCacheUpdateManager( );
      auto repair_response = update_manager.RepairAndOpenCache(
          {"hrn:here:data::olp-here:ocm", "hrn:here:data::olp-here:ocm-japan"} );
    

Set up a static URL for API lookup requests

To setup a static URL for API lookup requests, use the api_lookup_settings field of the DataStoreServerSettings structure.

Note: If the static URL is not set or an empty string is returned, an HTTP request to the API. Lookup Service is used to get the URL.

Example:

server_settings.api_lookup_settings.catalog_endpoint_provider
    = [=]( const olp::client::HRN& hrn ) -> std::string {
    if ( hrn.GetService( ) == olp::client::HRN::Data
            && hrn.GetPartition( ) == "here" )
    {
        return static_url;
    }
    return std::string( );
};

In the example above, the following objects and parameters are used:

  • server_settings – the previously created DataStoreServerSettings instance.
  • static_url – the static URL that you want to use if the HERE Resource Name (HRN) of the catalog satisfies the conditions specified in the callback.

results matching ""

    No results matching ""