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
44 disp_binder_shptr_t{}
,
61 std::lock_guard< std::mutex > lock{
m_lock };
72 coop_listener_unique_ptr_t coop_listener )
85 disp_binder_shptr_t default_binder )
93 std::move(default_binder)
,
105 std::lock_guard< std::mutex > lock{
m_lock };
109 "a new coop can't be registered when shutdown "
118 const auto handle_registrations_in_progress = [
this]()
noexcept {
138 const auto coop_size = coop_ptr
->size();
146 std::lock_guard< std::mutex > lock{
m_lock };
152 handle_registrations_in_progress();
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 };
191 const auto dereg_reason =
193 const auto dereg_notificators =
200 if( dereg_notificators )
217 std::lock_guard< std::mutex > lock{
m_lock };
233 std::unique_lock< std::mutex > lock{
m_lock };
260 std::lock_guard< std::mutex > lock{
m_lock };
280 std::lock_guard< std::mutex > lock{
m_lock };
338 auto reg_notificators =
340 if( reg_notificators )
void call_all(environment_t &env, const coop_handle_t &coop, const coop_dereg_reason_t &reason) const noexcept
Call all notificators.
Type of smart handle for a cooperation.
bool operator!() const noexcept
Is this non-empty handle?
virtual void on_registered(environment_t &so_env, const coop_handle_t &coop) noexcept=0
Hook for the cooperation registration event.
virtual void on_deregistered(environment_t &so_env, const coop_handle_t &coop, const coop_dereg_reason_t &reason) noexcept=0
Hook for the cooperation deregistration event.
void call_all(environment_t &env, const coop_handle_t &coop) const noexcept
Call all notificators.
registration_status_t m_registration_status
The registration status of cooperation.
void deregister(int reason) noexcept
Deregister the cooperation with the specified reason.
void for_each_child(Lambda &&lambda) const
A helper method for doing some actions with children coops.
std::mutex m_lock
A lock for synchonization of some operations on coop.
registration_status_t
Registration status.
@ coop_registered
Cooperation is registered.
std::size_t size() const noexcept
Get agent count in the cooperation.
coop_handle_t handle() noexcept
Get handle for this coop.
coop_t(coop_id_t id, coop_handle_t parent, disp_binder_shptr_t coop_disp_binder, outliving_reference_t< environment_t > env)
Constructor.
A special type that plays role of unique_ptr for coop.
coop_t * operator->() const noexcept
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 coop_unique_holder_t make_coop(coop_id_t id, coop_handle_t parent, disp_binder_shptr_t default_binder, outliving_reference_t< environment_t > env)
static coop_reg_notificators_container_ref_t giveout_reg_notificators(coop_t &coop) noexcept
static void do_final_deregistration_actions(coop_t &coop)
static coop_dereg_reason_t dereg_reason(const coop_t &coop) noexcept
static void decrement_usage_count(coop_t &coop)
static coop_dereg_notificators_container_ref_t giveout_dereg_notificators(coop_t &coop) noexcept
static void increment_usage_count(coop_t &coop) noexcept
static void do_registration_specific_actions(coop_t &coop)
static coop_shptr_t make_from(coop_unique_holder_t holder) 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.
std::size_t m_total_coops
Total count of coops.
std::mutex m_lock
Lock for coop 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.
outliving_reference_t< environment_t > m_env
Environment to work in.
coop_repository_basis_t(outliving_reference_t< environment_t > environment, coop_listener_unique_ptr_t coop_listener)
std::atomic_uint_fast64_t m_coop_id_counter
Counter for coop_ids.
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.
std::size_t m_registrations_in_progress
Count of coops those are in registration now.
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.
std::shared_ptr< root_coop_t > m_root_coop
A special root coop.
coop_handle_t register_coop(coop_unique_holder_t agent_coop)
Register cooperation.
std::condition_variable m_shutdown_enabled_cond
std::size_t m_total_agents
Total count of agents.
coop_listener_unique_ptr_t m_coop_listener
Cooperation actions listener.
T * operator->() const noexcept
Helper class for indication of long-lived reference via its type.
outliving_reference_t(outliving_reference_t const &o) noexcept
#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.
auto invoke_noexcept_code(L lambda) noexcept -> decltype(lambda())
Details of SObjectizer run-time implementations.
Private part of message limit implementation.
const int rc_unable_to_register_coop_during_shutdown
It is impossible to register cooperation during SObjectizer Environment shutdown.
Statistical data for run-time monitoring of coop repository content.
final_deregistration_result_t(bool has_live_coop, bool total_deregistration_completed)