From 02e9f8aef325aac4f9e309fdf9e5699e39569458 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 15 Oct 2013 15:44:35 +0200 Subject: [PATCH] Rework facades to accept ServerPaths object as configuration --- Server/DataStructures/BaseDataFacade.h | 23 +++-- Server/DataStructures/InternalDataFacade.h | 108 +++++++-------------- Server/DataStructures/SharedDataFacade.h | 18 ++-- 3 files changed, 58 insertions(+), 91 deletions(-) diff --git a/Server/DataStructures/BaseDataFacade.h b/Server/DataStructures/BaseDataFacade.h index d1136f972..a53ba81f9 100644 --- a/Server/DataStructures/BaseDataFacade.h +++ b/Server/DataStructures/BaseDataFacade.h @@ -78,11 +78,9 @@ public: const unsigned id ) const = 0; - virtual unsigned GetOutDegree( const NodeID n ) const = 0; - - virtual NodeID GetTarget( const EdgeID e ) const = 0; - - virtual EdgeDataT &GetEdgeData( const EdgeID e ) = 0; + virtual TurnInstruction GetTurnInstructionForEdgeID( + const unsigned id + ) const = 0; virtual bool LocateClosestEndPointForCoordinate( const FixedPointCoordinate& input_coordinate, @@ -90,14 +88,21 @@ public: const unsigned zoom_level = 18 ) const = 0; - virtual EdgeID EndEdges( const NodeID n ) const = 0; - - //searches for a specific edge - virtual EdgeID FindEdge( const NodeID from, const NodeID to ) const = 0; + virtual bool FindPhantomNodeForCoordinate( + const FixedPointCoordinate & input_coordinate, + PhantomNode & resulting_phantom_node, + const unsigned zoom_level + ) const = 0; + virtual unsigned GetCheckSum() const = 0; virtual unsigned GetNameIndexFromEdgeID(const unsigned id) const = 0; + virtual void GetName( + const unsigned name_id, + std::string & result + ) const = 0; + std::string GetEscapedNameForNameID(const unsigned name_id) const { std::string temporary_string; GetName(name_id, temporary_string); diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index f1b5d3005..d2c6bbaf4 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -34,6 +34,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../../Util/BoostFileSystemFix.h" #include "../../Util/GraphLoader.h" #include "../../Util/IniFile.h" +#include "../../Util/ProgramOptions.h" #include "../../Util/SimpleLogger.h" template @@ -198,95 +199,60 @@ public: delete m_static_rtree; } - InternalDataFacade( - const IniFile & server_config, - const boost::filesystem::path & base_path - ) { - //check contents of config file - if ( !server_config.Holds("hsgrData")) { - throw OSRMException("no ram index file name in server ini"); - } - if ( !server_config.Holds("ramIndex") ) { - throw OSRMException("no mem index file name in server ini"); - } - if ( !server_config.Holds("fileIndex") ) { - throw OSRMException("no nodes file name in server ini"); - } - if ( !server_config.Holds("nodesData") ) { - throw OSRMException("no nodes file name in server ini"); - } - if ( !server_config.Holds("edgesData") ) { - throw OSRMException("no edges file name in server ini"); - } - + InternalDataFacade( const ServerPaths & server_paths ) { //generate paths of data files - boost::filesystem::path hsgr_path = boost::filesystem::absolute( - server_config.GetParameter("hsgrData"), - base_path - ); - boost::filesystem::path ram_index_path = boost::filesystem::absolute( - server_config.GetParameter("ramIndex"), - base_path - ); - boost::filesystem::path file_index_path = boost::filesystem::absolute( - server_config.GetParameter("fileIndex"), - base_path - ); - boost::filesystem::path node_data_path = boost::filesystem::absolute( - server_config.GetParameter("nodesData"), - base_path - ); - boost::filesystem::path edge_data_path = boost::filesystem::absolute( - server_config.GetParameter("edgesData"), - base_path - ); - boost::filesystem::path name_data_path = boost::filesystem::absolute( - server_config.GetParameter("namesData"), - base_path - ); - boost::filesystem::path timestamp_path = boost::filesystem::absolute( - server_config.GetParameter("timestamp"), - base_path - ); - - if ( !boost::filesystem::exists(hsgr_path) ) { - throw(".hsgr not found"); + if( server_paths.find("hsgrdata") == server_paths.end() ) { + throw OSRMException("no hsgr file given in ini file"); } - if ( !boost::filesystem::exists(ram_index_path) ) { - throw(".ramIndex not found"); + if( server_paths.find("ramindex") == server_paths.end() ) { + throw OSRMException("no ram index file given in ini file"); } - if ( !boost::filesystem::exists(file_index_path) ) { - throw(".fileIndex not found"); + if( server_paths.find("fileindex") == server_paths.end() ) { + throw OSRMException("no leaf index file given in ini file"); } - if ( !boost::filesystem::exists(node_data_path) ) { - throw(".nodes not found"); + if( server_paths.find("nodesdata") == server_paths.end() ) { + throw OSRMException("no nodes file given in ini file"); } - if ( !boost::filesystem::exists(edge_data_path) ) { - throw(".edges not found"); + if( server_paths.find("edgesdata") == server_paths.end() ) { + throw OSRMException("no edges file given in ini file"); } - if ( !boost::filesystem::exists(name_data_path) ) { - throw(".names not found"); + if( server_paths.find("namesdata") == server_paths.end() ) { + throw OSRMException("no names file given in ini file"); } - // check if data files empty - if ( 0 == boost::filesystem::file_size( node_data_path ) ) { - throw OSRMException("nodes file is empty"); - } - if ( 0 == boost::filesystem::file_size( edge_data_path ) ) { - throw OSRMException("edges file is empty"); - } + ServerPaths::const_iterator paths_iterator = server_paths.find("hsgrdata"); + BOOST_ASSERT(server_paths.end() != paths_iterator); + const boost::filesystem::path & hsgr_path = paths_iterator->second; + paths_iterator = server_paths.find("timestamp"); + BOOST_ASSERT(server_paths.end() != paths_iterator); + const boost::filesystem::path & timestamp_path = paths_iterator->second; + paths_iterator = server_paths.find("ramindex"); + BOOST_ASSERT(server_paths.end() != paths_iterator); + const boost::filesystem::path & ram_index_path = paths_iterator->second; + paths_iterator = server_paths.find("fileindex"); + BOOST_ASSERT(server_paths.end() != paths_iterator); + const boost::filesystem::path & file_index_path = paths_iterator->second; + paths_iterator = server_paths.find("nodesdata"); + BOOST_ASSERT(server_paths.end() != paths_iterator); + const boost::filesystem::path & nodes_data_path = paths_iterator->second; + paths_iterator = server_paths.find("edgesdata"); + BOOST_ASSERT(server_paths.end() != paths_iterator); + const boost::filesystem::path & edges_data_path = paths_iterator->second; + paths_iterator = server_paths.find("namesdata"); + BOOST_ASSERT(server_paths.end() != paths_iterator); + const boost::filesystem::path & names_data_path = paths_iterator->second; //load data SimpleLogger().Write() << "loading graph data"; LoadGraph(hsgr_path); SimpleLogger().Write() << "loading egde information"; - LoadNodeAndEdgeInformation(node_data_path, edge_data_path); + LoadNodeAndEdgeInformation(nodes_data_path, edges_data_path); SimpleLogger().Write() << "loading r-tree"; LoadRTree(ram_index_path, file_index_path); SimpleLogger().Write() << "loading timestamp"; LoadTimestamp(timestamp_path); SimpleLogger().Write() << "loading street names"; - LoadStreetNames(name_data_path); + LoadStreetNames(names_data_path); } //search graph access diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index b8daa1041..a542d67fe 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -29,7 +29,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../../DataStructures/StaticGraph.h" #include "../../DataStructures/StaticRTree.h" #include "../../Util/BoostFileSystemFix.h" -#include "../../Util/IniFile.h" +#include "../../Util/ProgramOptions.h" #include "../../Util/SimpleLogger.h" #include @@ -175,20 +175,16 @@ private: } public: - SharedDataFacade( - const IniFile & server_config, - const boost::filesystem::path base_path - ) { + SharedDataFacade( const ServerPaths & server_paths ) { //check contents of config file - if ( !server_config.Holds("fileIndex") ) { - throw OSRMException("no nodes file name in server ini"); + if( server_paths.find("fileindex") == server_paths.end() ) { + throw OSRMException("no leaf index file given in ini file"); } //generate paths of data files - boost::filesystem::path ram_index_path = boost::filesystem::absolute( - server_config.GetParameter("fileIndex"), - base_path - ); + ServerPaths::const_iterator paths_iterator = server_paths.find("fileindex"); + BOOST_ASSERT(server_paths.end() != paths_iterator); + boost::filesystem::path ram_index_path = paths_iterator->second; data_layout = (SharedDataLayout *)( SharedMemoryFactory::Get(LAYOUT_1)->Ptr()