From: Adam Dickmeiss Date: Fri, 14 Oct 2005 10:27:18 +0000 (+0000) Subject: Moving ThreadPoolSocketObserver and IThreadPoolMsg to yp2 namespace X-Git-Tag: YP2.0.0.2~214 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=5ed8cae5f8518ca4502a51f3884b323f4dbd744a;p=metaproxy-moved-to-github.git Moving ThreadPoolSocketObserver and IThreadPoolMsg to yp2 namespace --- diff --git a/src/filter_frontend_net.cpp b/src/filter_frontend_net.cpp index fbc48a0..ba81508 100644 --- a/src/filter_frontend_net.cpp +++ b/src/filter_frontend_net.cpp @@ -16,10 +16,10 @@ using namespace yp2; -class P2_Session : public yazpp_1::Z_Assoc { +class ZAssocServerChild : public yazpp_1::Z_Assoc { public: - ~P2_Session(); - P2_Session(yazpp_1::IPDU_Observable *the_PDU_Observable, + ~ZAssocServerChild(); + ZAssocServerChild(yazpp_1::IPDU_Observable *the_PDU_Observable, ThreadPoolSocketObserver *m_thread_pool_observer, const Package *package); int m_no_requests; @@ -43,14 +43,14 @@ private: class ThreadPoolPackage : public IThreadPoolMsg { public: - ThreadPoolPackage(Package *package, P2_Session *ses) : + ThreadPoolPackage(Package *package, ZAssocServerChild *ses) : m_session(ses), m_package(package) { }; ~ThreadPoolPackage(); IThreadPoolMsg *handle(); void result(); private: - P2_Session *m_session; + ZAssocServerChild *m_session; Package *m_package; }; @@ -82,7 +82,7 @@ IThreadPoolMsg *ThreadPoolPackage::handle() } -P2_Session::P2_Session(yazpp_1::IPDU_Observable *the_PDU_Observable, +ZAssocServerChild::ZAssocServerChild(yazpp_1::IPDU_Observable *the_PDU_Observable, ThreadPoolSocketObserver *my_thread_pool, const Package *package) : Z_Assoc(the_PDU_Observable) @@ -94,17 +94,17 @@ P2_Session::P2_Session(yazpp_1::IPDU_Observable *the_PDU_Observable, } -yazpp_1::IPDU_Observer *P2_Session::sessionNotify(yazpp_1::IPDU_Observable +yazpp_1::IPDU_Observer *ZAssocServerChild::sessionNotify(yazpp_1::IPDU_Observable *the_PDU_Observable, int fd) { return 0; } -P2_Session::~P2_Session() +ZAssocServerChild::~ZAssocServerChild() { } -void P2_Session::recv_GDU(Z_GDU *z_pdu, int len) +void ZAssocServerChild::recv_GDU(Z_GDU *z_pdu, int len) { m_no_requests++; @@ -116,7 +116,7 @@ void P2_Session::recv_GDU(Z_GDU *z_pdu, int len) m_thread_pool_observer->put(tp); } -void P2_Session::failNotify() +void ZAssocServerChild::failNotify() { // TODO: send Package to signal "close" if (m_session.is_closed()) @@ -132,20 +132,20 @@ void P2_Session::failNotify() m_thread_pool_observer->put(tp); } -void P2_Session::timeoutNotify() +void ZAssocServerChild::timeoutNotify() { failNotify(); } -void P2_Session::connectNotify() +void ZAssocServerChild::connectNotify() { } -class P2_Server : public yazpp_1::Z_Assoc { +class ZAssocServer : public yazpp_1::Z_Assoc { public: - ~P2_Server(); - P2_Server(yazpp_1::IPDU_Observable *the_PDU_Observable, + ~ZAssocServer(); + ZAssocServer(yazpp_1::IPDU_Observable *the_PDU_Observable, ThreadPoolSocketObserver *m_thread_pool_observer, const Package *package); private: @@ -163,7 +163,7 @@ private: }; -P2_Server::P2_Server(yazpp_1::IPDU_Observable *the_PDU_Observable, +ZAssocServer::ZAssocServer(yazpp_1::IPDU_Observable *the_PDU_Observable, ThreadPoolSocketObserver *thread_pool_observer, const Package *package) : Z_Assoc(the_PDU_Observable) @@ -173,31 +173,31 @@ P2_Server::P2_Server(yazpp_1::IPDU_Observable *the_PDU_Observable, } -yazpp_1::IPDU_Observer *P2_Server::sessionNotify(yazpp_1::IPDU_Observable +yazpp_1::IPDU_Observer *ZAssocServer::sessionNotify(yazpp_1::IPDU_Observable *the_PDU_Observable, int fd) { - P2_Session *my = new P2_Session(the_PDU_Observable, m_thread_pool_observer, + ZAssocServerChild *my = new ZAssocServerChild(the_PDU_Observable, m_thread_pool_observer, m_package); return my; } -P2_Server::~P2_Server() +ZAssocServer::~ZAssocServer() { } -void P2_Server::recv_GDU(Z_GDU *apdu, int len) +void ZAssocServer::recv_GDU(Z_GDU *apdu, int len) { } -void P2_Server::failNotify() +void ZAssocServer::failNotify() { } -void P2_Server::timeoutNotify() +void ZAssocServer::timeoutNotify() { } -void P2_Server::connectNotify() +void ZAssocServer::connectNotify() { } @@ -254,7 +254,7 @@ void FilterFrontendNet::process(Package &package) const { ThreadPoolSocketObserver threadPool(&mySocketManager, m_no_threads); - P2_Server z(my_PDU_Assoc, &threadPool, &package); + ZAssocServer z(my_PDU_Assoc, &threadPool, &package); z.server(m_listen_address.c_str()); while (mySocketManager.processEvent() > 0) diff --git a/src/p2.cpp b/src/p2.cpp index 0dac5e9..ced97d1 100644 --- a/src/p2.cpp +++ b/src/p2.cpp @@ -1,4 +1,4 @@ -/* $Id: p2.cpp,v 1.3 2005-10-08 23:29:32 adam Exp $ +/* $Id: p2.cpp,v 1.4 2005-10-14 10:27:18 adam Exp $ Copyright (c) 1998-2005, Index Data. This file is part of the yaz-proxy. @@ -58,7 +58,7 @@ void P2_Server::unlockConfig() } P2_Server::P2_Server(IPDU_Observable *the_PDU_Observable, - ThreadPoolSocketObserver *my_thread, + yp2::ThreadPoolSocketObserver *my_thread, P2_Config *config, P2_ModuleFactory *modules) : Z_Assoc(the_PDU_Observable) @@ -118,7 +118,8 @@ int main(int argc, char **argv) PDU_Assoc *my_PDU_Assoc = 0; - ThreadPoolSocketObserver my_thread(&mySocketManager, config.m_no_threads); + yp2::ThreadPoolSocketObserver my_thread(&mySocketManager, + config.m_no_threads); my_PDU_Assoc = new PDU_Assoc(&mySocketManager); diff --git a/src/p2_frontend.cpp b/src/p2_frontend.cpp index 83e6bc7..e43b54d 100644 --- a/src/p2_frontend.cpp +++ b/src/p2_frontend.cpp @@ -1,4 +1,4 @@ -/* $Id: p2_frontend.cpp,v 1.3 2005-10-08 23:29:32 adam Exp $ +/* $Id: p2_frontend.cpp,v 1.4 2005-10-14 10:27:18 adam Exp $ Copyright (c) 1998-2005, Index Data. This file is part of the yaz-proxy. @@ -28,7 +28,7 @@ using namespace yazpp_1; using namespace std; P2_Frontend::P2_Frontend(IPDU_Observable *the_PDU_Observable, - ThreadPoolSocketObserver + yp2::ThreadPoolSocketObserver *my_thread, P2_Server *server) : Z_Assoc(the_PDU_Observable) { diff --git a/src/p2_frontend.h b/src/p2_frontend.h index ea68a14..adae8b2 100644 --- a/src/p2_frontend.h +++ b/src/p2_frontend.h @@ -1,4 +1,4 @@ -/* $Id: p2_frontend.h,v 1.4 2005-10-13 20:06:45 adam Exp $ +/* $Id: p2_frontend.h,v 1.5 2005-10-14 10:27:18 adam Exp $ Copyright (c) 1998-2005, Index Data. This file is part of the yaz-proxy. @@ -69,7 +69,7 @@ class P2_Server : public yazpp_1::Z_Assoc { public: ~P2_Server(); P2_Server(yazpp_1::IPDU_Observable *the_PDU_Observable, - ThreadPoolSocketObserver *m_my_thread, + yp2::ThreadPoolSocketObserver *m_my_thread, P2_Config *config, P2_ModuleFactory *modules); P2_Config *lockConfig(); @@ -87,7 +87,7 @@ private: void connectNotify(); private: P2_Config *m_config; - ThreadPoolSocketObserver *m_my_thread; + yp2::ThreadPoolSocketObserver *m_my_thread; pthread_mutex_t m_mutex_config; }; @@ -102,14 +102,14 @@ public: yazpp_1::Yaz_Z_Query m_query; }; -class P2_Msg : public IThreadPoolMsg { +class P2_Msg : public yp2::IThreadPoolMsg { public: int m_close_flag; yazpp_1::GDU *m_gdu; yazpp_1::GDU *m_output; P2_Frontend *m_front; P2_Server *m_server; - IThreadPoolMsg *handle(); + yp2::IThreadPoolMsg *handle(); void result(); P2_Msg(yazpp_1::GDU *gdu, P2_Frontend *front, P2_Server *server); virtual ~P2_Msg(); @@ -131,7 +131,7 @@ class P2_Frontend : public yazpp_1::Z_Assoc { public: ~P2_Frontend(); P2_Frontend(yazpp_1::IPDU_Observable *the_PDU_Observable, - ThreadPoolSocketObserver *m_my_thread, P2_Server *server); + yp2::ThreadPoolSocketObserver *m_my_thread, P2_Server *server); IPDU_Observer* sessionNotify(yazpp_1::IPDU_Observable *the_PDU_Observable, int fd); @@ -147,7 +147,7 @@ class P2_Frontend : public yazpp_1::Z_Assoc { private: yazpp_1::GDUQueue m_in_queue; - ThreadPoolSocketObserver *m_my_thread; + yp2::ThreadPoolSocketObserver *m_my_thread; P2_Server *m_server; private: bool P2_Frontend::search(Z_GDU *z_gdu); diff --git a/src/p2_msg.cpp b/src/p2_msg.cpp index 5996c1c..a0c50e1 100644 --- a/src/p2_msg.cpp +++ b/src/p2_msg.cpp @@ -1,4 +1,4 @@ -/* $Id: p2_msg.cpp,v 1.3 2005-10-08 23:29:32 adam Exp $ +/* $Id: p2_msg.cpp,v 1.4 2005-10-14 10:27:18 adam Exp $ Copyright (c) 1998-2005, Index Data. This file is part of the yaz-proxy. @@ -318,7 +318,7 @@ Z_APDU *P2_Msg::frontend_present_apdu(Z_APDU *request_apdu, ODR odr) return zget_APDU(odr, Z_APDU_presentResponse); } -IThreadPoolMsg *P2_Msg::handle() +yp2::IThreadPoolMsg *P2_Msg::handle() { ODR odr = odr_createmem(ODR_ENCODE); yaz_log(YLOG_LOG, "P2_Msg:handle begin"); diff --git a/src/test_thread_pool_observer.cpp b/src/test_thread_pool_observer.cpp index 532aefd..9c3f8a1 100644 --- a/src/test_thread_pool_observer.cpp +++ b/src/test_thread_pool_observer.cpp @@ -1,4 +1,4 @@ -/* $Id: test_thread_pool_observer.cpp,v 1.4 2005-10-13 20:06:45 adam Exp $ +/* $Id: test_thread_pool_observer.cpp,v 1.5 2005-10-14 10:27:18 adam Exp $ Copyright (c) 1998-2005, Index Data. This file is part of the yaz-proxy. @@ -36,9 +36,9 @@ using namespace yazpp_1; class My_Timer_Thread; -class My_Msg : public IThreadPoolMsg { +class My_Msg : public yp2::IThreadPoolMsg { public: - IThreadPoolMsg *handle(); + yp2::IThreadPoolMsg *handle(); void result(); int m_val; My_Timer_Thread *m_timer; @@ -48,17 +48,17 @@ class My_Timer_Thread : public ISocketObserver { private: ISocketObservable *m_obs; int m_fd[2]; - ThreadPoolSocketObserver *m_t; + yp2::ThreadPoolSocketObserver *m_t; public: int m_sum; int m_requests; int m_responses; - My_Timer_Thread(ISocketObservable *obs, ThreadPoolSocketObserver *t); + My_Timer_Thread(ISocketObservable *obs, yp2::ThreadPoolSocketObserver *t); void socketNotify(int event); }; -IThreadPoolMsg *My_Msg::handle() +yp2::IThreadPoolMsg *My_Msg::handle() { My_Msg *res = new My_Msg; @@ -77,7 +77,7 @@ void My_Msg::result() } My_Timer_Thread::My_Timer_Thread(ISocketObservable *obs, - ThreadPoolSocketObserver *t) : m_obs(obs) + yp2::ThreadPoolSocketObserver *t) : m_obs(obs) { pipe(m_fd); m_t = t; @@ -101,7 +101,7 @@ BOOST_AUTO_TEST_CASE( thread_pool_observer1 ) { SocketManager mySocketManager; - ThreadPoolSocketObserver m(&mySocketManager, 3); + yp2::ThreadPoolSocketObserver m(&mySocketManager, 3); My_Timer_Thread t(&mySocketManager, &m) ; while (t.m_responses < 30 && mySocketManager.processEvent() > 0) ; diff --git a/src/thread_pool_observer.cpp b/src/thread_pool_observer.cpp index 72325ce..40323d9 100644 --- a/src/thread_pool_observer.cpp +++ b/src/thread_pool_observer.cpp @@ -1,4 +1,4 @@ -/* $Id: thread_pool_observer.cpp,v 1.5 2005-10-14 10:08:40 adam Exp $ +/* $Id: thread_pool_observer.cpp,v 1.6 2005-10-14 10:27:18 adam Exp $ Copyright (c) 1998-2005, Index Data. This file is part of the yaz-proxy. @@ -29,6 +29,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "thread_pool_observer.hpp" using namespace yazpp_1; +using namespace yp2; IThreadPoolMsg::~IThreadPoolMsg() { diff --git a/src/thread_pool_observer.hpp b/src/thread_pool_observer.hpp index 4f9636d..c52dca1 100644 --- a/src/thread_pool_observer.hpp +++ b/src/thread_pool_observer.hpp @@ -1,4 +1,4 @@ -/* $Id: thread_pool_observer.hpp,v 1.2 2005-10-14 10:08:40 adam Exp $ +/* $Id: thread_pool_observer.hpp,v 1.3 2005-10-14 10:27:18 adam Exp $ Copyright (c) 1998-2005, Index Data. This file is part of the yaz-proxy. @@ -33,47 +33,49 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -class IThreadPoolMsg { -public: - virtual IThreadPoolMsg *handle() = 0; - virtual void result() = 0; - virtual ~IThreadPoolMsg(); -}; - -class ThreadPoolSocketObserver : public yazpp_1::ISocketObserver { -private: - class Worker { +namespace yp2 { + class IThreadPoolMsg { public: - Worker(ThreadPoolSocketObserver *s) : m_s(s) {}; - ThreadPoolSocketObserver *m_s; - void operator() (void) { - m_s->run(0); - } + virtual IThreadPoolMsg *handle() = 0; + virtual void result() = 0; + virtual ~IThreadPoolMsg(); }; -public: - ThreadPoolSocketObserver(yazpp_1::ISocketObservable *obs, int no_threads); - virtual ~ThreadPoolSocketObserver(); - void socketNotify(int event); - void put(IThreadPoolMsg *m); - IThreadPoolMsg *get(); - void run(void *p); - int m_fd[2]; -private: - yazpp_1::ISocketObservable *m_SocketObservable; - int m_no_threads; - boost::thread_group m_thrds; - std::deque m_input; - std::deque m_output; + class ThreadPoolSocketObserver : public yazpp_1::ISocketObserver { + private: + class Worker { + public: + Worker(ThreadPoolSocketObserver *s) : m_s(s) {}; + ThreadPoolSocketObserver *m_s; + void operator() (void) { + m_s->run(0); + } + }; + public: + ThreadPoolSocketObserver(yazpp_1::ISocketObservable *obs, + int no_threads); + virtual ~ThreadPoolSocketObserver(); + void socketNotify(int event); + void put(IThreadPoolMsg *m); + IThreadPoolMsg *get(); + void run(void *p); + int m_fd[2]; + private: + yazpp_1::ISocketObservable *m_SocketObservable; + int m_no_threads; + boost::thread_group m_thrds; - boost::mutex m_mutex_input_data; - boost::condition m_cond_input_data; - boost::mutex m_mutex_output_data; - bool m_stop_flag; + std::deque m_input; + std::deque m_output; - -}; + boost::mutex m_mutex_input_data; + boost::condition m_cond_input_data; + boost::mutex m_mutex_output_data; + bool m_stop_flag; + + }; +} #endif /* * Local variables: