bitz-server  0.1.6
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> // pid_t, fork() etc.
24 #include <socket/socket.h> // socket-library
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 workers_count;
54  unsigned int worker_id;
55 
57  worker_pool_t * worker_pool;
58  };
59 
60 
64  Manager( unsigned short port, const std::string &address = "", int backlog = 128 ) throw( ManagerException );
65 
69  virtual ~Manager();
70 
71  virtual void spawn( unsigned int max_workers = BITZ_MAX_WORKERS, unsigned int max_worker_requests = BITZ_MAX_WORKER_REQUESTS ) throw( ManagerException );
72  virtual void shutdown( bool graceful = true ) throw();
73  virtual void reap_worker( pid_t worker_pid ) throw();
74  virtual void manager_workers() throw();
75 
76 
77  private:
78  manager_t _manager;
79 
80  virtual void spawn_worker( unsigned int worker_id ) throw( ManagerException );
81 
82  };
83 
84 } /* end of namespace bitz */
85 
86 #endif /* !BITZ_MANAGER_H */
87 
Definition: socket.h:256
Definition: echo.cpp:23
Manager(unsigned short port, const std::string &address="", int backlog=128)
Definition: manager.cpp:31
Definition: worker.h:30
Definition: manager_exception.h:27
Definition: manager.h:43
Definition: manager.h:40
Definition: manager.h:49