aboutsummaryrefslogtreecommitdiff
path: root/web/apache/service
blob: 2b97108e35266c7fdd66429e4dded73a2513178a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// file      : web/apache/service -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC
// license   : MIT; see accompanying LICENSE file

#ifndef WEB_APACHE_SERVICE
#define WEB_APACHE_SERVICE

#include <string>

#include <web/module>

namespace web
{
  namespace apache
  {
    class service
    {
    public:
      // Note that the module exemplar is stored by-reference.
      //
      template <typename M>
      service (const std::string& name, const M& exemplar)
          : exemplar_ (exemplar), handle_ (&handle_impl<M>) {}

      //@@ Implementation calls handle_ function pointer below:
      //
      // handle_ (rq, rs, l, exemplar_);
      //

    private:
      template <typename M>
      static void
      handle_impl (request& rq, response& rs, log& l, const module& exemplar)
      {
        M m (static_cast<const M&> (exemplar));
        m.handle (rq, rs, l);
      }

      const M& exemplar_;
      void (*handle_) (request&, response&, log&, const module&);
    };
  }
}

#endif // WEB_APACHE_SERVICE