aboutsummaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
Diffstat (limited to 'web')
-rw-r--r--web/apache/service46
-rw-r--r--web/module13
2 files changed, 59 insertions, 0 deletions
diff --git a/web/apache/service b/web/apache/service
new file mode 100644
index 0000000..3c7a398
--- /dev/null
+++ b/web/apache/service
@@ -0,0 +1,46 @@
+// 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_common
+ {
+ //@@ Implementation that calls handle() below goes here.
+ //
+
+ virtual void
+ handle (request&, response&, log&) = 0;
+ };
+
+ template <typename M>
+ class service: public service_common
+ {
+ public:
+ // Note that the module exemplar is stored by-reference.
+ //
+ service (const std::string& name, const M& exemplar);
+
+ virtual void
+ handle (request& rq, response& rs, log& l)
+ {
+ M m (exemplar_);
+ m.handle (rq, rs, l);
+ }
+
+ private:
+ const M& exemplar_;
+ };
+ }
+}
+
+#endif // WEB_APACHE_SERVICE
diff --git a/web/module b/web/module
index d36bb26..e9787a4 100644
--- a/web/module
+++ b/web/module
@@ -22,6 +22,8 @@ namespace web
// HTTP status code.
//
+ // @@ Define some commonly used constants?
+ //
using status_code = uint16_t;
struct name_value
@@ -92,6 +94,17 @@ namespace web
write (const char* msg);
};
+ // The web server creates a new module instance for each request
+ // by copy-initializing it with the module exemplar. This way we
+ // achieve two things: we can freely use module data members
+ // without worrying about multi-threading issues and we
+ // automatically get started with the initial state for each
+ // request. If you really need to share some rw-data between
+ // all the modules, use static data members with appropriate
+ // locking. See the <service> header in one of the web server
+ // directories (e.g., apache/) if you need to see the code that
+ // does this.
+ //
class module
{
public: