SObjectizer  5.5
Classes | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
so_5::environment_t Class Referenceabstract

SObjectizer Environment. More...

#include <environment.hpp>

Inheritance diagram for so_5::environment_t:
so_5::anonymous_namespace{wrapped_env.cpp}::actual_environment_t so_5::api::impl::so_quick_environment_t< Init >

Classes

struct  internals_t
 Internal details of SObjectizer Environment object. More...
 

Public Member Functions

 environment_t (environment_params_t &&so_environment_params)
 
virtual ~environment_t ()
 
 environment_t (const environment_t &)=delete
 
environment_toperator= (const environment_t &)=delete
 
void call_exception_logger (const std::exception &event_exception, const std::string &coop_name)
 Call event exception logger for logging an exception. More...
 
exception_reaction_t exception_reaction () const
 An exception reaction for the whole SO Environment. More...
 
error_logger_terror_logger () const
 Get the error_logger object. More...
 
template<class Agent , typename... Args>
std::unique_ptr< Agent > make_agent (Args &&... args)
 Helper method for simplification of agents creation. More...
 
stats::controller_tstats_controller ()
 Access to controller of run-time monitoring. More...
 
stats::repository_tstats_repository ()
 Access to repository of data sources for run-time monitoring. More...
 
template<typename... Args>
void introduce_coop (Args &&... args)
 Helper method for simplification of cooperation creation and registration. More...
 
work_thread_activity_tracking_t work_thread_activity_tracking () const
 Get activity tracking flag for the whole SObjectizer Environment. More...
 
disp_binder_unique_ptr_t so_make_default_disp_binder ()
 Get binding to the default dispatcher. More...
 
bool autoshutdown_disabled () const
 Get autoshutdown_disabled flag. More...
 
so_5::timer_id_t schedule_timer (const std::type_index &type_wrapper, const message_ref_t &msg, const mbox_t &mbox, std::chrono::steady_clock::duration pause, std::chrono::steady_clock::duration period)
 Schedule timer event. More...
 
void single_timer (const std::type_index &type_wrapper, const message_ref_t &msg, const mbox_t &mbox, std::chrono::steady_clock::duration pause)
 Schedule a single shot timer event. More...
 
template<typename Lambda >
mbox_t make_custom_mbox (Lambda &&lambda)
 Create a custom mbox. More...
 
Methods for working with mboxes.
mbox_t create_mbox ()
 Create an anonymous mbox with the default mutex. More...
 
mbox_t create_mbox (nonempty_name_t mbox_name)
 Create named mbox. More...
 
mbox_t create_local_mbox ()
 
mbox_t create_local_mbox (nonempty_name_t mbox_name)
 
Method for working with message chains.
mchain_t create_mchain (const mchain_params_t &params)
 Create message chain. More...
 
Method for working with dispatchers.
dispatcher_tquery_default_dispatcher ()
 Access to the default dispatcher. More...
 
dispatcher_ref_t query_named_dispatcher (const std::string &disp_name)
 Get named dispatcher. More...
 
void install_exception_logger (event_exception_logger_unique_ptr_t logger)
 Set up an exception logger. More...
 
dispatcher_ref_t add_dispatcher_if_not_exists (const std::string &disp_name, std::function< dispatcher_unique_ptr_t() > disp_factory)
 Add named dispatcher if it is not exists. More...
 
Methods for working with cooperations.
coop_unique_ptr_t create_coop (nonempty_name_t name)
 Create a cooperation. More...
 
coop_unique_ptr_t create_coop (autoname_indicator_t indicator())
 Create a cooperation with automatically generated name. More...
 
coop_unique_ptr_t create_coop (nonempty_name_t name, disp_binder_unique_ptr_t disp_binder)
 Create a cooperation. More...
 
coop_unique_ptr_t create_coop (autoname_indicator_t indicator(), disp_binder_unique_ptr_t disp_binder)
 Create a cooperation with automatically generated name. More...
 
void register_coop (coop_unique_ptr_t agent_coop)
 Register a cooperation. More...
 
template<class A >
void register_agent_as_coop (nonempty_name_t coop_name, std::unique_ptr< A > agent)
 Register single agent as a cooperation. More...
 
template<class A >
void register_agent_as_coop (autoname_indicator_t indicator(), std::unique_ptr< A > agent)
 Register single agent as a cooperation with automatically generated name. More...
 
void register_agent_as_coop (nonempty_name_t coop_name, agent_t *agent)
 Register single agent as a cooperation. More...
 
void register_agent_as_coop (autoname_indicator_t indicator(), agent_t *agent)
 Register single agent as a cooperation with automatically generated name. More...
 
template<class A >
void register_agent_as_coop (nonempty_name_t coop_name, std::unique_ptr< A > agent, disp_binder_unique_ptr_t disp_binder)
 Register single agent as a cooperation with specified dispatcher binder. More...
 
template<class A >
void register_agent_as_coop (autoname_indicator_t indicator(), std::unique_ptr< A > agent, disp_binder_unique_ptr_t disp_binder)
 Register single agent as a cooperation with specified dispatcher binder and automatically generated name. More...
 
void register_agent_as_coop (nonempty_name_t coop_name, agent_t *agent, disp_binder_unique_ptr_t disp_binder)
 Register single agent as a cooperation with specified dispatcher binder. More...
 
void register_agent_as_coop (autoname_indicator_t indicator(), agent_t *agent, disp_binder_unique_ptr_t disp_binder)
 Register single agent as a cooperation with specified dispatcher binder and automatically generated name. More...
 
void deregister_coop (nonempty_name_t name, int reason)
 Deregister the cooperation. More...
 
Methods for working with timer events.
template<class Message >
so_5::timer_id_t schedule_timer (std::type_index subscription_type, std::unique_ptr< Message > msg, message_mutability_t mutability, const mbox_t &mbox, std::chrono::steady_clock::duration pause, std::chrono::steady_clock::duration period)
 Schedule timer event. More...
 
