First implementation of moving the algorithmic core into a library
This commit is contained in:
parent
4430cbc3cb
commit
bfef8f39b7
@ -21,12 +21,12 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#ifndef BASECONFIGURATION_H_
|
||||
#define BASECONFIGURATION_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "../DataStructures/HashTable.h"
|
||||
|
||||
#include <exception>
|
||||
#include <fstream>
|
||||
|
||||
#include "../DataStructures/HashTable.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
class BaseConfiguration {
|
||||
public:
|
||||
@ -73,7 +73,11 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void Tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters = "=") {
|
||||
void Tokenize(
|
||||
const std::string& str,
|
||||
std::vector<std::string>& 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)
|
||||
|
@ -21,10 +21,10 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#ifndef INPUTFILEUTIL_H_
|
||||
#define INPUTFILEUTIL_H_
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
// 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);
|
||||
|
@ -25,7 +25,6 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
#ifdef __linux__
|
||||
#include <cxxabi.h>
|
||||
#include <execinfo.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 <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
}
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
}
|
||||
#elif defined _WIN32
|
||||
#include <windows.h>
|
||||
#include <windows.h>
|
||||
#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 */
|
||||
|
||||
|
@ -23,12 +23,12 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#define _OPENMPREPLACEMENTY_H
|
||||
|
||||
#ifdef _OPENMP
|
||||
#include <omp.h>
|
||||
#include <omp.h>
|
||||
#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
|
||||
|
@ -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 <string>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
@ -29,9 +33,6 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#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 >
|
||||
|
63
routed.cpp
63
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 <sys/mman.h>
|
||||
#endif
|
||||
#include <iostream>
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/date_time.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
#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 <iostream>
|
||||
|
||||
#ifdef _WIN32
|
||||
boost::function0<void> 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;
|
||||
|
Loading…
Reference in New Issue
Block a user