RESTinio
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
restinio::sync_chain::growable_size_chain_t< Extra_Data_Factory > Class Template Reference

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

#include <growable_size.hpp>

Classes

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 actual_request_handle_t = generic_request_handle_t< typename Extra_Data_Factory::data_t >
 
using handler_holder_t = std::function< request_handling_status_t(const actual_request_handle_t &) >
 

Private Member Functions

 growable_size_chain_t (creation_token_t)
 The main constructor. More...
 

Private Attributes

std::vector< handler_holder_tm_handlers
 

Friends

class builder_t
 

Detailed Description

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

A holder of variable-size chain of synchronous handlers.

Note
Once a list of handler is filled and an instance of growable_size_chain_t is created that instance can't be changed: a new handler can't be added, and an old handler 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.

struct my_traits : public restinio::default_traits_t {
};
// The first handler in the chain.
{
... // Checks values of HTTP-fields and rejects invalid requests.
}
// The second handler in the chain.
{
... // Checks user's credentials and rejects requests from
// non-authentificated users.
}
// 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);
on_thread_pool<my_traits>(16)
.address(...)
.port(...)
.request_handler(builder.release())
);

Usage example for the case when some extra-data is incorporated into a request object.

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;
extra_data_factory>;
};
using my_request_handle_t =
// The first handler in the chain.
const my_request_handle_t & req )
{
... // Checks values of HTTP-fields and rejects invalid requests.
}
// The second handler in the chain.
const my_request_handle_t & req )
{
... // Checks user's credentials and rejects requests from
// non-authentificated users.
}
// The last handler in the chain.
const my_request_handle_t & req )
{
auto & field_values = std::get<
std::optional<my_extra_data_factory::request_specific_fields_t>>(req->extra_data());
auto & user_info = std::get<
std::optional<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);
on_thread_pool<my_traits>(16)
.address(...)
.port(...)
.request_handler(builder.release())
);
Template Parameters
Extra_Data_FactoryThe type of extra-data-factory specified in the server's traits.
Since
v.0.6.13
Examples:
sample/extra_data_factory/main.cpp.

Definition at line 158 of file growable_size.hpp.

Member Typedef Documentation

◆ actual_request_handle_t

template<typename Extra_Data_Factory = no_extra_data_factory_t>
using restinio::sync_chain::growable_size_chain_t< Extra_Data_Factory >::actual_request_handle_t = generic_request_handle_t< typename Extra_Data_Factory::data_t >
private

Definition at line 228 of file growable_size.hpp.

◆ handler_holder_t

template<typename Extra_Data_Factory = no_extra_data_factory_t>
using restinio::sync_chain::growable_size_chain_t< Extra_Data_Factory >::handler_holder_t = std::function< request_handling_status_t(const actual_request_handle_t &) >
private

Definition at line 232 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::sync_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 242 of file growable_size.hpp.

◆ growable_size_chain_t() [2/2]

template<typename Extra_Data_Factory = no_extra_data_factory_t>
restinio::sync_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::sync_chain::growable_size_chain_t< Extra_Data_Factory >::operator() ( const actual_request_handle_t req) const
inline

Definition at line 254 of file growable_size.hpp.

Friends And Related Function Documentation

◆ builder_t

template<typename Extra_Data_Factory = no_extra_data_factory_t>
friend class builder_t
friend

Definition at line 165 of file growable_size.hpp.

Member Data Documentation

◆ m_handlers

template<typename Extra_Data_Factory = no_extra_data_factory_t>
std::vector< handler_holder_t > restinio::sync_chain::growable_size_chain_t< Extra_Data_Factory >::m_handlers
private

Definition at line 234 of file growable_size.hpp.


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