RESTinio
Loading...
Searching...
No Matches
restinio::async_chain::growable_size_chain_t< Extra_Data_Factory > Class Template Reference

A holder of variable-size chain of asynchronous handlers. More...

#include <growable_size.hpp>

Classes

class  actual_controller_t
 Actual implementation of the controller interface. More...
class  builder_t
 A builder of an instance of growable_size_chain. More...
struct  creation_token_t

Public Member Functions

 growable_size_chain_t ()=delete
request_handling_status_t operator() (const actual_request_handle_t &req) const

Private Types

using unique_controller_t = unique_async_handling_controller_t< Extra_Data_Factory >
 Short alias for a handling controller.
using scheduler_holder_t = generic_async_request_scheduler_t< Extra_Data_Factory >
 Short alias for a scheduler.
using schedulers_vector_t = std::vector< scheduler_holder_t >
 Short alias for a vector of schedulers.
using actual_request_handle_t
 Short alias to a smart pointer to the source request.
using actual_on_next_result_t
 Short alias for the result of controller's on_next method.

Private Member Functions

 growable_size_chain_t (creation_token_t)
 The main constructor.

Private Attributes

schedulers_vector_t m_schedulers
 The vector of schedulers.

Friends

class builder_t

Detailed Description

template<typename Extra_Data_Factory = no_extra_data_factory_t>
class restinio::async_chain::growable_size_chain_t< Extra_Data_Factory >

A holder of variable-size chain of asynchronous handlers.

Note
Once a list of schedulers is filled and an instance of growable_size_chain_t is created that instance can't be changed: a new scheduler can't be added, and an old scheduler can be removed. The creation of growable_size_chain_t instance is performed by the help of growable_size_chain_t::builder_t class.

Usage example for the case when there is no extra-data in a request object (please note that this is simplified example without actual asynchronous code, all schedulers work as synchronous handlers):

struct my_traits : public restinio::default_traits_t {
};
// The first handler in the chain.
{
... // Checks values of HTTP-fields and rejects invalid requests.
// Activation of the next handler.
next( std::move(controller) );
}
// The second handler in the chain.
{
... // Checks user's credentials and rejects requests from
// non-authentificated users.
// Activation of the next handler.
next( std::move(controller) );
}
// The last handler in the chain.
{
... // Actual processing.
}
// Building of a chain.
if(config.force_headers_checking())
builder.add(headers_checker);
if(config.force_user_authentification())
builder.add(authentificator);
builder.add(actual_handler);
.address(...)
.port(...)
.request_handler(builder.release())
);
std::unique_ptr< growable_size_chain_t > release() noexcept
Stop adding of new schedulers and acquire the chain instance.
void add(Scheduler &&scheduler)
Add a new scheduler to the chain.
A holder of variable-size chain of asynchronous handlers.
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
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_thread_pool_settings_t< Traits > on_thread_pool(std::size_t pool_size)
A special marker for the case when http_server must be run on an thread pool.
void run(asio_ns::io_context &ioctx, run_on_this_thread_settings_t< Traits > &&settings)
Helper function for running http server until ctrl+c is hit.
traits_t< asio_timer_manager_t, null_logger_t > default_traits_t
Definition traits.hpp:413
details::autodetect_request_handler_type request_handler_t
Definition traits.hpp:251

Usage example for the case when some extra-data is incorporated into a request object: (please note that this is simplified example without actual asynchronous code, all schedulers work as synchronous handlers):

struct my_extra_data_factory {
// A data formed by checker of HTTP-fields.
struct request_specific_fields_t {...};
// A data formed by user-authentificator.
struct user_info_t {...};
// A data to be incorporated into a request object.
using data_t = std::tuple<
std::optional<request_specific_fields_t>,
std::optional<user_info_t>>;
void make_within(restinio::extra_data_buffer_t<data_t> buf) {
new(buf.get()) data_t{};
}
};
struct my_traits : public restinio::default_traits_t {
using extra_data_factory_t = my_extra_data_factory;
using request_handler_t = restinio::async_chain::growable_size_chain_t<
extra_data_factory>;
};
using my_unique_controller_t =
using my_request_handle_t = my_unique_controller_t::actual_request_handle_t;
// The first handler in the chain.
my_unique_controller_t controller )
{
const my_request_handle_t req = acceptor->request_handle();
... // Checks values of HTTP-fields and rejects invalid requests.
...
next( std::move(controller) );
}
// The second handler in the chain.
my_unique_controller_t controller )
{
const my_request_handle_t req = acceptor->request_handle();
... // Checks user's credentials and rejects requests from
// non-authentificated users.
...
next( std::move(controller) );
}
// The last handler in the chain.
my_unique_controller_t controller )
{
const my_request_handle_t req = acceptor->request_handle();
auto & field_values = std::get<my_extra_data_factory::request_specific_fields_t>(req->extra_data());
auto & user_info = std::get<my_extra_data_factory::user_info_t>(req->extra_data());
... // Actual processing.
}
// Building of a chain.
if(config.force_headers_checking())
builder.add(headers_checker);
if(config.force_user_authentification())
builder.add(authentificator);
builder.add(actual_handler);
.address(...)
.port(...)
.request_handler(builder.release())
);
Helper for holding a pointer to a buffer where a new object of type Extra_Data should be constructed.
void * get() const noexcept
void add(Handler &&handler)
Add a new handler to the chain.
std::unique_ptr< growable_size_chain_t > release() noexcept
Stop adding of new handlers and acquire the chain instance.
Template Parameters
Extra_Data_FactoryThe type of extra-data-factory specified in the server's traits.
Since
v.0.7.0

