diff --git a/config.xml b/config.xml index fc9a828..629f3f0 100644 --- a/config.xml +++ b/config.xml @@ -7,6 +7,24 @@ + + + + + + + + + + + + + + + + + + diff --git a/helpers/config.hpp b/helpers/config.hpp index f9b9b79..1c483cc 100644 --- a/helpers/config.hpp +++ b/helpers/config.hpp @@ -137,24 +137,26 @@ struct ParmsXmlVisitor { } - long long getNumParam(const std::string& key, long long defaultValue) + long long getNumParam(const std::string& key, long long defaultValue) const { - if(parameters.count(key)) return atoll(parameters[key].c_str()); + auto it = parameters.find(key); + if(it != parameters.end()) return atoll(it->second.c_str()); else return defaultValue; } - long long getNumParam(const std::string& key) + long long getNumParam(const std::string& key) const { return getNumParam(key, 0); } - std::string getParam(std::string key, std::string defaultValue) + std::string getParam(std::string key, std::string defaultValue) const { - if(parameters.count(key)) return parameters[key]; + auto it = parameters.find(key); + if(it != parameters.end()) return it->second; else return defaultValue; } - std::string getParam(const std::string& key) + std::string getParam(const std::string& key) const { return getParam(key, ""); } diff --git a/server.cpp b/server.cpp index b140b84..8b9195e 100644 --- a/server.cpp +++ b/server.cpp @@ -185,7 +185,7 @@ template struct Exec //printf("%s\n",url.c_str()); //time_t ctt = time(0); //std::cout << asctime(localtime(&ctt)) << std::endl; - ServiceInterface* s = ServicesFactory::getService(url, params); + ServiceInterface* s = ServicesFactory::getService(url); if(s) { rep = s->processRequest(m,mger); @@ -263,6 +263,8 @@ int main(int argc, char *argv[]) XmlFileParser::parseXmlFile(config,params); fclose(config); + ServicesFactory::init(params); + std::vector indexes; std::map symbols; std::map charconvs; diff --git a/services/ServicesFactory.cpp b/services/ServicesFactory.cpp index 9c5b30f..dff343d 100644 --- a/services/ServicesFactory.cpp +++ b/services/ServicesFactory.cpp @@ -1,17 +1,72 @@ #include "ServicesFactory.hpp" #include -ServiceInterface* ServicesFactory::getService(std::string service, ParmsXmlVisitor& params) + +bool ServicesFactory::_enabledPingService{false}; +bool ServicesFactory::_enabledRelationListService{false}; +bool ServicesFactory::_enabledIdxListService{false}; +bool ServicesFactory::_enabledIdxDetailService{false}; +bool ServicesFactory::_enabledRelationDetailService{false}; +bool ServicesFactory::_enabledWayDetailService{false}; +bool ServicesFactory::_enabledSvgService{false}; +bool ServicesFactory::_enabledMapDisplayService{false}; +bool ServicesFactory::_enabledTileService{false}; +bool ServicesFactory::_enabledGeoLocationService{false}; + +int ServicesFactory::_cacheLevel; +std::string ServicesFactory::_defaultColor; +std::string ServicesFactory::_locale; + +void ServicesFactory::init(const ParmsXmlVisitor& params) +{ + _locale = params.getParam("locale"); + _cacheLevel = params.getNumParam("CacheLevel", 8); + _defaultColor = params.getParam("DefaultColor"); + + _enabledPingService = (params.getParam("PingService") == "enabled"); + if(_enabledPingService) std::cout << "ping service enabled \n"; + + _enabledRelationListService = (params.getParam("RelationListService") == "enabled"); + if(_enabledRelationListService) std::cout << "relation list service enabled \n"; + + _enabledIdxListService = (params.getParam("IdxListService") == "enabled"); + if(_enabledIdxListService) std::cout << "index list service enabled \n"; + + _enabledIdxDetailService = (params.getParam("IdxDetailService") == "enabled"); + if(_enabledIdxDetailService) std::cout << "index detail service enabled \n"; + + _enabledRelationDetailService = (params.getParam("RelationDetailService") == "enabled"); + if(_enabledRelationDetailService) std::cout << "relation detail service enabled \n"; + + _enabledWayDetailService = (params.getParam("WayDetailService") == "enabled"); + if(_enabledWayDetailService) std::cout << "way detail service enabled \n"; + + _enabledSvgService = (params.getParam("SvgService") == "enabled"); + if(_enabledSvgService) std::cout << "svg service enabled \n"; + + _enabledMapDisplayService = (params.getParam("MapDisplayService") == "enabled"); + if(_enabledMapDisplayService) std::cout << "map display service enabled \n"; + + _enabledTileService = (params.getParam("TileService") == "enabled"); + if(_enabledTileService) std::cout << "tile service enabled \n"; + + _enabledGeoLocationService = (params.getParam("GeolocationService") == "enabled"); + if(_enabledGeoLocationService) std::cout << "geolocation service enabled \n"; + +} + + +ServiceInterface* ServicesFactory::getService(std::string service) { - if(service == "/ping") return new Ping; - if(service == "/geoloc") return new Geolocation; - else if (service == "/relation/list") return new RelationList; - else if (service == "/index/list") return new IdxList; - else if (service == "/index/get") return new IdxDetail; - else if (service == "/relation/get") return new RelationDetail; - else if (service == "/way/get") return new WayDetail; - else if (service == "/svgMap.svg") return new Svg; - else if ((service == "/MapDisplay")||(service =="/")) return new MapDisplay; - else if(service.find(".svg") != std::string::npos) + if(_enabledPingService && service == "/ping") return new Ping; + else if(_enabledGeoLocationService && service == "/geoloc") return new Geolocation; + else if (_enabledRelationListService && service == "/relation/list") return new RelationList; + else if (_enabledIdxListService && service == "/index/list") return new IdxList; + else if (_enabledIdxDetailService && service == "/index/get") return new IdxDetail; + else if (_enabledRelationDetailService && service == "/relation/get") return new RelationDetail; + else if (_enabledWayDetailService && service == "/way/get") return new WayDetail; + else if (_enabledSvgService && service == "/svgMap.svg") return new Svg; + else if (_enabledMapDisplayService && ((service == "/MapDisplay")||(service =="/"))) return new MapDisplay; + else if(_enabledTileService && service.find(".svg") != std::string::npos) { unsigned int pos = 0; const char* c = service.c_str(); @@ -25,7 +80,7 @@ ServiceInterface* ServicesFactory::getService(std::string service, ParmsXmlVisit while(pos < service.length() && (*(c+pos) != '/')) pos++; if(pos < service.length()) y = atoll(c+pos+1); //std::cout << x <<":" << y << ";" << z << "\n"; - return new Tile(z, x, y, params.getNumParam("CacheLevel", 8), params.getParam("locale"), params.getParam("DefaultColor", "#888888")); + return new Tile(z, x, y, _cacheLevel, _locale, _defaultColor); } else return NULL; diff --git a/services/ServicesFactory.hpp b/services/ServicesFactory.hpp index 2b60f33..58be8db 100644 --- a/services/ServicesFactory.hpp +++ b/services/ServicesFactory.hpp @@ -1,5 +1,6 @@ #ifndef SERVICESFACTORY_HPP #define SERVICESFACTORY_HPP +#include #include "../CompiledDataManager.hpp" #include "Ping.hpp" #include "RelationList.hpp" @@ -15,8 +16,24 @@ class ServicesFactory { private: +static bool _enabledPingService; +static bool _enabledRelationListService; +static bool _enabledIdxListService; +static bool _enabledIdxDetailService; +static bool _enabledRelationDetailService; +static bool _enabledWayDetailService; +static bool _enabledSvgService; +static bool _enabledMapDisplayService; +static bool _enabledTileService; +static bool _enabledGeoLocationService; +static int _cacheLevel; +static std::string _defaultColor; +static std::string _locale; + + public: - static ServiceInterface* getService(std::string service,ParmsXmlVisitor& params); + static void init(const ParmsXmlVisitor& params); + static ServiceInterface* getService(std::string service); static void releaseService(ServiceInterface* service); }; #endif