template<class Message >
so_5::timer_id_t schedule_timer (std::unique_ptr< Message > msg, const mbox_t &mbox, std::chrono::steady_clock::duration pause, std::chrono::steady_clock::duration period)
 Schedule timer event. More...
 
template<class Message >
so_5::timer_id_t schedule_timer (std::unique_ptr< Message > msg, const mbox_t &mbox, unsigned int delay_msec, unsigned int period_msec)
 Schedule timer event. More...
 
template<class Message >
so_5::timer_id_t schedule_timer (const mbox_t &mbox, std::chrono::steady_clock::duration pause, std::chrono::steady_clock::duration period)
 Schedule a timer event for a signal. More...
 
template<class Message >
so_5::timer_id_t schedule_timer (const mbox_t &mbox, unsigned int delay_msec, unsigned int period_msec)
 Schedule a timer event for a signal. More...
 
template<class Message >
void single_timer (std::unique_ptr< Message > msg, const mbox_t &mbox, std::chrono::steady_clock::duration pause)
 Schedule a single shot timer event. More...
 
template<class Message >
void single_timer (std::type_index subscription_type, std::unique_ptr< Message > msg, message_mutability_t mutability, const mbox_t &mbox, std::chrono::steady_clock::duration pause)
 Schedule a single shot timer event. More...
 
template<class Message >
void single_timer (std::unique_ptr< Message > msg, const mbox_t &mbox, unsigned int delay_msec)
 Schedule a single shot timer event. More...
 
template<class Message >
void single_timer (const mbox_t &mbox, std::chrono::steady_clock::duration pause)
 Schedule a single shot timer event for a signal. More...
 
template<class Message >
void single_timer (std::type_index subscription_type, const mbox_t &mbox, std::chrono::steady_clock::duration pause)
 Schedule a single shot timer event for a signal. More...
 
template<class Message >
void single_timer (const mbox_t &mbox, unsigned int delay_msec)
 Schedule a single shot timer event for a signal. More...
 
Methods for working with layers.
template<class SO_Layer >
SO_Layer * query_layer_noexcept () const
 
template<class SO_Layer >
SO_Layer * query_layer () const
 Get access to the layer with exception if layer is not found. More...
 
template<class SO_Layer >
void add_extra_layer (std::unique_ptr< SO_Layer > layer_ptr)
 Add an additional layer. More...
 
template<class SO_Layer >
void add_extra_layer (SO_Layer *layer_raw_ptr)
 Add an additional layer via raw pointer. More...
 
Methods for starting, initializing and stopping of the Run-Time.
void run ()
 Run the SObjectizer Run-Time. More...
 
virtual void init ()=0
 Initialization hook. More...
 
void stop ()
 Send a shutdown signal to the Run-Time. More...
 
Methods for working with stop_guards.
stop_guard_t::setup_result_t setup_stop_guard (stop_guard_shptr_t guard, stop_guard_t::what_if_stop_in_progress_t reaction_on_stop_in_progress=stop_guard_t::what_if_stop_in_progress_t::throw_exception)
 Set up a new stop_guard. More...
 
void remove_stop_guard (stop_guard_shptr_t guard)
 Remove stop_guard and complete the stop operation if necessary. More...
 
Methods for working with msg_tracing's filters.
void change_message_delivery_tracer_filter (so_5::msg_tracing::filter_shptr_t filter)
 Change the current msg_tracing's filter to a new one. More...
 

Private Member Functions

environment_tself_ref ()
 Auxiliary methods for getting reference to itself. More...
 
layer_tquery_layer (const std::type_index &type) const
 Access to an additional layer. More...
 
void add_extra_layer (const std::type_index &type, const layer_ref_t &layer)
 Add an additional layer. More...
 
void remove_extra_layer (const std::type_index &type)
 Remove an additional layer. More...
 
mbox_t do_make_custom_mbox (custom_mbox_details::creator_iface_t &creator)
 Actual creation of a custom mbox. More...
 
Implementation details related to run/stop functionality.
void impl__run_stats_controller_and_go_further ()
 Run controller for run-time monitoring and call next run stage. More...
 
void impl__run_layers_and_go_further ()
 Run layers and call next run stage. More...
 
void impl__run_dispatcher_and_go_further ()
 Run dispatchers and call next run stage. More...
 
void impl__run_infrastructure ()
 Launch environment infrastructure and wait for finish. More...
 

Private Attributes

std::unique_ptr< internals_tm_impl
 SObjectizer Environment internals. More...
 

Friends

class so_5::impl::internal_env_iface_t
 

Detailed Description

SObjectizer Environment.

Basic information

The SObjectizer Environment provides a basic infrastructure for the SObjectizer Run-Time execution.

The main method of starting SObjectizer Environment creates a class derived from the environment_t and reimplementing the environment_t::init() method. This method should be used to define starting actions of application. For example first application cooperations can be registered here and starting messages can be sent to them.

The SObjectizer Environment calls the environment_t::init() when the SObjectizer Run-Time is successfully started. If something happened during the Run-Time startup then the method init() will not be called.

The SObjectizer Run-Time is started by the environment_t::run(). This method blocks the caller thread until SObjectizer completely finished its work.

The SObjectizer Run-Time is finished by the environment_t::stop(). This method doesn't block the caller thread. Instead it sends a special shutdown signal to the Run-Time. The SObjectizer Run-Time then informs agents about this and waits finish of agents work. The SObjectizer Run-Time finishes if all agents are stopped and all cooperations are deregistered.

Methods of the SObjectizer Environment can be splitted into the following groups:

Methods for working with mboxes.

SObjectizer Environment allows creation of named and anonymous mboxes. Syncronization objects for these mboxes can be obtained from common pools or assigned by a user during mbox creation.

Mboxes are created by environment_t::create_mbox() methods. All these methods return the mbox_t which is a smart reference to the mbox.

An anonymous mbox is automatically destroyed when the last reference to it is destroyed. So, to save the anonymous mbox, the mbox_ref from the create_mbox() should be stored somewhere.

