RESTinio
Loading...
Searching...
No Matches
common.hpp
Go to the documentation of this file.
1
7#pragma once
8
10
12{
13
25{
27 ok,
31};
32
47[[nodiscard]]
48inline constexpr schedule_result_t
50
70[[nodiscard]]
71inline constexpr schedule_result_t
73
74// Just a forward declaration.
75template< typename Extra_Data_Factory = no_extra_data_factory_t >
76class async_handling_controller_t;
77
83template< typename Extra_Data_Factory = no_extra_data_factory_t >
85 std::unique_ptr< async_handling_controller_t< Extra_Data_Factory > >;
86
92template< typename Extra_Data_Factory = no_extra_data_factory_t >
94 std::function<
96 >;
97
107
118template< typename Extra_Data_Factory = no_extra_data_factory_t >
119using on_next_result_t = std::variant<
122 >;
123
124// Just a forward declaration.
125template< typename Extra_Data_Factory >
126void
128
144template< typename Extra_Data_Factory /*= no_extra_data_factory_t*/ >
204
206{
207
218template< typename Request_Handle >
219void
221{
222 req->create_response( status_not_found() ).done();
223}
224
235template< typename Request_Handle >
236void
238{
239 req->create_response( status_internal_server_error() ).done();
240}
241
253template< typename Extra_Data_Factory >
255{
257
258 void
261 {
262 // We have to store request_handle before further processing because
263 // m_controller becomes empty after passing to the `handler`.
264 const auto req = m_controller->request_handle();
265 const auto schedule_result = handler( std::move(m_controller) );
266 switch( schedule_result )
267 {
268 case schedule_result_t::ok:
269 /* nothing to do */
270 // It's assumed that handler will call next() when it'll be
271 // appropriate.
272 break;
273
274 case schedule_result_t::failure:
276 break;
277 }
278 }
279
280 void
282 const no_more_schedulers_t & ) const
283 {
284 make_not_implemented_response( m_controller->request_handle() );
285 }
286};
287
288} /* namespace impl */
289
325template< typename Extra_Data_Factory >
326void
333
334} /* namespace restinio::async_chain */
335
Interface of a controller of an async chan.
Definition common.hpp:146
generic_request_handle_t< typename Extra_Data_Factory::data_t > actual_request_handle_t
Short alias for request_handle type.
Definition common.hpp:154
friend void next(unique_async_handling_controller_t< Extra_Data_Factory_For_Next > controller)
virtual actual_on_next_result_t on_next()=0
Command to try find a next scheduler to be invoked.
on_next_result_t< Extra_Data_Factory > actual_on_next_result_t
Short alias for the result type of on_next method.
Definition common.hpp:162
generic_async_request_scheduler_t< typename Extra_Data_Factory::data_t > actual_async_request_scheduler_t
Short alias for async_request_scheduler type.
Definition common.hpp:158
virtual const actual_request_handle_t & request_handle() const noexcept=0
Get reference to the source request.
void make_internal_server_error_response(const Request_Handle &req)
Helper to make a negative response with "Internal Server Error" status.
Definition common.hpp:237
void make_not_implemented_response(const Request_Handle &req)
Helper to make a negative response with "Not Implemented" status.
Definition common.hpp:220
std::function< schedule_result_t(unique_async_handling_controller_t< Extra_Data_Factory >) > generic_async_request_scheduler_t
Short alias for a type of a scheduler to be used in async chains.
Definition common.hpp:93
constexpr schedule_result_t ok() noexcept
Helper function to be used if scheduling was successful.
Definition common.hpp:49
void next(unique_async_handling_controller_t< Extra_Data_Factory > controller)
Command to try to switch to the next handler in an async chain.
Definition common.hpp:327
std::variant< generic_async_request_scheduler_t< Extra_Data_Factory >, no_more_schedulers_t > on_next_result_t
Special type to be used as result of async_handling_controller's on_next method.
Definition common.hpp:119
constexpr schedule_result_t failure() noexcept
Helper function to be used if scheduling failed.
Definition common.hpp:72
schedule_result_t
Type for return value of a scheduler in a chain.
Definition common.hpp:25
@ failure
The scheduling of the actual processing failed. Note, that there is no additional information about t...
@ ok
The scheduling of the actual processing was successful.
std::unique_ptr< async_handling_controller_t< Extra_Data_Factory > > unique_async_handling_controller_t
Short alias for unique_ptr to async_handling_controller.
Definition common.hpp:84
std::shared_ptr< generic_request_t< Extra_Data > > generic_request_handle_t
An alias for shared-pointer to incoming request.
run_on_this_thread_settings_t< Traits > on_this_thread()
A special marker for the case when http_server must be run on the context of the current thread.
http_status_line_t status_internal_server_error()
http_status_line_t status_not_found()
Helper type to be used as handler of variant values in std::visit.
Definition common.hpp:255
void operator()(const no_more_schedulers_t &) const
Definition common.hpp:281
void operator()(const generic_async_request_scheduler_t< Extra_Data_Factory > &handler) const
Definition common.hpp:259
unique_async_handling_controller_t< Extra_Data_Factory > & m_controller
Definition common.hpp:256
Special type to be used as an indicator that there are no more schedulers in an async chain.
Definition common.hpp:106