2
3
6
7
8
9
10
11
12#include <so_5/impl/coop_repository_basis.hpp>
14#include <so_5/environment.hpp>
16#include <so_5/details/rollback_on_exception.hpp>
31
32
33
34
35
61 std::lock_guard< std::mutex > lock{ m_lock };
64 for_each_child( [](
coop_t & child ) {
72 coop_listener_unique_ptr_t coop_listener )
76 m_root_coop = std::make_shared< root_coop_t >(
85 disp_binder_shptr_t default_binder )
88 parent = m_root_coop->handle();
90 return coop_private_iface_t::make_coop(
93 std::move(default_binder),
105 std::lock_guard< std::mutex > lock{ m_lock };
106 if( status_t::normal != m_status )
108 rc_unable_to_register_coop_during_shutdown,
109 "a new coop can't be registered when shutdown "
114 ++m_registrations_in_progress;
118 const auto handle_registrations_in_progress = [
this]()
noexcept {
121 --m_registrations_in_progress;
125 if( 0u == m_registrations_in_progress &&
126 status_t::pending_shutdown == m_status )
128 m_shutdown_enabled_cond.notify_one();
138 const auto coop_size = coop_ptr->size();
141 result = do_registration_specific_actions( std::move(coop_ptr) );
145 details::invoke_noexcept_code( [&] {
146 std::lock_guard< std::mutex > lock{ m_lock };
149 m_total_agents += coop_size;
152 handle_registrations_in_progress();
159 details::invoke_noexcept_code( [&] {
160 std::lock_guard< std::mutex > lock{ m_lock };
162 handle_registrations_in_progress();
174 coop_shptr_t coop )
noexcept
178 std::lock_guard< std::mutex > lock{ m_lock };
180 m_total_agents -= coop->size();
185 coop_private_iface_t::do_final_deregistration_actions( *coop );
190 const auto handle = coop->handle();
191 const auto dereg_reason =
192 coop_private_iface_t::dereg_reason( *coop );
193 const auto dereg_notificators =
194 coop_private_iface_t::giveout_dereg_notificators( *coop );
200 if( dereg_notificators )
201 dereg_notificators->call_all(
207 if( m_coop_listener )
208 m_coop_listener->on_deregistered(
217 std::lock_guard< std::mutex > lock{ m_lock };
219 return final_deregistration_result_t{
222 0u != m_total_coops || 0 != m_registrations_in_progress,
223 status_t::shutdown == m_status && 0u == m_total_coops
233 std::unique_lock< std::mutex > lock{ m_lock };
235 if( !m_registrations_in_progress )
246 m_shutdown_enabled_cond.wait( lock,
247 [
this] {
return 0 == m_registrations_in_progress; } );
253 m_root_coop->deregister_children_on_shutdown();
260 std::lock_guard< std::mutex > lock{ m_lock };
280 std::lock_guard< std::mutex > lock{ m_lock };
322 coop_shptr_t coop{ coop_private_iface_t::make_from( std::move(coop_ptr) ) };
331 coop_private_iface_t::do_registration_specific_actions( *coop );
333 auto result = coop->handle();
338 auto reg_notificators =
339 coop_private_iface_t::giveout_reg_notificators( *coop );
340 if( reg_notificators )
341 reg_notificators->call_all( m_env.get(), result );
344 if( m_coop_listener )
345 m_coop_listener->on_registered( m_env.get(), result );
Type of smart handle for a cooperation.
registration_status_t m_registration_status
The registration status of cooperation.
void deregister(int reason) noexcept
Deregister the cooperation with the specified reason.
registration_status_t
Registration status.
@ coop_registered
Cooperation is registered.
A special type that plays role of unique_ptr for coop.
An interface for environment_infrastructure entity.
Special guard to increment and decrement cooperation usage counters.
coop_usage_counter_guard_t(coop_t &coop)
~coop_usage_counter_guard_t()
A special class for accessing private members of agent_coop.
static void decrement_usage_count(coop_t &coop)
static void increment_usage_count(coop_t &coop) noexcept
root_coop_t(coop_id_t id, outliving_reference_t< environment_t > env)
void deregister_children_on_shutdown() noexcept
A basic part for various implementations of coop_repository.
environment_t & environment()
Access to SObjectizer Environment.
status_t m_status
Status of repository.
coop_unique_holder_t make_coop(coop_handle_t parent, disp_binder_shptr_t default_binder)
Create an instance of a new coop.
void deregister_all_coop() noexcept
Deregisted all cooperations.
coop_repository_basis_t(outliving_reference_t< environment_t > environment, coop_listener_unique_ptr_t coop_listener)
final_deregistration_result_t final_deregister_coop(coop_shptr_t coop) noexcept
Do final actions of the cooperation deregistration.
try_switch_to_shutdown_result_t
Result of attempt to switch to shutdown state.
@ already_in_shutdown_state
coop_handle_t do_registration_specific_actions(coop_unique_holder_t coop_ptr)
An actual implementation of registration of a coop.
environment_infrastructure_t::coop_repository_stats_t query_stats()
Get the current statistic for run-time monitoring.
status_t
Enumeration of possible repository statuses.
try_switch_to_shutdown_result_t try_switch_to_shutdown() noexcept
Try to switch repository to shutdown state.
coop_handle_t register_coop(coop_unique_holder_t agent_coop)
Register cooperation.
Helper class for indication of long-lived reference via its type.
#define SO_5_THROW_EXCEPTION(error_code, desc)
Enumeration of cooperation deregistration reasons.
const int shutdown
Deregistration because SObjectizer Environment shutdown.
Some reusable and low-level classes/functions which can be used in public header files.
Details of SObjectizer run-time implementations.
Private part of message limit implementation.
Statistical data for run-time monitoring of coop repository content.