Named mbox must be destroyed manually by calling the environment_t::destroy_mbox() method. But physically the deletion of the named mbox postponed to the deletion of last reference to it. So if there is some reference to the named mbox it instance will live with this reference. But mbox itself will be removed from SObjectizer Environment lists.

Methods for working with cooperations.

Cooperations can be created by environment_t::create_coop() methods.

The method environment_t::register_coop() should be used for the cooperation registration.

Method environment_t::deregister_coop() should be used for the cooperation deregistration.

Methods for

sending delayed and periodic messages.

Receiving of delayed and/or periodic messages are named as timer events.

The timer event can be created and destroyed. If the timer event for a delayed message is destroyed before message timeout is expired then message delivery will be canceled. For periodic messages destroying of the timer event means that message delivery will be stopped.

Timer events can be created by environment_t::schedule_timer() methods. The one version of the schedule_timer() is intended for messages with an actual data. The second one – for the signals without the message data.

Methods schedule_timer() return a special reference for the timer event. Timer event destroyed when this reference destroyed. So it is necessary to store this reference somewhere. Also the timer event can be destroyed by the so_5::timer_thread::timer_id_ref_t::release() method.

A special method environment_t::single_timer() can be used in case when a single shot timer event is necessary. With using this method there is no need to store reference for the scheduled single shot timer event.

Examples:
so_5/adv_thread_pool_fifo/main.cpp, so_5/blinking_led/main.cpp, so_5/chameneos_prealloc_msgs/main.cpp, so_5/chameneos_simple/main.cpp, so_5/chstate/main.cpp, so_5/chstate_msg_tracing/main.cpp, so_5/collector_many_performers/main.cpp, so_5/collector_performer_pair/main.cpp, so_5/coop_listener/main.cpp, so_5/coop_notification/main.cpp, so_5/coop_user_resources/main.cpp, so_5/custom_error_logger/main.cpp, so_5/deadletter_handler/main.cpp, so_5/delivery_filters/main.cpp, so_5/dining_philosophers/main.cpp, so_5/dining_philosophers_2/main.cpp, so_5/disp/main.cpp, so_5/exception_logger/main.cpp, so_5/exception_reaction/main.cpp, so_5/hardwork_imit/main.cpp, so_5/hello_all/main.cpp, so_5/hello_delay/main.cpp, so_5/hello_evt_handler/main.cpp, so_5/hello_evt_lambda/main.cpp, so_5/hello_periodic/main.cpp, so_5/hello_world/main.cpp, so_5/hello_world_adhoc/main.cpp, so_5/hello_world_simple_not_mtsafe/main.cpp, so_5/intercom_statechart/main.cpp, so_5/machine_control/main.cpp, so_5/make_pipeline/main.cpp, so_5/many_timers/main.cpp, so_5/modify_resend_as_immutable/main.cpp, so_5/mutable_msg_agents/main.cpp, so_5/news_board/main.cpp, so_5/nohandler_msg_tracing/main.cpp, so_5/parent_coop/main.cpp, so_5/ping_pong/main.cpp, so_5/ping_pong_minimal/main.cpp, so_5/ping_pong_with_owner/main.cpp, so_5/prio_work_stealing/main.cpp, so_5/private_dispatcher_for_children/main.cpp, so_5/private_dispatcher_hello/main.cpp, so_5/private_dispatcher_restarts/main.cpp, so_5/producer_consumer_mchain/main.cpp, so_5/queue_size_stats/main.cpp, so_5/redirect_and_transform/main.cpp, so_5/selective_msg_tracing/main.cpp, so_5/simple_message_deadline/main.cpp, so_5/state_deep_history/main.cpp, so_5/stop_guard/main.cpp, so_5/subscriptions/main.cpp, so_5/svc/exceptions/main.cpp, so_5/svc/hello/main.cpp, so_5/svc/parallel_sum/main.cpp, so_5/two_handlers/main.cpp, and so_5/work_generation/main.cpp.

Constructor & Destructor Documentation

◆ environment_t() [1/2]

so_5::environment_t::environment_t ( environment_params_t &&  so_environment_params)
explicit
Parameters
so_environment_paramsInitialization params.

◆ ~environment_t()

so_5::environment_t::~environment_t ( )
virtual

◆ environment_t() [2/2]

so_5::environment_t::environment_t ( const environment_t )
delete

Member Function Documentation

◆ add_dispatcher_if_not_exists()

dispatcher_ref_t so_5::environment_t::add_dispatcher_if_not_exists ( const std::string &  disp_name,
std::function< dispatcher_unique_ptr_t() >  disp_factory 
)

Add named dispatcher if it is not exists.

Since
v.5.4.0
Usage:
so_5::environment_t & env = ...;
"my_coop_dispatcher",
Exceptions
so_5::exception_tif dispatcher cannot be added.
Parameters
disp_nameDispatcher name.
disp_factoryDispatcher factory.

◆ add_extra_layer() [1/3]

template<class SO_Layer >
void so_5::environment_t::add_extra_layer ( std::unique_ptr< SO_Layer >  layer_ptr)
inline

Add an additional layer.

◆ add_extra_layer() [2/3]

template<class SO_Layer >
void so_5::environment_t::add_extra_layer ( SO_Layer *  layer_raw_ptr)
inline

Add an additional layer via raw pointer.

Since
v.5.2.0.4

◆ add_extra_layer() [3/3]

void so_5::environment_t::add_extra_layer ( const std::type_index &  type,
const layer_ref_t layer 
)
private

Add an additional layer.

◆ autoshutdown_disabled()

bool so_5::environment_t::autoshutdown_disabled ( ) const

Get autoshutdown_disabled flag.

Autoshutdown feature is on by default. It can be turned off in environment_params_t. This methods returns true if autoshutdown is turned off.

Since
v.5.5.19

◆ call_exception_logger()

void so_5::environment_t::call_exception_logger ( const std::exception &  event_exception,
const std::string &  coop_name 
)

