bitz-server  2.0.1
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 <spdlog/spdlog.h>
25 #include <psocksxx/tcpnsockstream.h>
26 
27 #include "manager_exception.h"
28 #include "worker.h"
29 
30 #ifndef BITZ_MAX_WORKERS
31 #define BITZ_MAX_WORKERS 2
32 #endif
33 
34 #ifndef BITZ_MAX_WORKER_REQUESTS
35 #define BITZ_MAX_WORKER_REQUESTS 100
36 #endif
37 
38 
39 namespace bitz {
40 
41  class Manager {
42  public:
43 
44  struct worker_pool_t {
45  pid_t worker_pid;
46  unsigned int worker_id;
47  Worker * worker;
48  };
49 
50  struct manager_t {
51  bool worker;
52  unsigned int max_workers;
53  unsigned int max_worker_requests;
54  unsigned int comm_timeout;
55  unsigned int workers_count;
56  unsigned int worker_id;
57 
58  psocksxx::tcpnsockstream * socket;
59  worker_pool_t * worker_pool;
60  };
61 
62 
66  Manager( unsigned short port, const std::string &address = "0.0.0.0", int backlog = 128 ) throw( ManagerException );
67 
71  virtual ~Manager();
72 
73  virtual void spawn( unsigned int max_workers = BITZ_MAX_WORKERS,
74  unsigned int max_worker_requests = BITZ_MAX_WORKER_REQUESTS,
75  unsigned int comm_timeout = 0 ) throw( ManagerException );
76 
77  virtual void shutdown( bool graceful = true ) throw();
78  virtual void reap_worker( pid_t worker_pid ) throw();
79  virtual void manage_workers() throw();
80 
81 
82  private:
83  manager_t _manager;
84  std::shared_ptr<spdlog::logger> _logger;
85 
86  virtual void spawn_worker( unsigned int worker_id ) throw( ManagerException );
87 
88  };
89 
90 } /* end of namespace bitz */
91 
92 #endif /* !BITZ_MANAGER_H */
93 
Definition: echo.cpp:23
virtual ~Manager()
Definition: manager.cpp:64
Definition: worker.h:31
Definition: manager_exception.h:27
Definition: manager.h:44
Definition: manager.h:41
Definition: manager.h:50
Manager(unsigned short port, const std::string &address="0.0.0.0", int backlog=128)
Definition: manager.cpp:30