From bfef8f39b7bfefcfba728a5dd10623c4c95453dc Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 26 Jun 2013 19:47:47 -0400 Subject: [PATCH] First implementation of moving the algorithmic core into a library --- Util/BaseConfiguration.h | 16 ++++++---- Util/InputFileUtil.h | 4 +-- Util/LinuxStackTrace.h | 1 - Util/MachineInfo.h | 22 +++++++------- Util/OpenMPWrapper.h | 10 +++---- Util/StringUtil.h | 7 +++-- routed.cpp | 63 +++++++++++++--------------------------- 7 files changed, 53 insertions(+), 70 deletions(-) diff --git a/Util/BaseConfiguration.h b/Util/BaseConfiguration.h index 69bc61f89..a998c6189 100644 --- a/Util/BaseConfiguration.h +++ b/Util/BaseConfiguration.h @@ -21,12 +21,12 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef BASECONFIGURATION_H_ #define BASECONFIGURATION_H_ -#include -#include +#include "../DataStructures/HashTable.h" + #include #include - -#include "../DataStructures/HashTable.h" +#include +#include class BaseConfiguration { public: @@ -73,7 +73,11 @@ public: } private: - void Tokenize(const std::string& str, std::vector& tokens, const std::string& delimiters = "=") { + void Tokenize( + const std::string& str, + std::vector& tokens, + const std::string& delimiters = "=" + ) { std::string::size_type lastPos = str.find_first_not_of(delimiters, 0); std::string::size_type pos = str.find_first_of(delimiters, lastPos); @@ -86,6 +90,7 @@ private: pos = str.find_first_of(delimiters, lastPos); } } + void TrimStringRight(std::string& str) { std::string::size_type pos = str.find_last_not_of(" "); if (pos != std::string::npos) @@ -93,6 +98,7 @@ private: else str.erase( str.begin() , str.end() ); } + void TrimStringLeft(std::string& str) { std::string::size_type pos = str.find_first_not_of(" "); if (pos != std::string::npos) diff --git a/Util/InputFileUtil.h b/Util/InputFileUtil.h index 685d92f3f..b130d2136 100644 --- a/Util/InputFileUtil.h +++ b/Util/InputFileUtil.h @@ -21,10 +21,10 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef INPUTFILEUTIL_H_ #define INPUTFILEUTIL_H_ -#include - #include "../typedefs.h" +#include + // Check if file exists and if it can be opened for reading with ifstream an object inline bool testDataFile(const std::string & filename){ boost::filesystem::path fileToTest(filename); diff --git a/Util/LinuxStackTrace.h b/Util/LinuxStackTrace.h index a3a23a7c5..593c07d41 100644 --- a/Util/LinuxStackTrace.h +++ b/Util/LinuxStackTrace.h @@ -25,7 +25,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include - #ifdef __linux__ #include #include diff --git a/Util/MachineInfo.h b/Util/MachineInfo.h index 7c0f31c3b..bdb085aa5 100644 --- a/Util/MachineInfo.h +++ b/Util/MachineInfo.h @@ -1,17 +1,17 @@ /* open source routing machine Copyright (C) Dennis Luxen, others 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 @@ -23,11 +23,11 @@ #if defined(__APPLE__) || defined(__FreeBSD__) extern "C" { -#include -#include -} + #include + #include +} #elif defined _WIN32 -#include + #include #endif enum Endianness { @@ -55,28 +55,28 @@ inline unsigned swapEndian(unsigned x) { inline unsigned GetPhysicalmemory(void){ #if defined(SUN5) || defined(__linux__) return (sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE)); - + #elif defined(__APPLE__) int mib[2] = {CTL_HW, HW_MEMSIZE}; long long memsize; size_t len = sizeof(memsize); sysctl(mib, 2, &memsize, &len, NULL, 0); return memsize/1024; - + #elif defined(__FreeBSD__) int mib[2] = {CTL_HW, HW_PHYSMEM}; long long memsize; size_t len = sizeof(memsize); sysctl(mib, 2, &memsize, &len, NULL, 0); return memsize/1024; - + #elif defined(_WIN32) MEMORYSTATUSEX status; status.dwLength = sizeof(status); GlobalMemoryStatusEx(&status); return status.ullTotalPhys/1024; #else - std::cout << "[Warning] Compiling on unknown architecture." << std::endl + std::cout << "[Warning] Compiling on unknown architecture." << std::endl << "Please file a ticket at http://project-osrm.org" << std::endl; return 2048*1024; /* 128 Mb default memory */ diff --git a/Util/OpenMPWrapper.h b/Util/OpenMPWrapper.h index 232dcbd62..520ac252c 100644 --- a/Util/OpenMPWrapper.h +++ b/Util/OpenMPWrapper.h @@ -23,12 +23,12 @@ or see http://www.gnu.org/licenses/agpl.txt. #define _OPENMPREPLACEMENTY_H #ifdef _OPENMP -#include + #include #else -inline const int omp_get_num_procs() { return 1; } -inline const int omp_get_max_threads() { return 1; } -inline const int omp_get_thread_num() { return 0; } -inline const void omp_set_num_threads(int i) {} + inline const int omp_get_num_procs() { return 1; } + inline const int omp_get_max_threads() { return 1; } + inline const int omp_get_thread_num() { return 0; } + inline const void omp_set_num_threads(int i) {} #endif #endif diff --git a/Util/StringUtil.h b/Util/StringUtil.h index b09ac166a..951a21c4a 100644 --- a/Util/StringUtil.h +++ b/Util/StringUtil.h @@ -21,6 +21,10 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef STRINGUTIL_H_ #define STRINGUTIL_H_ + +#include "../DataStructures/Coordinate.h" +#include "../typedefs.h" + #include #include @@ -29,9 +33,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include -#include "../DataStructures/Coordinate.h" -#include "../typedefs.h" - // precision: position after decimal point // length: maximum number of digits including comma and decimals template< int length, int precision > diff --git a/routed.cpp b/routed.cpp index e097bd70d..596f610d7 100644 --- a/routed.cpp +++ b/routed.cpp @@ -17,34 +17,28 @@ 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 "Library/OSRM.h" + +#include "Server/ServerFactory.h" + +#include "Util/BaseConfiguration.h" +#include "Util/InputFileUtil.h" +#include "Util/OpenMPWrapper.h" + #ifdef __linux__ +#include "Util/LinuxStackTrace.h" #include #endif -#include + #include #include #include #include -#include "Server/DataStructures/QueryObjectsStorage.h" -#include "Server/ServerConfiguration.h" -#include "Server/ServerFactory.h" - -#include "Plugins/HelloWorldPlugin.h" -#include "Plugins/LocatePlugin.h" -#include "Plugins/NearestPlugin.h" -#include "Plugins/TimestampPlugin.h" -#include "Plugins/ViaRoutePlugin.h" - -#include "Util/InputFileUtil.h" -#include "Util/OpenMPWrapper.h" - -#ifndef _WIN32 -#include "Util/LinuxStackTrace.h" -#endif - -typedef http::RequestHandler RequestHandler; +#include #ifdef _WIN32 boost::function0 console_ctrl_function; @@ -70,7 +64,7 @@ int main (int argc, char * argv[]) { if(!mlockall(MCL_CURRENT | MCL_FUTURE)) WARN("Process " << argv[0] << "could not be locked to RAM"); #endif -#ifndef _WIN32 +#ifdef __linux__ installCrashHandler(argv[0]); #endif @@ -83,7 +77,8 @@ int main (int argc, char * argv[]) { //} try { - std::cout << std::endl << "[server] starting up engines, saved at " << __TIMESTAMP__ << std::endl; + std::cout << "\n starting up engines, compile at " << + __DATE__ << ", " __TIME__ << std::endl; #ifndef _WIN32 int sig = 0; @@ -93,28 +88,11 @@ int main (int argc, char * argv[]) { pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask); #endif - ServerConfiguration serverConfig((argc > 1 ? argv[1] : "server.ini")); + BaseConfiguration serverConfig((argc > 1 ? argv[1] : "server.ini")); + OSRM routing_machine((argc > 1 ? argv[1] : "server.ini")); + Server * s = ServerFactory::CreateServer(serverConfig); - RequestHandler & h = s->GetRequestHandlerPtr(); - - QueryObjectsStorage * objects = new QueryObjectsStorage(serverConfig.GetParameter("hsgrData"), - serverConfig.GetParameter("ramIndex"), - serverConfig.GetParameter("fileIndex"), - serverConfig.GetParameter("nodesData"), - serverConfig.GetParameter("edgesData"), - serverConfig.GetParameter("namesData"), - serverConfig.GetParameter("timestamp") - ); - - h.RegisterPlugin(new HelloWorldPlugin()); - - h.RegisterPlugin(new LocatePlugin(objects)); - - h.RegisterPlugin(new NearestPlugin(objects)); - - h.RegisterPlugin(new TimestampPlugin(objects)); - - h.RegisterPlugin(new ViaRoutePlugin(objects)); + s->GetRequestHandlerPtr().RegisterRoutingMachine(&routing_machine); boost::thread t(boost::bind(&Server::Run, s)); @@ -146,7 +124,6 @@ int main (int argc, char * argv[]) { std::cout << "[server] freeing objects" << std::endl; delete s; - delete objects; std::cout << "[server] shutdown completed" << std::endl; } catch (std::exception& e) { std::cerr << "[fatal error] exception: " << e.what() << std::endl;