RESTinio
Loading...
Searching...
No Matches
fixed_size.hpp
Go to the documentation of this file.
1
7#pragma once
8
10
11#include <array>
12
14{
15
176template<
177 std::size_t Size,
178 typename Extra_Data_Factory = no_extra_data_factory_t >
180{
183
186
188 using schedulers_array_t = std::array< scheduler_holder_t, Size >;
189
193
197
205 : public async_handling_controller_t< Extra_Data_Factory >
206 {
212
217 std::size_t m_current{};
218
219 public:
227
228 [[nodiscard]]
230 request_handle() const noexcept override { return m_request; }
231
232 private:
233 [[nodiscard]]
235 on_next() override
236 {
237 const auto index_to_use = m_current;
238 ++m_current;
239
240 if( index_to_use >= m_schedulers.size() )
241 {
242 return { no_more_schedulers_t{} };
243 }
244 else
245 {
246 return { m_schedulers[ index_to_use ] };
247 }
248 }
249 };
250
252
257
259 template<
260 typename Head,
261 typename... Tail >
262 void
263 store_to( std::size_t index, Head && head, Tail && ...tail )
264 {
265 m_schedulers[ index ] =
266 [scheduler = std::move(head)]
268 {
269 return scheduler( std::move(controller) );
270 };
271
272 if constexpr( 0u != sizeof...(tail) )
273 store_to( index + 1u, std::forward<Tail>(tail)... );
274 }
275
276public:
284
292 template< typename... Schedulers >
294 {
295 static_assert( Size == sizeof...(schedulers),
296 "Wrong number of parameters for the constructor of "
297 "fixed_size_chain_t<Size>. Exact `Size` parameters expected" );
298
299 store_to( 0u, std::forward<Schedulers>(schedulers)... );
300 }
301
308 [[nodiscard]]
311 {
313 std::make_unique< actual_controller_t >(
314 req,
315 m_schedulers );
316 next( std::move(controller) );
317
318 return request_accepted();
319 }
320};
321
322} /* namespace restinio::async_chain */
323
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
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
Actual implementation of the controller interface.
std::size_t m_current
Index of the current scheduler to be used.
const actual_request_handle_t & request_handle() const noexcept override
Get reference to the source request.
actual_controller_t(actual_request_handle_t request, const schedulers_array_t &schedulers)
Initializing constructor.
const actual_request_handle_t m_request
The source request.
actual_on_next_result_t on_next() override
Command to try find a next scheduler to be invoked.
A holder of fixed-size chain of asynchronous handlers.
unique_async_handling_controller_t< Extra_Data_Factory > unique_controller_t
Short alias for unique controller type.
schedulers_array_t m_schedulers
The array of schedulers.
fixed_size_chain_t(Schedulers &&...schedulers)
Initializing constructor.
request_handling_status_t operator()(const actual_request_handle_t &req) const
typename async_handling_controller_t< Extra_Data_Factory >::actual_on_next_result_t actual_on_next_result_t
Short alias for the result of controller's on_next method.
std::array< scheduler_holder_t, Size > schedulers_array_t
Short alias for an array of request handlers.
generic_async_request_scheduler_t< Extra_Data_Factory > scheduler_holder_t
Short alias for a request handler.
typename async_handling_controller_t< Extra_Data_Factory >::actual_request_handle_t actual_request_handle_t
Short alias to a smart pointer to the source request.
void store_to(std::size_t index, Head &&head, Tail &&...tail)
Helper method to initialize the array of schedulers.
Common stuff for different types of async handlers chains.
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
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
schedule_result_t
Type for return value of a scheduler in a chain.
Definition common.hpp:25
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
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.
constexpr request_handling_status_t request_accepted() noexcept
request_handling_status_t
Request handling status.
Special type to be used as an indicator that there are no more schedulers in an async chain.
Definition common.hpp:106