Definition at line 180 of file growable_size.hpp.

Member Typedef Documentation

◆ actual_on_next_result_t

template<typename Extra_Data_Factory = no_extra_data_factory_t>
using restinio::async_chain::growable_size_chain_t< Extra_Data_Factory >::actual_on_next_result_t
private
Initial value:
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

Short alias for the result of controller's on_next method.

Definition at line 200 of file growable_size.hpp.

◆ actual_request_handle_t

template<typename Extra_Data_Factory = no_extra_data_factory_t>
using restinio::async_chain::growable_size_chain_t< Extra_Data_Factory >::actual_request_handle_t
private
Initial value:
generic_request_handle_t< typename Extra_Data_Factory::data_t > actual_request_handle_t
Short alias for request_handle type.
Definition common.hpp:154

Short alias to a smart pointer to the source request.

Definition at line 196 of file growable_size.hpp.

◆ scheduler_holder_t

template<typename Extra_Data_Factory = no_extra_data_factory_t>
using restinio::async_chain::growable_size_chain_t< Extra_Data_Factory >::scheduler_holder_t = generic_async_request_scheduler_t< Extra_Data_Factory >
private

Short alias for a scheduler.

Definition at line 190 of file growable_size.hpp.

◆ schedulers_vector_t

template<typename Extra_Data_Factory = no_extra_data_factory_t>
using restinio::async_chain::growable_size_chain_t< Extra_Data_Factory >::schedulers_vector_t = std::vector< scheduler_holder_t >
private

Short alias for a vector of schedulers.

Definition at line 193 of file growable_size.hpp.

◆ unique_controller_t

template<typename Extra_Data_Factory = no_extra_data_factory_t>
using restinio::async_chain::growable_size_chain_t< Extra_Data_Factory >::unique_controller_t = unique_async_handling_controller_t< Extra_Data_Factory >
private

Short alias for a handling controller.

Definition at line 187 of file growable_size.hpp.

Constructor & Destructor Documentation

◆ growable_size_chain_t() [1/2]

template<typename Extra_Data_Factory = no_extra_data_factory_t>
restinio::async_chain::growable_size_chain_t< Extra_Data_Factory >::growable_size_chain_t ( creation_token_t )
inlineprivate

The main constructor.

It has that form because the default constructor is public and marked as deleted.

Definition at line 328 of file growable_size.hpp.

◆ growable_size_chain_t() [2/2]

template<typename Extra_Data_Factory = no_extra_data_factory_t>
restinio::async_chain::growable_size_chain_t< Extra_Data_Factory >::growable_size_chain_t ( )
delete
Note
The default constructor is disable because an instance of that class should be created and filled by using builder_t.

Member Function Documentation

◆ operator()()

template<typename Extra_Data_Factory = no_extra_data_factory_t>
request_handling_status_t restinio::async_chain::growable_size_chain_t< Extra_Data_Factory >::operator() ( const actual_request_handle_t & req) const
inlinenodiscard

Initiates execution of the first scheduler in the chain.

Note
Always returns request_handling_status_t::accepted.

Definition at line 346 of file growable_size.hpp.

◆ builder_t

template<typename Extra_Data_Factory = no_extra_data_factory_t>
friend class builder_t
friend

Definition at line 257 of file growable_size.hpp.

Member Data Documentation

◆ m_schedulers

template<typename Extra_Data_Factory = no_extra_data_factory_t>
schedulers_vector_t restinio::async_chain::growable_size_chain_t< Extra_Data_Factory >::m_schedulers
private

The vector of schedulers.

Definition at line 320 of file growable_size.hpp.


The documentation for this class was generated from the following file: