From 8bd7d57dd818ec6e9f5769dbb3c2c8fbd1a6fffe Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 25 Nov 2014 10:04:12 +0100 Subject: [PATCH] fixed compilation of simple client - adapted to new lib interface - fixed return codes of command line parsing - reformatted code --- tools/simpleclient.cpp | 61 ++++++++++-------------------------------- 1 file changed, 14 insertions(+), 47 deletions(-) diff --git a/tools/simpleclient.cpp b/tools/simpleclient.cpp index d9c8217b9..801bd36eb 100644 --- a/tools/simpleclient.cpp +++ b/tools/simpleclient.cpp @@ -27,37 +27,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../Library/OSRM.h" #include "../Util/git_sha.hpp" +#include "../Util/json_renderer.hpp" #include "../Util/ProgramOptions.h" #include "../Util/simple_logger.hpp" -#include -#include -#include +#include +#include +#include -#include -#include - -#include -#include #include -#include - -// Dude, real recursions on the OS stack? You must be brave... -void print_tree(boost::property_tree::ptree const &property_tree, const unsigned recursion_depth) -{ - auto end = property_tree.end(); - for (auto tree_iterator = property_tree.begin(); tree_iterator != end; ++tree_iterator) - { - for (unsigned current_recursion = 0; current_recursion < recursion_depth; - ++current_recursion) - { - std::cout << " " << std::flush; - } - std::cout << tree_iterator->first << ": " << tree_iterator->second.get_value() - << std::endl; - print_tree(tree_iterator->second, recursion_depth + 1); - } -} int main(int argc, const char *argv[]) { @@ -68,7 +46,6 @@ int main(int argc, const char *argv[]) int ip_port, requested_thread_num; bool use_shared_memory = false, trial_run = false; ServerPaths server_paths; - const unsigned init_result = GenerateServerProgramOptions(argc, argv, server_paths, @@ -78,11 +55,14 @@ int main(int argc, const char *argv[]) use_shared_memory, trial_run); - if (init_result == INIT_FAILED) + if (init_result == INIT_OK_DO_NOT_START_ENGINE) { return 0; } - + if (init_result == INIT_FAILED) + { + return 1; + } SimpleLogger().Write() << "starting up engines, " << g_GIT_DESCRIPTION; OSRM routing_machine(server_paths, use_shared_memory); @@ -93,7 +73,7 @@ int main(int argc, const char *argv[]) route_parameters.alternate_route = true; // get an alternate route, too route_parameters.geometry = true; // retrieve geometry of route route_parameters.compression = true; // polyline encoding - route_parameters.check_sum = UINT_MAX; // see wiki + route_parameters.check_sum = -1; // see wiki route_parameters.service = "viaroute"; // that's routing route_parameters.output_format = "json"; route_parameters.jsonp_parameter = ""; // set for jsonp wrapping @@ -106,23 +86,10 @@ int main(int argc, const char *argv[]) // target_coordinate route_parameters.coordinates.emplace_back(52.513191 * COORDINATE_PRECISION, 13.415852 * COORDINATE_PRECISION); - http::Reply osrm_reply; - routing_machine.RunQuery(route_parameters, osrm_reply); - - // attention: super-inefficient hack below: - - std::stringstream my_stream; - for (const auto &element : osrm_reply.content) - { - std::cout << element; - my_stream << element; - } - std::cout << std::endl; - - boost::property_tree::ptree property_tree; - boost::property_tree::read_json(my_stream, property_tree); - - print_tree(property_tree, 0); + JSON::Object json_result; + const int result_code = routing_machine.RunQuery(route_parameters, json_result); + SimpleLogger().Write() << "http code: " << result_code; + JSON::render(SimpleLogger().Write(), json_result); } catch (std::exception ¤t_exception) {