Refactoring of Plugins

This commit is contained in:
Dennis Luxen 2013-08-13 18:09:20 +02:00
parent 124e555ed0
commit c50b4c72d7
6 changed files with 46 additions and 44 deletions

View File

@ -33,8 +33,7 @@ public:
BasePlugin() { }
//Maybe someone can explain the pure virtual destructor thing to me (dennis)
virtual ~BasePlugin() { }
virtual std::string GetDescriptor() const = 0;
virtual std::string GetVersionString() const = 0 ;
virtual const std::string & GetDescriptor() const = 0;
virtual void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) = 0;
inline bool checkCoord(const _Coordinate & c) {
@ -48,7 +47,6 @@ public:
}
return true;
}
};
#endif /* BASEPLUGIN_H_ */

View File

@ -1,8 +1,21 @@
/*
* LocatePlugin.h
*
* Created on: 01.01.2011
* Author: dennis
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.
*/
#ifndef HELLOWORLDPLUGIN_H_
@ -15,10 +28,9 @@
class HelloWorldPlugin : public BasePlugin {
public:
HelloWorldPlugin() {}
HelloWorldPlugin() : descriptor_string("hello"){}
virtual ~HelloWorldPlugin() { }
std::string GetDescriptor() const { return std::string("hello"); }
std::string GetVersionString() const { return std::string("0.1a"); }
const std::string & GetDescriptor() const { return descriptor_string; }
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) {
reply.status = http::Reply::ok;
@ -45,6 +57,8 @@ public:
reply.content.append(content.str());
reply.content.append("</body></html>");
}
private:
std::string descriptor_string;
};
#endif /* HELLOWORLDPLUGIN_H_ */

View File

@ -27,18 +27,15 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "../Server/DataStructures/QueryObjectsStorage.h"
#include "../Util/StringUtil.h"
#include <fstream>
/*
* This Plugin locates the nearest node in the road network for a given coordinate.
*/
class LocatePlugin : public BasePlugin {
public:
LocatePlugin(QueryObjectsStorage * objects) {
LocatePlugin(QueryObjectsStorage * objects) : descriptor_string("locate") {
nodeHelpDesk = objects->nodeHelpDesk;
}
std::string GetDescriptor() const { return std::string("locate"); }
std::string GetVersionString() const { return std::string("0.3 (DL)"); }
const std::string & GetDescriptor() const { return descriptor_string; }
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) {
//check number of parameters
if(!routeParameters.coordinates.size()) {
@ -102,6 +99,7 @@ public:
private:
NodeInformationHelpDesk * nodeHelpDesk;
std::string descriptor_string;
};
#endif /* LOCATEPLUGIN_H_ */

View File

@ -28,21 +28,22 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "../Server/DataStructures/QueryObjectsStorage.h"
#include "../Util/StringUtil.h"
#include <fstream>
/*
* This Plugin locates the nearest point on a street in the road network for a given coordinate.
*/
class NearestPlugin : public BasePlugin {
public:
NearestPlugin(QueryObjectsStorage * objects) : names(objects->names) {
NearestPlugin(QueryObjectsStorage * objects )
:
names(objects->names),
descriptor_string("nearest")
{
nodeHelpDesk = objects->nodeHelpDesk;
descriptorTable.insert(std::make_pair("" , 0)); //default descriptor
descriptorTable.insert(std::make_pair("json", 1));
}
std::string GetDescriptor() const { return std::string("nearest"); }
std::string GetVersionString() const { return std::string("0.3 (DL)"); }
const std::string & GetDescriptor() const { return descriptor_string; }
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) {
//check number of parameters
if(!routeParameters.coordinates.size()) {
@ -112,6 +113,7 @@ private:
NodeInformationHelpDesk * nodeHelpDesk;
HashTable<std::string, unsigned> descriptorTable;
std::vector<std::string> & names;
std::string descriptor_string;
};
#endif /* NearestPlugin_H_ */

View File

@ -24,14 +24,12 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "BasePlugin.h"
#include "RouteParameters.h"
#include <cassert>
class TimestampPlugin : public BasePlugin {
public:
TimestampPlugin(QueryObjectsStorage * o) : objects(o) {
}
std::string GetDescriptor() const { return std::string("timestamp"); }
std::string GetVersionString() const { return std::string("0.3 (DL)"); }
TimestampPlugin(QueryObjectsStorage * o)
: objects(o), descriptor_string("timestamp")
{ }
const std::string & GetDescriptor() const { return descriptor_string; }
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) {
std::string tmp;
@ -70,6 +68,7 @@ public:
}
private:
QueryObjectsStorage * objects;
std::string descriptor_string;
};
#endif /* TIMESTAMPPLUGIN_H_ */

View File

@ -38,8 +38,6 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
@ -49,17 +47,20 @@ private:
std::vector<std::string> & names;
StaticGraph<QueryEdge::EdgeData> * graph;
HashTable<std::string, unsigned> descriptorTable;
std::string pluginDescriptorString;
SearchEngine * searchEnginePtr;
public:
ViaRoutePlugin(QueryObjectsStorage * objects, std::string psd = "viaroute") : names(objects->names), pluginDescriptorString(psd) {
ViaRoutePlugin(QueryObjectsStorage * objects)
:
names(objects->names),
descriptor_string("viaroute")
{
nodeHelpDesk = objects->nodeHelpDesk;
graph = objects->graph;
searchEnginePtr = new SearchEngine(graph, nodeHelpDesk, names);
descriptorTable.insert(std::make_pair("" , 0)); //default descriptor
descriptorTable.insert(std::make_pair("" , 0));
descriptorTable.insert(std::make_pair("json", 0));
descriptorTable.insert(std::make_pair("gpx" , 1));
}
@ -68,8 +69,8 @@ public:
delete searchEnginePtr;
}
std::string GetDescriptor() const { return pluginDescriptorString; }
std::string GetVersionString() const { return std::string("0.3 (DL)"); }
const std::string & GetDescriptor() const { return descriptor_string; }
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) {
//check number of parameters
if( 2 > routeParameters.coordinates.size() ) {
@ -209,17 +210,7 @@ public:
return;
}
private:
inline bool checkCoord(const _Coordinate & c) {
if(
c.lat > 90*COORDINATE_PRECISION ||
c.lat < -90*COORDINATE_PRECISION ||
c.lon > 180*COORDINATE_PRECISION ||
c.lon < -180*COORDINATE_PRECISION
) {
return false;
}
return true;
}
std::string descriptor_string;
};