RESTinio
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
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):

};
// 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())
if(config.force_user_authentification())
.address(...)
.port(...)
.request_handler(builder.release())
);
A builder of an instance of growable_size_chain.
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_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.
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.

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):

// 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{};
}
};
using extra_data_factory_t = my_extra_data_factory;
extra_data_factory>;
};
using my_request_handle_t = my_unique_controller_t::actual_request_handle_t;
// The first handler in the chain.
{
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.
{
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.
{
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())
if(config.force_user_authentification())
.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
A builder of an instance of growable_size_chain.
void add(Handler &&handler)
Add a new handler to the chain.
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

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

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()()

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.

Friends And Related Symbol Documentation

◆ 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

The vector of schedulers.

Definition at line 320 of file growable_size.hpp.


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