restinio::sync_chain::fixed_size_chain_t< Size, Extra_Data_Factory > Class Template Reference

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

`#include <fixed_size.hpp>`

## Public Member Functions

| fixed_size_chain_t ()=delete
template<typename... Handlers>
| fixed_size_chain_t (Handlers &&...handlers)
| Initializing constructor. More...
RESTINIO_NODISCARD 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

template<std::size_t >
void | store_to () noexcept
template<std::size_t Index, typename Head , typename... Tail>
void | store_to (Head &&head, Tail &&...tail)

## Private Attributes

std::array< handler_holder_t, Size > | m_handlers

## Detailed Description

template<std::size_t Size, typename Extra_Data_Factory = no_extra_data_factory_t>
class restinio::sync_chain::fixed_size_chain_t< Size, Extra_Data_Factory >

A holder of fixed-size chain of synchronous handlers.

Note
  An instance of that type is intended to be filled with actual handlers at the creation time. After that new handlers can't be added to the chain, and old handlers can't be removed from the chain.

Usage example for the case when there is no extra-data in a request object.

struct my_traits : public restinio::default_traits_t {
using request_handler_t = restinio::sync_chain::fixed_size_chain_t<3>;
};
// The first handler in the chain.
restinio::request_handling_status_t headers_checker(
const restinio::request_handle_t & req )
{
... // Checks values of HTTP-fields and rejects invalid requests.
}
// The second handler in the chain.
restinio::request_handling_status_t authentificator(
const restinio::request_handle_t & req )
{
... // Checks user's credentials and rejects requests from
// non-authentificated users.
}
// The last handler in the chain.
restinio::request_handling_status_t actual_handler(
const restinio::request_handle_t & req )
{
... // Actual processing.
}
restinio::run(
on_thread_pool<my_traits>(16)
.address(...)
.port(...)
.request_handler(
// Just enumerate all handlers.
headers_checker,
authentificator,
actual_handler )
);
restinio::sync_chain::fixed_size_chain_t
A holder of fixed-size chain of synchronous handlers.
Definition: fixed_size.hpp:164
restinio::run
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.
Definition: http_server_run.hpp:216
restinio::request_handling_status_t
request_handling_status_t
Request handling status.
Definition: common_types.hpp:26
restinio::request_handle_t
std::shared_ptr< request_t > request_handle_t
An alias for handle for incoming request without additional extra-data.
Definition: request_handler.hpp:463
restinio::traits_t
Definition: traits.hpp:147

An instance of `fixed_size_chain_t` can also be created manually and passed to server's settings by `unique_ptr`:

auto chain = std::make_unique<restinio::fixed_size_chain_t<3>>(
headers_checker, authentificator, actual_handler);
...
restinio::run(
on_thread_pool<my_traits>(16)
.address(...)
.port(...)
.request_handler(std::move(chain))
);
nonstd::optional_lite::std11::move
T & move(T &t)
Definition: optional.hpp:465

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<request_specific_fields_t, 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::sync_chain::fixed_size_chain_t<
3,
extra_data_factory>;
};
using my_request_handle_t =
restinio::generic_request_handle_t<my_extra_data_factory::data_t>;
// The first handler in the chain.
restinio::request_handling_status_t headers_checker(
const my_request_handle_t & req )
{
... // Checks values of HTTP-fields and rejects invalid requests.
}
// The second handler in the chain.
restinio::request_handling_status_t authentificator(
const my_request_handle_t & req )
{
... // Checks user's credentials and rejects requests from
// non-authentificated users.
}
// The last handler in the chain.
restinio::request_handling_status_t actual_handler(
const my_request_handle_t & req )
{
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.
}
restinio::run(
on_thread_pool<my_traits>(16)
.address(...)
.port(...)
.request_handler(
// Just enumerate all handlers.
headers_checker,
authentificator,
actual_handler )
);
restinio::extra_data_buffer_t
Helper for holding a pointer to a buffer where a new object of type Extra_Data should be constructed.
Definition: request_handler.hpp:52
restinio::extra_data_buffer_t::get
RESTINIO_NODISCARD void * get() const noexcept
Definition: request_handler.hpp:60
restinio::generic_request_handle_t
std::shared_ptr< generic_request_t< Extra_Data > > generic_request_handle_t
An alias for shared-pointer to incoming request.
Definition: request_handler.hpp:447

