diff options
author | ipknHama <ipknhama@gmail.com> | 2014-08-08 03:53:36 +0900 |
---|---|---|
committer | ipknHama <ipknhama@gmail.com> | 2014-08-08 03:53:36 +0900 |
commit | 3018ff063acb747065adea877e3e2ac9423f5233 (patch) | |
tree | 110f1a6596242b7837c16f88b4838d6fd93dc93c /include/crow.h | |
parent | a0c93f5b84cc11b30bc6320ac26127832ef8bf7a (diff) | |
parent | 001c66b378d200bdecc8a4a692c5a73a7d426b8f (diff) | |
download | crow-3018ff063acb747065adea877e3e2ac9423f5233.tar.gz crow-3018ff063acb747065adea877e3e2ac9423f5233.zip |
Merge branch 'directory-restructuring'
Directory structure changed.
Crow becomes a complete header-only library with http_parser_merged.h.
Provides amalgamated crow_all.h (all feature in one header file).
Diffstat (limited to 'include/crow.h')
-rw-r--r-- | include/crow.h | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/include/crow.h b/include/crow.h new file mode 100644 index 0000000..55572bf --- /dev/null +++ b/include/crow.h @@ -0,0 +1,89 @@ +#pragma once + +#include <string> +#include <functional> +#include <memory> +#include <future> +#include <cstdint> +#include <type_traits> +#include <thread> + +#include "settings.h" +#include "logging.h" +#include "http_server.h" +#include "utility.h" +#include "routing.h" + +// TEST +#include <iostream> + +#define CROW_ROUTE(app, url) app.route<crow::black_magic::get_parameter_tag(url)>(url) + +namespace crow +{ + class Crow + { + public: + using self_t = Crow; + Crow() + { + } + + void handle(const request& req, response& res) + { + return router_.handle(req, res); + } + + template <uint64_t Tag> + auto route(std::string&& rule) + -> typename std::result_of<decltype(&Router::new_rule_tagged<Tag>)(Router, std::string&&)>::type + { + return router_.new_rule_tagged<Tag>(std::move(rule)); + } + + self_t& port(std::uint16_t port) + { + port_ = port; + return *this; + } + + self_t& multithreaded() + { + return concurrency(std::thread::hardware_concurrency()); + } + + self_t& concurrency(std::uint16_t concurrency) + { + if (concurrency < 1) + concurrency = 1; + concurrency_ = concurrency; + return *this; + } + + void validate() + { + router_.validate(); + } + + void run() + { + validate(); + Server<self_t> server(this, port_, concurrency_); + server.run(); + } + + void debug_print() + { + CROW_LOG_DEBUG << "Routing:"; + router_.debug_print(); + } + + private: + uint16_t port_ = 80; + uint16_t concurrency_ = 1; + + Router router_; + }; + using App = Crow; +}; + |