Call event exception logger for logging an exception.

Since
v.5.2.3.
Parameters
event_exceptionException caught.
coop_nameA cooperation to which agent is belong.

◆ change_message_delivery_tracer_filter()

void so_5::environment_t::change_message_delivery_tracer_filter ( so_5::msg_tracing::filter_shptr_t  filter)

Change the current msg_tracing's filter to a new one.

Usage example:

// Turn message delivery tracing on.
params.message_delivery_tracer(
// Disable all trace messages.
// It is expected that trace filter will be changed in the future.
params.message_delivery_tracer_filter(
...
} );
...
void some_agent_t::turn_msg_tracing_on() {
// Remove trace filter. As result all trace messages will be printed.
so_environment().change_message_delivery_tracer_filter(
...
}
Note
It is possible that there are active calls to so_5::msg_tracing::filter_t::filter() methods at the time of invocation of change_message_delivery_tracer_filter(). In this case all active calls will be completed with the previous filter. This could lead to mixture of messages in the trace: some of them will be enabled by old filter and some of them will be enabled by new filter. And it is possible that messages enabled by new filter will precede messages enabled by old filter.
Exceptions
exception_tif message delivery tracing is disabled.
Since
v.5.5.22
Parameters
filterA new filter to be used. It can be an empty pointer. In this case all trace messages will be passed to tracer object.
Examples:
so_5/selective_msg_tracing/main.cpp.

◆ create_coop() [1/4]

coop_unique_ptr_t so_5::environment_t::create_coop ( nonempty_name_t  name)

Create a cooperation.

Returns
A new cooperation with name. This cooperation will use default dispatcher binders.
Parameters
nameA new cooperation name.
Examples:
so_5/hardwork_imit/main.cpp.

◆ create_coop() [2/4]

coop_unique_ptr_t so_5::environment_t::create_coop ( autoname_indicator_t   indicator())

Create a cooperation with automatically generated name.

Since
v.5.5.1
Returns
A new cooperation with automatically generated name. This cooperation will use default dispatcher binders.

◆ create_coop() [3/4]

coop_unique_ptr_t so_5::environment_t::create_coop ( nonempty_name_t  name,
disp_binder_unique_ptr_t  disp_binder 
)

Create a cooperation.

A binder disp_binder will be used for binding cooperation agents to the dispatcher. This binder will be default binder for this cooperation.

so_5::coop_unique_ptr_t coop = so_env.create_coop(
"some_coop",
"active_group",
"some_active_group" ) );
// That agent will be bound to the dispatcher "active_group"
// and will be member of an active group with name
// "some_active_group".
coop->make_agent< a_some_agent_t >();
Parameters
nameA new cooperation name.
disp_binderA default binder for this cooperation.

◆ create_coop() [4/4]

coop_unique_ptr_t so_5::environment_t::create_coop ( autoname_indicator_t   indicator(),
disp_binder_unique_ptr_t  disp_binder 
)

Create a cooperation with automatically generated name.

Since
v.5.5.1
Returns
A cooperation with automatically generated name and disp_binder as the default dispatcher binder.
Parameters
indicatorA new cooperation name.
disp_binderA default binder for this cooperation.

◆ create_local_mbox() [1/2]

mbox_t so_5::environment_t::create_local_mbox ( )
inline
Deprecated:
Will be removed in v.5.6.0. Use create_mbox() instead.

◆ create_local_mbox() [2/2]

mbox_t so_5::environment_t::create_local_mbox ( nonempty_name_t  mbox_name)
inline
Deprecated:
Will be removed in v.5.6.0. Use create_mbox() instead.

◆ create_mbox() [1/2]

mbox_t so_5::environment_t::create_mbox ( )

◆ create_mbox() [2/2]

mbox_t so_5::environment_t::create_mbox ( nonempty_name_t  mbox_name)

Create named mbox.

If mbox_name is unique then a new mbox will be created. If not the reference to existing mbox will be returned.

Parameters
mbox_nameMbox name.

◆ create_mchain()

mchain_t so_5::environment_t::create_mchain ( const mchain_params_t params)

Create message chain.

