forked from Project-OSRM/osrm-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routed.cpp
154 lines (127 loc) · 4.66 KB
/
routed.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
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.
*/
#ifdef __linux__
#include <sys/mman.h>
#endif
#include <iostream>
#include <signal.h>
#include <boost/thread.hpp>
#include <boost/bind.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;
#ifdef _WIN32
boost::function0<void> console_ctrl_function;
BOOL WINAPI console_ctrl_handler(DWORD ctrl_type)
{
switch (ctrl_type)
{
case CTRL_C_EVENT:
case CTRL_BREAK_EVENT:
case CTRL_CLOSE_EVENT:
case CTRL_SHUTDOWN_EVENT:
console_ctrl_function();
return TRUE;
default:
return FALSE;
}
}
#endif
int main (int argc, char * argv[0]) {
#ifdef __linux__
if(!mlockall(MCL_CURRENT | MCL_FUTURE))
WARN("Process " << argv[0] << "could not be locked to RAM");
#endif
#ifndef _WIN32
installCrashHandler(argv[0]);
#endif
// Bug - testing not necessary. testDataFiles also tries to open the first
// argv, which is the name of exec file
//if(testDataFiles(argc, argv)==false) {
//std::cerr << "[error] at least one data file name seems to be bogus!" << std::endl;
//exit(-1);
//}
try {
std::cout << std::endl << "[server] starting up engines, saved at " << __TIMESTAMP__ << std::endl;
#ifndef _WIN32
int sig = 0;
sigset_t new_mask;
sigset_t old_mask;
sigfillset(&new_mask);
pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask);
#endif
ServerConfiguration serverConfig((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));
boost::thread t(boost::bind(&Server::Run, s));
#ifndef _WIN32
sigset_t wait_mask;
pthread_sigmask(SIG_SETMASK, &old_mask, 0);
sigemptyset(&wait_mask);
sigaddset(&wait_mask, SIGINT);
sigaddset(&wait_mask, SIGQUIT);
sigaddset(&wait_mask, SIGTERM);
pthread_sigmask(SIG_BLOCK, &wait_mask, 0);
std::cout << "[server] running and waiting for requests" << std::endl;
sigwait(&wait_mask, &sig);
#else
// Set console control handler to allow server to be stopped.
console_ctrl_function = boost::bind(&Server::Stop, s);
SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
std::cout << "[server] running and waiting for requests" << std::endl;
s->Run();
#endif
std::cout << "[server] initiating shutdown" << std::endl;
s->Stop();
std::cout << "[server] stopping threads" << std::endl;
t.join();
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;
}
#ifdef __linux__
munlockall();
#endif
return 0;
}