diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 15d0a7e5b..6054db470 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -40,7 +40,7 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory( if(restriction_iter == m_restriction_map.end()) { index = m_restriction_bucket_list.size(); m_restriction_bucket_list.resize(index+1); - m_restriction_map[restriction_source] = index; + m_restriction_map.emplace(restriction_source, index); } else { index = restriction_iter->second; //Map already contains an is_only_*-restriction diff --git a/Library/OSRM.cpp b/Library/OSRM.cpp index 1a0c8f5e9..79f6b869f 100644 --- a/Library/OSRM.cpp +++ b/Library/OSRM.cpp @@ -106,9 +106,9 @@ OSRM::~OSRM() { void OSRM::RegisterPlugin(BasePlugin * plugin) { SimpleLogger().Write() << "loaded plugin: " << plugin->GetDescriptor(); if( pluginMap.find(plugin->GetDescriptor()) != pluginMap.end() ) { - delete pluginMap[plugin->GetDescriptor()]; + delete pluginMap.find(plugin->GetDescriptor())->second; } - pluginMap.insert(std::make_pair(plugin->GetDescriptor(), plugin)); + pluginMap.emplace(plugin->GetDescriptor(), plugin); } void OSRM::RunQuery(RouteParameters & route_parameters, http::Reply & reply) { diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index 381b370a9..7efb06a10 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -24,7 +24,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "BasePlugin.h" #include "../Algorithms/ObjectToBase64.h" -#include "../DataStructures/HashTable.h" #include "../DataStructures/QueryEdge.h" #include "../DataStructures/StaticGraph.h" #include "../DataStructures/SearchEngine.h" @@ -35,6 +34,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Util/SimpleLogger.h" #include "../Util/StringUtil.h" +#include + #include #include @@ -58,9 +59,9 @@ public: searchEnginePtr = new SearchEngine(objects); - descriptorTable.insert(std::make_pair("" , 0)); - descriptorTable.insert(std::make_pair("json", 0)); - descriptorTable.insert(std::make_pair("gpx" , 1)); + // descriptorTable.emplace("" , 0); + descriptorTable.emplace("json", 0); + descriptorTable.emplace("gpx" , 1); } virtual ~ViaRoutePlugin() { @@ -129,7 +130,11 @@ public: } _DescriptorConfig descriptorConfig; - unsigned descriptorType = descriptorTable[routeParameters.outputFormat]; + + unsigned descriptorType = 0; + if(descriptorTable.find(routeParameters.outputFormat) != descriptorTable.end() ) { + descriptorType = descriptorTable.find(routeParameters.outputFormat)->second; + } descriptorConfig.z = routeParameters.zoomLevel; descriptorConfig.instructions = routeParameters.printInstructions; descriptorConfig.geometry = routeParameters.geometry; diff --git a/Server/BasicDatastructures.h b/Server/BasicDatastructures.h index 633675684..6d6d17485 100644 --- a/Server/BasicDatastructures.h +++ b/Server/BasicDatastructures.h @@ -129,7 +129,6 @@ std::vector Reply::HeaderstoBuffers(){ buffers.push_back(ToBuffer(status)); for (std::size_t i = 0; i < headers.size(); ++i) { Header& h = headers[i]; -// std::cout << h.name << ": " << h.value << std::endl; buffers.push_back(boost::asio::buffer(h.name)); buffers.push_back(boost::asio::buffer(seperators)); buffers.push_back(boost::asio::buffer(h.value)); diff --git a/Server/Connection.h b/Server/Connection.h index ffd6be3dc..1f1019d9a 100644 --- a/Server/Connection.h +++ b/Server/Connection.h @@ -25,12 +25,13 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "RequestHandler.h" #include "RequestParser.h" -#include #include +#include +#include #include +#include #include #include -#include #include @@ -39,88 +40,178 @@ or see http://www.gnu.org/licenses/agpl.txt. namespace http { /// Represents a single connection from a client. -class Connection : public boost::enable_shared_from_this, private boost::noncopyable { +class Connection : public boost::enable_shared_from_this, + private boost::noncopyable { public: - explicit Connection(boost::asio::io_service& io_service, RequestHandler& handler) : strand(io_service), TCPsocket(io_service), requestHandler(handler) {} + explicit Connection( + boost::asio::io_service& io_service, + RequestHandler& handler + ) : strand(io_service), TCP_socket(io_service), request_handler(handler) { } boost::asio::ip::tcp::socket& socket() { - return TCPsocket; + return TCP_socket; } /// Start the first asynchronous operation for the connection. void start() { - TCPsocket.async_read_some(boost::asio::buffer(incomingDataBuffer), strand.wrap( boost::bind(&Connection::handleRead, this->shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred))); + TCP_socket.async_read_some( + boost::asio::buffer(incoming_data_buffer), + strand.wrap( boost::bind( + &Connection::handle_read, + this->shared_from_this(), + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred) + ) + ); } private: - void handleRead(const boost::system::error_code& e, std::size_t bytes_transferred) { - if (!e) { - CompressionType compressionType(noCompression); + void handle_read( + const boost::system::error_code& e, + std::size_t bytes_transferred + ) { + if( !e ) { + CompressionType compression_type(noCompression); boost::tribool result; - boost::tie(result, boost::tuples::ignore) = requestParser.Parse( request, incomingDataBuffer.data(), incomingDataBuffer.data() + bytes_transferred, &compressionType); + boost::tie(result, boost::tuples::ignore) = request_parser.Parse( + request, + incoming_data_buffer.data(), + incoming_data_buffer.data() + bytes_transferred, + &compression_type + ); - if (result) { - // std::cout << "----" << std::endl; - // if(compressionType == gzipRFC1952) - // std::cout << "[debug] using gzip" << std::endl; - // if(compressionType == deflateRFC1951) - // std::cout << "[debug] using deflate" << std::endl; - // if(compressionType == noCompression) - // std::cout << "[debug] no compression" << std::endl; - request.endpoint = TCPsocket.remote_endpoint().address(); - requestHandler.handle_request(request, reply); + if( result ) { + request.endpoint = TCP_socket.remote_endpoint().address(); + request_handler.handle_request(request, reply); - Header compressionHeader; - std::vector compressed; - std::vector outputBuffer; - switch(compressionType) { + Header compression_header; + std::vector compressed_output; + std::vector output_buffer; + switch(compression_type) { case deflateRFC1951: - compressionHeader.name = "Content-Encoding"; - compressionHeader.value = "deflate"; - reply.headers.insert(reply.headers.begin(), compressionHeader); //push_back(compressionHeader); - compressCharArray(reply.content.c_str(), reply.content.length(), compressed, compressionType); - reply.setSize(compressed.size()); - outputBuffer = reply.HeaderstoBuffers(); - outputBuffer.push_back(boost::asio::buffer(compressed)); - boost::asio::async_write(TCPsocket, outputBuffer, strand.wrap( boost::bind(&Connection::handleWrite, this->shared_from_this(), boost::asio::placeholders::error))); + compression_header.name = "Content-Encoding"; + compression_header.value = "deflate"; + reply.headers.insert( + reply.headers.begin(), + compression_header + ); + compressCharArray( + reply.content.c_str(), + reply.content.length(), + compressed_output, + compression_type + ); + reply.setSize(compressed_output.size()); + output_buffer = reply.HeaderstoBuffers(); + output_buffer.push_back( + boost::asio::buffer(compressed_output) + ); + boost::asio::async_write( + TCP_socket, + output_buffer, + strand.wrap( + boost::bind( + &Connection::handle_write, + this->shared_from_this(), + boost::asio::placeholders::error + ) + ) + ); break; case gzipRFC1952: - compressionHeader.name = "Content-Encoding"; - compressionHeader.value = "gzip"; - reply.headers.insert(reply.headers.begin(), compressionHeader); - compressCharArray(reply.content.c_str(), reply.content.length(), compressed, compressionType); - reply.setSize(compressed.size()); - outputBuffer = reply.HeaderstoBuffers(); - outputBuffer.push_back(boost::asio::buffer(compressed)); - boost::asio::async_write(TCPsocket, outputBuffer, strand.wrap( boost::bind(&Connection::handleWrite, this->shared_from_this(), boost::asio::placeholders::error)));break; + compression_header.name = "Content-Encoding"; + compression_header.value = "gzip"; + reply.headers.insert( + reply.headers.begin(), + compression_header + ); + compressCharArray( + reply.content.c_str(), + reply.content.length(), + compressed_output, + compression_type + ); + reply.setSize(compressed_output.size()); + output_buffer = reply.HeaderstoBuffers(); + output_buffer.push_back( + boost::asio::buffer(compressed_output) + ); + boost::asio::async_write( + TCP_socket, + output_buffer, + strand.wrap( + boost::bind( + &Connection::handle_write, + this->shared_from_this(), + boost::asio::placeholders::error + ) + ) + ); + break; case noCompression: - boost::asio::async_write(TCPsocket, reply.toBuffers(), strand.wrap( boost::bind(&Connection::handleWrite, this->shared_from_this(), boost::asio::placeholders::error))); + boost::asio::async_write( + TCP_socket, + reply.toBuffers(), + strand.wrap( + boost::bind( + &Connection::handle_write, + this->shared_from_this(), + boost::asio::placeholders::error + ) + ) + ); break; } - } else if (!result) { reply = Reply::stockReply(Reply::badRequest); - boost::asio::async_write(TCPsocket, reply.toBuffers(), strand.wrap( boost::bind(&Connection::handleWrite, this->shared_from_this(), boost::asio::placeholders::error))); + boost::asio::async_write( + TCP_socket, + reply.toBuffers(), + strand.wrap( + boost::bind( + &Connection::handle_write, + this->shared_from_this(), + boost::asio::placeholders::error + ) + ) + ); } else { - TCPsocket.async_read_some(boost::asio::buffer(incomingDataBuffer), strand.wrap( boost::bind(&Connection::handleRead, this->shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred))); + TCP_socket.async_read_some( + boost::asio::buffer(incoming_data_buffer), + strand.wrap( + boost::bind( + &Connection::handle_read, + this->shared_from_this(), + boost::asio::placeholders::error, + boost::asio::placeholders::bytes_transferred + ) + ) + ); } } } /// Handle completion of a write operation. - void handleWrite(const boost::system::error_code& e) { + void handle_write(const boost::system::error_code& e) { if (!e) { // Initiate graceful connection closure. boost::system::error_code ignoredEC; - TCPsocket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignoredEC); + TCP_socket.shutdown( + boost::asio::ip::tcp::socket::shutdown_both, + ignoredEC + ); } - // No new asynchronous operations are started. This means that all shared_ptr - // references to the connection object will disappear and the object will be - // destroyed automatically after this handler returns. The connection class's - // destructor closes the socket. } - void compressCharArray(const void *in_data, size_t in_data_size, std::vector &buffer, CompressionType type) { + // Big thanks to deusty who explains how to use gzip compression by + // the right call to deflateInit2(): + // http://deusty.blogspot.com/2007/07/gzip-compressiondecompression.html + void compressCharArray( + const char * in_data, + size_t in_data_size, + std::vector & buffer, + CompressionType type + ) { const size_t BUFSIZE = 128 * 1024; unsigned char temp_buffer[BUFSIZE]; @@ -140,20 +231,23 @@ private: deflateInit(&strm, Z_BEST_SPEED); break; case gzipRFC1952: - /* - * Big thanks to deusty who explains how to have gzip compression turned on by the right call to deflateInit2(): - * http://deusty.blogspot.com/2007/07/gzip-compressiondecompression.html - */ - deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, (15+16), 9, Z_DEFAULT_STRATEGY); + deflateInit2( + &strm, + Z_DEFAULT_COMPRESSION, + Z_DEFLATED, + (15+16), + 9, + Z_DEFAULT_STRATEGY + ); break; default: - assert(false); + BOOST_ASSERT_MSG(false, "should not happen"); break; } int deflate_res = Z_OK; do { - if (strm.avail_out == 0) { + if ( 0 == strm.avail_out ) { buffer.insert(buffer.end(), temp_buffer, temp_buffer + BUFSIZE); strm.next_out = temp_buffer; strm.avail_out = BUFSIZE; @@ -162,17 +256,25 @@ private: } while (deflate_res == Z_OK); - assert(deflate_res == Z_STREAM_END); - buffer.insert(buffer.end(), temp_buffer, temp_buffer + BUFSIZE - strm.avail_out); + BOOST_ASSERT_MSG( + deflate_res == Z_STREAM_END, + "compression not properly finished" + ); + + buffer.insert( + buffer.end(), + temp_buffer, + temp_buffer + BUFSIZE - strm.avail_out + ); deflateEnd(&strm); } boost::asio::io_service::strand strand; - boost::asio::ip::tcp::socket TCPsocket; - RequestHandler& requestHandler; - boost::array incomingDataBuffer; + boost::asio::ip::tcp::socket TCP_socket; + RequestHandler& request_handler; + boost::array incoming_data_buffer; Request request; - RequestParser requestParser; + RequestParser request_parser; Reply reply; }; diff --git a/Server/RequestHandler.h b/Server/RequestHandler.h index af2217f7b..76953403e 100644 --- a/Server/RequestHandler.h +++ b/Server/RequestHandler.h @@ -40,7 +40,7 @@ or see http://www.gnu.org/licenses/agpl.txt. class RequestHandler : private boost::noncopyable { public: typedef APIGrammar APIGrammarParser; - explicit RequestHandler() { } + explicit RequestHandler() : routing_machine(NULL) { } void handle_request(const http::Request& req, http::Reply& rep){ //parse command @@ -90,6 +90,10 @@ public: rep.content += "^
"; } else { //parsing done, lets call the right plugin to handle the request + BOOST_ASSERT_MSG( + routing_machine != NULL, + "pointer not init'ed" + ); routing_machine->RunQuery(routeParameters, rep); return; } diff --git a/Util/SimpleLogger.h b/Util/SimpleLogger.h index 8bbc6e4fe..6de7ebddf 100644 --- a/Util/SimpleLogger.h +++ b/Util/SimpleLogger.h @@ -59,6 +59,8 @@ private: class SimpleLogger { public: + SimpleLogger() : level(logINFO) { } + std::ostringstream& Write(LogLevel l = logINFO) { try { boost::mutex::scoped_lock lock(logger_mutex); diff --git a/features/bicycle/access_node.feature b/features/bicycle/access_node.feature index f28be7508..a926896e9 100644 --- a/features/bicycle/access_node.feature +++ b/features/bicycle/access_node.feature @@ -22,7 +22,7 @@ Reference: http://wiki.openstreetmap.org/wiki/Key:access | | no | yes | x | | | yes | no | | - Scenario: Bike - Overwriting implied acccess on nodes + Scenario: Bike - Overwriting implied acccess on nodes doesn't overwrite way Then routability should be | highway | node/access | node/vehicle | node/bicycle | bothw | | cycleway | | | | x | diff --git a/features/step_definitions/data.rb b/features/step_definitions/data.rb index 82b178ff1..1e9fa7149 100644 --- a/features/step_definitions/data.rb +++ b/features/step_definitions/data.rb @@ -23,11 +23,11 @@ Given /^the node map$/ do |table| raise "*** node invalid name '#{name}', must be single characters" unless name.size == 1 raise "*** invalid node name '#{name}', must me alphanumeric" unless name.match /[a-z0-9]/ if name.match /[a-z]/ - raise "*** duplicate node '#{name}'" if name_node_hash[name] - add_osm_node name, *table_coord_to_lonlat(ci,ri) + raise "*** duplicate node '#{name}'" if name_node_hash[name] + add_osm_node name, *table_coord_to_lonlat(ci,ri) else - raise "*** duplicate node '#{name}'" if location_hash[name] - add_location name, *table_coord_to_lonlat(ci,ri) + raise "*** duplicate node '#{name}'" if location_hash[name] + add_location name, *table_coord_to_lonlat(ci,ri) end end end @@ -39,9 +39,9 @@ Given /^the node locations$/ do |table| name = row['node'] raise "*** duplicate node '#{name}'" if find_node_by_name name if name.match /[a-z]/ - add_osm_node name, row['lon'].to_f, row['lat'].to_f + add_osm_node name, row['lon'].to_f, row['lat'].to_f else - add_location name, row['lon'].to_f, row['lat'].to_f + add_location name, row['lon'].to_f, row['lat'].to_f end end end diff --git a/features/step_definitions/locate.rb b/features/step_definitions/locate.rb index a47f3e045..26f8fdd36 100644 --- a/features/step_definitions/locate.rb +++ b/features/step_definitions/locate.rb @@ -48,4 +48,4 @@ When /^I request locate (\d+) times I should get$/ do |n,table| ok = false unless step "I request locate I should get", table end ok -end \ No newline at end of file +end diff --git a/features/step_definitions/nearest.rb b/features/step_definitions/nearest.rb index e23305661..6c0af7a0f 100644 --- a/features/step_definitions/nearest.rb +++ b/features/step_definitions/nearest.rb @@ -48,4 +48,4 @@ When /^I request nearest (\d+) times I should get$/ do |n,table| ok = false unless step "I request nearest I should get", table end ok -end \ No newline at end of file +end diff --git a/features/support/config.rb b/features/support/config.rb index 63350d511..9c4cb0fd7 100644 --- a/features/support/config.rb +++ b/features/support/config.rb @@ -13,18 +13,18 @@ end def write_server_ini s=<<-EOF -Threads = 1 -IP = 0.0.0.0 -Port = #{OSRM_PORT} + Threads = 1 + IP = 0.0.0.0 + Port = #{OSRM_PORT} -hsgrData=#{@osm_file}.osrm.hsgr -nodesData=#{@osm_file}.osrm.nodes -edgesData=#{@osm_file}.osrm.edges -ramIndex=#{@osm_file}.osrm.ramIndex -fileIndex=#{@osm_file}.osrm.fileIndex -namesData=#{@osm_file}.osrm.names -timestamp=#{@osm_file}.osrm.timestamp -EOF + hsgrData=#{@osm_file}.osrm.hsgr + nodesData=#{@osm_file}.osrm.nodes + edgesData=#{@osm_file}.osrm.edges + ramIndex=#{@osm_file}.osrm.ramIndex + fileIndex=#{@osm_file}.osrm.fileIndex + namesData=#{@osm_file}.osrm.names + timestamp=#{@osm_file}.osrm.timestamp + EOF File.open( 'server.ini', 'w') {|f| f.write( s ) } end diff --git a/features/support/data.rb b/features/support/data.rb index c794f6e4b..6af83d96c 100644 --- a/features/support/data.rb +++ b/features/support/data.rb @@ -19,12 +19,12 @@ BIN_PATH = '../build' DEFAULT_ORIGIN = [1,1] class Location - attr_accessor :lon,:lat + attr_accessor :lon,:lat - def initialize lon,lat - @lat = lat - @lon = lon - end + def initialize lon,lat + @lat = lat + @lon = lon + end end def sanitized_scenario_title @@ -125,29 +125,29 @@ def build_ways_from_table table end def table_coord_to_lonlat ci,ri - [@origin[0]+ci*@zoom, @origin[1]-ri*@zoom] + [@origin[0]+ci*@zoom, @origin[1]-ri*@zoom] end def add_osm_node name,lon,lat - node = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, lon, lat - node << { :name => name } - node.uid = OSM_UID - osm_db << node - name_node_hash[name] = node + node = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, lon, lat + node << { :name => name } + node.uid = OSM_UID + osm_db << node + name_node_hash[name] = node end def add_location name,lon,lat - location_hash[name] = Location.new(lon,lat) + location_hash[name] = Location.new(lon,lat) end def find_node_by_name s - raise "***invalid node name '#{s}', must be single characters" unless s.size == 1 - raise "*** invalid node name '#{s}', must be alphanumeric" unless s.match /[a-z0-9]/ - if s.match /[a-z]/ - from_node = name_node_hash[ s.to_s ] - else - from_node = location_hash[ s.to_s ] - end + raise "***invalid node name '#{s}', must be single characters" unless s.size == 1 + raise "*** invalid node name '#{s}', must be alphanumeric" unless s.match /[a-z0-9]/ + if s.match /[a-z]/ + from_node = name_node_hash[ s.to_s ] + else + from_node = location_hash[ s.to_s ] + end end def find_way_by_name s diff --git a/features/support/file.rb b/features/support/file.rb index cd8fd14b3..602f07e48 100644 --- a/features/support/file.rb +++ b/features/support/file.rb @@ -1,5 +1,5 @@ class File - + #read last n lines of a file. useful for getting last part of a big log file. def tail(n) buffer = 1024 diff --git a/features/support/fuzzy.rb b/features/support/fuzzy.rb index 3513b7af1..066d9c5a8 100644 --- a/features/support/fuzzy.rb +++ b/features/support/fuzzy.rb @@ -1,4 +1,3 @@ - class FuzzyMatch def self.match got, want @@ -31,4 +30,3 @@ class FuzzyMatch end end - diff --git a/features/support/hash.rb b/features/support/hash.rb index 7639364fb..6381af62d 100644 --- a/features/support/hash.rb +++ b/features/support/hash.rb @@ -47,4 +47,3 @@ end def fingerprint @fingerprint ||= Digest::SHA1.hexdigest "#{bin_extract_hash}-#{bin_prepare_hash}-#{bin_routed_hash}-#{profile_hash}-#{lua_lib_hash}-#{osm_hash}" end - diff --git a/features/support/hooks.rb b/features/support/hooks.rb index 29e09b785..e3b6df0e5 100644 --- a/features/support/hooks.rb +++ b/features/support/hooks.rb @@ -12,7 +12,7 @@ Before do |scenario| end Around('@stress') do |scenario, block| - Timeout.timeout(STRESS_TIMEOUT) do + Timeout.timeout(STRESS_TIMEOUT) do block.call end end diff --git a/features/support/log.rb b/features/support/log.rb index 7aed85029..1607bfb59 100644 --- a/features/support/log.rb +++ b/features/support/log.rb @@ -63,5 +63,3 @@ end def log_preprocess_done end - - diff --git a/routed.cpp b/routed.cpp index b4b6b0c0e..de6ad1472 100644 --- a/routed.cpp +++ b/routed.cpp @@ -73,16 +73,6 @@ int main (int argc, char * argv[]) { installCrashHandler(argv[0]); #endif - - // Bug - testing not necessary. testDataFiles also tries to open the first - // argv, which is the name of exec file - //if(testDataFiles(argc, argv)==false) { - //std::cerr << "[error] at least one data file name seems to be bogus!" << std::endl; - //exit(-1); - //} - - //std::cout << "fingerprint: " << UUID::GetInstance().GetUUID() << std::endl; - SimpleLogger().Write() << "starting up engines, compiled at " << __DATE__ << ", " __TIME__;