X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Ffilter_frontend_net.cpp;h=3554d63305779fd0eb8557c1c591207832a20d53;hb=f47e8cf4cde2ba5465106e219c803e6424a4f177;hp=5c1f119477de39980c2518b55210ce6e692bfb9c;hpb=dccdc0c5b4c4eb59f9ccdd5b2b93731fe10fb927;p=metaproxy-moved-to-github.git diff --git a/src/filter_frontend_net.cpp b/src/filter_frontend_net.cpp index 5c1f119..3554d63 100644 --- a/src/filter_frontend_net.cpp +++ b/src/filter_frontend_net.cpp @@ -1,14 +1,13 @@ -/* $Id: filter_frontend_net.cpp,v 1.8 2005-11-07 12:31:43 adam Exp $ +/* $Id: filter_frontend_net.cpp,v 1.15 2006-01-11 11:51:49 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% */ - #include "config.hpp" +#include "pipe.hpp" #include "filter.hpp" -#include "router.hpp" #include "package.hpp" #include "thread_pool_observer.hpp" #include "filter_frontend_net.hpp" @@ -20,10 +19,18 @@ #include namespace yp2 { + namespace filter { + class FrontendNet::Rep { + friend class FrontendNet; + int m_no_threads; + std::vector m_ports; + int m_listen_duration; + }; + } class My_Timer_Thread : public yazpp_1::ISocketObserver { private: yazpp_1::ISocketObservable *m_obs; - int m_fd[2]; + Pipe m_pipe; bool m_timeout; public: My_Timer_Thread(yazpp_1::ISocketObservable *obs, int duration); @@ -213,12 +220,15 @@ void yp2::ZAssocServer::connectNotify() { } -yp2::filter::FrontendNet::FrontendNet() +yp2::filter::FrontendNet::FrontendNet() : m_p(new Rep) { - m_no_threads = 5; - m_listen_duration = 0; + m_p->m_no_threads = 5; + m_p->m_listen_duration = 0; } +yp2::filter::FrontendNet::~FrontendNet() +{ +} bool yp2::My_Timer_Thread::timeout() { @@ -227,10 +237,9 @@ bool yp2::My_Timer_Thread::timeout() yp2::My_Timer_Thread::My_Timer_Thread(yazpp_1::ISocketObservable *obs, int duration) : - m_obs(obs), m_timeout(false) + m_obs(obs), m_pipe(9123), m_timeout(false) { - pipe(m_fd); - obs->addObserver(m_fd[0], this); + obs->addObserver(m_pipe.read_fd(), this); obs->maskObserver(this, yazpp_1::SOCKET_OBSERVE_READ); obs->timeoutObserver(this, duration); } @@ -239,52 +248,103 @@ void yp2::My_Timer_Thread::socketNotify(int event) { m_timeout = true; m_obs->deleteObserver(this); - close(m_fd[0]); - close(m_fd[1]); } -void yp2::filter::FrontendNet::process(Package &package) const { +void yp2::filter::FrontendNet::process(Package &package) const +{ + if (m_p->m_ports.size() == 0) + return; + yazpp_1::SocketManager mySocketManager; My_Timer_Thread *tt = 0; - if (m_listen_duration) - tt = new My_Timer_Thread(&mySocketManager, m_listen_duration); + if (m_p->m_listen_duration) + tt = new My_Timer_Thread(&mySocketManager, m_p->m_listen_duration); - ThreadPoolSocketObserver threadPool(&mySocketManager, m_no_threads); + ThreadPoolSocketObserver threadPool(&mySocketManager, m_p->m_no_threads); - yp2::ZAssocServer **az = new yp2::ZAssocServer *[m_ports.size()]; + yp2::ZAssocServer **az = new yp2::ZAssocServer *[m_p->m_ports.size()]; // Create yp2::ZAssocServer for each port size_t i; - for (i = 0; im_ports.size(); i++) { // create a PDU assoc object (one per yp2::ZAssocServer) yazpp_1::PDU_Assoc *as = new yazpp_1::PDU_Assoc(&mySocketManager); // create ZAssoc with PDU Assoc az[i] = new yp2::ZAssocServer(as, &threadPool, &package); - az[i]->server(m_ports[i].c_str()); + az[i]->server(m_p->m_ports[i].c_str()); } while (mySocketManager.processEvent() > 0) { if (tt && tt->timeout()) break; } - for (i = 0; im_ports.size(); i++) delete az[i]; delete [] az; delete tt; } +void yp2::filter::FrontendNet::configure(const xmlNode * ptr) +{ + if (!ptr || !ptr->children) + { + throw yp2::filter::FilterException("No ports for Frontend"); + } + std::vector ports; + for (ptr = ptr->children; ptr; ptr = ptr->next) + { + if (ptr->type != XML_ELEMENT_NODE) + continue; + if (!strcmp((const char *) ptr->name, "port")) + { + std::string port = yp2::xml::get_text(ptr); + ports.push_back(port); + + } + else if (!strcmp((const char *) ptr->name, "threads")) + { + std::string threads_str = yp2::xml::get_text(ptr); + int threads = atoi(threads_str.c_str()); + if (threads < 1) + throw yp2::filter::FilterException("Bad value for threads: " + + threads_str); + m_p->m_no_threads = threads; + } + else + { + throw yp2::filter::FilterException("Bad element " + + std::string((const char *) + ptr->name)); + } + } + m_p->m_ports = ports; +} + std::vector &yp2::filter::FrontendNet::ports() { - return m_ports; + return m_p->m_ports; } int &yp2::filter::FrontendNet::listen_duration() { - return m_listen_duration; + return m_p->m_listen_duration; +} + +static yp2::filter::Base* filter_creator() +{ + return new yp2::filter::FrontendNet; +} + +extern "C" { + struct yp2_filter_struct yp2_filter_frontend_net = { + 0, + "frontend_net", + filter_creator + }; } /*