Added test_package1
[metaproxy-moved-to-github.git] / src / thread_pool_observer.h
1 /* $Id: thread_pool_observer.h,v 1.2 2005-10-12 23:30:43 adam Exp $
2    Copyright (c) 1998-2005, Index Data.
3
4 This file is part of the yaz-proxy.
5
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
9 version.
10
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
14 for more details.
15
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
19 02111-1307, USA.
20  */
21
22 #include <boost/thread/thread.hpp>
23 #include <boost/thread/mutex.hpp>
24 #include <boost/thread/condition.hpp>
25
26 #include <unistd.h>
27 #include <ctype.h>
28
29 #if HAVE_DLFCN_H
30 #include <dlfcn.h>
31 #endif
32
33 #include <deque>
34 #include <yaz++/socket-observer.h>
35 #include <yaz/yconfig.h>
36
37 class IThreadPoolMsg {
38 public:
39     virtual IThreadPoolMsg *handle() = 0;
40     virtual void result() = 0;
41     virtual ~IThreadPoolMsg();
42 };
43
44 class ThreadPoolSocketObserver : public yazpp_1::ISocketObserver {
45  public:
46     ThreadPoolSocketObserver(yazpp_1::ISocketObservable *obs, int no_threads);
47     virtual ~ThreadPoolSocketObserver();
48     void socketNotify(int event);
49     void put(IThreadPoolMsg *m);
50     IThreadPoolMsg *get();
51     void run(void *p);
52     int m_fd[2];
53 private:
54     yazpp_1::ISocketObservable *m_SocketObservable;
55     int m_no_threads;
56     boost::thread_group m_thrds;
57
58     std::deque<IThreadPoolMsg *> m_input;
59     std::deque<IThreadPoolMsg *> m_output;
60
61     boost::mutex m_mutex_input_data;
62     boost::condition m_cond_input_data;
63     boost::mutex m_mutex_output_data;
64     bool m_stop_flag;
65 };
66
67 /*
68  * Local variables:
69  * c-basic-offset: 4
70  * indent-tabs-mode: nil
71  * End:
72  * vim: shiftwidth=4 tabstop=8 expandtab
73  */
74