rikitiki  v0.1.67
Build C++ web server modules that allow easy routing and deployment.
server.h
1 /* Copyright (C) 2012-2013 Justin Berger
2  The full license is available in the LICENSE file at the root of this project and is also available at http://opensource.org/licenses/MIT. */
3 
4 #pragma once
5 
6 #include <rikitiki/config.h>
7 #include <vector>
8 #include <sstream>
9 #include "content_types.h"
10 
11 #include <mxcomp/macros.h>
12 #include <mxcomp/tuple_ext.h>
13 #include <tuple>
14 
15 #include <rikitiki/log/log>
16 #include <rikitiki/http_statuses.h>
17 
18 #if RT_USE_CTEMPLATE
19 #include <rikitiki/ctemplate/templatePreprocessor.h>
20 #endif
21 
22 namespace rikitiki {
23  class ConnContext;
24 
28  struct Handler {
29  virtual bool Handle(ConnContext& ctx) = 0;
30  virtual bool visible() const = 0;
31  virtual std::string name() const = 0;
32  virtual std::string desc() const;
33  virtual ~Handler();
34  };
35 
40  HandlerException() : status(0){}
41  HandlerException(const HttpStatus& s) : status(&s){}
45  const HttpStatus* status;
46  };
47 
48 
54  class Server {
55  protected:
56  public:
57  std::vector<Handler*> handlers;
58  virtual ~Server();
59  Server();
60 
61  #ifdef RT_USE_CTEMPLATE
62  std::vector<ctemplates::TemplatePreprocessor*> templatePreprocessors;
63  void AddPreprocessor( rikitiki::ctemplates::TemplatePreprocessor*);
64  #endif
65 
66  typedef bool (*handle_t)(ConnContext& ctx);
67 
68  bool Handle(ConnContext& ctx);
69 
70  void AddHandler( Handler& handler);
71  void AddHandler( Handler* handler);
72  void AddHandler( handle_t handler );
73 
74  template <typename T>
75  void Register( T& t ){
76  t.Register(*this);
77  }
78  };
79 
80 }