-/* $Id: ex_router_flexml.cpp,v 1.3 2006-01-04 11:19:04 adam Exp $
+/* $Id: ex_router_flexml.cpp,v 1.4 2006-01-04 14:15:45 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
"</route>\n"
"</routes>\n"
"</yp2>\n";
-
- yp2::RouterFleXML rflexml(xmlconf);
+
+ yp2::FilterFactory factory;
+ yp2::RouterFleXML rflexml(xmlconf, factory);
-/* $Id: factory_static.cpp,v 1.2 2006-01-04 11:55:31 adam Exp $
+/* $Id: factory_static.cpp,v 1.3 2006-01-04 14:15:45 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include "filter_virt_db.hpp"
#include "filter_z3950_client.hpp"
-yp2::FactoryStatic::FactoryStatic(yp2::FilterFactory &factory)
+yp2::FactoryStatic::FactoryStatic()
{
struct yp2_filter_struct *buildins[] = {
&yp2_filter_backend_test,
int i;
for (i = 0; buildins[i]; i++)
- factory.add_creator(buildins[i]->type, buildins[i]->creator);
+ add_creator(buildins[i]->type, buildins[i]->creator);
}
-/* $Id: factory_static.hpp,v 1.1 2006-01-04 11:19:04 adam Exp $
+/* $Id: factory_static.hpp,v 1.2 2006-01-04 14:15:45 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include "filter_factory.hpp"
namespace yp2 {
- class FactoryStatic {
+ class FactoryStatic : public FilterFactory {
public:
- FactoryStatic(yp2::FilterFactory &factory);
+ FactoryStatic();
};
}
-/* $Id: router_flexml.cpp,v 1.7 2006-01-04 11:19:04 adam Exp $
+/* $Id: router_flexml.cpp,v 1.8 2006-01-04 14:15:45 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
friend class RouterFleXML;
Rep();
- typedef std::map<std::string, boost::shared_ptr<const yp2::filter::Base> >
- IdFilterMap ;
- typedef std::list<std::string> FilterIdList;
- typedef std::map<std::string, FilterIdList > IdRouteMap ;
+ typedef std::map<std::string,
+ boost::shared_ptr<const yp2::filter::Base > >
+ IdFilterMap ;
- bool m_xinclude;
IdFilterMap m_id_filter_map;
- FilterIdList m_filter_id_list;
- IdRouteMap m_id_route_map;
void create_filter(std::string type,
const xmlDoc * xmldoc,
const xmlNode* jump_to_next(const xmlNode* node, int xml_node_type);
const xmlNode* jump_to_children(const xmlNode* node, int xml_node_type);
- FilterFactory m_factory;
+ bool m_xinclude;
+ private:
+ FilterFactory *m_factory; // TODO shared_ptr
};
}
//const xmlNode *val;
}
- yp2::filter::Base* filter_base = m_factory.create(type_value);
+ yp2::filter::Base* filter_base = m_factory->create(type_value);
+
+ filter_base->configure(node2);
+
+ if (m_id_filter_map.find(id_value) != m_id_filter_map.end())
+ throw XMLError("Filter " + id_value + " already defined");
+
+ m_id_filter_map[id_value] =
+ boost::shared_ptr<yp2::filter::Base>(filter_base);
node2 = jump_to_next(node2, XML_ELEMENT_NODE);
}
{
}
-yp2::RouterFleXML::RouterFleXML(std::string xmlconf)
+yp2::RouterFleXML::RouterFleXML(std::string xmlconf, yp2::FilterFactory &factory)
: m_p(new Rep)
{
- {
- yp2::FactoryStatic fs(m_p->m_factory);
- }
+
+ m_p->m_factory = &factory;
LIBXML_TEST_VERSION;
-/* $Id: router_flexml.hpp,v 1.7 2005-12-08 15:34:08 adam Exp $
+/* $Id: router_flexml.hpp,v 1.8 2006-01-04 14:15:45 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include "router.hpp"
+#include "filter_factory.hpp"
+
#include <stdexcept>
#include <boost/scoped_ptr.hpp>
{
class Rep;
public:
- RouterFleXML(std::string xmlconf);
+ RouterFleXML(std::string xmlconf, yp2::FilterFactory &factory);
~RouterFleXML();
-/* $Id: test_router_flexml.cpp,v 1.9 2006-01-04 11:55:32 adam Exp $
+/* $Id: test_router_flexml.cpp,v 1.10 2006-01-04 14:15:45 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include "filter.hpp"
#include "router_flexml.hpp"
-#include "filter_factory.hpp"
+#include "factory_static.hpp"
#define BOOST_AUTO_TEST_MAIN
#include <boost/test/auto_unit_test.hpp>
using namespace boost::unit_test;
+static bool tfilter_destroyed = false;
class TFilter: public yp2::filter::Base {
public:
void process(yp2::Package & package) const {};
+ ~TFilter() { tfilter_destroyed = true; };
};
-
+
+static yp2::filter::Base* filter_creator()
+{
+ return new TFilter;
+}
BOOST_AUTO_UNIT_TEST( test_router_flexml_1 )
{
" <filter id=\"log_cout1\" type=\"log\">\n"
" <logfile>mylog1.log</logfile>\n"
" </filter>\n"
+ " <filter id=\"tfilter_id\" type=\"tfilter\">\n"
+ " <someelement/>\n"
+ " </filter>\n"
" <filter id=\"log_cout2\" type=\"log\">\n"
" <logfile>mylog2.log</logfile>\n"
" </filter>\n"
" </route>\n"
" </routes>\n"
"</yp2>\n";
- yp2::RouterFleXML rflexml(xmlconf);
- }
- catch ( yp2::RouterFleXML::XMLError &e) {
- std::cout << "XMLError: " << e.what() << "\n";
- BOOST_CHECK (false);
+
+ yp2::FactoryStatic factory;
+ factory.add_creator("tfilter", filter_creator);
+ yp2::RouterFleXML rflexml(xmlconf, factory);
}
- catch ( yp2::FilterFactoryException &e) {
- std::cout << "FilterFactoryException: " << e.what() << "\n";
+ catch ( std::runtime_error &e) {
+ std::cout << "std::runtime error: " << e.what() << "\n";
BOOST_CHECK (false);
}
catch ( ... ) {
BOOST_CHECK (false);
}
+ BOOST_CHECK(tfilter_destroyed == true);
}
BOOST_AUTO_UNIT_TEST( test_router_flexml_2 )
" <filter id=\"front_default\" type=\"frontend_net\">\n"
" <port>210</port>\n";
- yp2::RouterFleXML rflexml(xmlconf_invalid);
+ yp2::FilterFactory factory;
+ yp2::RouterFleXML rflexml(xmlconf_invalid, factory);
}
catch ( yp2::RouterFleXML::XMLError &e) {
got_xml_error = true;
}
+ catch ( std::runtime_error &e) {
+ std::cout << "std::runtime error: " << e.what() << "\n";
+ BOOST_CHECK (false);
+ }
catch ( ... ) {
;
}
" </y:routes>\n"
"</y:yp2>\n";
- yp2::RouterFleXML rflexml(xmlconf);
+ yp2::FactoryStatic factory;
+ yp2::RouterFleXML rflexml(xmlconf, factory);
+ }
+ catch ( std::runtime_error &e) {
+ std::cout << "std::runtime error: " << e.what() << "\n";
+ BOOST_CHECK (false);
}
catch ( ... ) {
BOOST_CHECK (false);