SObjectizer  5.8
Loading...
Searching...
No Matches
coop_repository_basis.hpp
Go to the documentation of this file.
1/*
2 SObjectizer 5.
3*/
4
5/*!
6 * \file
7 * \brief Basic part of coop_repository functionality.
8 *
9 * \since
10 * v.5.5.19
11 */
12
13#pragma once
14
15#include <so_5/impl/coop_private_iface.hpp>
16
17#include <so_5/exception.hpp>
18
19#include <so_5/agent.hpp>
20#include <so_5/coop_listener.hpp>
21#include <so_5/environment_infrastructure.hpp>
22
23#include <so_5/stats/repository.hpp>
24
25#include <map>
26#include <memory>
27#include <set>
28#include <string>
29#include <mutex>
30#include <condition_variable>
31
32#if defined( SO_5_MSVC )
33 #pragma warning(push)
34 #pragma warning(disable: 4251)
35#endif
36
37namespace so_5
38{
39
40namespace impl
41{
42
43//
44// coop_repository_basis_t
45//
46
47/*!
48 * \brief A basic part for various implementations of coop_repository.
49 *
50 * \since
51 * v.5.5.19
52 */
54{
57
58public:
60 //! SObjectizer Environment.
62 //! Cooperation action listener.
63 coop_listener_unique_ptr_t coop_listener );
64
65 //! Create an instance of a new coop.
66 /*!
67 * \since
68 * v.5.6.0
69 */
70 [[nodiscard]]
73 //! Parent coop.
74 //! Can be empty. In that case there won't be any parent coop.
75 coop_handle_t parent,
76 //! Default binder for that coop.
77 disp_binder_shptr_t default_binder );
78
79 //! Register cooperation.
80 [[nodiscard]]
83 //! Cooperation to be registered.
84 coop_unique_holder_t agent_coop );
85
86 /*!
87 * Type for return value of final_deregister_coop method.
88 *
89 * This method must return two boolean values:
90 * - the first value equals to true if there is at least one live coop;
91 * - the second value equals to true if total deregistration is in
92 * progress and there is no more live coops;
93 *
94 * \since
95 * v.5.5.19
96 */
97 struct [[nodiscard]] final_deregistration_result_t
98 {
101
103 bool has_live_coop,
104 bool total_deregistration_completed )
105 : m_has_live_coop( has_live_coop )
106 , m_total_deregistration_completed( total_deregistration_completed )
107 {}
108 };
109
110 //! Do final actions of the cooperation deregistration.
111 /*!
112 * \note
113 * This method is noexcept since v.5.8.0.
114 *
115 * \retval true there are some live cooperations.
116 * \retval false there is no more live cooperations.
117 */
120 //! Cooperation name to be deregistered.
121 coop_shptr_t coop ) noexcept;
122
123 //! Deregisted all cooperations.
124 /*!
125 * All cooperations will be deregistered at the SObjectizer shutdown.
126 *
127 * \return Count of coops to be completely deregistered.
128 */
129 void
130 deregister_all_coop() noexcept;
131
132 /*!
133 * \brief Result of attempt to switch to shutdown state.
134 *
135 * \since
136 * v.5.6.0
137 */
138 enum class [[nodiscard]] try_switch_to_shutdown_result_t
139 {
140 switched,
142 };
143
144 /*!
145 * \brief Try to switch repository to shutdown state.
146 *
147 * \note
148 * This method doesn't call deregister_all_coop().
149 * It only changes state of repository to 'shutdown'.
150 * This prevents from registration of new cooperations.
151 *
152 * \since
153 * v.5.6.0
154 */
156 try_switch_to_shutdown() noexcept;
157
158 /*!
159 * \since
160 * v.5.5.0
161 *
162 * \brief Access to SObjectizer Environment.
163 *
164 * \note This access is necessary to use error_logger for
165 * logging error messages.
166 */
167 [[nodiscard]]
169 environment();
170
171 /*!
172 * \since
173 * v.5.5.4
174 *
175 * \brief Get the current statistic for run-time monitoring.
176 */
177 [[nodiscard]]
179 query_stats();
180
181protected:
182 class root_coop_t;
183
184 //! Enumeration of possible repository statuses.
185 enum class status_t
186 {
187 normal,
190 };
191
192 //! Environment to work in.
194
195 //! Counter for coop_ids.
197
198 //! Lock for coop repository.
200
201 //! Status of repository.
203
204 //! Condition variable to wait a possibility to do actions
205 //! in deregister_all_coop.
207
208 //! Total count of coops.
210
211 //! Total count of agents.
213
214 //! Count of coops those are in registration now.
216
217 //! Cooperation actions listener.
219
220 //! A special root coop.
221 /*!
222 * \attention
223 * This coop can't be deregistered!
224 */
226
227 //! An actual implementation of registration of a coop.
228 [[nodiscard]]
231};
232
233} /* namespace impl */
234
235} /* namespace so_5 */
236
237#if defined( SO_5_MSVC )
238 #pragma warning(pop)
239#endif
Type of smart handle for a cooperation.
Agent cooperation.
Definition coop.hpp:389
registration_status_t m_registration_status
The registration status of cooperation.
Definition coop.hpp:1092
void deregister(int reason) noexcept
Deregister the cooperation with the specified reason.
Definition coop.hpp:907
registration_status_t
Registration status.
Definition coop.hpp:956
@ coop_registered
Cooperation is registered.
A special type that plays role of unique_ptr for coop.
Definition coop.hpp:1342
An interface for environment_infrastructure entity.
SObjectizer Environment.
Special guard to increment and decrement cooperation usage counters.
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)
A basic part for various implementations of coop_repository.
environment_t & environment()
Access to SObjectizer Environment.
coop_repository_basis_t(coop_repository_basis_t &&)=delete
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.
coop_handle_t do_registration_specific_actions(coop_unique_holder_t coop_ptr)
An actual implementation of registration of a coop.
coop_repository_basis_t(const coop_repository_basis_t &)=delete
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::size_t m_total_agents
Total count of agents.
coop_listener_unique_ptr_t m_coop_listener
Cooperation actions listener.
Helper class for indication of long-lived reference via its type.
Definition outliving.hpp:98
#define SO_5_TYPE
Definition declspec.hpp:46
#define SO_5_THROW_EXCEPTION(error_code, desc)
Definition exception.hpp:74
Enumeration of cooperation deregistration reasons.
Definition coop.hpp:39
const int shutdown
Deregistration because SObjectizer Environment shutdown.
Definition coop.hpp:49
Some reusable and low-level classes/functions which can be used in public header files.
Details of SObjectizer run-time implementations.
Definition agent.cpp:905
Private part of message limit implementation.
Definition agent.cpp:33
Statistical data for run-time monitoring of coop repository content.
final_deregistration_result_t(bool has_live_coop, bool total_deregistration_completed)