RESTinio

traits.hpp
Go to the documentation of this file.
1/*
2 restinio
3*/
4
9#pragma once
10
11#include <restinio/request_handler.hpp>
12#include <restinio/asio_timer_manager.hpp>
13#include <restinio/null_logger.hpp>
14#include <restinio/connection_state_listener.hpp>
15#include <restinio/ip_blocker.hpp>
16#include <restinio/default_strands.hpp>
17#include <restinio/connection_count_limiter.hpp>
18
19#include <restinio/utils/metaprogramming.hpp>
20
21 namespace restinio
22{
23
24 namespace details
25{
26
27 namespace valid_request_handler_type_check
28{
29
30 template< typename, typename, typename = restinio::utils::metaprogramming::void_t<> >
31 struct valid_handler_type : public std::false_type {};
32
33 template< typename Handler, typename Extra_Data_Factory >
34 struct valid_handler_type<
35 Handler,
36 Extra_Data_Factory,
37 restinio::utils::metaprogramming::void_t<
38 std::enable_if_t<
39 std::is_same<
40 request_handling_status_t,
41 decltype(std::declval<Handler>()(
42 std::declval<
43 generic_request_handle_t<
44 typename Extra_Data_Factory::data_t
45 >
46 >()))
47 >::value,
48 bool
49 >
50 >
51 > : public std::true_type
52{};
53
54} /* namespace valid_request_handler_type_check */
55
56//
57// autodetect_request_handler_type
58//
92 struct autodetect_request_handler_type {};
93
94//
95// actual_request_handler_type_detector
96//
102 template<
103 typename Request_Handler,
104 typename Extra_Data_Factory >
105 struct actual_request_handler_type_detector
106{
107 static_assert(
108 valid_request_handler_type_check::valid_handler_type<
109 Request_Handler,
110 Extra_Data_Factory
111 >::value,
112 "Request_Handler should be invocable with "
113 "generic_request_handle_t<Extra_Data_Factory::data_t>" );
114
115 using request_handler_t = Request_Handler;
116};
117
124 template< typename Extra_Data_Factory >
125 struct actual_request_handler_type_detector<
126 autodetect_request_handler_type,
127 Extra_Data_Factory >
128{
129 using request_handler_t = std::function<
130 request_handling_status_t(
131 generic_request_handle_t<typename Extra_Data_Factory::data_t>) >;
132};
133
134} /* namespace details */
135
136//
137// traits_t
138//
139
140 template <
141 typename Timer_Manager,
142 typename Logger,
143 typename Request_Handler = details::autodetect_request_handler_type,
144 typename Strand = default_strand_t,
145 typename Socket = asio_ns::ip::tcp::socket >
146 struct traits_t
147{
183 using http_methods_mapper_t = default_http_methods_t;
184
213 using connection_state_listener_t = connection_state::noop_listener_t;
214
247 using ip_blocker_t = ip_blocker::noop_ip_blocker_t;
248
249 using timer_manager_t = Timer_Manager;
250 using logger_t = Logger;
251 using request_handler_t = Request_Handler;
252 using strand_t = Strand;
253 using stream_socket_t = Socket;
254
278 static constexpr bool use_connection_count_limiter = false;
279
357 using extra_data_factory_t = no_extra_data_factory_t;
358};
359
360//
361// request_handler_type_from_traits_t
362//
374 template< typename Traits >
375 using request_handler_type_from_traits_t =
376 typename details::actual_request_handler_type_detector<
377 typename Traits::request_handler_t,
378 typename Traits::extra_data_factory_t
379 >::request_handler_t;
380
381//
382// generic_request_type_from_traits_t
383//
394 template< typename Traits >
395 using generic_request_type_from_traits_t =
396 generic_request_t< typename Traits::extra_data_factory_t::data_t >;
397
398//
399// single_thread_traits_t
400//
401
402 template <
403 typename Timer_Manager,
404 typename Logger,
405 typename Request_Handler = details::autodetect_request_handler_type >
406 using single_thread_traits_t =
407 traits_t< Timer_Manager, Logger, Request_Handler, noop_strand_t >;
408
409//
410// default_traits_t
411//
412
413 using default_traits_t = traits_t< asio_timer_manager_t, null_logger_t >;
414
430 using default_single_thread_traits_t = single_thread_traits_t<
431 asio_timer_manager_t,
432 null_logger_t >;
433
434} /* namespace restinio */
435
asio_timer_manager.hpp
restinio::asio_timer_manager_t
Timer factory implementation using asio timers.
Definition: asio_timer_manager.hpp:31
restinio::default_http_methods_t
The default implementation for http_method_mapper.
Definition: http_headers.hpp:1832
restinio::generic_request_t
HTTP Request data.
Definition: request_handler.hpp:201
restinio::null_logger_t
No operation logger.
Definition: null_logger.hpp:23
connection_count_limiter.hpp
Stuff related to limits of active parallel connections.
connection_state_listener.hpp
Stuff related to connection state listeners.
default_strands.hpp
Typedefs for default strands.
ip_blocker.hpp
Stuff related to IP blockers.
metaprogramming.hpp
Various tools for C++ metaprogramming.
nonstd::optional_lite::std11::false_type
bool_constant< false > false_type
Definition: optional.hpp:460
nonstd::optional_lite::std11::true_type
bool_constant< true > true_type
Definition: optional.hpp:459
restinio::utils::metaprogramming::void_t
typename make_void< Ts... >::type void_t
Definition: metaprogramming.hpp:28
restinio
Definition: asio_include.hpp:21
restinio::default_strand_t
asio_ns::strand< default_asio_executor > default_strand_t
A typedef for the default strand type.
Definition: default_strands.hpp:23
restinio::generic_request_handle_t
std::shared_ptr< generic_request_t< Extra_Data > > generic_request_handle_t
An alias for shared-pointer to incoming request.
Definition: request_handler.hpp:447
restinio::request_handling_status_t
request_handling_status_t
Request handling status.
Definition: common_types.hpp:26
restinio::request_handler_type_from_traits_t
typename details::actual_request_handler_type_detector< typename Traits::request_handler_t, typename Traits::extra_data_factory_t >::request_handler_t request_handler_type_from_traits_t
A metafunction for extraction a request-handler type from server's traits.
Definition: traits.hpp:379
null_logger.hpp
request_handler.hpp
restinio::connection_state::noop_listener_t
The default no-op state listener.
Definition: connection_state_listener.hpp:274
restinio::details::actual_request_handler_type_detector< autodetect_request_handler_type, Extra_Data_Factory >::request_handler_t
std::function< request_handling_status_t(generic_request_handle_t< typename Extra_Data_Factory::data_t >) > request_handler_t
Definition: traits.hpp:131
restinio::details::actual_request_handler_type_detector
A metafunction for the detection of type of a request-handler.
Definition: traits.hpp:106
restinio::details::actual_request_handler_type_detector::request_handler_t
Request_Handler request_handler_t
Definition: traits.hpp:115
restinio::details::autodetect_request_handler_type
A special type to be used as indicator that the type of a request handler should be automatically det...
Definition: traits.hpp:92
restinio::details::valid_request_handler_type_check::valid_handler_type
Definition: traits.hpp:31
restinio::ip_blocker::noop_ip_blocker_t
The default no-op IP-blocker.
Definition: ip_blocker.hpp:94
restinio::no_extra_data_factory_t
The default extra-data-factory to be used in server's traits if a user doesn't specify own one.
Definition: request_handler.hpp:75
restinio::traits_t
Definition: traits.hpp:147
restinio::traits_t::timer_manager_t
Timer_Manager timer_manager_t
Definition: traits.hpp:249
restinio::traits_t::logger_t
Logger logger_t
Definition: traits.hpp:250
restinio::traits_t::stream_socket_t
Socket stream_socket_t
Definition: traits.hpp:253
restinio::traits_t::request_handler_t
Request_Handler request_handler_t
Definition: traits.hpp:251
restinio::traits_t::strand_t
Strand strand_t
Definition: traits.hpp:252
restinio::traits_t::use_connection_count_limiter
static constexpr bool use_connection_count_limiter
A flag that enables or disables the usage of connection count limiter.
Definition: traits.hpp:278