osrm-backend/routed.cpp

123 lines
3.9 KiB
C++
Raw Normal View History

2010-07-09 05:05:40 -04:00
/*
open source routing machine
Copyright (C) Dennis Luxen, 2010
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU AFFERO General Public License as published by
the Free Software Foundation; either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
or see http://www.gnu.org/licenses/agpl.txt.
*/
2010-07-09 05:05:40 -04:00
#include <climits>
#include <fstream>
#include <istream>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#ifdef _OPENMP
#include <omp.h>
#endif
#include "typedefs.h"
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include "HttpServer/server.h"
2010-09-15 09:49:26 -04:00
#include "Contractor/GraphLoader.h"
#include "DataStructures/StaticGraph.h"
2010-07-09 05:05:40 -04:00
using namespace std;
typedef ContractionCleanup::Edge::EdgeData EdgeData;
typedef StaticGraph<EdgeData>::InputEdge GridEdge;
typedef http::server<StaticGraph<EdgeData> > server;
2010-07-09 05:05:40 -04:00
/*
* TODO: Description of command line arguments
*/
int main (int argc, char *argv[])
{
2010-09-15 09:49:26 -04:00
if(argc < 4)
{
cerr << "Correct usage:" << endl << argv[0] << " <hsgr data> <nodes data> <ram index> <file index>" << endl;
exit(-1);
}
ifstream hsgrInStream(argv[1], ios::binary);
ifstream nodesInStream(argv[2], ios::binary);
NodeInformationHelpDesk * nodeInfoHelper = new NodeInformationHelpDesk(argv[3], argv[4]);
double time = get_timestamp();
cout << "deserializing edge data from " << argv[1] << " ..." << flush;
std::vector< GridEdge> * edgeList = new std::vector< GridEdge>();
readHSGRFromStream(hsgrInStream, edgeList);
hsgrInStream.close();
cout << "in " << get_timestamp() - time << "s" << endl;
time = get_timestamp();
cout << "deserializing node map and building nearest neighbor grid ..." << flush;
nodeInfoHelper->initNNGrid(nodesInStream);
cout << "in " << get_timestamp() - time << "s" << endl;
StaticGraph<EdgeData> * graph = new StaticGraph<EdgeData>(nodeInfoHelper->getNumberOfNodes()-1, *edgeList);
delete edgeList;
time = get_timestamp();
cout << "constructing search graph ..." << flush;
SearchEngine<EdgeData, StaticGraph<EdgeData> > * sEngine = new SearchEngine<EdgeData, StaticGraph<EdgeData> >(graph, nodeInfoHelper);
cout << "in " << get_timestamp() - time << "s" << endl;
time = get_timestamp();
try {
// Block all signals for background thread.
sigset_t new_mask;
sigfillset(&new_mask);
sigset_t old_mask;
pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask);
cout << "starting web server ..." << flush;
// Run server in background thread.
server s("0.0.0.0", "5000", omp_get_num_procs(), sEngine);
boost::thread t(boost::bind(&server::run, &s));
cout << "ok" << endl;
// Restore previous signals.
pthread_sigmask(SIG_SETMASK, &old_mask, 0);
// Wait for signal indicating time to shut down.
sigset_t wait_mask;
sigemptyset(&wait_mask);
sigaddset(&wait_mask, SIGINT);
sigaddset(&wait_mask, SIGQUIT);
sigaddset(&wait_mask, SIGTERM);
pthread_sigmask(SIG_BLOCK, &wait_mask, 0);
int sig = 0;
sigwait(&wait_mask, &sig);
// Stop the server.
s.stop();
t.join();
}
catch (std::exception& e)
{
std::cerr << "exception: " << e.what() << "\n";
}
cout << "graceful shutdown after " << get_timestamp() - time << "s" << endl;
delete sEngine;
delete graph;
delete nodeInfoHelper;
return 0;
2010-07-09 05:05:40 -04:00
}