2013-06-26 20:05:42 -04:00
|
|
|
/*
|
2013-10-14 07:42:28 -04:00
|
|
|
|
|
|
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
Redistributions of source code must retain the above copyright notice, this list
|
|
|
|
of conditions and the following disclaimer.
|
|
|
|
Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
2013-06-26 20:05:42 -04:00
|
|
|
|
|
|
|
#include "OSRM.h"
|
2013-08-19 16:41:46 -04:00
|
|
|
#include <boost/foreach.hpp>
|
2013-06-26 20:05:42 -04:00
|
|
|
|
|
|
|
|
2013-08-19 16:41:46 -04:00
|
|
|
OSRM::OSRM(boost::unordered_map<const std::string,boost::filesystem::path>& paths) {
|
|
|
|
objects = new QueryObjectsStorage( paths );
|
2013-06-26 20:05:42 -04:00
|
|
|
RegisterPlugin(new HelloWorldPlugin());
|
|
|
|
RegisterPlugin(new LocatePlugin(objects));
|
|
|
|
RegisterPlugin(new NearestPlugin(objects));
|
|
|
|
RegisterPlugin(new TimestampPlugin(objects));
|
|
|
|
RegisterPlugin(new ViaRoutePlugin(objects));
|
|
|
|
}
|
|
|
|
|
|
|
|
OSRM::~OSRM() {
|
2013-07-08 08:52:43 -04:00
|
|
|
BOOST_FOREACH(PluginMap::value_type & plugin_pointer, pluginMap) {
|
2013-06-26 20:05:42 -04:00
|
|
|
delete plugin_pointer.second;
|
|
|
|
}
|
2013-07-03 10:54:51 -04:00
|
|
|
delete objects;
|
2013-06-26 20:05:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSRM::RegisterPlugin(BasePlugin * plugin) {
|
2013-08-08 10:19:25 -04:00
|
|
|
SimpleLogger().Write() << "loaded plugin: " << plugin->GetDescriptor();
|
2013-08-09 07:24:05 -04:00
|
|
|
if( pluginMap.find(plugin->GetDescriptor()) != pluginMap.end() ) {
|
2013-09-17 08:37:12 -04:00
|
|
|
delete pluginMap.find(plugin->GetDescriptor())->second;
|
2013-08-09 07:24:05 -04:00
|
|
|
}
|
2013-09-17 08:37:12 -04:00
|
|
|
pluginMap.emplace(plugin->GetDescriptor(), plugin);
|
2013-06-26 20:05:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSRM::RunQuery(RouteParameters & route_parameters, http::Reply & reply) {
|
2013-07-08 08:52:43 -04:00
|
|
|
const PluginMap::const_iterator & iter = pluginMap.find(route_parameters.service);
|
2013-06-26 20:05:42 -04:00
|
|
|
if(pluginMap.end() != iter) {
|
|
|
|
reply.status = http::Reply::ok;
|
|
|
|
iter->second->HandleRequest(route_parameters, reply );
|
|
|
|
} else {
|
|
|
|
reply = http::Reply::stockReply(http::Reply::badRequest);
|
|
|
|
}
|
|
|
|
}
|