bitz-server  2.0.1
py.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_PY_H
21 #define BITZ_PY_H
22 
23 #include <Python.h>
24 
25 #include <bitz/modifier.h>
26 #include <spdlog/spdlog.h>
27 
28 
29 namespace bitz {
30 
31  class Py : public Modifier {
32  public:
33 
34  struct config_t {
35  std::string module_path;
36  std::string module_name;
37  };
38 
39  Py();
40  virtual ~Py();
41 
42  icap::Response * modify( icap::Request * request ) throw();
43  icap::Response * preview( icap::Request * request ) throw();
44 
45  private:
46  config_t _config;
47  PyObject * _pymodule;
48  std::shared_ptr<spdlog::logger> _logger;
49 
50  void load_configs() throw();
51  void init_python() throw();
52  void cleanup_python() throw();
53 
54  icap::Response * python_response( icap::Request * request, const std::string &method ) throw();
55 
56  };
57 
58 } /* end of namespace bitz */
59 
60 
61 /* class factories */
62 
63 extern "C" bitz::Modifier * create() {
64  return new bitz::Py;
65 }
66 
67 extern "C" void destroy( bitz::Modifier * m ) {
68  delete m;
69 }
70 
71 #endif /* !BITZ_PY_H */
72 
Definition: response.h:29
Definition: echo.cpp:23
Definition: py.h:34
icap::Response * preview(icap::Request *request)
Definition: py.cpp:65
Definition: modifier.h:29
Definition: py.h:31
icap::Response * modify(icap::Request *request)
Definition: py.cpp:57
Definition: request.h:29