Maintain storage_config exposed API

This commit is contained in:
Pepijn Schoen 2017-07-07 16:42:07 +02:00 committed by Daniel J. H
parent 0b5c7a97a7
commit 8da40419ee
13 changed files with 52 additions and 34 deletions

View File

@ -30,7 +30,7 @@ int main(int argc, const char *argv[])
// Configure based on a .osrm base path, and no datasets in shared mem from osrm-datastore
EngineConfig config;
config.storage_config.UseDefaultOutputNames(argv[1]);
config.storage_config = {argv[1]};
config.use_shared_memory = false;
// Routing machine with several services (such as Route, Table, Nearest, Trip, Match)

View File

@ -72,6 +72,11 @@ struct ExtractorConfig final : storage::IOConfig
{
}
void UseDefaultOutputNames(const boost::filesystem::path &base)
{
IOConfig::UseDefaultOutputNames(base);
}
boost::filesystem::path input_path;
boost::filesystem::path profile_path;

View File

@ -97,9 +97,8 @@ inline engine_config_ptr argumentsToEngineConfig(const Nan::FunctionCallbackInfo
if (args[0]->IsString())
{
std::string base_path(*v8::String::Utf8Value(args[0]->ToString()));
engine_config->storage_config = osrm::StorageConfig();
engine_config->storage_config.UseDefaultOutputNames(base_path);
engine_config->storage_config = osrm::StorageConfig(
*v8::String::Utf8Value(Nan::To<v8::String>(args[0]).ToLocalChecked()));
engine_config->use_shared_memory = false;
return engine_config;
}
@ -122,9 +121,8 @@ inline engine_config_ptr argumentsToEngineConfig(const Nan::FunctionCallbackInfo
if (!path->IsUndefined())
{
std::string base_path(*v8::String::Utf8Value(path->ToString()));
engine_config->storage_config = osrm::StorageConfig();
engine_config->storage_config.UseDefaultOutputNames(base_path);
engine_config->storage_config =
osrm::StorageConfig(*v8::String::Utf8Value(Nan::To<v8::String>(path).ToLocalChecked()));
engine_config->use_shared_memory = false;
}
if (!shared_memory->IsUndefined())

View File

@ -26,6 +26,11 @@ struct PartitionConfig final : storage::IOConfig
{
}
void UseDefaultOutputNames(const boost::filesystem::path &base)
{
IOConfig::UseDefaultOutputNames(base);
}
unsigned requested_num_threads;
double balance;

View File

@ -23,6 +23,21 @@ struct IOConfig
{
}
bool IsValid() const;
boost::filesystem::path GetPath(const std::string &fileName) const
{
if (!IsConfigured(fileName, required_input_files) &&
!IsConfigured(fileName, optional_input_files) && !IsConfigured(fileName, output_files))
{
throw util::exception("Tried to access file which is not configured: " + fileName);
}
return {base_path.string() + fileName};
}
boost::filesystem::path base_path;
protected:
// Infer the base path from the path of the .osrm file
void UseDefaultOutputNames(const boost::filesystem::path &base)
{
@ -45,20 +60,6 @@ struct IOConfig
base_path = {path};
}
bool IsValid() const;
boost::filesystem::path GetPath(const std::string &fileName) const
{
if (!IsConfigured(fileName, required_input_files) &&
!IsConfigured(fileName, optional_input_files) && !IsConfigured(fileName, output_files))
{
throw util::exception("Tried to access file which is not configured: " + fileName);
}
return {base_path.string() + fileName};
}
boost::filesystem::path base_path;
private:
static bool IsConfigured(const std::string &fileName,
const std::vector<boost::filesystem::path> &paths)

View File

@ -44,6 +44,11 @@ namespace storage
*/
struct StorageConfig final : IOConfig
{
StorageConfig(const boost::filesystem::path &base) : StorageConfig()
{
IOConfig::UseDefaultOutputNames(base);
}
StorageConfig()
: IOConfig({".osrm.ramIndex",
".osrm.fileIndex",

View File

@ -64,6 +64,11 @@ struct UpdaterConfig final : storage::IOConfig
{
}
void UseDefaultOutputNames(const boost::filesystem::path &base)
{
IOConfig::UseDefaultOutputNames(base);
}
double log_edge_updates_factor;
std::time_t valid_now;

View File

@ -30,7 +30,7 @@ int main(int argc, const char *argv[]) try
// Configure based on a .osrm base path, and no datasets in shared mem from osrm-datastore
EngineConfig config;
config.storage_config.UseDefaultOutputNames(argv[1]);
config.storage_config = {argv[1]};
config.use_shared_memory = false;
// Routing machine with several services (such as Route, Table, Nearest, Trip, Match)

View File

@ -229,7 +229,7 @@ int main(int argc, const char *argv[]) try
}
if (!base_path.empty())
{
config.storage_config.UseDefaultOutputNames(base_path);
config.storage_config = storage::StorageConfig(base_path);
}
if (!config.use_shared_memory && !config.storage_config.IsValid())
{

View File

@ -163,8 +163,7 @@ int main(const int argc, const char *argv[]) try
{
return EXIT_SUCCESS;
}
storage::StorageConfig config;
config.UseDefaultOutputNames(base_path);
storage::StorageConfig config(base_path);
if (!config.IsValid())
{
util::Log(logERROR) << "Config contains invalid file paths. Exiting!";

View File

@ -14,7 +14,7 @@ getOSRM(const std::string &base_path,
osrm::EngineConfig::Algorithm algorithm = osrm::EngineConfig::Algorithm::CH)
{
osrm::EngineConfig config;
config.storage_config.UseDefaultOutputNames(base_path);
config.storage_config = {base_path};
config.use_shared_memory = false;
config.algorithm = algorithm;

View File

@ -28,7 +28,7 @@ BOOST_AUTO_TEST_CASE(test_trip_limits)
using namespace osrm;
EngineConfig config;
config.storage_config.UseDefaultOutputNames(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
config.storage_config = {OSRM_TEST_DATA_DIR "/ch/monaco.osrm"};
config.use_shared_memory = false;
config.max_locations_trip = 2;
@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(test_route_limits)
using namespace osrm;
EngineConfig config;
config.storage_config.UseDefaultOutputNames(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
config.storage_config = {OSRM_TEST_DATA_DIR "/ch/monaco.osrm"};
config.use_shared_memory = false;
config.max_locations_viaroute = 2;
@ -82,7 +82,7 @@ BOOST_AUTO_TEST_CASE(test_table_limits)
using namespace osrm;
EngineConfig config;
config.storage_config.UseDefaultOutputNames(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
config.storage_config = {OSRM_TEST_DATA_DIR "/ch/monaco.osrm"};
config.use_shared_memory = false;
config.max_locations_distance_table = 2;
@ -109,7 +109,7 @@ BOOST_AUTO_TEST_CASE(test_match_limits)
using namespace osrm;
EngineConfig config;
config.storage_config.UseDefaultOutputNames(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
config.storage_config = {OSRM_TEST_DATA_DIR "/ch/monaco.osrm"};
config.use_shared_memory = false;
config.max_locations_map_matching = 2;
@ -136,7 +136,7 @@ BOOST_AUTO_TEST_CASE(test_nearest_limits)
using namespace osrm;
EngineConfig config;
config.storage_config.UseDefaultOutputNames(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
config.storage_config = {OSRM_TEST_DATA_DIR "/ch/monaco.osrm"};
config.use_shared_memory = false;
config.max_results_nearest = 2;

View File

@ -14,7 +14,7 @@ BOOST_AUTO_TEST_CASE(test_ch)
using namespace osrm;
EngineConfig config;
config.use_shared_memory = false;
config.storage_config.UseDefaultOutputNames(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
config.storage_config = storage::StorageConfig(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
config.algorithm = EngineConfig::Algorithm::CH;
OSRM osrm{config};
}
@ -24,7 +24,7 @@ BOOST_AUTO_TEST_CASE(test_corech)
using namespace osrm;
EngineConfig config;
config.use_shared_memory = false;
config.storage_config.UseDefaultOutputNames(OSRM_TEST_DATA_DIR "/corech/monaco.osrm");
config.storage_config = storage::StorageConfig(OSRM_TEST_DATA_DIR "/corech/monaco.osrm");
config.algorithm = EngineConfig::Algorithm::CoreCH;
OSRM osrm{config};
}
@ -34,7 +34,7 @@ BOOST_AUTO_TEST_CASE(test_mld)
using namespace osrm;
EngineConfig config;
config.use_shared_memory = false;
config.storage_config.UseDefaultOutputNames(OSRM_TEST_DATA_DIR "/mld/monaco.osrm");
config.storage_config = storage::StorageConfig(OSRM_TEST_DATA_DIR "/mld/monaco.osrm");
config.algorithm = EngineConfig::Algorithm::MLD;
OSRM osrm{config};
}