libiqxmlrpc  0.12.12
executor.h
1 // Libiqxmlrpc - an object-oriented XML-RPC solution.
2 // Copyright (C) 2011 Anton Dedov
3 
4 #ifndef _iqxmlrpc_executor_h_
5 #define _iqxmlrpc_executor_h_
6 
7 #include "lock.h"
8 #include "method.h"
9 
10 #ifdef _MSC_VER
11 #pragma warning(push)
12 #pragma warning(disable: 4275)
13 #endif
14 
15 #include <boost/thread/thread.hpp>
16 #include <boost/thread/mutex.hpp>
17 #include <boost/thread/condition.hpp>
18 
19 #ifdef _MSC_VER
20 #pragma warning(pop)
21 #endif
22 
23 #include <deque>
24 #include <vector>
25 
26 namespace iqnet
27 {
28  class Reactor_base;
29 }
30 
31 namespace iqxmlrpc {
32 
33 class Server;
34 class Server_connection;
35 class Response;
36 
37 class Serial_executor_factory;
38 class Pool_executor_factory;
39 
41 {
43  typedef iqnet::Null_lock Lock;
44 };
45 
47 {
49  typedef boost::mutex Lock;
50 };
51 
53 class LIBIQXMLRPC_API Executor {
54 protected:
55  Method* method;
56  Interceptor* interceptors;
57 
58 private:
59  Server* server;
60  Server_connection* conn;
61 
62 public:
64  virtual ~Executor();
65 
66  void set_interceptors(Interceptor* ic) { interceptors = ic; }
67 
69  virtual void execute( const Param_list& params ) = 0;
70 
71 protected:
72  void schedule_response( const Response& );
73  void interrupt_server();
74 };
75 
76 
78 class LIBIQXMLRPC_API Executor_factory_base {
79 public:
80  virtual ~Executor_factory_base() {}
81 
82  virtual Executor* create(
83  Method*,
84  Server*,
86  ) = 0;
87 
88  virtual iqnet::Reactor_base* create_reactor() = 0;
89 };
90 
91 
93 class LIBIQXMLRPC_API Serial_executor: public Executor {
94 public:
96  Executor( m, s, c ) {}
97 
98  void execute( const Param_list& );
99 };
100 
101 
103 class LIBIQXMLRPC_API Serial_executor_factory: public Executor_factory_base {
104 public:
105  Executor* create( Method* m, Server* s, Server_connection* c );
106  iqnet::Reactor_base* create_reactor();
107 };
108 
109 #ifdef _MSC_VER
110 #pragma warning(push)
111 #pragma warning(disable: 4251)
112 #endif
113 
115 class LIBIQXMLRPC_API Pool_executor: public Executor {
116  Pool_executor_factory* pool;
117  Param_list params;
118 
119 public:
121  ~Pool_executor();
122 
123  void execute( const Param_list& );
124  void process_actual_execution();
125 };
126 
128 class LIBIQXMLRPC_API Pool_executor_factory: public Executor_factory_base {
129  class Pool_thread;
130  friend class Pool_thread;
131 
132  boost::thread_group threads;
133  std::vector<Pool_thread*> pool;
134 
135  // Objects Pool_thread works with
136  std::deque<Pool_executor*> req_queue;
137  boost::mutex req_queue_lock;
138  boost::condition req_queue_cond;
139 
140  bool in_destructor;
141  boost::mutex destructor_lock;
142 
143 public:
144  Pool_executor_factory(unsigned num_threads);
146 
147  Executor* create( Method* m, Server* s, Server_connection* c );
148  iqnet::Reactor_base* create_reactor();
149 
151  void add_threads(unsigned num);
152 
153  void register_executor( Pool_executor* );
154 
155 private:
156  // Pool_thread interface
157  bool is_being_destructed();
158 
159 private:
160  void destruction_started();
161 };
162 
163 #ifdef _MSC_VER
164 #pragma warning(pop)
165 #endif
166 
167 } // namespace iqxmlrpc
168 
169 #endif
170 // vim:ts=2:sw=2:et
XML-RPC response.
Definition: response.h:28
Factory class for Serial_executor.
Definition: executor.h:103
Abstract base for Executor's factories.
Definition: executor.h:78
Object-oriented networking/multithreading infrastructure.
Definition: acceptor.h:11
An Executor which plans request to be executed by a pool of threads.
Definition: executor.h:115
XML-RPC server.
Definition: server.h:34
Definition: method.h:48
Class which provides null synchronization.
Definition: lock.h:13
Abstract executor class. Defines the policy for method execution.
Definition: executor.h:53
Definition: executor.h:46
Base class for XML-RPC server connections.
Definition: server_conn.h:26
Factory for Pool_executor objects. It is also serves as a pool of threads.
Definition: executor.h:128
XML-RPC library.
Definition: auth_plugin.cc:6
Definition: executor.h:40
Interceptor's base class.
Definition: method.h:99
std::vector< Value > Param_list
Method's parameters type.
Definition: method.h:22
Definition: reactor.h:44
Single thread executor.
Definition: executor.h:93