From 74d5524719194de5dc96abd552562fa473088677 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 9 Jul 2010 09:12:30 +0200 Subject: [PATCH] Introduce filter method 'start' Method 'start' can do initialization for a filter . It is called after fork and is good for creating threads etc. Doing that for method 'configure' is bad (threads are stopped when fork occur). --- include/metaproxy/filter.hpp | 2 ++ include/metaproxy/router.hpp | 1 + src/filter.cpp | 6 ++++++ src/filter_session_shared.cpp | 9 +++++++++ src/filter_session_shared.hpp | 1 + src/metaproxy_prog.cpp | 1 + src/router_chain.cpp | 9 +++++++++ src/router_chain.hpp | 1 + src/router_flexml.cpp | 17 +++++++++++++++++ src/router_flexml.hpp | 1 + 10 files changed, 48 insertions(+) diff --git a/include/metaproxy/filter.hpp b/include/metaproxy/filter.hpp index 691eda4..0fbd019 100644 --- a/include/metaproxy/filter.hpp +++ b/include/metaproxy/filter.hpp @@ -38,6 +38,8 @@ namespace metaproxy_1 { /// configuration during filter load virtual void configure(const xmlNode * ptr, bool test_only); + + virtual void start() const; }; class FilterException : public std::runtime_error { diff --git a/include/metaproxy/router.hpp b/include/metaproxy/router.hpp index 392f048..5fdf382 100644 --- a/include/metaproxy/router.hpp +++ b/include/metaproxy/router.hpp @@ -42,6 +42,7 @@ namespace metaproxy_1 virtual ~Router(){}; virtual RoutePos *createpos() const = 0; + virtual void start() = 0; }; class RoutePos : boost::noncopyable { diff --git a/src/filter.cpp b/src/filter.cpp index 430cbbb..95b7e91 100644 --- a/src/filter.cpp +++ b/src/filter.cpp @@ -28,6 +28,12 @@ void mp::filter::Base::configure(const xmlNode * ptr, bool test_only) mp::xml::check_empty(ptr); } +void mp::filter::Base::start() const +{ + +} + + /* * Local variables: * c-basic-offset: 4 diff --git a/src/filter_session_shared.cpp b/src/filter_session_shared.cpp index c6615ea..f0f84f7 100644 --- a/src/filter_session_shared.cpp +++ b/src/filter_session_shared.cpp @@ -179,6 +179,7 @@ namespace metaproxy_1 { private: void init(Package &package, const Z_GDU *gdu, FrontendPtr frontend); + void start(); boost::mutex m_mutex; boost::condition m_cond_session_ready; std::map m_clients; @@ -1017,6 +1018,10 @@ yf::SessionShared::Rep::Rep() m_resultset_ttl = 30; m_resultset_max = 10; m_session_ttl = 90; +} + +void yf::SessionShared::Rep::start() +{ yf::SessionShared::Worker w(this); m_thrds.add_thread(new boost::thread(w)); } @@ -1028,6 +1033,10 @@ yf::SessionShared::SessionShared() : m_p(new SessionShared::Rep) yf::SessionShared::~SessionShared() { } +void yf::SessionShared::start() const +{ + m_p->start(); +} yf::SessionShared::Frontend::Frontend(Rep *rep) : m_is_virtual(false), m_p(rep) { diff --git a/src/filter_session_shared.hpp b/src/filter_session_shared.hpp index de65d29..fdca85a 100644 --- a/src/filter_session_shared.hpp +++ b/src/filter_session_shared.hpp @@ -53,6 +53,7 @@ namespace metaproxy_1 { SessionShared(); void process(metaproxy_1::Package & package) const; void configure(const xmlNode * ptr, bool test_only); + void start() const; private: boost::scoped_ptr m_p; }; diff --git a/src/metaproxy_prog.cpp b/src/metaproxy_prog.cpp index f9815df..b598a81 100644 --- a/src/metaproxy_prog.cpp +++ b/src/metaproxy_prog.cpp @@ -67,6 +67,7 @@ static void handler(void *data) signal(SIGTERM, sig_term_handler); #endif + routerp->start(); mp::Package pack; pack.router(*routerp).move(); /* should never exit */ diff --git a/src/router_chain.cpp b/src/router_chain.cpp index 2ab2924..959007b 100644 --- a/src/router_chain.cpp +++ b/src/router_chain.cpp @@ -17,6 +17,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "router_chain.hpp" +#include #include @@ -49,6 +50,14 @@ mp::RouterChain::~RouterChain() { } +void mp::RouterChain::start() +{ + std::list::const_iterator it; + + for (it = m_p->m_filter_list.begin(); it != m_p->m_filter_list.end(); it++) + (*it)->start(); +} + const mp::filter::Base *mp::RouterChain::Pos::move(const char *route) { if (it == m_p->m_filter_list.end()) diff --git a/src/router_chain.hpp b/src/router_chain.hpp index 4924aca..7cb1ff3 100644 --- a/src/router_chain.hpp +++ b/src/router_chain.hpp @@ -34,6 +34,7 @@ namespace metaproxy_1 { virtual ~RouterChain(); virtual RoutePos *createpos() const; RouterChain & append(const filter::Base &filter); + void start(); private: boost::scoped_ptr m_p; /// disabled because class is singleton diff --git a/src/router_flexml.cpp b/src/router_flexml.cpp index 759ef06..59021e8 100644 --- a/src/router_flexml.cpp +++ b/src/router_flexml.cpp @@ -395,6 +395,23 @@ mp::RouterFleXML::Pos::~Pos() } +void mp::RouterFleXML::start() +{ + std::map::iterator route_it; + + route_it = m_p->m_routes.begin(); + while (route_it != m_p->m_routes.end()) + { + RouterFleXML::Route route = route_it->second; + + std::list >::iterator it; + + for (it = route.m_list.begin(); it != route.m_list.end(); it++) + (*it)->start(); + route_it++; + } +} + /* * Local variables: * c-basic-offset: 4 diff --git a/src/router_flexml.hpp b/src/router_flexml.hpp index 79b921b..2f208bd 100644 --- a/src/router_flexml.hpp +++ b/src/router_flexml.hpp @@ -43,6 +43,7 @@ namespace metaproxy_1 ~RouterFleXML(); virtual RoutePos *createpos() const; + void start(); private: boost::scoped_ptr m_p; }; -- 1.7.10.4