refactor and migrate root directory

This commit is contained in:
Dennis Luxen 2014-05-08 19:40:29 +02:00
parent fdd0c8470f
commit c924b2067c
4 changed files with 522 additions and 504 deletions

View File

@ -53,7 +53,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string> #include <string>
#include <vector> #include <vector>
int main( const int argc, const char * argv[] ) int main(const int argc, const char *argv[])
{ {
LogPolicy::GetInstance().Unmute(); LogPolicy::GetInstance().Unmute();
SharedBarriers barrier; SharedBarriers barrier;
@ -66,108 +66,111 @@ int main( const int argc, const char * argv[] )
} }
#endif #endif
try { try
try { {
boost::interprocess::scoped_lock< try
boost::interprocess::named_mutex {
> pending_lock(barrier.pending_update_mutex); boost::interprocess::scoped_lock<boost::interprocess::named_mutex> pending_lock(
} catch(...) { barrier.pending_update_mutex);
}
catch (...)
{
// hard unlock in case of any exception. // hard unlock in case of any exception.
barrier.pending_update_mutex.unlock(); barrier.pending_update_mutex.unlock();
} }
} catch(const std::exception & e) { }
catch (const std::exception &e)
{
SimpleLogger().Write(logWARNING) << "[exception] " << e.what(); SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
} }
try { try
{
SimpleLogger().Write(logDEBUG) << "Checking input parameters"; SimpleLogger().Write(logDEBUG) << "Checking input parameters";
ServerPaths server_paths; ServerPaths server_paths;
if( if (!GenerateDataStoreOptions(argc, argv, server_paths))
!GenerateDataStoreOptions( {
argc,
argv,
server_paths
)
) {
return 0; return 0;
} }
if( server_paths.find("hsgrdata") == server_paths.end() ) { if (server_paths.find("hsgrdata") == server_paths.end())
{
throw OSRMException("no hsgr file found"); throw OSRMException("no hsgr file found");
} }
if( server_paths.find("ramindex") == server_paths.end() ) { if (server_paths.find("ramindex") == server_paths.end())
{
throw OSRMException("no ram index file found"); throw OSRMException("no ram index file found");
} }
if( server_paths.find("fileindex") == server_paths.end() ) { if (server_paths.find("fileindex") == server_paths.end())
{
throw OSRMException("no leaf index file found"); throw OSRMException("no leaf index file found");
} }
if( server_paths.find("nodesdata") == server_paths.end() ) { if (server_paths.find("nodesdata") == server_paths.end())
{
throw OSRMException("no nodes file found"); throw OSRMException("no nodes file found");
} }
if( server_paths.find("edgesdata") == server_paths.end() ) { if (server_paths.find("edgesdata") == server_paths.end())
{
throw OSRMException("no edges file found"); throw OSRMException("no edges file found");
} }
if( server_paths.find("namesdata") == server_paths.end() ) { if (server_paths.find("namesdata") == server_paths.end())
{
throw OSRMException("no names file found"); throw OSRMException("no names file found");
} }
if( server_paths.find("geometry") == server_paths.end() ) { if (server_paths.find("geometry") == server_paths.end())
{
throw OSRMException("no geometry file found"); throw OSRMException("no geometry file found");
} }
ServerPaths::const_iterator paths_iterator = server_paths.find("hsgrdata"); ServerPaths::const_iterator paths_iterator = server_paths.find("hsgrdata");
BOOST_ASSERT(server_paths.end() != paths_iterator); BOOST_ASSERT(server_paths.end() != paths_iterator);
BOOST_ASSERT(!paths_iterator->second.empty()); BOOST_ASSERT(!paths_iterator->second.empty());
const boost::filesystem::path & hsgr_path = paths_iterator->second; const boost::filesystem::path &hsgr_path = paths_iterator->second;
paths_iterator = server_paths.find("timestamp"); paths_iterator = server_paths.find("timestamp");
BOOST_ASSERT(server_paths.end() != paths_iterator); BOOST_ASSERT(server_paths.end() != paths_iterator);
BOOST_ASSERT(!paths_iterator->second.empty()); BOOST_ASSERT(!paths_iterator->second.empty());
const boost::filesystem::path & timestamp_path = paths_iterator->second; const boost::filesystem::path &timestamp_path = paths_iterator->second;
paths_iterator = server_paths.find("ramindex"); paths_iterator = server_paths.find("ramindex");
BOOST_ASSERT(server_paths.end() != paths_iterator); BOOST_ASSERT(server_paths.end() != paths_iterator);
BOOST_ASSERT(!paths_iterator->second.empty()); BOOST_ASSERT(!paths_iterator->second.empty());
const boost::filesystem::path & ram_index_path = paths_iterator->second; const boost::filesystem::path &ram_index_path = paths_iterator->second;
paths_iterator = server_paths.find("fileindex"); paths_iterator = server_paths.find("fileindex");
BOOST_ASSERT(server_paths.end() != paths_iterator); BOOST_ASSERT(server_paths.end() != paths_iterator);
BOOST_ASSERT(!paths_iterator->second.empty()); BOOST_ASSERT(!paths_iterator->second.empty());
const boost::filesystem::path index_file_path_absolute = boost::filesystem::portable_canonical(paths_iterator->second); const boost::filesystem::path index_file_path_absolute =
const std::string & file_index_file_name = index_file_path_absolute.string(); boost::filesystem::portable_canonical(paths_iterator->second);
const std::string &file_index_file_name = index_file_path_absolute.string();
paths_iterator = server_paths.find("nodesdata"); paths_iterator = server_paths.find("nodesdata");
BOOST_ASSERT(server_paths.end() != paths_iterator); BOOST_ASSERT(server_paths.end() != paths_iterator);
BOOST_ASSERT(!paths_iterator->second.empty()); BOOST_ASSERT(!paths_iterator->second.empty());
const boost::filesystem::path & nodes_data_path = paths_iterator->second; const boost::filesystem::path &nodes_data_path = paths_iterator->second;
paths_iterator = server_paths.find("edgesdata"); paths_iterator = server_paths.find("edgesdata");
BOOST_ASSERT(server_paths.end() != paths_iterator); BOOST_ASSERT(server_paths.end() != paths_iterator);
BOOST_ASSERT(!paths_iterator->second.empty()); BOOST_ASSERT(!paths_iterator->second.empty());
const boost::filesystem::path & edges_data_path = paths_iterator->second; const boost::filesystem::path &edges_data_path = paths_iterator->second;
paths_iterator = server_paths.find("namesdata"); paths_iterator = server_paths.find("namesdata");
BOOST_ASSERT(server_paths.end() != paths_iterator); BOOST_ASSERT(server_paths.end() != paths_iterator);
BOOST_ASSERT(!paths_iterator->second.empty()); BOOST_ASSERT(!paths_iterator->second.empty());
const boost::filesystem::path & names_data_path = paths_iterator->second; const boost::filesystem::path &names_data_path = paths_iterator->second;
paths_iterator = server_paths.find("geometry"); paths_iterator = server_paths.find("geometry");
BOOST_ASSERT(server_paths.end() != paths_iterator); BOOST_ASSERT(server_paths.end() != paths_iterator);
BOOST_ASSERT(!paths_iterator->second.empty()); BOOST_ASSERT(!paths_iterator->second.empty());
const boost::filesystem::path & geometries_data_path = paths_iterator->second; const boost::filesystem::path &geometries_data_path = paths_iterator->second;
// get the shared memory segment to use // get the shared memory segment to use
bool use_first_segment = SharedMemory::RegionExists( LAYOUT_2 ); bool use_first_segment = SharedMemory::RegionExists(LAYOUT_2);
SharedDataType LAYOUT = ( use_first_segment ? LAYOUT_1 : LAYOUT_2 ); SharedDataType LAYOUT = (use_first_segment ? LAYOUT_1 : LAYOUT_2);
SharedDataType DATA = ( use_first_segment ? DATA_1 : DATA_2 ); SharedDataType DATA = (use_first_segment ? DATA_1 : DATA_2);
// Allocate a memory layout in shared memory, deallocate previous // Allocate a memory layout in shared memory, deallocate previous
SharedMemory * layout_memory = SharedMemoryFactory::Get( SharedMemory *layout_memory = SharedMemoryFactory::Get(LAYOUT, sizeof(SharedDataLayout));
LAYOUT, SharedDataLayout *shared_layout_ptr = static_cast<SharedDataLayout *>(layout_memory->Ptr());
sizeof(SharedDataLayout) shared_layout_ptr = new (layout_memory->Ptr()) SharedDataLayout();
);
SharedDataLayout * shared_layout_ptr = static_cast<SharedDataLayout *>(
layout_memory->Ptr()
);
shared_layout_ptr = new(layout_memory->Ptr()) SharedDataLayout();
std::copy( std::copy(file_index_file_name.begin(),
file_index_file_name.begin(), (file_index_file_name.length() <= 1024 ? file_index_file_name.end()
(file_index_file_name.length() <= 1024 ? file_index_file_name.end() : file_index_file_name.begin()+1023), : file_index_file_name.begin() + 1023),
shared_layout_ptr->ram_index_file_name shared_layout_ptr->ram_index_file_name);
);
// add zero termination // add zero termination
unsigned end_of_string_index = std::min((std::size_t)1023, file_index_file_name.length()); unsigned end_of_string_index = std::min((std::size_t)1023, file_index_file_name.length());
shared_layout_ptr->ram_index_file_name[end_of_string_index] = '\0'; shared_layout_ptr->ram_index_file_name[end_of_string_index] = '\0';
@ -175,38 +178,28 @@ int main( const int argc, const char * argv[] )
// collect number of elements to store in shared memory object // collect number of elements to store in shared memory object
SimpleLogger().Write() << "load names from: " << names_data_path; SimpleLogger().Write() << "load names from: " << names_data_path;
// number of entries in name index // number of entries in name index
boost::filesystem::ifstream name_stream( boost::filesystem::ifstream name_stream(names_data_path, std::ios::binary);
names_data_path, std::ios::binary
);
unsigned name_index_size = 0; unsigned name_index_size = 0;
name_stream.read((char *)&name_index_size, sizeof(unsigned)); name_stream.read((char *)&name_index_size, sizeof(unsigned));
shared_layout_ptr->name_index_list_size = name_index_size; shared_layout_ptr->name_index_list_size = name_index_size;
SimpleLogger().Write() << "size: " << name_index_size; SimpleLogger().Write() << "size: " << name_index_size;
// SimpleLogger().Write() << "name index size: " << shared_layout_ptr->name_index_list_size;
BOOST_ASSERT_MSG(0 != shared_layout_ptr->name_index_list_size, "name file broken"); BOOST_ASSERT_MSG(0 != shared_layout_ptr->name_index_list_size, "name file broken");
unsigned number_of_chars = 0; unsigned number_of_chars = 0;
name_stream.read((char *)&number_of_chars, sizeof(unsigned)); name_stream.read((char *)&number_of_chars, sizeof(unsigned));
shared_layout_ptr->name_char_list_size = number_of_chars; shared_layout_ptr->name_char_list_size = number_of_chars;
// SimpleLogger().Write() << "name char size: " << shared_layout_ptr->name_char_list_size;
//Loading information for original edges // Loading information for original edges
boost::filesystem::ifstream edges_input_stream( boost::filesystem::ifstream edges_input_stream(edges_data_path, std::ios::binary);
edges_data_path,
std::ios::binary
);
unsigned number_of_original_edges = 0; unsigned number_of_original_edges = 0;
edges_input_stream.read((char*)&number_of_original_edges, sizeof(unsigned)); edges_input_stream.read((char *)&number_of_original_edges, sizeof(unsigned));
shared_layout_ptr->via_node_list_size = number_of_original_edges; shared_layout_ptr->via_node_list_size = number_of_original_edges;
shared_layout_ptr->name_id_list_size = number_of_original_edges; shared_layout_ptr->name_id_list_size = number_of_original_edges;
shared_layout_ptr->turn_instruction_list_size = number_of_original_edges; shared_layout_ptr->turn_instruction_list_size = number_of_original_edges;
shared_layout_ptr->geometries_indicators = number_of_original_edges; shared_layout_ptr->geometries_indicators = number_of_original_edges;
boost::filesystem::ifstream hsgr_input_stream( boost::filesystem::ifstream hsgr_input_stream(hsgr_path, std::ios::binary);
hsgr_path,
std::ios::binary
);
UUID uuid_loaded, uuid_orig; UUID uuid_loaded, uuid_orig;
hsgr_input_stream.read((char *)&uuid_loaded, sizeof(UUID)); hsgr_input_stream.read((char *)&uuid_loaded, sizeof(UUID));
@ -222,135 +215,111 @@ int main( const int argc, const char * argv[] )
// load checksum // load checksum
unsigned checksum = 0; unsigned checksum = 0;
hsgr_input_stream.read((char*)&checksum, sizeof(unsigned) ); hsgr_input_stream.read((char *)&checksum, sizeof(unsigned));
shared_layout_ptr->checksum = checksum; shared_layout_ptr->checksum = checksum;
// load graph node size // load graph node size
unsigned number_of_graph_nodes = 0; unsigned number_of_graph_nodes = 0;
hsgr_input_stream.read( hsgr_input_stream.read((char *)&number_of_graph_nodes, sizeof(unsigned));
(char*) &number_of_graph_nodes,
sizeof(unsigned)
);
BOOST_ASSERT_MSG( BOOST_ASSERT_MSG((0 != number_of_graph_nodes), "number of nodes is zero");
(0 != number_of_graph_nodes),
"number of nodes is zero"
);
shared_layout_ptr->graph_node_list_size = number_of_graph_nodes; shared_layout_ptr->graph_node_list_size = number_of_graph_nodes;
// load graph edge size // load graph edge size
unsigned number_of_graph_edges = 0; unsigned number_of_graph_edges = 0;
hsgr_input_stream.read( (char*) &number_of_graph_edges, sizeof(unsigned) ); hsgr_input_stream.read((char *)&number_of_graph_edges, sizeof(unsigned));
BOOST_ASSERT_MSG( BOOST_ASSERT_MSG(0 != number_of_graph_edges, "number of graph edges is zero");
0 != number_of_graph_edges,
"number of graph edges is zero"
);
shared_layout_ptr->graph_edge_list_size = number_of_graph_edges; shared_layout_ptr->graph_edge_list_size = number_of_graph_edges;
// load rsearch tree size // load rsearch tree size
boost::filesystem::ifstream tree_node_file( boost::filesystem::ifstream tree_node_file(ram_index_path, std::ios::binary);
ram_index_path,
std::ios::binary
);
uint32_t tree_size = 0; uint32_t tree_size = 0;
tree_node_file.read((char*)&tree_size, sizeof(uint32_t)); tree_node_file.read((char *)&tree_size, sizeof(uint32_t));
shared_layout_ptr->r_search_tree_size = tree_size; shared_layout_ptr->r_search_tree_size = tree_size;
//load timestamp size // load timestamp size
std::string m_timestamp; std::string m_timestamp;
if( boost::filesystem::exists(timestamp_path) ) { if (boost::filesystem::exists(timestamp_path))
boost::filesystem::ifstream timestampInStream( timestamp_path ); {
if(!timestampInStream) { boost::filesystem::ifstream timestamp_stream(timestamp_path);
SimpleLogger().Write(logWARNING) << if (!timestamp_stream)
timestamp_path << " not found. setting to default"; {
} else { SimpleLogger().Write(logWARNING) << timestamp_path
getline(timestampInStream, m_timestamp); << " not found. setting to default";
timestampInStream.close(); }
else
{
getline(timestamp_stream, m_timestamp);
timestamp_stream.close();
} }
} }
if(m_timestamp.empty()) { if (m_timestamp.empty())
{
m_timestamp = "n/a"; m_timestamp = "n/a";
} }
if(25 < m_timestamp.length()) { if (25 < m_timestamp.length())
{
m_timestamp.resize(25); m_timestamp.resize(25);
} }
shared_layout_ptr->timestamp_length = m_timestamp.length(); shared_layout_ptr->timestamp_length = m_timestamp.length();
//load coordinate size // load coordinate size
boost::filesystem::ifstream nodes_input_stream( boost::filesystem::ifstream nodes_input_stream(nodes_data_path, std::ios::binary);
nodes_data_path,
std::ios::binary
);
unsigned coordinate_list_size = 0; unsigned coordinate_list_size = 0;
nodes_input_stream.read((char *)&coordinate_list_size, sizeof(unsigned)); nodes_input_stream.read((char *)&coordinate_list_size, sizeof(unsigned));
shared_layout_ptr->coordinate_list_size = coordinate_list_size; shared_layout_ptr->coordinate_list_size = coordinate_list_size;
// load geometries sizes // load geometries sizes
std::ifstream geometry_input_stream( std::ifstream geometry_input_stream(geometries_data_path.c_str(), std::ios::binary);
geometries_data_path.c_str(),
std::ios::binary
);
unsigned number_of_geometries_indices = 0; unsigned number_of_geometries_indices = 0;
unsigned number_of_compressed_geometries = 0; unsigned number_of_compressed_geometries = 0;
geometry_input_stream.read((char *)&number_of_geometries_indices, sizeof(unsigned)); geometry_input_stream.read((char *)&number_of_geometries_indices, sizeof(unsigned));
shared_layout_ptr->geometries_index_list_size = number_of_geometries_indices; shared_layout_ptr->geometries_index_list_size = number_of_geometries_indices;
boost::iostreams::seek(geometry_input_stream, number_of_geometries_indices*sizeof(unsigned), BOOST_IOS::cur); boost::iostreams::seek(
geometry_input_stream.read( (char *)&number_of_compressed_geometries, sizeof(unsigned)); geometry_input_stream, number_of_geometries_indices * sizeof(unsigned), BOOST_IOS::cur);
geometry_input_stream.read((char *)&number_of_compressed_geometries, sizeof(unsigned));
shared_layout_ptr->geometries_list_size = number_of_compressed_geometries; shared_layout_ptr->geometries_list_size = number_of_compressed_geometries;
// allocate shared memory block // allocate shared memory block
SimpleLogger().Write() << "allocating shared memory of " << shared_layout_ptr->GetSizeOfLayout() << " bytes"; SimpleLogger().Write() << "allocating shared memory of "
SharedMemory * shared_memory = SharedMemoryFactory::Get( << shared_layout_ptr->GetSizeOfLayout() << " bytes";
DATA, SharedMemory *shared_memory =
shared_layout_ptr->GetSizeOfLayout() SharedMemoryFactory::Get(DATA, shared_layout_ptr->GetSizeOfLayout());
); char *shared_memory_ptr = static_cast<char *>(shared_memory->Ptr());
char * shared_memory_ptr = static_cast<char *>(shared_memory->Ptr());
// read actual data into shared memory object // // read actual data into shared memory object //
// Loading street names // Loading street names
unsigned * name_index_ptr = (unsigned*)( unsigned *name_index_ptr =
shared_memory_ptr + shared_layout_ptr->GetNameIndexOffset() (unsigned *)(shared_memory_ptr + shared_layout_ptr->GetNameIndexOffset());
);
name_stream.read( name_stream.read((char *)name_index_ptr,
(char*)name_index_ptr, shared_layout_ptr->name_index_list_size * sizeof(unsigned));
shared_layout_ptr->name_index_list_size*sizeof(unsigned)
);
char * name_char_ptr = shared_memory_ptr + shared_layout_ptr->GetNameListOffset(); char *name_char_ptr = shared_memory_ptr + shared_layout_ptr->GetNameListOffset();
name_stream.read( name_stream.read(name_char_ptr, shared_layout_ptr->name_char_list_size * sizeof(char));
name_char_ptr,
shared_layout_ptr->name_char_list_size*sizeof(char)
);
name_stream.close(); name_stream.close();
//load original edge information // load original edge information
NodeID * via_node_ptr = (NodeID *)( NodeID *via_node_ptr =
shared_memory_ptr + shared_layout_ptr->GetViaNodeListOffset() (NodeID *)(shared_memory_ptr + shared_layout_ptr->GetViaNodeListOffset());
);
unsigned * name_id_ptr = (unsigned *)( unsigned *name_id_ptr =
shared_memory_ptr + shared_layout_ptr->GetNameIDListOffset() (unsigned *)(shared_memory_ptr + shared_layout_ptr->GetNameIDListOffset());
);
TurnInstruction * turn_instructions_ptr = (TurnInstruction *)( TurnInstruction *turn_instructions_ptr =
shared_memory_ptr + shared_layout_ptr->GetTurnInstructionListOffset() (TurnInstruction *)(shared_memory_ptr +
); shared_layout_ptr->GetTurnInstructionListOffset());
unsigned * geometries_indicator_ptr = (unsigned *)( unsigned *geometries_indicator_ptr =
shared_memory_ptr + shared_layout_ptr->GetGeometriesIndicatorOffset() (unsigned *)(shared_memory_ptr + shared_layout_ptr->GetGeometriesIndicatorOffset());
);
OriginalEdgeData current_edge_data; OriginalEdgeData current_edge_data;
for(unsigned i = 0; i < number_of_original_edges; ++i) { for (unsigned i = 0; i < number_of_original_edges; ++i)
edges_input_stream.read( {
(char*)&(current_edge_data), edges_input_stream.read((char *)&(current_edge_data), sizeof(OriginalEdgeData));
sizeof(OriginalEdgeData)
);
via_node_ptr[i] = current_edge_data.via_node; via_node_ptr[i] = current_edge_data.via_node;
name_id_ptr[i] = current_edge_data.name_id; name_id_ptr[i] = current_edge_data.name_id;
turn_instructions_ptr[i] = current_edge_data.turn_instruction; turn_instructions_ptr[i] = current_edge_data.turn_instruction;
const unsigned bucket = i / 32; const unsigned bucket = i / 32;
@ -365,125 +334,117 @@ int main( const int argc, const char * argv[] )
// load compressed geometry // load compressed geometry
unsigned temporary_value; unsigned temporary_value;
unsigned * geometries_index_ptr = (unsigned *)( unsigned *geometries_index_ptr =
shared_memory_ptr + shared_layout_ptr->GetGeometriesIndexListOffset() (unsigned *)(shared_memory_ptr + shared_layout_ptr->GetGeometriesIndexListOffset());
);
geometry_input_stream.seekg(0, geometry_input_stream.beg); geometry_input_stream.seekg(0, geometry_input_stream.beg);
geometry_input_stream.read((char *)&temporary_value, sizeof(unsigned)); geometry_input_stream.read((char *)&temporary_value, sizeof(unsigned));
BOOST_ASSERT(temporary_value == shared_layout_ptr->geometries_index_list_size); BOOST_ASSERT(temporary_value == shared_layout_ptr->geometries_index_list_size);
geometry_input_stream.read( geometry_input_stream.read((char *)geometries_index_ptr,
(char *)geometries_index_ptr, shared_layout_ptr->geometries_index_list_size *
shared_layout_ptr->geometries_index_list_size*sizeof(unsigned) sizeof(unsigned));
);
unsigned * geometries_list_ptr = (unsigned *)( unsigned *geometries_list_ptr =
shared_memory_ptr + shared_layout_ptr->GetGeometryListOffset() (unsigned *)(shared_memory_ptr + shared_layout_ptr->GetGeometryListOffset());
);
geometry_input_stream.read((char *)&temporary_value, sizeof(unsigned)); geometry_input_stream.read((char *)&temporary_value, sizeof(unsigned));
BOOST_ASSERT(temporary_value == shared_layout_ptr->geometries_list_size); BOOST_ASSERT(temporary_value == shared_layout_ptr->geometries_list_size);
geometry_input_stream.read( geometry_input_stream.read((char *)geometries_list_ptr,
(char *)geometries_list_ptr, shared_layout_ptr->geometries_list_size * sizeof(unsigned));
shared_layout_ptr->geometries_list_size*sizeof(unsigned)
);
// Loading list of coordinates // Loading list of coordinates
FixedPointCoordinate * coordinates_ptr = (FixedPointCoordinate *)( FixedPointCoordinate *coordinates_ptr =
shared_memory_ptr + shared_layout_ptr->GetCoordinateListOffset() (FixedPointCoordinate *)(shared_memory_ptr +
); shared_layout_ptr->GetCoordinateListOffset());
NodeInfo current_node; NodeInfo current_node;
for(unsigned i = 0; i < coordinate_list_size; ++i) { for (unsigned i = 0; i < coordinate_list_size; ++i)
{
nodes_input_stream.read((char *)&current_node, sizeof(NodeInfo)); nodes_input_stream.read((char *)&current_node, sizeof(NodeInfo));
coordinates_ptr[i] = FixedPointCoordinate(current_node.lat, current_node.lon); coordinates_ptr[i] = FixedPointCoordinate(current_node.lat, current_node.lon);
} }
nodes_input_stream.close(); nodes_input_stream.close();
//store timestamp // store timestamp
char * timestamp_ptr = static_cast<char *>( char *timestamp_ptr =
shared_memory_ptr + shared_layout_ptr->GetTimeStampOffset() static_cast<char *>(shared_memory_ptr + shared_layout_ptr->GetTimeStampOffset());
); std::copy(m_timestamp.c_str(), m_timestamp.c_str() + m_timestamp.length(), timestamp_ptr);
std::copy(
m_timestamp.c_str(),
m_timestamp.c_str()+m_timestamp.length(),
timestamp_ptr
);
// store search tree portion of rtree // store search tree portion of rtree
char * rtree_ptr = static_cast<char *>( char *rtree_ptr =
shared_memory_ptr + shared_layout_ptr->GetRSearchTreeOffset() static_cast<char *>(shared_memory_ptr + shared_layout_ptr->GetRSearchTreeOffset());
);
tree_node_file.read(rtree_ptr, sizeof(RTreeNode)*tree_size); tree_node_file.read(rtree_ptr, sizeof(RTreeNode) * tree_size);
tree_node_file.close(); tree_node_file.close();
// load the nodes of the search graph // load the nodes of the search graph
QueryGraph::NodeArrayEntry * graph_node_list_ptr = (QueryGraph::NodeArrayEntry*)( QueryGraph::NodeArrayEntry *graph_node_list_ptr =
shared_memory_ptr + shared_layout_ptr->GetGraphNodeListOffset() (QueryGraph::NodeArrayEntry *)(shared_memory_ptr +
); shared_layout_ptr->GetGraphNodeListOffset());
hsgr_input_stream.read( hsgr_input_stream.read((char *)graph_node_list_ptr,
(char*) graph_node_list_ptr, shared_layout_ptr->graph_node_list_size *
shared_layout_ptr->graph_node_list_size*sizeof(QueryGraph::NodeArrayEntry) sizeof(QueryGraph::NodeArrayEntry));
);
// load the edges of the search graph // load the edges of the search graph
QueryGraph::EdgeArrayEntry * graph_edge_list_ptr = (QueryGraph::EdgeArrayEntry *)( QueryGraph::EdgeArrayEntry *graph_edge_list_ptr =
shared_memory_ptr + shared_layout_ptr->GetGraphEdgeListOffset() (QueryGraph::EdgeArrayEntry *)(shared_memory_ptr +
); shared_layout_ptr->GetGraphEdgeListOffset());
hsgr_input_stream.read( hsgr_input_stream.read((char *)graph_edge_list_ptr,
(char*) graph_edge_list_ptr, shared_layout_ptr->graph_edge_list_size *
shared_layout_ptr->graph_edge_list_size*sizeof(QueryGraph::EdgeArrayEntry) sizeof(QueryGraph::EdgeArrayEntry));
);
hsgr_input_stream.close(); hsgr_input_stream.close();
// acquire lock // acquire lock
SharedMemory * data_type_memory = SharedMemoryFactory::Get( SharedMemory *data_type_memory =
CURRENT_REGIONS, SharedMemoryFactory::Get(CURRENT_REGIONS, sizeof(SharedDataTimestamp), true, false);
sizeof(SharedDataTimestamp), SharedDataTimestamp *data_timestamp_ptr =
true, static_cast<SharedDataTimestamp *>(data_type_memory->Ptr());
false
);
SharedDataTimestamp * data_timestamp_ptr = static_cast<SharedDataTimestamp*>(
data_type_memory->Ptr()
);
boost::interprocess::scoped_lock< boost::interprocess::scoped_lock<boost::interprocess::named_mutex> query_lock(
boost::interprocess::named_mutex barrier.query_mutex);
> query_lock(barrier.query_mutex);
// notify all processes that were waiting for this condition // notify all processes that were waiting for this condition
if (0 < barrier.number_of_queries) { if (0 < barrier.number_of_queries)
{
barrier.no_running_queries_condition.wait(query_lock); barrier.no_running_queries_condition.wait(query_lock);
} }
data_timestamp_ptr->layout = LAYOUT; data_timestamp_ptr->layout = LAYOUT;
data_timestamp_ptr->data = DATA; data_timestamp_ptr->data = DATA;
data_timestamp_ptr->timestamp +=1; data_timestamp_ptr->timestamp += 1;
if(use_first_segment) { if (use_first_segment)
BOOST_ASSERT( DATA == DATA_1 ); {
BOOST_ASSERT( LAYOUT == LAYOUT_1 ); BOOST_ASSERT(DATA == DATA_1);
if( !SharedMemory::Remove(DATA_2) ) { BOOST_ASSERT(LAYOUT == LAYOUT_1);
if (!SharedMemory::Remove(DATA_2))
{
SimpleLogger().Write(logWARNING) << "could not delete DATA_2"; SimpleLogger().Write(logWARNING) << "could not delete DATA_2";
} }
if( !SharedMemory::Remove(LAYOUT_2) ) { if (!SharedMemory::Remove(LAYOUT_2))
{
SimpleLogger().Write(logWARNING) << "could not delete LAYOUT_2"; SimpleLogger().Write(logWARNING) << "could not delete LAYOUT_2";
} }
} else { }
BOOST_ASSERT( DATA == DATA_2 ); else
BOOST_ASSERT( LAYOUT == LAYOUT_2 ); {
if( !SharedMemory::Remove(DATA_1) ) { BOOST_ASSERT(DATA == DATA_2);
BOOST_ASSERT(LAYOUT == LAYOUT_2);
if (!SharedMemory::Remove(DATA_1))
{
SimpleLogger().Write(logWARNING) << "could not delete DATA_1"; SimpleLogger().Write(logWARNING) << "could not delete DATA_1";
} }
if( !SharedMemory::Remove(LAYOUT_1) ) { if (!SharedMemory::Remove(LAYOUT_1))
{
SimpleLogger().Write(logWARNING) << "could not delete LAYOUT_1"; SimpleLogger().Write(logWARNING) << "could not delete LAYOUT_1";
} }
} }
SimpleLogger().Write() << "all data loaded"; SimpleLogger().Write() << "all data loaded";
shared_layout_ptr->PrintInformation(); shared_layout_ptr->PrintInformation();
} catch(const std::exception & e) { }
catch (const std::exception &e)
{
SimpleLogger().Write(logWARNING) << "caught exception: " << e.what(); SimpleLogger().Write(logWARNING) << "caught exception: " << e.what();
} }

View File

@ -49,38 +49,46 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <fstream> #include <fstream>
#include <string> #include <string>
ExtractorCallbacks * extractCallBacks; ExtractorCallbacks *extractor_callbacks;
UUID uuid; UUID uuid;
int main (int argc, char *argv[]) { int main(int argc, char *argv[])
try { {
try
{
LogPolicy::GetInstance().Unmute(); LogPolicy::GetInstance().Unmute();
std::chrono::time_point<std::chrono::steady_clock> startup_time = std::chrono::steady_clock::now(); std::chrono::time_point<std::chrono::steady_clock> startup_time =
std::chrono::steady_clock::now();
boost::filesystem::path config_file_path, input_path, profile_path; boost::filesystem::path config_file_path, input_path, profile_path;
int requested_num_threads; int requested_num_threads;
// declare a group of options that will be allowed only on command line // declare a group of options that will be allowed only on command line
boost::program_options::options_description generic_options("Options"); boost::program_options::options_description generic_options("Options");
generic_options.add_options() generic_options.add_options()("version,v", "Show version")("help,h",
("version,v", "Show version") "Show this help message")(
("help,h", "Show this help message") "config,c",
("config,c", boost::program_options::value<boost::filesystem::path>(&config_file_path)->default_value("extractor.ini"), boost::program_options::value<boost::filesystem::path>(&config_file_path)
"Path to a configuration file."); ->default_value("extractor.ini"),
"Path to a configuration file.");
// declare a group of options that will be allowed both on command line and in config file // declare a group of options that will be allowed both on command line and in config file
boost::program_options::options_description config_options("Configuration"); boost::program_options::options_description config_options("Configuration");
config_options.add_options() config_options.add_options()("profile,p",
("profile,p", boost::program_options::value<boost::filesystem::path>(&profile_path)->default_value("profile.lua"), boost::program_options::value<boost::filesystem::path>(
"Path to LUA routing profile") &profile_path)->default_value("profile.lua"),
("threads,t", boost::program_options::value<int>(&requested_num_threads)->default_value(8), "Path to LUA routing profile")(
"Number of threads to use"); "threads,t",
boost::program_options::value<int>(&requested_num_threads)->default_value(8),
"Number of threads to use");
// hidden options, will be allowed both on command line and in config file, but will not be shown to the user // hidden options, will be allowed both on command line and in config file, but will not be
// shown to the user
boost::program_options::options_description hidden_options("Hidden options"); boost::program_options::options_description hidden_options("Hidden options");
hidden_options.add_options() hidden_options.add_options()(
("input,i", boost::program_options::value<boost::filesystem::path>(&input_path), "input,i",
"Input file in .osm, .osm.bz2 or .osm.pbf format"); boost::program_options::value<boost::filesystem::path>(&input_path),
"Input file in .osm, .osm.bz2 or .osm.pbf format");
// positional option // positional option
boost::program_options::positional_options_description positional_options; boost::program_options::positional_options_description positional_options;
@ -93,21 +101,25 @@ int main (int argc, char *argv[]) {
boost::program_options::options_description config_file_options; boost::program_options::options_description config_file_options;
config_file_options.add(config_options).add(hidden_options); config_file_options.add(config_options).add(hidden_options);
boost::program_options::options_description visible_options(boost::filesystem::basename(argv[0]) + " <input.osm/.osm.bz2/.osm.pbf> [options]"); boost::program_options::options_description visible_options(
boost::filesystem::basename(argv[0]) + " <input.osm/.osm.bz2/.osm.pbf> [options]");
visible_options.add(generic_options).add(config_options); visible_options.add(generic_options).add(config_options);
// parse command line options // parse command line options
boost::program_options::variables_map option_variables; boost::program_options::variables_map option_variables;
boost::program_options::store(boost::program_options::command_line_parser(argc, argv). boost::program_options::store(boost::program_options::command_line_parser(argc, argv)
options(cmdline_options).positional(positional_options).run(), option_variables); .options(cmdline_options)
.positional(positional_options)
.run(),
option_variables);
if(option_variables.count("version")) if (option_variables.count("version"))
{ {
SimpleLogger().Write() << g_GIT_DESCRIPTION; SimpleLogger().Write() << g_GIT_DESCRIPTION;
return 0; return 0;
} }
if(option_variables.count("help")) if (option_variables.count("help"))
{ {
SimpleLogger().Write() << visible_options; SimpleLogger().Write() << visible_options;
return 0; return 0;
@ -116,37 +128,40 @@ int main (int argc, char *argv[]) {
boost::program_options::notify(option_variables); boost::program_options::notify(option_variables);
// parse config file // parse config file
if(boost::filesystem::is_regular_file(config_file_path)) if (boost::filesystem::is_regular_file(config_file_path))
{ {
SimpleLogger().Write() << "Reading options from: " << config_file_path.string(); SimpleLogger().Write() << "Reading options from: " << config_file_path.string();
std::string config_str; std::string config_str;
PrepareConfigFile(config_file_path.c_str(), config_str); PrepareConfigFile(config_file_path.c_str(), config_str);
std::stringstream config_stream( config_str ); std::stringstream config_stream(config_str);
boost::program_options::store(parse_config_file(config_stream, config_file_options), option_variables); boost::program_options::store(parse_config_file(config_stream, config_file_options),
option_variables);
boost::program_options::notify(option_variables); boost::program_options::notify(option_variables);
} }
if(!option_variables.count("input")) if (!option_variables.count("input"))
{ {
SimpleLogger().Write() << visible_options; SimpleLogger().Write() << visible_options;
return 0; return 0;
} }
if(1 > requested_num_threads) if (1 > requested_num_threads)
{ {
SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger"; SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
return 1; return 1;
} }
if(!boost::filesystem::is_regular_file(input_path)) if (!boost::filesystem::is_regular_file(input_path))
{ {
SimpleLogger().Write(logWARNING) << "Input file " << input_path.string() << " not found!"; SimpleLogger().Write(logWARNING) << "Input file " << input_path.string()
<< " not found!";
return 1; return 1;
} }
if(!boost::filesystem::is_regular_file(profile_path)) if (!boost::filesystem::is_regular_file(profile_path))
{ {
SimpleLogger().Write(logWARNING) << "Profile " << profile_path.string() << " not found!"; SimpleLogger().Write(logWARNING) << "Profile " << profile_path.string()
<< " not found!";
return 1; return 1;
} }
@ -154,29 +169,30 @@ int main (int argc, char *argv[]) {
SimpleLogger().Write() << "Input file: " << input_path.filename().string(); SimpleLogger().Write() << "Input file: " << input_path.filename().string();
SimpleLogger().Write() << "Profile: " << profile_path.filename().string(); SimpleLogger().Write() << "Profile: " << profile_path.filename().string();
SimpleLogger().Write() << "Threads: " << real_num_threads << " (requested " << requested_num_threads << ")"; SimpleLogger().Write() << "Threads: " << real_num_threads << " (requested "
<< requested_num_threads << ")";
/*** Setup Scripting Environment ***/ /*** Setup Scripting Environment ***/
ScriptingEnvironment scriptingEnvironment(profile_path.c_str()); ScriptingEnvironment scripting_environment(profile_path.c_str());
omp_set_num_threads(real_num_threads); omp_set_num_threads(real_num_threads);
bool file_has_pbf_format(false); bool file_has_pbf_format(false);
std::string output_file_name = input_path.string(); std::string output_file_name = input_path.string();
std::string restrictionsFileName = input_path.string(); std::string restriction_fileName = input_path.string();
std::string::size_type pos = output_file_name.find(".osm.bz2"); std::string::size_type pos = output_file_name.find(".osm.bz2");
if(pos==std::string::npos) if (pos == std::string::npos)
{ {
pos = output_file_name.find(".osm.pbf"); pos = output_file_name.find(".osm.pbf");
if (pos!=std::string::npos) if (pos != std::string::npos)
{ {
file_has_pbf_format = true; file_has_pbf_format = true;
} }
} }
if (pos==std::string::npos) if (pos == std::string::npos)
{ {
pos = output_file_name.find(".pbf"); pos = output_file_name.find(".pbf");
if (pos!=std::string::npos) if (pos != std::string::npos)
{ {
file_has_pbf_format = true; file_has_pbf_format = true;
} }
@ -187,67 +203,73 @@ int main (int argc, char *argv[]) {
if (pos == std::string::npos) if (pos == std::string::npos)
{ {
output_file_name.append(".osrm"); output_file_name.append(".osrm");
restrictionsFileName.append(".osrm.restrictions"); restriction_fileName.append(".osrm.restrictions");
} }
else else
{ {
output_file_name.replace(pos, 5, ".osrm"); output_file_name.replace(pos, 5, ".osrm");
restrictionsFileName.replace(pos, 5, ".osrm.restrictions"); restriction_fileName.replace(pos, 5, ".osrm.restrictions");
} }
} }
else else
{ {
output_file_name.replace(pos, 8, ".osrm"); output_file_name.replace(pos, 8, ".osrm");
restrictionsFileName.replace(pos, 8, ".osrm.restrictions"); restriction_fileName.replace(pos, 8, ".osrm.restrictions");
} }
boost::unordered_map<std::string, NodeID> stringMap; boost::unordered_map<std::string, NodeID> string_map;
ExtractionContainers externalMemory; ExtractionContainers extraction_containers;
stringMap[""] = 0; string_map[""] = 0;
extractCallBacks = new ExtractorCallbacks(&externalMemory, &stringMap); extractor_callbacks = new ExtractorCallbacks(&extraction_containers, &string_map);
BaseParser* parser; BaseParser *parser;
if(file_has_pbf_format) if (file_has_pbf_format)
{ {
parser = new PBFParser(input_path.c_str(), extractCallBacks, scriptingEnvironment); parser = new PBFParser(input_path.c_str(), extractor_callbacks, scripting_environment);
} }
else else
{ {
parser = new XMLParser(input_path.c_str(), extractCallBacks, scriptingEnvironment); parser = new XMLParser(input_path.c_str(), extractor_callbacks, scripting_environment);
} }
if(!parser->ReadHeader()) if (!parser->ReadHeader())
{ {
throw OSRMException("Parser not initialized!"); throw OSRMException("Parser not initialized!");
} }
SimpleLogger().Write() << "Parsing in progress.."; SimpleLogger().Write() << "Parsing in progress..";
std::chrono::time_point<std::chrono::steady_clock> parsing_start_time = std::chrono::steady_clock::now(); std::chrono::time_point<std::chrono::steady_clock> parsing_start_time =
std::chrono::steady_clock::now();
parser->Parse(); parser->Parse();
std::chrono::duration<double> parsing_duration = std::chrono::steady_clock::now() - parsing_start_time; std::chrono::duration<double> parsing_duration =
SimpleLogger().Write() << "Parsing finished after " << parsing_duration.count() << " seconds"; std::chrono::steady_clock::now() - parsing_start_time;
SimpleLogger().Write() << "Parsing finished after " << parsing_duration.count()
<< " seconds";
if (externalMemory.all_edges_list.empty()) if (extraction_containers.all_edges_list.empty())
{ {
SimpleLogger().Write(logWARNING) << "The input data is empty, exiting."; SimpleLogger().Write(logWARNING) << "The input data is empty, exiting.";
return 1; return 1;
} }
externalMemory.PrepareData(output_file_name, restrictionsFileName); extraction_containers.PrepareData(output_file_name, restriction_fileName);
delete parser; delete parser;
delete extractCallBacks; delete extractor_callbacks;
std::chrono::duration<double> extraction_duration = std::chrono::steady_clock::now() - startup_time; std::chrono::duration<double> extraction_duration =
SimpleLogger().Write() << "extraction finished after " << extraction_duration.count() << "s"; std::chrono::steady_clock::now() - startup_time;
SimpleLogger().Write() << "To prepare the data for routing, run: " << "./osrm-prepare " << output_file_name << std::endl; SimpleLogger().Write() << "extraction finished after " << extraction_duration.count()
<< "s";
SimpleLogger().Write() << "To prepare the data for routing, run: "
<< "./osrm-prepare " << output_file_name << std::endl;
} }
catch(boost::program_options::too_many_positional_options_error& e) catch (boost::program_options::too_many_positional_options_error &e)
{ {
SimpleLogger().Write(logWARNING) << "Only one input file can be specified"; SimpleLogger().Write(logWARNING) << "Only one input file can be specified";
return 1; return 1;
} }
catch(std::exception & e) catch (std::exception &e)
{ {
SimpleLogger().Write(logWARNING) << "Exception occured: " << e.what(); SimpleLogger().Write(logWARNING) << "Exception occured: " << e.what();
return 1; return 1;

View File

@ -56,43 +56,53 @@ typedef QueryEdge::EdgeData EdgeData;
typedef DynamicGraph<EdgeData>::InputEdge InputEdge; typedef DynamicGraph<EdgeData>::InputEdge InputEdge;
typedef StaticGraph<EdgeData>::InputEdge StaticEdge; typedef StaticGraph<EdgeData>::InputEdge StaticEdge;
std::vector<NodeInfo> internalToExternalNodeMapping; std::vector<NodeInfo> internal_to_external_node_map;
std::vector<TurnRestriction> inputRestrictions; std::vector<TurnRestriction> restriction_list;
std::vector<NodeID> bollardNodes; std::vector<NodeID> barrier_node_list;
std::vector<NodeID> trafficLightNodes; std::vector<NodeID> traffic_light_list;
std::vector<ImportEdge> edgeList; std::vector<ImportEdge> edge_list;
int main (int argc, char *argv[]) { int main(int argc, char *argv[])
try { {
try
{
LogPolicy::GetInstance().Unmute(); LogPolicy::GetInstance().Unmute();
std::chrono::time_point<std::chrono::steady_clock> startupTime = std::chrono::steady_clock::now(); std::chrono::time_point<std::chrono::steady_clock> startup_time =
std::chrono::steady_clock::now();
boost::filesystem::path config_file_path, input_path, restrictions_path, profile_path; boost::filesystem::path config_file_path, input_path, restrictions_path, profile_path;
int requested_num_threads; int requested_num_threads;
// declare a group of options that will be allowed only on command line // declare a group of options that will be allowed only on command line
boost::program_options::options_description generic_options("Options"); boost::program_options::options_description generic_options("Options");
generic_options.add_options() generic_options.add_options()("version,v", "Show version")("help,h",
("version,v", "Show version") "Show this help message")(
("help,h", "Show this help message") "config,c",
("config,c", boost::program_options::value<boost::filesystem::path>(&config_file_path)->default_value("contractor.ini"), boost::program_options::value<boost::filesystem::path>(&config_file_path)
"Path to a configuration file."); ->default_value("contractor.ini"),
"Path to a configuration file.");
// declare a group of options that will be allowed both on command line and in config file // declare a group of options that will be allowed both on command line and in config file
boost::program_options::options_description config_options("Configuration"); boost::program_options::options_description config_options("Configuration");
config_options.add_options() config_options.add_options()(
("restrictions,r", boost::program_options::value<boost::filesystem::path>(&restrictions_path), "restrictions,r",
"Restrictions file in .osrm.restrictions format") boost::program_options::value<boost::filesystem::path>(&restrictions_path),
("profile,p", boost::program_options::value<boost::filesystem::path>(&profile_path)->default_value("profile.lua"), "Restrictions file in .osrm.restrictions format")(
"Path to LUA routing profile") "profile,p",
("threads,t", boost::program_options::value<int>(&requested_num_threads)->default_value(8), boost::program_options::value<boost::filesystem::path>(&profile_path)
"Number of threads to use"); ->default_value("profile.lua"),
"Path to LUA routing profile")(
"threads,t",
boost::program_options::value<int>(&requested_num_threads)->default_value(8),
"Number of threads to use");
// hidden options, will be allowed both on command line and in config file, but will not be shown to the user // hidden options, will be allowed both on command line and in config file, but will not be
// shown to the user
boost::program_options::options_description hidden_options("Hidden options"); boost::program_options::options_description hidden_options("Hidden options");
hidden_options.add_options() hidden_options.add_options()(
("input,i", boost::program_options::value<boost::filesystem::path>(&input_path), "input,i",
"Input file in .osm, .osm.bz2 or .osm.pbf format"); boost::program_options::value<boost::filesystem::path>(&input_path),
"Input file in .osm, .osm.bz2 or .osm.pbf format");
// positional option // positional option
boost::program_options::positional_options_description positional_options; boost::program_options::positional_options_description positional_options;
@ -105,46 +115,59 @@ int main (int argc, char *argv[]) {
boost::program_options::options_description config_file_options; boost::program_options::options_description config_file_options;
config_file_options.add(config_options).add(hidden_options); config_file_options.add(config_options).add(hidden_options);
boost::program_options::options_description visible_options("Usage: " + boost::filesystem::basename(argv[0]) + " <input.osrm> [options]"); boost::program_options::options_description visible_options(
"Usage: " + boost::filesystem::basename(argv[0]) + " <input.osrm> [options]");
visible_options.add(generic_options).add(config_options); visible_options.add(generic_options).add(config_options);
// parse command line options // parse command line options
boost::program_options::variables_map option_variables; boost::program_options::variables_map option_variables;
boost::program_options::store(boost::program_options::command_line_parser(argc, argv). boost::program_options::store(boost::program_options::command_line_parser(argc, argv)
options(cmdline_options).positional(positional_options).run(), option_variables); .options(cmdline_options)
.positional(positional_options)
.run(),
option_variables);
if(option_variables.count("version")) { if (option_variables.count("version"))
{
SimpleLogger().Write() << g_GIT_DESCRIPTION; SimpleLogger().Write() << g_GIT_DESCRIPTION;
return 0; return 0;
} }
if(option_variables.count("help")) { if (option_variables.count("help"))
{
SimpleLogger().Write() << "\n" << visible_options; SimpleLogger().Write() << "\n" << visible_options;
return 0; return 0;
} }
boost::program_options::notify(option_variables); boost::program_options::notify(option_variables);
if(!option_variables.count("restrictions")) { if (!option_variables.count("restrictions"))
{
restrictions_path = std::string(input_path.string() + ".restrictions"); restrictions_path = std::string(input_path.string() + ".restrictions");
} }
if(!option_variables.count("input")) { if (!option_variables.count("input"))
{
SimpleLogger().Write() << "\n" << visible_options; SimpleLogger().Write() << "\n" << visible_options;
return 0; return 0;
} }
if(!boost::filesystem::is_regular_file(input_path)) { if (!boost::filesystem::is_regular_file(input_path))
SimpleLogger().Write(logWARNING) << "Input file " << input_path.string() << " not found!"; {
SimpleLogger().Write(logWARNING) << "Input file " << input_path.string()
<< " not found!";
return 1; return 1;
} }
if(!boost::filesystem::is_regular_file(profile_path)) { if (!boost::filesystem::is_regular_file(profile_path))
SimpleLogger().Write(logWARNING) << "Profile " << profile_path.string() << " not found!"; {
SimpleLogger().Write(logWARNING) << "Profile " << profile_path.string()
<< " not found!";
return 1; return 1;
} }
if(1 > requested_num_threads) { if (1 > requested_num_threads)
{
SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger"; SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
return 1; return 1;
} }
@ -154,286 +177,305 @@ int main (int argc, char *argv[]) {
SimpleLogger().Write() << "Input file: " << input_path.filename().string(); SimpleLogger().Write() << "Input file: " << input_path.filename().string();
SimpleLogger().Write() << "Restrictions file: " << restrictions_path.filename().string(); SimpleLogger().Write() << "Restrictions file: " << restrictions_path.filename().string();
SimpleLogger().Write() << "Profile: " << profile_path.filename().string(); SimpleLogger().Write() << "Profile: " << profile_path.filename().string();
SimpleLogger().Write() << "Threads: " << real_num_threads << " (requested " << requested_num_threads << ")"; SimpleLogger().Write() << "Threads: " << real_num_threads << " (requested "
<< requested_num_threads << ")";
omp_set_num_threads(real_num_threads); omp_set_num_threads(real_num_threads);
LogPolicy::GetInstance().Unmute(); LogPolicy::GetInstance().Unmute();
boost::filesystem::ifstream restrictionsInstream(restrictions_path, std::ios::binary); boost::filesystem::ifstream restriction_stream(restrictions_path, std::ios::binary);
TurnRestriction restriction; TurnRestriction restriction;
UUID uuid_loaded, uuid_orig; UUID uuid_loaded, uuid_orig;
unsigned usableRestrictionsCounter(0); unsigned number_of_usable_restrictions = 0;
restrictionsInstream.read((char*)&uuid_loaded, sizeof(UUID)); restriction_stream.read((char *)&uuid_loaded, sizeof(UUID));
if( !uuid_loaded.TestPrepare(uuid_orig) ) { if (!uuid_loaded.TestPrepare(uuid_orig))
SimpleLogger().Write(logWARNING) << {
".restrictions was prepared with different build.\n" SimpleLogger().Write(logWARNING) << ".restrictions was prepared with different build.\n"
"Reprocess to get rid of this warning."; "Reprocess to get rid of this warning.";
} }
restrictionsInstream.read( restriction_stream.read((char *)&number_of_usable_restrictions, sizeof(unsigned));
(char*)&usableRestrictionsCounter, restriction_list.resize(number_of_usable_restrictions);
sizeof(unsigned) restriction_stream.read((char *)&(restriction_list[0]),
); number_of_usable_restrictions * sizeof(TurnRestriction));
inputRestrictions.resize(usableRestrictionsCounter); restriction_stream.close();
restrictionsInstream.read(
(char *)&(inputRestrictions[0]),
usableRestrictionsCounter*sizeof(TurnRestriction)
);
restrictionsInstream.close();
boost::filesystem::ifstream in; boost::filesystem::ifstream in;
in.open(input_path, std::ios::in|std::ios::binary); in.open(input_path, std::ios::in | std::ios::binary);
const std::string nodeOut = input_path.string() + ".nodes"; const std::string node_filename = input_path.string() + ".nodes";
const std::string edgeOut = input_path.string() + ".edges"; const std::string edge_out = input_path.string() + ".edges";
const std::string geometry_filename = input_path.string() + ".geometry"; const std::string geometry_filename = input_path.string() + ".geometry";
const std::string graphOut = input_path.string() + ".hsgr"; const std::string graphOut = input_path.string() + ".hsgr";
const std::string rtree_nodes_path = input_path.string() + ".ramIndex"; const std::string rtree_nodes_path = input_path.string() + ".ramIndex";
const std::string rtree_leafs_path = input_path.string() + ".fileIndex"; const std::string rtree_leafs_path = input_path.string() + ".fileIndex";
/*** Setup Scripting Environment ***/ /*** Setup Scripting Environment ***/
// Create a new lua state // Create a new lua state
lua_State *myLuaState = luaL_newstate(); lua_State *lua_state = luaL_newstate();
// Connect LuaBind to this lua state // Connect LuaBind to this lua state
luabind::open(myLuaState); luabind::open(lua_state);
//open utility libraries string library; // open utility libraries string library;
luaL_openlibs(myLuaState); luaL_openlibs(lua_state);
//adjust lua load path // adjust lua load path
luaAddScriptFolderToLoadPath( myLuaState, profile_path.c_str() ); luaAddScriptFolderToLoadPath(lua_state, profile_path.c_str());
// Now call our function in a lua script // Now call our function in a lua script
if(0 != luaL_dofile(myLuaState, profile_path.c_str() )) { if (0 != luaL_dofile(lua_state, profile_path.c_str()))
std::cerr << {
lua_tostring(myLuaState,-1) << std::cerr << lua_tostring(lua_state, -1) << " occured in scripting block" << std::endl;
" occured in scripting block" <<
std::endl;
}
EdgeBasedGraphFactory::SpeedProfileProperties speedProfile;
if(0 != luaL_dostring( myLuaState, "return traffic_signal_penalty\n")) {
std::cerr << lua_tostring(myLuaState,-1) << " occured in scripting block" << std::endl;
return 1; return 1;
} }
speedProfile.trafficSignalPenalty = 10*lua_tointeger(myLuaState, -1);
SimpleLogger().Write(logDEBUG) << "traffic_signal_penalty: " << speedProfile.trafficSignalPenalty;
if(0 != luaL_dostring( myLuaState, "return u_turn_penalty\n")) { EdgeBasedGraphFactory::SpeedProfileProperties speed_profile;
std::cerr <<
lua_tostring(myLuaState,-1) << if (0 != luaL_dostring(lua_state, "return traffic_signal_penalty\n"))
" occured in scripting block" << {
std::endl; std::cerr << lua_tostring(lua_state, -1) << " occured in scripting block" << std::endl;
return 1; return 1;
} }
speedProfile.uTurnPenalty = 10*lua_tointeger(myLuaState, -1); speed_profile.trafficSignalPenalty = 10 * lua_tointeger(lua_state, -1);
SimpleLogger().Write(logDEBUG)
<< "traffic_signal_penalty: " << speed_profile.trafficSignalPenalty;
speedProfile.has_turn_penalty_function = lua_function_exists( myLuaState, "turn_function" ); if (0 != luaL_dostring(lua_state, "return u_turn_penalty\n"))
{
std::cerr << lua_tostring(lua_state, -1) << " occured in scripting block" << std::endl;
return 1;
}
speed_profile.uTurnPenalty = 10 * lua_tointeger(lua_state, -1);
std::vector<ImportEdge> edgeList; speed_profile.has_turn_penalty_function = lua_function_exists(lua_state, "turn_function");
NodeID nodeBasedNodeNumber = readBinaryOSRMGraphFromStream(in, edgeList, bollardNodes, trafficLightNodes, &internalToExternalNodeMapping, inputRestrictions);
std::vector<ImportEdge> edge_list;
NodeID number_of_node_based_nodes = readBinaryOSRMGraphFromStream(in,
edge_list,
barrier_node_list,
traffic_light_list,
&internal_to_external_node_map,
restriction_list);
in.close(); in.close();
if( edgeList.empty() ) { if (edge_list.empty())
{
SimpleLogger().Write(logWARNING) << "The input data is empty, exiting."; SimpleLogger().Write(logWARNING) << "The input data is empty, exiting.";
return 1; return 1;
} }
SimpleLogger().Write() << SimpleLogger().Write() << restriction_list.size() << " restrictions, "
inputRestrictions.size() << " restrictions, " << << barrier_node_list.size() << " bollard nodes, "
bollardNodes.size() << " bollard nodes, " << << traffic_light_list.size() << " traffic lights";
trafficLightNodes.size() << " traffic lights";
/*** /***
* Building an edge-expanded graph from node-based input and turn restrictions * Building an edge-expanded graph from node-based input and turn restrictions
*/ */
SimpleLogger().Write() << "Generating edge-expanded graph representation"; SimpleLogger().Write() << "Generating edge-expanded graph representation";
EdgeBasedGraphFactory * edgeBasedGraphFactory = new EdgeBasedGraphFactory (nodeBasedNodeNumber, edgeList, bollardNodes, trafficLightNodes, inputRestrictions, internalToExternalNodeMapping, speedProfile); EdgeBasedGraphFactory *edge_based_graph_factor =
std::vector<ImportEdge>().swap(edgeList); new EdgeBasedGraphFactory(number_of_node_based_nodes,
edgeBasedGraphFactory->Run(edgeOut,geometry_filename, myLuaState); edge_list,
std::vector<TurnRestriction>().swap(inputRestrictions); barrier_node_list,
std::vector<NodeID>().swap(bollardNodes); traffic_light_list,
std::vector<NodeID>().swap(trafficLightNodes); restriction_list,
unsigned edgeBasedNodeNumber = edgeBasedGraphFactory->GetNumberOfEdgeBasedNodes(); internal_to_external_node_map,
BOOST_ASSERT( speed_profile);
edgeBasedNodeNumber != std::numeric_limits<unsigned>::max() edge_list.clear();
); edge_list.shrink_to_fit();
DeallocatingVector<EdgeBasedEdge> edgeBasedEdgeList;
edgeBasedGraphFactory->GetEdgeBasedEdges(edgeBasedEdgeList);
std::vector<EdgeBasedNode> nodeBasedEdgeList;
edgeBasedGraphFactory->GetEdgeBasedNodes(nodeBasedEdgeList);
delete edgeBasedGraphFactory;
std::chrono::duration<double> expansionHasFinishedTime = std::chrono::steady_clock::now() - startupTime; edge_based_graph_factor->Run(edge_out, geometry_filename, lua_state);
restriction_list.clear();
restriction_list.shrink_to_fit();
barrier_node_list.clear();
barrier_node_list.shrink_to_fit();
traffic_light_list.clear();
traffic_light_list.shrink_to_fit();
unsigned number_of_edge_based_nodes = edge_based_graph_factor->GetNumberOfEdgeBasedNodes();
BOOST_ASSERT(number_of_edge_based_nodes != std::numeric_limits<unsigned>::max());
DeallocatingVector<EdgeBasedEdge> edgeBasedEdgeList;
edge_based_graph_factor->GetEdgeBasedEdges(edgeBasedEdgeList);
std::vector<EdgeBasedNode> node_based_edge_list;
edge_based_graph_factor->GetEdgeBasedNodes(node_based_edge_list);
delete edge_based_graph_factor;
std::chrono::duration<double> end_of_expansion_time =
std::chrono::steady_clock::now() - startup_time;
// Building grid-like nearest-neighbor data structure // Building grid-like nearest-neighbor data structure
SimpleLogger().Write() << "building r-tree ..."; SimpleLogger().Write() << "building r-tree ...";
StaticRTree<EdgeBasedNode> * rtree = StaticRTree<EdgeBasedNode> *rtree =
new StaticRTree<EdgeBasedNode>( new StaticRTree<EdgeBasedNode>(node_based_edge_list,
nodeBasedEdgeList, rtree_nodes_path.c_str(),
rtree_nodes_path.c_str(), rtree_leafs_path.c_str(),
rtree_leafs_path.c_str(), internal_to_external_node_map);
internalToExternalNodeMapping
);
delete rtree; delete rtree;
IteratorbasedCRC32<std::vector<EdgeBasedNode> > crc32; IteratorbasedCRC32<std::vector<EdgeBasedNode>> crc32;
unsigned crc32OfNodeBasedEdgeList = crc32(nodeBasedEdgeList.begin(), nodeBasedEdgeList.end() ); unsigned node_based_edge_list_CRC32 =
nodeBasedEdgeList.clear(); crc32(node_based_edge_list.begin(), node_based_edge_list.end());
std::vector<EdgeBasedNode>(nodeBasedEdgeList).swap(nodeBasedEdgeList); node_based_edge_list.clear();
SimpleLogger().Write() << "CRC32: " << crc32OfNodeBasedEdgeList; node_based_edge_list.shrink_to_fit();
SimpleLogger().Write() << "CRC32: " << node_based_edge_list_CRC32;
/*** /***
* Writing info on original (node-based) nodes * Writing info on original (node-based) nodes
*/ */
SimpleLogger().Write() << "writing node map ..."; SimpleLogger().Write() << "writing node map ...";
boost::filesystem::ofstream mapOutFile(nodeOut, std::ios::binary); boost::filesystem::ofstream node_stream(node_filename, std::ios::binary);
const unsigned size_of_mapping = internalToExternalNodeMapping.size(); const unsigned size_of_mapping = internal_to_external_node_map.size();
mapOutFile.write((char *)&size_of_mapping, sizeof(unsigned)); node_stream.write((char *)&size_of_mapping, sizeof(unsigned));
mapOutFile.write( node_stream.write((char *)&(internal_to_external_node_map[0]),
(char *)&(internalToExternalNodeMapping[0]), size_of_mapping * sizeof(NodeInfo));
size_of_mapping*sizeof(NodeInfo) node_stream.close();
); internal_to_external_node_map.clear();
mapOutFile.close(); internal_to_external_node_map.shrink_to_fit();
std::vector<NodeInfo>().swap(internalToExternalNodeMapping);
/*** /***
* Contracting the edge-expanded graph * Contracting the edge-expanded graph
*/ */
SimpleLogger().Write() << "initializing contractor"; SimpleLogger().Write() << "initializing contractor";
Contractor* contractor = new Contractor( edgeBasedNodeNumber, edgeBasedEdgeList ); Contractor *contractor = new Contractor(number_of_edge_based_nodes, edgeBasedEdgeList);
std::chrono::time_point<std::chrono::steady_clock> contraction_start_timestamp = std::chrono::steady_clock::now(); std::chrono::time_point<std::chrono::steady_clock> contraction_start_timestamp =
std::chrono::steady_clock::now();
contractor->Run(); contractor->Run();
std::chrono::duration<double> contraction_duration = std::chrono::steady_clock::now() - contraction_start_timestamp; std::chrono::duration<double> contraction_duration =
SimpleLogger().Write() << std::chrono::steady_clock::now() - contraction_start_timestamp;
"Contraction took " << SimpleLogger().Write() << "Contraction took " << contraction_duration.count() << " sec";
contraction_duration.count() <<
" sec";
DeallocatingVector< QueryEdge > contractedEdgeList; DeallocatingVector<QueryEdge> contracted_edge_list;
contractor->GetEdges( contractedEdgeList ); contractor->GetEdges(contracted_edge_list);
delete contractor; delete contractor;
/*** /***
* Sorting contracted edges in a way that the static query graph can read some in in-place. * Sorting contracted edges in a way that the static query graph can read some in in-place.
*/ */
std::sort(contractedEdgeList.begin(), contractedEdgeList.end()); std::sort(contracted_edge_list.begin(), contracted_edge_list.end());
unsigned max_used_node_id = 0; unsigned max_used_node_id = 0;
unsigned contracted_edge_count = contractedEdgeList.size(); unsigned contracted_edge_count = contracted_edge_list.size();
SimpleLogger().Write() << SimpleLogger().Write() << "Serializing compacted graph of " << contracted_edge_count
"Serializing compacted graph of " << << " edges";
contracted_edge_count <<
" edges";
boost::filesystem::ofstream hsgr_output_stream(graphOut, std::ios::binary); boost::filesystem::ofstream hsgr_output_stream(graphOut, std::ios::binary);
hsgr_output_stream.write((char*)&uuid_orig, sizeof(UUID) ); hsgr_output_stream.write((char *)&uuid_orig, sizeof(UUID));
for (const QueryEdge & edge : contractedEdgeList) for (const QueryEdge &edge : contracted_edge_list)
{ {
BOOST_ASSERT( UINT_MAX != edge.source ); BOOST_ASSERT(UINT_MAX != edge.source);
BOOST_ASSERT( UINT_MAX != edge.target ); BOOST_ASSERT(UINT_MAX != edge.target);
max_used_node_id = std::max(max_used_node_id, edge.source); max_used_node_id = std::max(max_used_node_id, edge.source);
max_used_node_id = std::max(max_used_node_id, edge.target); max_used_node_id = std::max(max_used_node_id, edge.target);
} }
SimpleLogger().Write(logDEBUG) << "input graph has " << edgeBasedNodeNumber << " nodes"; SimpleLogger().Write(logDEBUG) << "input graph has " << number_of_edge_based_nodes << " nodes";
SimpleLogger().Write(logDEBUG) << "contracted graph has " << max_used_node_id << " nodes"; SimpleLogger().Write(logDEBUG) << "contracted graph has " << max_used_node_id << " nodes";
max_used_node_id+=1; max_used_node_id += 1;
std::vector< StaticGraph<EdgeData>::NodeArrayEntry > node_array; std::vector<StaticGraph<EdgeData>::NodeArrayEntry> node_array;
node_array.resize( edgeBasedNodeNumber + 1); node_array.resize(number_of_edge_based_nodes + 1);
SimpleLogger().Write() << "Building node array"; SimpleLogger().Write() << "Building node array";
StaticGraph<EdgeData>::EdgeIterator edge = 0; StaticGraph<EdgeData>::EdgeIterator edge = 0;
StaticGraph<EdgeData>::EdgeIterator position = 0; StaticGraph<EdgeData>::EdgeIterator position = 0;
StaticGraph<EdgeData>::EdgeIterator lastEdge = edge; StaticGraph<EdgeData>::EdgeIterator lastEdge = edge;
for ( StaticGraph<EdgeData>::NodeIterator node = 0; node < max_used_node_id; ++node) for (StaticGraph<EdgeData>::NodeIterator node = 0; node < max_used_node_id; ++node)
{ {
lastEdge = edge; lastEdge = edge;
while ((edge < contracted_edge_count) && (contractedEdgeList[edge].source == node)) while ((edge < contracted_edge_count) && (contracted_edge_list[edge].source == node))
{ {
++edge; ++edge;
} }
node_array[node].firstEdge = position; //=edge node_array[node].firstEdge = position; //=edge
position += edge - lastEdge; //remove position += edge - lastEdge; // remove
} }
for (unsigned sentinel_counter = max_used_node_id; for (unsigned sentinel_counter = max_used_node_id; sentinel_counter != node_array.size();
sentinel_counter != node_array.size(); ++sentinel_counter)
++sentinel_counter
)
{ {
//sentinel element, guarded against underflow // sentinel element, guarded against underflow
node_array[sentinel_counter].firstEdge = contracted_edge_count; node_array[sentinel_counter].firstEdge = contracted_edge_count;
} }
unsigned node_array_size = node_array.size(); unsigned node_array_size = node_array.size();
//serialize crc32, aka checksum // serialize crc32, aka checksum
hsgr_output_stream.write((char*) &crc32OfNodeBasedEdgeList, sizeof(unsigned)); hsgr_output_stream.write((char *)&node_based_edge_list_CRC32, sizeof(unsigned));
//serialize number of nodes // serialize number of nodes
hsgr_output_stream.write((char*) &node_array_size, sizeof(unsigned)); hsgr_output_stream.write((char *)&node_array_size, sizeof(unsigned));
//serialize number of edges // serialize number of edges
hsgr_output_stream.write((char*) &contracted_edge_count, sizeof(unsigned)); hsgr_output_stream.write((char *)&contracted_edge_count, sizeof(unsigned));
//serialize all nodes // serialize all nodes
hsgr_output_stream.write((char*) &node_array[0], sizeof(StaticGraph<EdgeData>::NodeArrayEntry)*node_array_size); hsgr_output_stream.write((char *)&node_array[0],
//serialize all edges sizeof(StaticGraph<EdgeData>::NodeArrayEntry) * node_array_size);
// serialize all edges
SimpleLogger().Write() << "Building edge array"; SimpleLogger().Write() << "Building edge array";
edge = 0; edge = 0;
int usedEdgeCounter = 0; int number_of_used_edges = 0;
StaticGraph<EdgeData>::EdgeArrayEntry currentEdge; StaticGraph<EdgeData>::EdgeArrayEntry current_edge;
for (unsigned edge = 0; edge < contractedEdgeList.size(); ++edge) for (unsigned edge = 0; edge < contracted_edge_list.size(); ++edge)
{ {
// no eigen loops // no eigen loops
BOOST_ASSERT(contractedEdgeList[edge].source != contractedEdgeList[edge].target); BOOST_ASSERT(contracted_edge_list[edge].source != contracted_edge_list[edge].target);
currentEdge.target = contractedEdgeList[edge].target; current_edge.target = contracted_edge_list[edge].target;
currentEdge.data = contractedEdgeList[edge].data; current_edge.data = contracted_edge_list[edge].data;
// every target needs to be valid // every target needs to be valid
BOOST_ASSERT(currentEdge.target < max_used_node_id); BOOST_ASSERT(current_edge.target < max_used_node_id);
if(currentEdge.data.distance <= 0) { if (current_edge.data.distance <= 0)
SimpleLogger().Write(logWARNING) << {
"Edge: " << edge << SimpleLogger().Write(logWARNING) << "Edge: " << edge
",source: " << contractedEdgeList[edge].source << << ",source: " << contracted_edge_list[edge].source
", target: " << contractedEdgeList[edge].target << << ", target: " << contracted_edge_list[edge].target
", dist: " << currentEdge.data.distance; << ", dist: " << current_edge.data.distance;
SimpleLogger().Write(logWARNING) << SimpleLogger().Write(logWARNING) << "Failed at adjacency list of node "
"Failed at adjacency list of node " << contractedEdgeList[edge].source << "/" << node_array.size()-1; << contracted_edge_list[edge].source << "/"
<< node_array.size() - 1;
return 1; return 1;
} }
hsgr_output_stream.write((char*) &currentEdge, sizeof(StaticGraph<EdgeData>::EdgeArrayEntry)); hsgr_output_stream.write((char *)&current_edge,
++usedEdgeCounter; sizeof(StaticGraph<EdgeData>::EdgeArrayEntry));
++number_of_used_edges;
} }
hsgr_output_stream.close(); hsgr_output_stream.close();
std::chrono::duration<double> entire_duration = std::chrono::steady_clock::now() - startupTime; std::chrono::duration<double> entire_duration =
std::chrono::steady_clock::now() - startup_time;
SimpleLogger().Write() << "Preprocessing : " << entire_duration.count() << " seconds"; SimpleLogger().Write() << "Preprocessing : " << entire_duration.count() << " seconds";
SimpleLogger().Write() << "Expansion : " << SimpleLogger().Write() << "Expansion : "
(nodeBasedNodeNumber/expansionHasFinishedTime.count()) << " nodes/sec and " << << (number_of_node_based_nodes / end_of_expansion_time.count())
(edgeBasedNodeNumber/expansionHasFinishedTime.count()) << " edges/sec"; << " nodes/sec and "
<< (number_of_edge_based_nodes / end_of_expansion_time.count())
<< " edges/sec";
SimpleLogger().Write() << "Contraction: " << SimpleLogger().Write() << "Contraction: "
(edgeBasedNodeNumber/contraction_duration.count()) << " nodes/sec and " << << (number_of_edge_based_nodes / contraction_duration.count())
usedEdgeCounter/contraction_duration.count() << " edges/sec"; << " nodes/sec and "
<< number_of_used_edges / contraction_duration.count() << " edges/sec";
node_array.clear(); node_array.clear();
SimpleLogger().Write() << "finished preprocessing"; SimpleLogger().Write() << "finished preprocessing";
} catch(boost::program_options::too_many_positional_options_error&) { }
catch (boost::program_options::too_many_positional_options_error &)
{
SimpleLogger().Write(logWARNING) << "Only one file can be specified"; SimpleLogger().Write(logWARNING) << "Only one file can be specified";
return 1; return 1;
} catch(boost::program_options::error& e) { }
catch (boost::program_options::error &e)
{
SimpleLogger().Write(logWARNING) << e.what(); SimpleLogger().Write(logWARNING) << e.what();
return 1; return 1;
} catch ( const std::exception &e ) { }
catch (const std::exception &e)
{
SimpleLogger().Write(logWARNING) << "Exception occured: " << e.what() << std::endl; SimpleLogger().Write(logWARNING) << "Exception occured: " << e.what() << std::endl;
return 1; return 1;
} }

View File

@ -26,9 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "Library/OSRM.h" #include "Library/OSRM.h"
#include "Server/ServerFactory.h" #include "Server/ServerFactory.h"
#include "Util/GitDescription.h" #include "Util/GitDescription.h"
#include "Util/ProgramOptions.h" #include "Util/ProgramOptions.h"
#include "Util/SimpleLogger.h" #include "Util/SimpleLogger.h"
@ -38,12 +36,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <sys/mman.h> #include <sys/mman.h>
#endif #endif
#include <boost/thread.hpp> // for timed join.
#include <signal.h> #include <signal.h>
#include <boost/bind.hpp> #include <functional>
// #include <boost/date_time.hpp>
#include <boost/thread.hpp>
#include <iostream> #include <iostream>
#ifdef _WIN32 #ifdef _WIN32
@ -51,27 +48,27 @@ boost::function0<void> console_ctrl_function;
BOOL WINAPI console_ctrl_handler(DWORD ctrl_type) BOOL WINAPI console_ctrl_handler(DWORD ctrl_type)
{ {
switch (ctrl_type) switch (ctrl_type)
{ {
case CTRL_C_EVENT: case CTRL_C_EVENT:
case CTRL_BREAK_EVENT: case CTRL_BREAK_EVENT:
case CTRL_CLOSE_EVENT: case CTRL_CLOSE_EVENT:
case CTRL_SHUTDOWN_EVENT: case CTRL_SHUTDOWN_EVENT:
console_ctrl_function(); console_ctrl_function();
return TRUE; return TRUE;
default: default:
return FALSE; return FALSE;
} }
} }
#endif #endif
int main (int argc, const char * argv[]) int main(int argc, const char *argv[])
{ {
try try
{ {
LogPolicy::GetInstance().Unmute(); LogPolicy::GetInstance().Unmute();
bool use_shared_memory = false, trial = false; bool use_shared_memory = false, trial_run = false;
std::string ip_address; std::string ip_address;
int ip_port, requested_thread_num; int ip_port, requested_thread_num;
@ -84,7 +81,7 @@ int main (int argc, const char * argv[])
ip_port, ip_port,
requested_thread_num, requested_thread_num,
use_shared_memory, use_shared_memory,
trial); trial_run);
if (init_result == INIT_OK_DO_NOT_START_ENGINE) if (init_result == INIT_OK_DO_NOT_START_ENGINE)
{ {
return 0; return 0;
@ -101,11 +98,10 @@ int main (int argc, const char * argv[])
SimpleLogger().Write(logWARNING) << argv[0] << " could not be locked to RAM"; SimpleLogger().Write(logWARNING) << argv[0] << " could not be locked to RAM";
} }
#endif #endif
SimpleLogger().Write() << SimpleLogger().Write() << "starting up engines, " << g_GIT_DESCRIPTION << ", "
"starting up engines, " << g_GIT_DESCRIPTION << ", " << << "compiled at " << __DATE__ << ", " __TIME__;
"compiled at " << __DATE__ << ", " __TIME__;
if(use_shared_memory) if (use_shared_memory)
{ {
SimpleLogger().Write(logDEBUG) << "Loading from shared memory"; SimpleLogger().Write(logDEBUG) << "Loading from shared memory";
} }
@ -132,21 +128,18 @@ int main (int argc, const char * argv[])
#endif #endif
OSRM osrm_lib(server_paths, use_shared_memory); OSRM osrm_lib(server_paths, use_shared_memory);
Server * routing_server = ServerFactory::CreateServer( Server *routing_server =
ip_address, ServerFactory::CreateServer(ip_address, ip_port, requested_thread_num);
ip_port,
requested_thread_num
);
routing_server->GetRequestHandlerPtr().RegisterRoutingMachine(&osrm_lib); routing_server->GetRequestHandlerPtr().RegisterRoutingMachine(&osrm_lib);
if( trial ) if (trial_run)
{ {
SimpleLogger().Write() << "trial run, quitting after successful initialization"; SimpleLogger().Write() << "trial run, quitting after successful initialization";
} }
else else
{ {
boost::thread server_thread(boost::bind(&Server::Run, routing_server)); boost::thread server_thread(std::bind(&Server::Run, routing_server));
#ifndef _WIN32 #ifndef _WIN32
sigset_t wait_mask; sigset_t wait_mask;
@ -160,7 +153,7 @@ int main (int argc, const char * argv[])
sigwait(&wait_mask, &sig); sigwait(&wait_mask, &sig);
#else #else
// Set console control handler to allow server to be stopped. // Set console control handler to allow server to be stopped.
console_ctrl_function = boost::bind(&Server::Stop, routing_server); console_ctrl_function = std::bind(&Server::Stop, routing_server);
SetConsoleCtrlHandler(console_ctrl_handler, TRUE); SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
SimpleLogger().Write() << "running and waiting for requests"; SimpleLogger().Write() << "running and waiting for requests";
routing_server->Run(); routing_server->Run();
@ -179,7 +172,7 @@ int main (int argc, const char * argv[])
delete routing_server; delete routing_server;
SimpleLogger().Write() << "shutdown completed"; SimpleLogger().Write() << "shutdown completed";
} }
catch (const std::exception& e) catch (const std::exception &e)
{ {
SimpleLogger().Write(logWARNING) << "exception: " << e.what(); SimpleLogger().Write(logWARNING) << "exception: " << e.what();
return 1; return 1;