Since
v.5.5.13
Usage examples:
so_5::environment_t & env = ...;
// Create mchain with size-unlimited queue.
auto ch1 = env.create_mchain(
// Create mchain with size-limited queue without a timeout
// on attempt to push another message to full mchain...
auto ch2 = env.create_mchain(
// ...maximum size of the chain.
100,
// ...memory for chain will be allocated and deallocated dynamically...
// ...an exception will be thrown on overflow.
// Create mchain with size-limited queue with a timeout for 200ms
// on attempt to push another message to full mchain...
auto ch3 = env.create_mchain(
// ...maximum size of the chain.
100,
// ...memory for chain will be preallocated...
// ...an oldest message from mchain will be removed on overflow...
// ...timeout for waiting on attempt to push a message into full mchain.
std::chrono::milliseconds(200) ) );
// Create size-unlimited mchain with custom notificator for
// 'not_empty' situations.
auto ch4 = env.create_mchain(
so_5::make_unlimited_mchain_params().not_empty_notificator(
[&] { some_widget.send_notify(); } ) );
Parameters
paramsParameters for a new bag.
Examples:
so_5/producer_consumer_mchain/main.cpp.

◆ deregister_coop()

void so_5::environment_t::deregister_coop ( nonempty_name_t  name,
int  reason 
)

Deregister the cooperation.

Method searches the cooperation within registered cooperations and if it is found deregisters it.

Deregistration can take some time.

At first a special signal is sent to cooperation agents. By receiving these signal agents stop receiving new messages. When the local event queue for an agent becomes empty the agent informs the cooperation about this. When the cooperation receives all these signals from agents it informs the SObjectizer Run-Time. Only after this the cooperation is deregistered on the special thread context.

After the cooperation deregistration agents are unbound from dispatchers. And name of the cooperation is removed from the list of registered cooperations.

Parameters
nameName of the cooperation to be registered.
reasonDeregistration reason.
Examples:
so_5/ping_pong_with_owner/main.cpp, and so_5/wrapped_env_demo/main.cpp.

◆ do_make_custom_mbox()

mbox_t so_5::environment_t::do_make_custom_mbox ( custom_mbox_details::creator_iface_t creator)
private

Actual creation of a custom mbox.

Since
v.5.5.19.2

◆ error_logger()

error_logger_t & so_5::environment_t::error_logger ( ) const

Get the error_logger object.

Since
v.5.5.0

◆ exception_reaction()

exception_reaction_t so_5::environment_t::exception_reaction ( ) const

An exception reaction for the whole SO Environment.

Since
v.5.3.0

◆ impl__run_dispatcher_and_go_further()

void so_5::environment_t::impl__run_dispatcher_and_go_further ( )
private

Run dispatchers and call next run stage.

◆ impl__run_infrastructure()

void so_5::environment_t::impl__run_infrastructure ( )
private

Launch environment infrastructure and wait for finish.

Since
v.5.5.19

◆ impl__run_layers_and_go_further()

void so_5::environment_t::impl__run_layers_and_go_further ( )
private

Run layers and call next run stage.

◆ impl__run_stats_controller_and_go_further()

void so_5::environment_t::impl__run_stats_controller_and_go_further ( )
private

Run controller for run-time monitoring and call next run stage.

Since
v.5.5.4

◆ init()

virtual void so_5::environment_t::init ( )
pure virtual

Initialization hook.

Attention
A hang inside of this method will prevent the Run-Time from stopping. For example if a dialog with an application user is performed inside init() then SObjectizer cannot finish its work until this dialog is finished.

Implemented in so_5::api::impl::so_quick_environment_t< Init >, and so_5::anonymous_namespace{wrapped_env.cpp}::actual_environment_t.

◆ install_exception_logger()

void so_5::environment_t::install_exception_logger ( event_exception_logger_unique_ptr_t  logger)

Set up an exception logger.

Examples:
so_5/exception_logger/main.cpp.

◆ introduce_coop()

template<typename... Args>
void so_5::environment_t::introduce_coop ( Args &&...  args)

Helper method for simplification of cooperation creation and registration.

Since
v.5.5.5
Usage samples:
// For the case when name for new coop will be generated automatically.
// And default dispatcher will be used for binding.
env.introduce_coop( []( so_5::coop_t & coop ) {
coop.make_agent< first_agent >(...);
coop.make_agent< second_agent >(...);
});
// For the case when name is specified.
// Default dispatcher will be used for binding.
env.introduce_coop( "main-coop", []( so_5::coop_t & coop ) {
coop.make_agent< first_agent >(...);
coop.make_agent< second_agent >(...);
});
// For the case when name is automatically generated and
// dispatcher binder is specified.
[]( so_5::coop_t & coop ) {
coop.make_agent< first_agent >(...);
coop.make_agent< second_agent >(...);
} );
// For the case when name is explicitly defined and
// dispatcher binder is specified.
"main-coop",
[]( so_5::coop_t & coop ) {
coop.make_agent< first_agent >(...);
coop.make_agent< second_agent >(...);
} );
Examples:
so_5/adv_thread_pool_fifo/main.cpp, so_5/blinking_led/main.cpp, so_5/chameneos_prealloc_msgs/main.cpp, so_5/chameneos_simple/main.cpp, so_5/chstate_msg_tracing/main.cpp, so_5/collector_many_performers/main.cpp, so_5/collector_performer_pair/main.cpp, so_5/convert_lib/main.cpp, so_5/coop_user_resources/main.cpp, so_5/dining_philosophers/main.cpp, so_5/dining_philosophers_2/main.cpp, so_5/disp/main.cpp, so_5/hello_all/main.cpp, so_5/hello_periodic/main.cpp, so_5/hello_world_adhoc/main.cpp, so_5/hello_world_simple_not_mtsafe/main.cpp, so_5/intercom_statechart/main.cpp, so_5/machine_control/main.cpp, so_5/many_timers/main.cpp, so_5/mchain_svc_req/main.cpp, so_5/modify_resend_as_immutable/main.cpp, so_5/mutable_msg_agents/main.cpp, so_5/news_board/main.cpp, so_5/nohandler_msg_tracing/main.cpp, so_5/ping_pong/main.cpp, so_5/ping_pong_minimal/main.cpp, so_5/prio_work_stealing/main.cpp, so_5/producer_consumer_mchain/main.cpp, so_5/queue_size_stats/main.cpp, so_5/redirect_and_transform/main.cpp, so_5/selective_msg_tracing/main.cpp, so_5/simple_message_deadline/main.cpp, so_5/state_deep_history/main.cpp, so_5/stop_guard/main.cpp, so_5/svc/exceptions/main.cpp, so_5/svc/hello/main.cpp, so_5/svc/parallel_sum/main.cpp, so_5/work_generation/main.cpp, so_5/wrapped_env_demo/main.cpp, and so_5/wrapped_env_demo_2/main.cpp.

◆ make_agent()

template<class Agent , typename... Args>
std::unique_ptr< Agent > so_5::environment_t::make_agent ( Args &&...  args)
inline

Helper method for simplification of agents creation.

