/* 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. */ #include #include #include #include #include #include #include #ifdef _OPENMP #include #endif #include "typedefs.h" #include #include #include #include "HttpServer/server.h" #include "Contractor/GraphLoader.h" #include "DataStructures/StaticGraph.h" using namespace std; typedef ContractionCleanup::Edge::EdgeData EdgeData; typedef StaticGraph::InputEdge GridEdge; typedef http::server > server; /* * TODO: Description of command line arguments */ int main (int argc, char *argv[]) { if(argc < 4) { cerr << "Correct usage:" << endl << argv[0] << " " << 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 * graph = new StaticGraph(nodeInfoHelper->getNumberOfNodes()-1, *edgeList); delete edgeList; time = get_timestamp(); cout << "constructing search graph ..." << flush; SearchEngine > * sEngine = new SearchEngine >(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; }