From: Adam Dickmeiss Date: Wed, 4 Jan 2006 14:30:51 +0000 (+0000) Subject: Rename yp2::FilterFactory to yp2::FactoryFilter X-Git-Tag: YP2.0.0.2~117 X-Git-Url: http://lists.indexdata.com/cgi-bin?a=commitdiff_plain;h=14d0e634d5061208301502d813d488d1e82f190b;p=metaproxy-moved-to-github.git Rename yp2::FilterFactory to yp2::FactoryFilter --- diff --git a/src/Makefile.am b/src/Makefile.am index f580fc9..8e86495 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.39 2006-01-04 11:19:04 adam Exp $ +## $Id: Makefile.am,v 1.40 2006-01-04 14:30:51 adam Exp $ MAINTAINERCLEANFILES = Makefile.in config.in config.hpp @@ -17,7 +17,7 @@ libyp2_la_SOURCES = \ router.hpp router_chain.hpp router_chain.cpp \ router_flexml.hpp router_flexml.cpp \ thread_pool_observer.cpp thread_pool_observer.hpp \ - filter.hpp filter.cpp filter_factory.cpp filter_factory.hpp \ + filter.hpp filter.cpp factory_filter.cpp factory_filter.hpp \ filter_frontend_net.cpp filter_frontend_net.hpp \ filter_log.cpp filter_log.hpp \ filter_virt_db.cpp filter_virt_db.hpp \ diff --git a/src/ex_router_flexml.cpp b/src/ex_router_flexml.cpp index c2e58f6..6fdb856 100644 --- a/src/ex_router_flexml.cpp +++ b/src/ex_router_flexml.cpp @@ -1,4 +1,4 @@ -/* $Id: ex_router_flexml.cpp,v 1.4 2006-01-04 14:15:45 adam Exp $ +/* $Id: ex_router_flexml.cpp,v 1.5 2006-01-04 14:30:51 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -35,7 +35,7 @@ int main(int argc, char **argv) "\n" "\n"; - yp2::FilterFactory factory; + yp2::FactoryFilter factory; yp2::RouterFleXML rflexml(xmlconf, factory); diff --git a/src/factory_filter.cpp b/src/factory_filter.cpp new file mode 100644 index 0000000..de786ff --- /dev/null +++ b/src/factory_filter.cpp @@ -0,0 +1,118 @@ +/* $Id: factory_filter.cpp,v 1.1 2006-01-04 14:30:51 adam Exp $ + Copyright (c) 2005, Index Data. + +%LICENSE% + */ + +#include "config.hpp" + +#include "factory_filter.hpp" + +#if HAVE_DLFCN_H +#include +#endif +#include +#include +#include +#include + +namespace yp2 { + class FactoryFilter::Rep { + typedef std::map CallbackMap; + typedef std::map::iterator + CallbackMapIt; + public: + friend class FactoryFilter; + CallbackMap m_fcm; + Rep(); + ~Rep(); + }; +} + +yp2::FactoryFilterException::FactoryFilterException(const std::string message) + : std::runtime_error("FilterException: " + message) +{ +} + +yp2::FactoryFilter::Rep::Rep() +{ +} + +yp2::FactoryFilter::Rep::~Rep() +{ +} + +yp2::FactoryFilter::FactoryFilter() : m_p(new yp2::FactoryFilter::Rep) +{ + +} + +yp2::FactoryFilter::~FactoryFilter() +{ + +} + +bool yp2::FactoryFilter::add_creator(std::string fi, + CreateFilterCallback cfc) +{ + return m_p->m_fcm.insert(Rep::CallbackMap::value_type(fi, cfc)).second; +} + + +bool yp2::FactoryFilter::drop_creator(std::string fi) +{ + return m_p->m_fcm.erase(fi) == 1; +} + +yp2::filter::Base* yp2::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 yp2::FactoryFilterException(msg); + } + // call create function + return (it->second()); +} + +#if HAVE_DLFCN_H +bool yp2::FactoryFilter::add_creator_dyn(const std::string &fi, + const std::string &path) +{ + if (m_p->m_fcm.find(fi) != m_p->m_fcm.end()) + { + return true; + } + + std::string full_path = path + "/yp2_filter_" + fi + ".so"; + void *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; + } + + std::string full_name = "yp2_filter_" + fi; + + void *dlsym_ptr = dlsym(dl_handle, full_name.c_str()); + if (!dlsym_ptr) + { + std::cout << "dlsym " << full_name << " failed\n"; + return false; + } + struct yp2_filter_struct *s = (struct yp2_filter_struct *) dlsym_ptr; + return add_creator(fi, s->creator); +} +#endif + +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * c-file-style: "stroustrup" + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ diff --git a/src/factory_filter.hpp b/src/factory_filter.hpp new file mode 100644 index 0000000..ab2acd8 --- /dev/null +++ b/src/factory_filter.hpp @@ -0,0 +1,57 @@ +/* $Id: factory_filter.hpp,v 1.1 2006-01-04 14:30:51 adam Exp $ + Copyright (c) 2005, Index Data. + +%LICENSE% + */ + +#ifndef FACTORY_FILTER_HPP +#define FACTORY_FILTER_HPP + +#include +#include +#include +#include + +#include +#include + +#include "filter.hpp" + +namespace yp2 { + class FactoryFilterException : public std::runtime_error { + public: + FactoryFilterException(const std::string message); + }; + + class FactoryFilter : public boost::noncopyable + { + typedef yp2::filter::Base* (*CreateFilterCallback)(); + + class Rep; + public: + /// true if registration ok + + FactoryFilter(); + ~FactoryFilter(); + + bool add_creator(std::string fi, CreateFilterCallback cfc); + + bool drop_creator(std::string fi); + + yp2::filter::Base* create(std::string fi); + + bool add_creator_dyn(const std::string &fi, const std::string &path); + private: + boost::scoped_ptr m_p; + }; +} + +#endif +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * c-file-style: "stroustrup" + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ diff --git a/src/factory_static.cpp b/src/factory_static.cpp index f988789..0c01970 100644 --- a/src/factory_static.cpp +++ b/src/factory_static.cpp @@ -1,4 +1,4 @@ -/* $Id: factory_static.cpp,v 1.3 2006-01-04 14:15:45 adam Exp $ +/* $Id: factory_static.cpp,v 1.4 2006-01-04 14:30:51 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -14,7 +14,7 @@ #include "filter.hpp" #include "package.hpp" -#include "filter_factory.hpp" +#include "factory_filter.hpp" #include "filter_backend_test.hpp" #include "filter_frontend_net.hpp" diff --git a/src/factory_static.hpp b/src/factory_static.hpp index d01d13c..29b77e8 100644 --- a/src/factory_static.hpp +++ b/src/factory_static.hpp @@ -1,4 +1,4 @@ -/* $Id: factory_static.hpp,v 1.2 2006-01-04 14:15:45 adam Exp $ +/* $Id: factory_static.hpp,v 1.3 2006-01-04 14:30:51 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -7,10 +7,10 @@ #ifndef FACTORY_STATIC_HPP #define FACTORY_STATIC_HPP -#include "filter_factory.hpp" +#include "factory_filter.hpp" namespace yp2 { - class FactoryStatic : public FilterFactory { + class FactoryStatic : public FactoryFilter { public: FactoryStatic(); }; diff --git a/src/filter_factory.cpp b/src/filter_factory.cpp deleted file mode 100644 index 6efdc89..0000000 --- a/src/filter_factory.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* $Id: filter_factory.cpp,v 1.3 2006-01-04 11:55:31 adam Exp $ - Copyright (c) 2005, Index Data. - -%LICENSE% - */ - -#include "config.hpp" - -#include "filter_factory.hpp" - -#if HAVE_DLFCN_H -#include -#endif -#include -#include -#include -#include - -namespace yp2 { - class FilterFactory::Rep { - typedef std::map CallbackMap; - typedef std::map::iterator - CallbackMapIt; - public: - friend class FilterFactory; - CallbackMap m_fcm; - Rep(); - ~Rep(); - }; -} - -yp2::FilterFactoryException::FilterFactoryException(const std::string message) - : std::runtime_error("FilterException: " + message) -{ -} - -yp2::FilterFactory::Rep::Rep() -{ -} - -yp2::FilterFactory::Rep::~Rep() -{ -} - -yp2::FilterFactory::FilterFactory() : m_p(new yp2::FilterFactory::Rep) -{ - -} - -yp2::FilterFactory::~FilterFactory() -{ - -} - -bool yp2::FilterFactory::add_creator(std::string fi, - CreateFilterCallback cfc) -{ - return m_p->m_fcm.insert(Rep::CallbackMap::value_type(fi, cfc)).second; -} - - -bool yp2::FilterFactory::drop_creator(std::string fi) -{ - return m_p->m_fcm.erase(fi) == 1; -} - -yp2::filter::Base* yp2::FilterFactory::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 yp2::FilterFactoryException(msg); - } - // call create function - return (it->second()); -} - -#if HAVE_DLFCN_H -bool yp2::FilterFactory::add_creator_dyn(const std::string &fi, - const std::string &path) -{ - if (m_p->m_fcm.find(fi) != m_p->m_fcm.end()) - { - return true; - } - - std::string full_path = path + "/yp2_filter_" + fi + ".so"; - void *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; - } - - std::string full_name = "yp2_filter_" + fi; - - void *dlsym_ptr = dlsym(dl_handle, full_name.c_str()); - if (!dlsym_ptr) - { - std::cout << "dlsym " << full_name << " failed\n"; - return false; - } - struct yp2_filter_struct *s = (struct yp2_filter_struct *) dlsym_ptr; - return add_creator(fi, s->creator); -} -#endif - -/* - * Local variables: - * c-basic-offset: 4 - * indent-tabs-mode: nil - * c-file-style: "stroustrup" - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ diff --git a/src/filter_factory.hpp b/src/filter_factory.hpp deleted file mode 100644 index c8b2251..0000000 --- a/src/filter_factory.hpp +++ /dev/null @@ -1,59 +0,0 @@ -/* $Id: filter_factory.hpp,v 1.7 2005-12-10 09:59:10 adam Exp $ - Copyright (c) 2005, Index Data. - -%LICENSE% - */ - -#ifndef FILTER_FACTORY_HPP -#define FILTER_FACTORY_HPP - -#include -#include -#include -#include - -#include -#include - -#include "filter.hpp" - - -namespace yp2 { - - class FilterFactoryException : public std::runtime_error { - public: - FilterFactoryException(const std::string message); - }; - - class FilterFactory : public boost::noncopyable - { - typedef yp2::filter::Base* (*CreateFilterCallback)(); - - class Rep; - public: - /// true if registration ok - - FilterFactory(); - ~FilterFactory(); - - bool add_creator(std::string fi, CreateFilterCallback cfc); - - bool drop_creator(std::string fi); - - yp2::filter::Base* create(std::string fi); - - bool add_creator_dyn(const std::string &fi, const std::string &path); - private: - boost::scoped_ptr m_p; - }; -} - -#endif -/* - * Local variables: - * c-basic-offset: 4 - * indent-tabs-mode: nil - * c-file-style: "stroustrup" - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ diff --git a/src/router_flexml.cpp b/src/router_flexml.cpp index 483990e..2abdfa8 100644 --- a/src/router_flexml.cpp +++ b/src/router_flexml.cpp @@ -1,4 +1,4 @@ -/* $Id: router_flexml.cpp,v 1.8 2006-01-04 14:15:45 adam Exp $ +/* $Id: router_flexml.cpp,v 1.9 2006-01-04 14:30:51 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -6,7 +6,7 @@ #include "config.hpp" #include "router_flexml.hpp" -#include "filter_factory.hpp" +#include "factory_filter.hpp" #include "factory_static.hpp" #include @@ -54,7 +54,7 @@ namespace yp2 { const xmlNode* jump_to_children(const xmlNode* node, int xml_node_type); bool m_xinclude; private: - FilterFactory *m_factory; // TODO shared_ptr + FactoryFilter *m_factory; // TODO shared_ptr }; } @@ -225,7 +225,7 @@ yp2::RouterFleXML::Rep::Rep() : { } -yp2::RouterFleXML::RouterFleXML(std::string xmlconf, yp2::FilterFactory &factory) +yp2::RouterFleXML::RouterFleXML(std::string xmlconf, yp2::FactoryFilter &factory) : m_p(new Rep) { diff --git a/src/router_flexml.hpp b/src/router_flexml.hpp index 9cce474..814d4c1 100644 --- a/src/router_flexml.hpp +++ b/src/router_flexml.hpp @@ -1,4 +1,4 @@ -/* $Id: router_flexml.hpp,v 1.8 2006-01-04 14:15:45 adam Exp $ +/* $Id: router_flexml.hpp,v 1.9 2006-01-04 14:30:51 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -6,7 +6,7 @@ #include "router.hpp" -#include "filter_factory.hpp" +#include "factory_filter.hpp" #include @@ -18,7 +18,7 @@ namespace yp2 { class Rep; public: - RouterFleXML(std::string xmlconf, yp2::FilterFactory &factory); + RouterFleXML(std::string xmlconf, yp2::FactoryFilter &factory); ~RouterFleXML(); diff --git a/src/test_filter_factory.cpp b/src/test_filter_factory.cpp index 4ee6960..81012d4 100644 --- a/src/test_filter_factory.cpp +++ b/src/test_filter_factory.cpp @@ -1,4 +1,4 @@ -/* $Id: test_filter_factory.cpp,v 1.9 2006-01-04 11:55:32 adam Exp $ +/* $Id: test_filter_factory.cpp,v 1.10 2006-01-04 14:30:51 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -11,7 +11,7 @@ #include "config.hpp" #include "filter.hpp" #include "package.hpp" -#include "filter_factory.hpp" +#include "factory_filter.hpp" #define BOOST_AUTO_TEST_MAIN @@ -53,7 +53,7 @@ BOOST_AUTO_UNIT_TEST( test_filter_factory_1 ) { try { - yp2::FilterFactory ffactory; + yp2::FactoryFilter ffactory; XFilter xf; YFilter yf; @@ -92,7 +92,7 @@ BOOST_AUTO_UNIT_TEST( test_filter_factory_1 ) BOOST_AUTO_UNIT_TEST( test_filter_factory_2 ) { try { - yp2::FilterFactory ffactory; + yp2::FactoryFilter ffactory; const std::string id = "dl"; diff --git a/src/test_router_flexml.cpp b/src/test_router_flexml.cpp index 05d7b84..5cefd7a 100644 --- a/src/test_router_flexml.cpp +++ b/src/test_router_flexml.cpp @@ -1,4 +1,4 @@ -/* $Id: test_router_flexml.cpp,v 1.10 2006-01-04 14:15:45 adam Exp $ +/* $Id: test_router_flexml.cpp,v 1.11 2006-01-04 14:30:51 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -84,7 +84,7 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_2 ) " \n" " 210\n"; - yp2::FilterFactory factory; + yp2::FactoryFilter factory; yp2::RouterFleXML rflexml(xmlconf_invalid, factory); } catch ( yp2::RouterFleXML::XMLError &e) {