Since
v.5.5.4
Note
Creates an instance of agent of type Agent by using environment_t::make_agent() template function and adds it to the cooperation. Uses the fact that most agent types use reference to the environment object as the first argument.
Returns
unique pointer to the new agent.
Template Parameters
Agenttype of agent to be created.
Argstype of parameters list for agent constructor.
Usage sample:
so_5::environment_t & env = ...;
// For the case of constructor like my_agent(environmen_t&).
auto a1 = env.make_agent< my_agent >();
// For the case of constructor like your_agent(environment_t&, std::string).
auto a2 = env.make_agent< your_agent >( "hello" );
// For the case of constructor like their_agent(environment_t&, std::string, mbox_t).
auto a3 = env.make_agent< their_agent >( "bye", a2->so_direct_mbox() );
Examples:
so_5/chstate/main.cpp, so_5/coop_listener/main.cpp, so_5/coop_notification/main.cpp, so_5/deadletter_handler/main.cpp, so_5/delivery_filters/main.cpp, so_5/exception_logger/main.cpp, so_5/exception_reaction/main.cpp, so_5/hello_delay/main.cpp, so_5/hello_evt_handler/main.cpp, so_5/hello_evt_lambda/main.cpp, so_5/hello_periodic/main.cpp, so_5/hello_world/main.cpp, so_5/make_pipeline/main.cpp, so_5/parent_coop/main.cpp, so_5/ping_pong_with_owner/main.cpp, so_5/private_dispatcher_for_children/main.cpp, so_5/private_dispatcher_hello/main.cpp, so_5/private_dispatcher_restarts/main.cpp, so_5/subscriptions/main.cpp, and so_5/two_handlers/main.cpp.

◆ make_custom_mbox()

template<typename Lambda >
mbox_t so_5::environment_t::make_custom_mbox ( Lambda &&  lambda)
inline

Create a custom mbox.

Template Parameters
Lambdatype of actual lambda with all creation actions. The Lambda must be lambda-function or functional objects with the following format:
Since
v.5.5.19.2

◆ operator=()

environment_t& so_5::environment_t::operator= ( const environment_t )
delete

◆ query_default_dispatcher()

dispatcher_t & so_5::environment_t::query_default_dispatcher ( )

Access to the default dispatcher.

◆ query_layer() [1/2]

template<class SO_Layer >
SO_Layer* so_5::environment_t::query_layer ( ) const
inline

Get access to the layer with exception if layer is not found.

◆ query_layer() [2/2]

layer_t * so_5::environment_t::query_layer ( const std::type_index &  type) const
private

Access to an additional layer.

◆ query_layer_noexcept()

template<class SO_Layer >
SO_Layer* so_5::environment_t::query_layer_noexcept ( ) const
inline

Get access to the layer without raising exception if layer is not found.

◆ query_named_dispatcher()

dispatcher_ref_t so_5::environment_t::query_named_dispatcher ( const std::string &  disp_name)

Get named dispatcher.

Returns
A reference to the dispatcher with the name disp_name. Zero reference if a dispatcher with such name is not found.
Parameters
disp_nameDispatcher name.

◆ register_agent_as_coop() [1/8]

template<class A >
void so_5::environment_t::register_agent_as_coop ( nonempty_name_t  coop_name,
std::unique_ptr< A >  agent 
)
inline

◆ register_agent_as_coop() [2/8]

template<class A >
void so_5::environment_t::register_agent_as_coop ( autoname_indicator_t   indicator(),
std::unique_ptr< A >  agent 
)
inline

Register single agent as a cooperation with automatically generated name.

Since
v.5.5.1.

It is just a helper methods for convience.

Usage sample:

std::unique_ptr< my_agent > a( new my_agent(...) );
so_env.register_agent_as_coop( so_5::autoname, std::move(a) );

◆ register_agent_as_coop() [3/8]

void so_5::environment_t::register_agent_as_coop ( nonempty_name_t  coop_name,
agent_t agent 
)
inline

Register single agent as a cooperation.

Since
v.5.2.1

It is just a helper methods for convience.

Usage sample:

so_env.register_agent_as_coop(
"sample_coop",
new my_agent_t(...) );

◆ register_agent_as_coop() [4/8]

void so_5::environment_t::register_agent_as_coop ( autoname_indicator_t   indicator(),
agent_t agent 
)
inline

Register single agent as a cooperation with automatically generated name.

Since
v.5.5.1

It is just a helper methods for convience.

Usage sample:

so_env.register_agent_as_coop( so_5::autoname, new my_agent_t(...) );

◆ register_agent_as_coop() [5/8]

template<class A >
void so_5::environment_t::register_agent_as_coop ( nonempty_name_t  coop_name,
std::unique_ptr< A >  agent,
disp_binder_unique_ptr_t  disp_binder 
)
inline

Register single agent as a cooperation with specified dispatcher binder.

Since
v.5.2.1

It is just a helper methods for convience.

Usage sample:

std::unique_ptr< my_agent > a( new my_agent(...) );
so_env.register_agent_as_coop(
"sample_coop",
std::move(a),
"active_group",
"some_active_group" ) );

◆ register_agent_as_coop() [6/8]

template<class A >
void so_5::environment_t::register_agent_as_coop ( autoname_indicator_t   indicator(),
std::unique_ptr< A >  agent,
disp_binder_unique_ptr_t  disp_binder 
)
inline

Register single agent as a cooperation with specified dispatcher binder and automatically generated name.

Since
v.5.5.1

It is just a helper methods for convience.

Usage sample:

std::unique_ptr< my_agent > a( new my_agent(...) );
so_env.register_agent_as_coop(
std::move(a),
"active_group",
"some_active_group" ) );

◆ register_agent_as_coop() [7/8]

void so_5::environment_t::register_agent_as_coop ( nonempty_name_t  coop_name,
agent_t agent,
disp_binder_unique_ptr_t  disp_binder 
)
inline

Register single agent as a cooperation with specified dispatcher binder.

Since
v.5.2.1

It is just a helper methods for convience.

Usage sample:

so_env.register_agent_as_coop(
"sample_coop",
new my_agent_t(...),
"active_group",
"some_active_group" ) );

◆ register_agent_as_coop() [8/8]

void so_5::environment_t::register_agent_as_coop ( autoname_indicator_t   indicator(),
agent_t agent,
disp_binder_unique_ptr_t  disp_binder 
)
inline

Register single agent as a cooperation with specified dispatcher binder and automatically generated name.

Since
v.5.5.1

It is just a helper methods for convience.

Usage sample:

so_env.register_agent_as_coop(
new my_agent_t(...),
"active_group",
"some_active_group" ) );

◆ register_coop()

void so_5::environment_t::register_coop ( coop_unique_ptr_t  agent_coop)

