X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ffactory_filter.cpp;h=a0c3d6eb294e4c9f2619e10fd9b4238ef8417b74;hb=953e615164c4c47ee871ef7901e90d6fcffd8473;hp=a7516bbbb8df046033365b0bb29725e1937743d0;hpb=637a685d61a9ff0e3f398a59da426979815c4d68;p=metaproxy-moved-to-github.git diff --git a/src/factory_filter.cpp b/src/factory_filter.cpp index a7516bb..a0c3d6e 100644 --- a/src/factory_filter.cpp +++ b/src/factory_filter.cpp @@ -1,7 +1,5 @@ -/* $Id: factory_filter.cpp,v 1.8 2007-05-09 21:23:09 adam Exp $ - Copyright (c) 2005-2007, Index Data. - -This file is part of Metaproxy. +/* This file is part of Metaproxy. + Copyright (C) Index Data Metaproxy is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -14,10 +12,9 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with Metaproxy; see the file LICENSE. If not, write to the -Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA -02111-1307, USA. - */ +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ #include "config.hpp" @@ -36,7 +33,7 @@ namespace mp = metaproxy_1; namespace metaproxy_1 { class FactoryFilter::Rep { typedef std::map CallbackMap; - typedef std::map::iterator + typedef std::map::iterator CallbackMapIt; public: friend class FactoryFilter; @@ -69,8 +66,8 @@ mp::FactoryFilter::~FactoryFilter() } -bool mp::FactoryFilter::add_creator(std::string fi, - CreateFilterCallback cfc) +bool mp::FactoryFilter::add_creator(const std::string &fi, + CreateFilterCallback cfc) { return m_p->m_fcm.insert(Rep::CallbackMap::value_type(fi, cfc)).second; } @@ -84,7 +81,7 @@ bool mp::FactoryFilter::drop_creator(std::string fi) bool mp::FactoryFilter::exist(std::string fi) { Rep::CallbackMap::const_iterator it = m_p->m_fcm.find(fi); - + if (it == m_p->m_fcm.end()) { return false; @@ -95,7 +92,7 @@ bool mp::FactoryFilter::exist(std::string fi) mp::filter::Base* mp::FactoryFilter::create(std::string fi) { Rep::CallbackMap::const_iterator it = m_p->m_fcm.find(fi); - + if (it == m_p->m_fcm.end()){ std::string msg = "filter type '" + fi + "' not found"; throw NotFound(msg); @@ -104,15 +101,6 @@ mp::filter::Base* mp::FactoryFilter::create(std::string fi) return (it->second()); } -bool mp::FactoryFilter::have_dl_support() -{ -#if HAVE_DLFCN_H - return true; -#else - return false; -#endif -} - bool mp::FactoryFilter::add_creator_dl(const std::string &fi, const std::string &path) { @@ -121,20 +109,24 @@ bool mp::FactoryFilter::add_creator_dl(const std::string &fi, { return true; } + std::string full_name = "metaproxy_1_filter_" + fi; - std::string full_path = path + "/metaproxy_filter_" + fi + ".so"; - void *dl_handle = dlopen(full_path.c_str(), RTLD_GLOBAL|RTLD_NOW); - if (!dl_handle) + void *dl_handle = dlopen(0, RTLD_GLOBAL|RTLD_NOW); + void *dlsym_ptr = dlsym(dl_handle, full_name.c_str()); + + if (!dlsym_ptr) { - const char *dl = dlerror(); - std::cout << "dlopen " << full_path << " failed. dlerror=" << dl << - std::endl; - return false; + std::string full_path = path + "/metaproxy_filter_" + fi + ".so"; + dl_handle = dlopen(full_path.c_str(), RTLD_GLOBAL|RTLD_NOW); + if (!dl_handle) + { + const char *dl = dlerror(); + std::cout << "dlopen " << full_path << " failed. dlerror=" << dl << + std::endl; + return false; + } + dlsym_ptr = dlsym(dl_handle, full_name.c_str()); } - - std::string full_name = "metaproxy_1_filter_" + fi; - - void *dlsym_ptr = dlsym(dl_handle, full_name.c_str()); if (!dlsym_ptr) { std::cout << "dlsym " << full_name << " failed\n"; @@ -150,8 +142,9 @@ bool mp::FactoryFilter::add_creator_dl(const std::string &fi, /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil - * c-file-style: "stroustrup" * End: * vim: shiftwidth=4 tabstop=8 expandtab */ +