-## $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
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 \
-/* $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%
"</routes>\n"
"</yp2>\n";
- yp2::FilterFactory factory;
+ yp2::FactoryFilter factory;
yp2::RouterFleXML rflexml(xmlconf, factory);
--- /dev/null
+/* $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 <dlfcn.h>
+#endif
+#include <stdexcept>
+#include <iostream>
+#include <string>
+#include <map>
+
+namespace yp2 {
+ class FactoryFilter::Rep {
+ typedef std::map<std::string, CreateFilterCallback> CallbackMap;
+ typedef std::map<std::string, CreateFilterCallback>::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
+ */
--- /dev/null
+/* $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 <stdexcept>
+#include <iostream>
+#include <string>
+#include <map>
+
+#include <boost/noncopyable.hpp>
+#include <boost/scoped_ptr.hpp>
+
+#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<Rep> m_p;
+ };
+}
+
+#endif
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * c-file-style: "stroustrup"
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
-/* $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%
#include "filter.hpp"
#include "package.hpp"
-#include "filter_factory.hpp"
+#include "factory_filter.hpp"
#include "filter_backend_test.hpp"
#include "filter_frontend_net.hpp"
-/* $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%
#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();
};
+++ /dev/null
-/* $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 <dlfcn.h>
-#endif
-#include <stdexcept>
-#include <iostream>
-#include <string>
-#include <map>
-
-namespace yp2 {
- class FilterFactory::Rep {
- typedef std::map<std::string, CreateFilterCallback> CallbackMap;
- typedef std::map<std::string, CreateFilterCallback>::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
- */
+++ /dev/null
-/* $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 <stdexcept>
-#include <iostream>
-#include <string>
-#include <map>
-
-#include <boost/noncopyable.hpp>
-#include <boost/scoped_ptr.hpp>
-
-#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<Rep> m_p;
- };
-}
-
-#endif
-/*
- * Local variables:
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * c-file-style: "stroustrup"
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
-/* $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%
#include "config.hpp"
#include "router_flexml.hpp"
-#include "filter_factory.hpp"
+#include "factory_filter.hpp"
#include "factory_static.hpp"
#include <iostream>
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
};
}
{
}
-yp2::RouterFleXML::RouterFleXML(std::string xmlconf, yp2::FilterFactory &factory)
+yp2::RouterFleXML::RouterFleXML(std::string xmlconf, yp2::FactoryFilter &factory)
: m_p(new Rep)
{
-/* $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%
#include "router.hpp"
-#include "filter_factory.hpp"
+#include "factory_filter.hpp"
#include <stdexcept>
{
class Rep;
public:
- RouterFleXML(std::string xmlconf, yp2::FilterFactory &factory);
+ RouterFleXML(std::string xmlconf, yp2::FactoryFilter &factory);
~RouterFleXML();
-/* $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%
#include "config.hpp"
#include "filter.hpp"
#include "package.hpp"
-#include "filter_factory.hpp"
+#include "factory_filter.hpp"
#define BOOST_AUTO_TEST_MAIN
{
try {
- yp2::FilterFactory ffactory;
+ yp2::FactoryFilter ffactory;
XFilter xf;
YFilter yf;
BOOST_AUTO_UNIT_TEST( test_filter_factory_2 )
{
try {
- yp2::FilterFactory ffactory;
+ yp2::FactoryFilter ffactory;
const std::string id = "dl";
-/* $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%
" <filter id=\"front_default\" type=\"frontend_net\">\n"
" <port>210</port>\n";
- yp2::FilterFactory factory;
+ yp2::FactoryFilter factory;
yp2::RouterFleXML rflexml(xmlconf_invalid, factory);
}
catch ( yp2::RouterFleXML::XMLError &e) {