Register a cooperation.

The cooperation registration includes following steps:

  • binding agents to the cooperation object;
  • checking uniques of the cooperation name. The cooperation will not be registered if its name isn't unique;
  • agent_t::so_define_agent() will be called for each agent in the cooperation;
  • binding of each agent to the dispatcher.

If all these actions are successful then the cooperation is marked as registered.

Parameters
agent_coopCooperation to be registered.
Examples:
so_5/hardwork_imit/main.cpp, so_5/make_pipeline/main.cpp, so_5/private_dispatcher_hello/main.cpp, and so_5/private_dispatcher_restarts/main.cpp.

◆ remove_extra_layer()

void so_5::environment_t::remove_extra_layer ( const std::type_index &  type)
private

Remove an additional layer.

◆ remove_stop_guard()

void so_5::environment_t::remove_stop_guard ( stop_guard_shptr_t  guard)

Remove stop_guard and complete the stop operation if necessary.

Every stop_guard which was added to the environment must be explicitely removed from the environment. It is done by this method. If there is no more stop_guard and the stop operation is in progress then the environment will complete the stop operation.

Usage examples:

// Note: an exception can be thrown if stop is in progress
class my_stop_guard
, public std::enable_shared_from_this< my_stop_guard >
{...};
class my_agent : public so_5::agent_t
{
...
void on_some_event()
{
// We need a stop_guard here.
m_my_guard = std::make_shared< my_stop_guard >(...);
so_environment().setup_stop_guard( m_my_guard );
}
void on_work_finished_signal()
{
// Stop_guard must be removed now.
so_environment().remove_stop_guard( m_my_guard );
}
private :
};
Since
v.5.5.19.2
Parameters
guardStop guard to be removed.
Examples:
so_5/stop_guard/main.cpp.

◆ run()

void so_5::environment_t::run ( )

Run the SObjectizer Run-Time.

◆ schedule_timer() [1/6]

template<class Message >
so_5::timer_id_t so_5::environment_t::schedule_timer ( std::type_index  subscription_type,
std::unique_ptr< Message >  msg,
message_mutability_t  mutability,
const mbox_t mbox,
std::chrono::steady_clock::duration  pause,
std::chrono::steady_clock::duration  period 
)
inline

Schedule timer event.

Attention
Values of pause and period should be non-negative.
Since
v.5.5.19
Parameters
subscription_typeMessage type for searching subscribers.
msgMessage to be sent after timeout.
mutabilityMessage mutability.
mboxMbox to which message will be delivered.
pauseTimeout before the first delivery.
periodPeriod of the delivery repetition for periodic messages.
Note
Value 0 indicates that it's not periodic message (will be delivered one time).

◆ schedule_timer() [2/6]

template<class Message >
so_5::timer_id_t so_5::environment_t::schedule_timer ( std::unique_ptr< Message >  msg,
const mbox_t mbox,
std::chrono::steady_clock::duration  pause,
std::chrono::steady_clock::duration  period 
)
inline

Schedule timer event.

Attention
Values of pause and period should be non-negative.
Since
v.5.5.0
Parameters
msgMessage to be sent after timeout.
mboxMbox to which message will be delivered.
pauseTimeout before the first delivery.
periodPeriod of the delivery repetition for periodic messages.
Note
Value 0 indicates that it's not periodic message (will be delivered one time).

◆ schedule_timer() [3/6]

template<class Message >
so_5::timer_id_t so_5::environment_t::schedule_timer ( std::unique_ptr< Message >  msg,
const mbox_t mbox,
unsigned int  delay_msec,
unsigned int  period_msec 
)
inline

Schedule timer event.

Deprecated:
Obsolete in v.5.5.0. Use versions with std::chrono::steady_clock::duration parameters.
Parameters
msgMessage to be sent after timeout.
mboxMbox to which message will be delivered.
delay_msecTimeout before the first delivery.
period_msecPeriod of the delivery repetition for periodic messages.
Note
Value 0 indicates that it's not periodic message (will be delivered one time).

◆ schedule_timer() [4/6]

template<class Message >
so_5::timer_id_t so_5::environment_t::schedule_timer ( const mbox_t mbox,
std::chrono::steady_clock::duration  pause,
std::chrono::steady_clock::duration  period 
)
inline

Schedule a timer event for a signal.

Attention
Values of pause and period should be non-negative.
Since
v.5.5.0
Parameters
mboxMbox to which signal will be delivered.
pauseTimeout before the first delivery.
periodPeriod of the delivery repetition for periodic messages.
Note
Value 0 indicates that it's not periodic message (will be delivered one time).

◆ schedule_timer() [5/6]

template<class Message >
so_5::timer_id_t so_5::environment_t::schedule_timer ( const mbox_t mbox,
unsigned int  delay_msec,
unsigned int  period_msec 
)
inline

Schedule a timer event for a signal.

Deprecated:
Obsolete in v.5.5.0. Use versions with std::chrono::steady_clock::duration parameters.
Parameters
mboxMbox to which signal will be delivered.
delay_msecTimeout before the first delivery.
period_msecPeriod of the delivery repetition for periodic messages.
Note
Value 0 indicates that it's not periodic message (will be delivered one time).

◆ schedule_timer() [6/6]

so_5::timer_id_t so_5::environment_t::schedule_timer ( const std::type_index &  type_wrapper,
const message_ref_t msg,
const mbox_t mbox,
std::chrono::steady_clock::duration  pause,
std::chrono::steady_clock::duration  period 
)

Schedule timer event.

Attention
Values of pause and period should be non-negative.
Note
Before v.5.5.19 this method was private.
Parameters
type_wrapperMessage type.
msgMessage to be sent after timeout.
mboxMbox to which message will be delivered.
pauseTimeout before the first delivery.
periodPeriod of the delivery repetition for periodic messages.
Note
Value 0 indicates that it's not periodic message (will be delivered one time).

◆ self_ref()

environment_t & so_5::environment_t::self_ref ( )
private

