2
3
5#include <so_5/impl/layer_core.hpp>
7#include <so_5/details/rollback_on_exception.hpp>
29 const layer_map_t::value_type & v )
37 const std::type_index & type,
38 const layer_ref_t & layer )
57 layer_map_t && so_layers )
63 [
this]( so_layer_list_t::value_type & item )
73inline so_layer_list_t::const_iterator
75 const so_layer_list_t & layers,
76 const std::type_index & type )
78 auto search_result = std::lower_bound( layers.begin(), layers.end(),
80 [](
const so_layer_list_t::value_type & a,
const std::type_index & b )
84 if( search_result != layers.end() && search_result->
m_true_type == type )
92 const std::type_index & type )
const
100 return layer_it->
m_layer.get();
110 return layer_it->
m_layer.get();
118 so_layer_list_t::iterator
122 for(; it != it_end; ++it )
154 const std::type_index & type,
155 const layer_ref_t & layer )
157 if(
nullptr == layer.get() )
160 "trying to add nullptr extra layer" );
165 "trying to add extra layer that already exists in default list" );
172 "trying to add extra layer that already exists in extra list" );
180 catch(
const std::exception & x )
184 std::string(
"layer raised an exception: " ) + x.what() );
198 catch(
const std::exception & x )
207 std::string(
"unable to store pointer to layer, exception: " ) +
212#if defined(__clang__
)
213#pragma clang diagnostic push
214#pragma clang diagnostic ignored "-Wmissing-prototypes"
228#if defined(__clang__
)
229#pragma clang diagnostic pop
An utility class for working with layers.
std::mutex m_extra_layers_lock
Object lock for the extra layers data.
void shutdown_default_layers()
Shutdown default layers.
environment_t & m_env
SObjectizer Environment to work with.
layer_t * query_layer(const std::type_index &type) const
Get a layer.
void shutdown_extra_layers()
Shutdown extra layers.
so_layer_list_t m_default_layers
Default layers.
void add_extra_layer(const std::type_index &type, const layer_ref_t &layer)
Add an extra layer.
so_layer_list_t m_extra_layers
Extra layers.
void start()
Start all layers.
layer_core_t(environment_t &env, layer_map_t &&so_layers)
void wait_extra_layers()
Blocking wait for the complete shutdown of all extra layers.
void wait_default_layers()
Blocking wait for the complete shutdown of all default layers.
void finish()
Shutdown all layers and wait for full stop of them.
An interface of the additional SObjectizer Environment layer.
virtual void start()
Start hook.
virtual void shutdown()
Shutdown signal hook.
virtual void wait()
Waiting for the complete shutdown of a layer.
void bind_to_environment(environment_t *env)
Bind layer to the SObjectizer Environment.
#define SO_5_THROW_EXCEPTION(error_code, desc)
Some reusable and low-level classes/functions which can be used in public header files.
auto do_with_rollback_on_exception(Main_Action main_action, Rollback_Action rollback_action) -> decltype(main_action())
Helper function for do some action with rollback in the case of an exception.
Details of SObjectizer run-time implementations.
so_layer_list_t::const_iterator search_for_layer(const so_layer_list_t &layers, const std::type_index &type)
Find layer in container.
void call_shutdown(typed_layer_ref_t &tl)
void call_wait(typed_layer_ref_t &tl)
Private part of message limit implementation.
const int rc_unable_to_start_extra_layer
Layer initialization is failed.
const int rc_trying_to_add_extra_layer_that_already_exists_in_extra_list
The layer is already bound to the SObjectizer Environment as an extra layer.
const int rc_trying_to_add_extra_layer_that_already_exists_in_default_list
The layer is already bound to the SObjectizer Environment as a default layer.
const int rc_trying_to_add_nullptr_extra_layer
Unable to bind a layer by the null pointer to it.
A special wrapper to store a layer with its type.
std::type_index m_true_type
Layer type.
bool operator<(const typed_layer_ref_t &tl) const
typed_layer_ref_t(const std::type_index &type, const layer_ref_t &layer)
layer_ref_t m_layer
Layer itself.
typed_layer_ref_t(const layer_map_t::value_type &v)