fixed compilation of simple client
- adapted to new lib interface - fixed return codes of command line parsing - reformatted code
This commit is contained in:
parent
4a6325696e
commit
8bd7d57dd8
@ -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 <osrm/Reply.h>
|
||||
#include <osrm/RouteParameters.h>
|
||||
#include <osrm/ServerPaths.h>
|
||||
#include <osrm/json_container.hpp>
|
||||
#include <osrm/route_parameters.hpp>
|
||||
#include <osrm/server_paths.hpp>
|
||||
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
// 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::string>()
|
||||
<< 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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user