First implementation of moving the algorithmic core into a library

This commit is contained in:
Dennis Luxen 2013-06-26 19:47:47 -04:00
parent 4430cbc3cb
commit bfef8f39b7
7 changed files with 53 additions and 70 deletions

View File

@ -21,12 +21,12 @@ or see http://www.gnu.org/licenses/agpl.txt.
#ifndef BASECONFIGURATION_H_ #ifndef BASECONFIGURATION_H_
#define BASECONFIGURATION_H_ #define BASECONFIGURATION_H_
#include <iostream> #include "../DataStructures/HashTable.h"
#include <string>
#include <exception> #include <exception>
#include <fstream> #include <fstream>
#include <iostream>
#include "../DataStructures/HashTable.h" #include <string>
class BaseConfiguration { class BaseConfiguration {
public: public:
@ -73,7 +73,11 @@ public:
} }
private: 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 lastPos = str.find_first_not_of(delimiters, 0);
std::string::size_type pos = str.find_first_of(delimiters, lastPos); std::string::size_type pos = str.find_first_of(delimiters, lastPos);
@ -86,6 +90,7 @@ private:
pos = str.find_first_of(delimiters, lastPos); pos = str.find_first_of(delimiters, lastPos);
} }
} }
void TrimStringRight(std::string& str) { void TrimStringRight(std::string& str) {
std::string::size_type pos = str.find_last_not_of(" "); std::string::size_type pos = str.find_last_not_of(" ");
if (pos != std::string::npos) if (pos != std::string::npos)
@ -93,6 +98,7 @@ private:
else else
str.erase( str.begin() , str.end() ); str.erase( str.begin() , str.end() );
} }
void TrimStringLeft(std::string& str) { void TrimStringLeft(std::string& str) {
std::string::size_type pos = str.find_first_not_of(" "); std::string::size_type pos = str.find_first_not_of(" ");
if (pos != std::string::npos) if (pos != std::string::npos)

View File

@ -21,10 +21,10 @@ or see http://www.gnu.org/licenses/agpl.txt.
#ifndef INPUTFILEUTIL_H_ #ifndef INPUTFILEUTIL_H_
#define INPUTFILEUTIL_H_ #define INPUTFILEUTIL_H_
#include <boost/filesystem.hpp>
#include "../typedefs.h" #include "../typedefs.h"
#include <boost/filesystem.hpp>
// Check if file exists and if it can be opened for reading with ifstream an object // Check if file exists and if it can be opened for reading with ifstream an object
inline bool testDataFile(const std::string & filename){ inline bool testDataFile(const std::string & filename){
boost::filesystem::path fileToTest(filename); boost::filesystem::path fileToTest(filename);

View File

@ -25,7 +25,6 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <string> #include <string>
#ifdef __linux__ #ifdef __linux__
#include <cxxabi.h> #include <cxxabi.h>
#include <execinfo.h> #include <execinfo.h>

View File

@ -23,11 +23,11 @@
#if defined(__APPLE__) || defined(__FreeBSD__) #if defined(__APPLE__) || defined(__FreeBSD__)
extern "C" { extern "C" {
#include <sys/types.h> #include <sys/types.h>
#include <sys/sysctl.h> #include <sys/sysctl.h>
} }
#elif defined _WIN32 #elif defined _WIN32
#include <windows.h> #include <windows.h>
#endif #endif
enum Endianness { enum Endianness {

View File

@ -23,12 +23,12 @@ or see http://www.gnu.org/licenses/agpl.txt.
#define _OPENMPREPLACEMENTY_H #define _OPENMPREPLACEMENTY_H
#ifdef _OPENMP #ifdef _OPENMP
#include <omp.h> #include <omp.h>
#else #else
inline const int omp_get_num_procs() { return 1; } inline const int omp_get_num_procs() { return 1; }
inline const int omp_get_max_threads() { return 1; } inline const int omp_get_max_threads() { return 1; }
inline const int omp_get_thread_num() { return 0; } inline const int omp_get_thread_num() { return 0; }
inline const void omp_set_num_threads(int i) {} inline const void omp_set_num_threads(int i) {}
#endif #endif
#endif #endif

View File

@ -21,6 +21,10 @@ or see http://www.gnu.org/licenses/agpl.txt.
#ifndef STRINGUTIL_H_ #ifndef STRINGUTIL_H_
#define STRINGUTIL_H_ #define STRINGUTIL_H_
#include "../DataStructures/Coordinate.h"
#include "../typedefs.h"
#include <string> #include <string>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
@ -29,9 +33,6 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <cstdio> #include <cstdio>
#include "../DataStructures/Coordinate.h"
#include "../typedefs.h"
// precision: position after decimal point // precision: position after decimal point
// length: maximum number of digits including comma and decimals // length: maximum number of digits including comma and decimals
template< int length, int precision > template< int length, int precision >

View File

@ -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 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
or see http://www.gnu.org/licenses/agpl.txt. 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__ #ifdef __linux__
#include "Util/LinuxStackTrace.h"
#include <sys/mman.h> #include <sys/mman.h>
#endif #endif
#include <iostream>
#include <signal.h> #include <signal.h>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/date_time.hpp> #include <boost/date_time.hpp>
#include <boost/thread.hpp> #include <boost/thread.hpp>
#include "Server/DataStructures/QueryObjectsStorage.h" #include <iostream>
#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;
#ifdef _WIN32 #ifdef _WIN32
boost::function0<void> console_ctrl_function; boost::function0<void> console_ctrl_function;
@ -70,7 +64,7 @@ int main (int argc, char * argv[]) {
if(!mlockall(MCL_CURRENT | MCL_FUTURE)) if(!mlockall(MCL_CURRENT | MCL_FUTURE))
WARN("Process " << argv[0] << "could not be locked to RAM"); WARN("Process " << argv[0] << "could not be locked to RAM");
#endif #endif
#ifndef _WIN32 #ifdef __linux__
installCrashHandler(argv[0]); installCrashHandler(argv[0]);
#endif #endif
@ -83,7 +77,8 @@ int main (int argc, char * argv[]) {
//} //}
try { 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 #ifndef _WIN32
int sig = 0; int sig = 0;
@ -93,28 +88,11 @@ int main (int argc, char * argv[]) {
pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask); pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask);
#endif #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); Server * s = ServerFactory::CreateServer(serverConfig);
RequestHandler & h = s->GetRequestHandlerPtr(); s->GetRequestHandlerPtr().RegisterRoutingMachine(&routing_machine);
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));
boost::thread t(boost::bind(&Server::Run, s)); 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; std::cout << "[server] freeing objects" << std::endl;
delete s; delete s;
delete objects;
std::cout << "[server] shutdown completed" << std::endl; std::cout << "[server] shutdown completed" << std::endl;
} catch (std::exception& e) { } catch (std::exception& e) {
std::cerr << "[fatal error] exception: " << e.what() << std::endl; std::cerr << "[fatal error] exception: " << e.what() << std::endl;