Same header and footer for all files. Header includes copyright +
[metaproxy-moved-to-github.git] / src / thread_pool_observer.hpp
1 /* $Id: thread_pool_observer.hpp,v 1.4 2005-10-15 14:09:09 adam Exp $
2    Copyright (c) 2005, Index Data.
3
4 %LICENSE%
5  */
6
7 #ifndef YP2_THREAD_POOL_OBSERVER_HPP
8 #define YP2_THREAD_POOL_OBSERVER_HPP
9
10 #include <boost/thread/thread.hpp>
11 #include <boost/thread/mutex.hpp>
12 #include <boost/thread/condition.hpp>
13
14 #include <unistd.h>
15 #include <ctype.h>
16
17 #include <deque>
18 #include <yaz++/socket-observer.h>
19 #include <yaz/yconfig.h>
20
21 namespace yp2 {
22     class IThreadPoolMsg {
23     public:
24         virtual IThreadPoolMsg *handle() = 0;
25         virtual void result() = 0;
26         virtual ~IThreadPoolMsg();
27     };
28
29     class ThreadPoolSocketObserver : public yazpp_1::ISocketObserver {
30     private:
31         class Worker {
32         public:
33             Worker(ThreadPoolSocketObserver *s) : m_s(s) {};
34             ThreadPoolSocketObserver *m_s;
35             void operator() (void) {
36                 m_s->run(0);
37             }
38         };
39     public:
40         ThreadPoolSocketObserver(yazpp_1::ISocketObservable *obs,
41                                  int no_threads);
42         virtual ~ThreadPoolSocketObserver();
43         void socketNotify(int event);
44         void put(IThreadPoolMsg *m);
45         IThreadPoolMsg *get();
46         void run(void *p);
47         int m_fd[2];
48     private:
49         yazpp_1::ISocketObservable *m_SocketObservable;
50         int m_no_threads;
51         boost::thread_group m_thrds;
52
53         std::deque<IThreadPoolMsg *> m_input;
54         std::deque<IThreadPoolMsg *> m_output;
55
56         boost::mutex m_mutex_input_data;
57         boost::condition m_cond_input_data;
58         boost::mutex m_mutex_output_data;
59         bool m_stop_flag;
60
61     
62     };
63 }
64 #endif
65 /*
66  * Local variables:
67  * c-basic-offset: 4
68  * indent-tabs-mode: nil
69  * c-file-style: "stroustrup"
70  * End:
71  * vim: shiftwidth=4 tabstop=8 expandtab
72  */
73