datasource_ptr datasource_cache::create(parameters const& params) { boost::optional<std::string> type = params.get<std::string>("type"); if (!type) { throw config_error(std::string("Could not create datasource. Required ") + "parameter 'type' is missing"); } datasource_ptr ds; #ifdef MAPNIK_STATIC_PLUGINS // return if it's created, raise otherwise ds = create_static_datasource(params); if (ds) { return ds; } #endif std::map<std::string,std::shared_ptr<PluginInfo> >::iterator itr; // add scope to ensure lock is released asap { #ifdef MAPNIK_THREADSAFE std::lock_guard<std::recursive_mutex> lock(instance_mutex_); #endif itr = plugins_.find(*type); if (itr == plugins_.end()) { std::string s("Could not create datasource for type: '"); s += *type + "'"; if (plugin_directories_.empty()) { s += " (no datasource plugin directories have been successfully registered)"; } else { s += " (searched for datasource plugins in '" + plugin_directories() + "')"; } throw config_error(s); } } if (!itr->second->valid()) { throw std::runtime_error(std::string("Cannot load library: ") + itr->second->get_error()); } // http://www.mr-edd.co.uk/blog/supressing_gcc_warnings #ifdef __GNUC__ __extension__ #endif create_ds create_datasource = reinterpret_cast<create_ds>(itr->second->get_symbol("create")); if (! create_datasource) { throw std::runtime_error(std::string("Cannot load symbols: ") + itr->second->get_error()); } ds = datasource_ptr(create_datasource(params), datasource_deleter()); return ds; }
datasource_ptr datasource_cache::create(parameters const& params) { boost::optional<std::string> type = params.get<std::string>("type"); if ( ! type) { throw config_error(std::string("Could not create datasource. Required ") + "parameter 'type' is missing"); } datasource_ptr ds; #ifdef MAPNIK_STATIC_PLUGINS // return if it's created, raise otherwise ds = create_static_datasource(params); if (ds) { return ds; } #endif #ifdef MAPNIK_THREADSAFE mapnik::scoped_lock lock(mutex_); #endif std::map<std::string,std::shared_ptr<PluginInfo> >::iterator itr=plugins_.find(*type); if (itr == plugins_.end()) { std::string s("Could not create datasource for type: '"); s += *type + "'"; if (plugin_directories_.empty()) { s += " (no datasource plugin directories have been successfully registered)"; } else { s += " (searched for datasource plugins in '" + plugin_directories() + "')"; } throw config_error(s); } if (! itr->second->valid()) { throw std::runtime_error(std::string("Cannot load library: ") + itr->second->get_error()); } // http://www.mr-edd.co.uk/blog/supressing_gcc_warnings #ifdef __GNUC__ __extension__ #endif create_ds* create_datasource = reinterpret_cast<create_ds*>(itr->second->get_symbol("create")); if (! create_datasource) { throw std::runtime_error(std::string("Cannot load symbols: ") + itr->second->get_error()); } ds = datasource_ptr(create_datasource(params), datasource_deleter()); #ifdef MAPNIK_LOG MAPNIK_LOG_DEBUG(datasource_cache) << "datasource_cache: Datasource=" << ds << " type=" << type; MAPNIK_LOG_DEBUG(datasource_cache) << "datasource_cache: Size=" << params.size(); parameters::const_iterator i = params.begin(); for (; i != params.end(); ++i) { MAPNIK_LOG_DEBUG(datasource_cache) << "datasource_cache: -- " << i->first << "=" << i->second; } #endif return ds; }