Template Parameters

  Size | The exact number of handlers in the chain.
  Extra_Data_Factory | The type of extra-data-factory specified in the server's traits.

Since
  v.0.6.13

Examples
  sample/chained_handlers/main.cpp.

Definition at line 163 of file fixed_size.hpp.

## Member Typedef Documentation

## actual_request_handle_t

template<std::size_t Size, typename Extra_Data_Factory = no_extra_data_factory_t>

using restinio::sync_chain::fixed_size_chain_t< Size, Extra_Data_Factory >::actual_request_handle_t = generic_request_handle_t< typename Extra_Data_Factory::data_t >

private

Definition at line 165 of file fixed_size.hpp.

## handler_holder_t

template<std::size_t Size, typename Extra_Data_Factory = no_extra_data_factory_t>

using restinio::sync_chain::fixed_size_chain_t< Size, Extra_Data_Factory >::handler_holder_t = std::function< request_handling_status_t(const actual_request_handle_t &) >

private

Definition at line 168 of file fixed_size.hpp.

## Constructor & Destructor Documentation

## fixed_size_chain_t() [1/2]

template<std::size_t Size, typename Extra_Data_Factory = no_extra_data_factory_t>

restinio::sync_chain::fixed_size_chain_t< Size, Extra_Data_Factory >::fixed_size_chain_t | ( |  | ) |

delete

Attention
  The default constructor is disabled. It's because a chain should be initialized by handlers at the creation time. Because of that fixed_size_chain_t isn't a DefaultConstructible type.

## fixed_size_chain_t() [2/2]

template<std::size_t Size, typename Extra_Data_Factory = no_extra_data_factory_t>
template<typename... Handlers>

restinio::sync_chain::fixed_size_chain_t< Size, Extra_Data_Factory >::fixed_size_chain_t | ( | Handlers &&... | handlers | ) |

inline

Initializing constructor.

Note
  The number of parameters should match the value of Size template parameter.

Definition at line 212 of file fixed_size.hpp.

## Member Function Documentation

## operator()()

template<std::size_t Size, typename Extra_Data_Factory = no_extra_data_factory_t>

RESTINIO_NODISCARD request_handling_status_t restinio::sync_chain::fixed_size_chain_t< Size, Extra_Data_Factory >::operator() | ( | const actual_request_handle_t & | req | ) | const

inline

Definition at line 223 of file fixed_size.hpp.

## store_to() [1/2]

template<std::size_t Size, typename Extra_Data_Factory = no_extra_data_factory_t>
template<std::size_t >

void restinio::sync_chain::fixed_size_chain_t< Size, Extra_Data_Factory >::store_to | ( |  | ) |

inlineprivatenoexcept

Definition at line 176 of file fixed_size.hpp.

## store_to() [2/2]

template<std::size_t Size, typename Extra_Data_Factory = no_extra_data_factory_t>
template<std::size_t Index, typename Head , typename... Tail>

void restinio::sync_chain::fixed_size_chain_t< Size, Extra_Data_Factory >::store_to | ( | Head && | head,
|  | Tail &&... | tail
| ) |  |

inlineprivate

Definition at line 183 of file fixed_size.hpp.

## Member Data Documentation

## m_handlers

template<std::size_t Size, typename Extra_Data_Factory = no_extra_data_factory_t>

std::array< handler_holder_t, Size > restinio::sync_chain::fixed_size_chain_t< Size, Extra_Data_Factory >::m_handlers

private

Definition at line 172 of file fixed_size.hpp.

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

- restinio/sync_chain/fixed_size.hpp