Exemplo n.º 1
0
int main(int argc, const char *argv[])
{
    LogPolicy::GetInstance().Unmute();
    try
    {
        std::string ip_address;
        int ip_port, requested_thread_num, max_locations_map_matching;
        bool trial_run = false;
        libosrm_config lib_config;
        const unsigned init_result = GenerateServerProgramOptions(
            argc, argv, lib_config.server_paths, ip_address, ip_port, requested_thread_num,
            lib_config.use_shared_memory, trial_run, lib_config.max_locations_distance_table,
            max_locations_map_matching);

        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(lib_config);

        RouteParameters route_parameters;
        route_parameters.zoom_level = 18;           // no generalization
        route_parameters.print_instructions = true; // turn by turn instructions
        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 = -1;            // see wiki
        route_parameters.service = "viaroute";      // that's routing
        route_parameters.output_format = "json";
        route_parameters.jsonp_parameter = ""; // set for jsonp wrapping
        route_parameters.language = "";        // unused atm
        // route_parameters.hints.push_back(); // see wiki, saves I/O if done properly

        // start_coordinate
        route_parameters.coordinates.emplace_back(52.519930 * COORDINATE_PRECISION,
                                                  13.438640 * COORDINATE_PRECISION);
        // target_coordinate
        route_parameters.coordinates.emplace_back(52.513191 * COORDINATE_PRECISION,
                                                  13.415852 * COORDINATE_PRECISION);
        osrm::json::Object json_result;
        const int result_code = routing_machine.RunQuery(route_parameters, json_result);
        SimpleLogger().Write() << "http code: " << result_code;
        osrm::json::render(SimpleLogger().Write(), json_result);
    }
    catch (std::exception &current_exception)
    {
        SimpleLogger().Write(logWARNING) << "caught exception: " << current_exception.what();
        return -1;
    }
    return 0;
}
Exemplo n.º 2
0
int main (int argc, char * argv[]) {
#ifdef __linux__
    if(!mlockall(MCL_CURRENT | MCL_FUTURE))
        WARN("Process " << argv[0] << "could not be locked to RAM");
#endif
#ifdef __linux__

    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);
    //}

    try {
        //std::cout << "fingerprint: " << UUID::GetInstance().GetUUID() << std::endl;

        std::cout << "starting up engines, compiled at " <<
                                        __DATE__ << ", " __TIME__ << std::endl;

#ifndef _WIN32
        int sig = 0;
        sigset_t new_mask;
        sigset_t old_mask;
        sigfillset(&new_mask);
        pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask);
#endif

        BaseConfiguration serverConfig((argc > 1 ? argv[1] : "server.ini"));
        OSRM routing_machine((argc > 1 ? argv[1] : "server.ini"));

        Server * s = ServerFactory::CreateServer(serverConfig);
        s->GetRequestHandlerPtr().RegisterRoutingMachine(&routing_machine);

        boost::thread t(boost::bind(&Server::Run, s));

#ifndef _WIN32
        sigset_t wait_mask;
        pthread_sigmask(SIG_SETMASK, &old_mask, 0);
        sigemptyset(&wait_mask);
        sigaddset(&wait_mask, SIGINT);
        sigaddset(&wait_mask, SIGQUIT);
        sigaddset(&wait_mask, SIGTERM);
        pthread_sigmask(SIG_BLOCK, &wait_mask, 0);
        std::cout << "[server] running and waiting for requests" << std::endl;
        sigwait(&wait_mask, &sig);
#else
        // Set console control handler to allow server to be stopped.
        console_ctrl_function = boost::bind(&Server::Stop, s);
        SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
        std::cout << "[server] running and waiting for requests" << std::endl;
        s->Run();
#endif

        std::cout << "[server] initiating shutdown" << std::endl;
        s->Stop();
        std::cout << "[server] stopping threads" << std::endl;

        if(!t.timed_join(boost::posix_time::seconds(2))) {
//        	INFO("Threads did not finish within 2 seconds. Hard abort!");
        }

        std::cout << "[server] freeing objects" << std::endl;
        delete s;
        std::cout << "[server] shutdown completed" << std::endl;
    } catch (std::exception& e) {
        std::cerr << "[fatal error] exception: " << e.what() << std::endl;
    }
#ifdef __linux__
    munlockall();
#endif

    return 0;
}