bitz-server  1.0.2
manager.h
1 /*
2  * bitz-server, An ICAP server implementation in C++
3  * Copyright (C) 2012 Uditha Atukorala
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19 
20 #ifndef BITZ_MANAGER_H
21 #define BITZ_MANAGER_H
22 
23 #include <unistd.h>
24 #include <psocksxx/tcpnsockstream.h>
25 
26 #include "manager_exception.h"
27 #include "worker.h"
28 
29 #ifndef BITZ_MAX_WORKERS
30 #define BITZ_MAX_WORKERS 2
31 #endif
32 
33 #ifndef BITZ_MAX_WORKER_REQUESTS
34 #define BITZ_MAX_WORKER_REQUESTS 100
35 #endif
36 
37 
38 namespace bitz {
39 
40  class Manager {
41  public:
42 
43  struct worker_pool_t {
44  pid_t worker_pid;
45  unsigned int worker_id;
46  Worker * worker;
47  };
48 
49  struct manager_t {
50  bool worker;
51  unsigned int max_workers;
52  unsigned int max_worker_requests;
53  unsigned int comm_timeout;
54  unsigned int workers_count;
55  unsigned int worker_id;
56 
57  psocksxx::tcpnsockstream * socket;
58  worker_pool_t * worker_pool;
59  };
60 
61 
65  Manager( unsigned short port, const std::string &address = "0.0.0.0", int backlog = 128 ) throw( ManagerException );
66 
70  virtual ~Manager();
71 
72  virtual void spawn( unsigned int max_workers = BITZ_MAX_WORKERS,
73  unsigned int max_worker_requests = BITZ_MAX_WORKER_REQUESTS,
74  unsigned int comm_timeout = 0 ) throw( ManagerException );
75 
76  virtual void shutdown( bool graceful = true ) throw();
77  virtual void reap_worker( pid_t worker_pid ) throw();
78  virtual void manager_workers() throw();
79 
80 
81  private:
82  manager_t _manager;
83 
84  virtual void spawn_worker( unsigned int worker_id ) throw( ManagerException );
85 
86  };
87 
88 } /* end of namespace bitz */
89 
90 #endif /* !BITZ_MANAGER_H */
91 
Definition: echo.cpp:23
virtual ~Manager()
Definition: manager.cpp:64
Definition: worker.h:30
Definition: manager_exception.h:27
Definition: manager.h:43
Definition: manager.h:40
Definition: manager.h:49
Manager(unsigned short port, const std::string &address="0.0.0.0", int backlog=128)
Definition: manager.cpp:31