Rename Msg_Thread to ThreadPoolSocketObserver. Rename IMsg_Thread
[metaproxy-moved-to-github.git] / src / thread_pool_observer.h
1 /* $Id: thread_pool_observer.h,v 1.1 2005-10-06 19:33:58 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 <pthread.h>
23 #include <unistd.h>
24 #include <ctype.h>
25
26 #if HAVE_DLFCN_H
27 #include <dlfcn.h>
28 #endif
29
30 #include <deque>
31 #include <yaz++/socket-observer.h>
32 #include <yaz/yconfig.h>
33
34 class IThreadPoolMsg {
35 public:
36     virtual IThreadPoolMsg *handle() = 0;
37     virtual void result() = 0;
38     virtual ~IThreadPoolMsg();
39 };
40
41 class ThreadPoolSocketObserver : public yazpp_1::ISocketObserver {
42  public:
43     ThreadPoolSocketObserver(yazpp_1::ISocketObservable *obs, int no_threads);
44     virtual ~ThreadPoolSocketObserver();
45     void socketNotify(int event);
46     void put(IThreadPoolMsg *m);
47     IThreadPoolMsg *get();
48     void run(void *p);
49     int m_fd[2];
50 private:
51     yazpp_1::ISocketObservable *m_SocketObservable;
52     int m_no_threads;
53     pthread_t *m_thread_id;
54
55     std::deque<IThreadPoolMsg *> m_input;
56     std::deque<IThreadPoolMsg *> m_output;
57     pthread_mutex_t m_mutex_input_data;
58     pthread_cond_t m_cond_input_data;
59     pthread_mutex_t m_mutex_output_data;
60     bool m_stop_flag;
61 };
62
63 /*
64  * Local variables:
65  * c-basic-offset: 4
66  * indent-tabs-mode: nil
67  * End:
68  * vim: shiftwidth=4 tabstop=8 expandtab
69  */
70