Auxiliary methods for getting reference to itself.

Could be used in constructors without compiler warnings.

◆ setup_stop_guard()

Set up a new stop_guard.

Usage examples:

// Add a stop_guard.
// Note: an exception can be thrown if stop is in progress
class my_stop_guard
, public std::enable_shared_from_this< my_stop_guard >
{...};
class my_agent : public so_5::agent_t
{
...
void on_some_event()
{
// We need a stop_guard here.
m_my_guard = std::make_shared< my_stop_guard >(...);
so_environment().setup_stop_guard( m_my_guard );
}
private :
};
//
// Add a stop_guard without throwing an exception if stop is in progress
//
class my_stop_guard
, public std::enable_shared_from_this< my_stop_guard >
{...};
class my_agent : public so_5::agent_t
{
...
void on_some_event()
{
// We need a stop_guard here.
m_my_guard = std::make_shared< my_stop_guard >(...);
const auto r = so_environment().setup_stop_guard(
m_my_guard,
... // handle error here.
}
private :
};
Note
Uniqueness of stop_guard is not checked. It means that it is possible to add the same stop_guard several times. But it seems to be useless.
Since
v.5.5.19.2
Parameters
guardStop guard to be set. Should not be nullptr.
reaction_on_stop_in_progressWhat to do is the stop operation is already in progress?
Examples:
so_5/stop_guard/main.cpp.

◆ single_timer() [1/7]

template<class Message >
void so_5::environment_t::single_timer ( std::unique_ptr< Message >  msg,
const mbox_t mbox,
std::chrono::steady_clock::duration  pause 
)
inline

Schedule a single shot timer event.

Attention
Value of pause should be non-negative.
Since
v.5.5.0
Parameters
msgMessage to be sent after timeout.
mboxMbox to which message will be delivered.
pauseTimeout before delivery.
Examples:
so_5/many_timers/main.cpp.

◆ single_timer() [2/7]

template<class Message >
void so_5::environment_t::single_timer ( std::type_index  subscription_type,
std::unique_ptr< Message >  msg,
message_mutability_t  mutability,
const mbox_t mbox,
std::chrono::steady_clock::duration  pause 
)
inline

Schedule a single shot timer event.

Intended to be used for delaying mutable messages.

Since
v.5.5.19
Parameters
subscription_typeType to be used for searching subscribers.
msgMessage to be sent after timeout.
mutabilityMutability flag for that message.
mboxMbox to which message will be delivered.
pauseTimeout before delivery.

◆ single_timer() [3/7]

template<class Message >
void so_5::environment_t::single_timer ( std::unique_ptr< Message >  msg,
const mbox_t mbox,
unsigned int  delay_msec 
)
inline

Schedule a single shot timer event.

Deprecated:
Obsolete in v.5.5.0. Use versions with std::chrono::steady_clock::duration parameters.
Parameters
msgMessage to be sent after timeout.
mboxMbox to which message will be delivered.
delay_msecTimeout before delivery.

◆ single_timer() [4/7]

template<class Message >
void so_5::environment_t::single_timer ( const mbox_t mbox,
std::chrono::steady_clock::duration  pause 
)
inline

Schedule a single shot timer event for a signal.

Since
v.5.5.0
Parameters
mboxMbox to which signal will be delivered.
pauseTimeout before delivery.

◆ single_timer() [5/7]

template<class Message >
void so_5::environment_t::single_timer ( std::type_index  subscription_type,
const mbox_t mbox,
std::chrono::steady_clock::duration  pause 
)
inline

Schedule a single shot timer event for a signal.

Intended to be used with mutable_msg<signal>.

Since
v.5.5.0
Parameters
subscription_typeType to be used for searching subscribers.
mboxMbox to which signal will be delivered.
pauseTimeout before delivery.

◆ single_timer() [6/7]

template<class Message >
void so_5::environment_t::single_timer ( const mbox_t mbox,
unsigned int  delay_msec 
)
inline

Schedule a single shot timer event for a signal.

Deprecated:
Obsolete in v.5.5.0. Use versions with std::chrono::steady_clock::duration parameters.
Parameters
mboxMbox to which signal will be delivered.
delay_msecTimeout before delivery.

◆ single_timer() [7/7]

void so_5::environment_t::single_timer ( const std::type_index &  type_wrapper,
const message_ref_t msg,
const mbox_t mbox,
std::chrono::steady_clock::duration  pause 
)

Schedule a single shot timer event.

Attention
Value of pause should be non-negative.
Note
Before v.5.5.19 this method was private.
Parameters
type_wrapperMessage type.
msgMessage to be sent after timeout.
mboxMbox to which message will be delivered.
pauseTimeout before the first delivery.

◆ so_make_default_disp_binder()

disp_binder_unique_ptr_t so_5::environment_t::so_make_default_disp_binder ( )

Get binding to the default dispatcher.

Note
This method is part of environment_t for possibility to write custom implementations of environment_infrastructure_t. Because of that this method can be changed or removed in future versions of SObjectizer.
Since
v.5.5.19

◆ stats_controller()

stats::controller_t & so_5::environment_t::stats_controller ( )

Access to controller of run-time monitoring.

Since
v.5.5.4
Examples:
so_5/queue_size_stats/main.cpp.

◆ stats_repository()

stats::repository_t & so_5::environment_t::stats_repository ( )

Access to repository of data sources for run-time monitoring.

Since
v.5.5.4

◆ stop()

void so_5::environment_t::stop ( )

◆ work_thread_activity_tracking()

work_thread_activity_tracking_t so_5::environment_t::work_thread_activity_tracking ( ) const

Get activity tracking flag for the whole SObjectizer Environment.

Since
v.5.5.18

Friends And Related Function Documentation

◆ so_5::impl::internal_env_iface_t

friend class so_5::impl::internal_env_iface_t
friend

Member Data Documentation

◆ m_impl

std::unique_ptr< internals_t > so_5::environment_t::m_impl
private

SObjectizer Environment internals.


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