1 /* $Id: test_thread_pool_observer.cpp,v 1.2 2005-10-08 23:29:32 adam Exp $
2 Copyright (c) 1998-2005, Index Data.
4 This file is part of the yaz-proxy.
6 YAZ proxy is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with YAZ proxy; see the file LICENSE. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 #include <yaz++/pdu-assoc.h>
27 #include <yaz++/socket-manager.h>
29 #include "thread_pool_observer.h"
31 using namespace yazpp_1;
33 class My_Msg : public IThreadPoolMsg {
35 IThreadPoolMsg *handle();
40 IThreadPoolMsg *My_Msg::handle()
42 My_Msg *res = new My_Msg;
46 printf("My_Msg::handle val=%d sleep=%d\n", m_val, sl);
53 printf("My_Msg::result val=%d\n", m_val);
56 class My_Timer_Thread : public ISocketObserver {
58 ISocketObservable *m_obs;
60 ThreadPoolSocketObserver *m_t;
62 My_Timer_Thread(ISocketObservable *obs, ThreadPoolSocketObserver *t);
63 void socketNotify(int event);
66 My_Timer_Thread::My_Timer_Thread(ISocketObservable *obs,
67 ThreadPoolSocketObserver *t) : m_obs(obs)
71 obs->addObserver(m_fd[0], this);
72 obs->maskObserver(this, SOCKET_OBSERVE_READ);
73 obs->timeoutObserver(this, 1);
76 void My_Timer_Thread::socketNotify(int event)
79 printf("Add %d\n", seq);
80 My_Msg *m = new My_Msg;
85 int main(int argc, char **argv)
87 SocketManager mySocketManager;
89 ThreadPoolSocketObserver m(&mySocketManager, 3);
90 My_Timer_Thread t(&mySocketManager, &m) ;
92 while (++i < 5 && mySocketManager.processEvent() > 0)
99 * indent-tabs-mode: nil
101 * vim: shiftwidth=4 tabstop=8 expandtab