SObjectizer 5.8
Loading...
Searching...
No Matches
internal_agent_iface.hpp
Go to the documentation of this file.
1/*
2 * SObjectizer-5
3 */
4
5/*!
6 * \since
7 * v.5.6.0
8 *
9 * \file
10 * \brief Helper class for accessing private functionality of agent-class.
11 */
12
13#pragma once
14
15#include <so_5/agent.hpp>
16
17#include <so_5/ret_code.hpp>
18
19namespace so_5 {
20
21namespace impl {
22
23//
24// internal_agent_iface_t
25//
26/*!
27 * \brief A special class for access to private/protected members
28 * of agent class.
29 *
30 * \since
31 * v.5.6.0
32 */
33class internal_agent_iface_t final
34 {
36
37 public:
38 explicit internal_agent_iface_t( agent_t & agent ) noexcept
39 : m_agent{ agent }
40 {}
41
42 void
44 {
46 }
47
48 void
53
54 void
55 shutdown_agent() noexcept
56 {
58 }
59
60 /*!
61 * \brief Setter for disp_binder.
62 *
63 * \attention
64 * It's not a thread safe method. But it's expected that it will be used
65 * in the context where just one entity owns the pointer to the agent.
66 *
67 * \since v.5.7.5
68 */
69 void
70 set_disp_binder( disp_binder_shptr_t binder )
71 {
75 "m_agent.m_disp_binder is not nullptr when "
76 "set_disp_binder is called" );
77
78 m_agent.m_disp_binder = std::move(binder);
79 }
80
81 /*!
82 * \brief Getter for disp_binder.
83 *
84 * \attention
85 * It's not a thread safe method. But it's expected that it will be used
86 * in the context where just one entity owns the pointer to the agent.
87 *
88 * \since v.5.7.5
89 */
90 [[nodiscard]]
93 {
97 "m_agent.m_disp_binder is nullptr when "
98 "query_disp_binder is called" );
99
100 return *m_agent.m_disp_binder;
101 }
102
103 /*!
104 * \brief Helper method that drops pointer to disp_binder.
105 *
106 * This method is intended to be used for rollback actions
107 * (for example, when disp_binder is set for the agent, but
108 * agent can't be stored in a coop).
109 *
110 * \attention
111 * It's not a thread safe method. But it's expected that it will be used
112 * in the context where just one entity owns the pointer to the agent.
113 *
114 * \since v.5.7.5
115 */
116 void
118 {
119 m_agent.m_disp_binder.reset();
120 }
121 };
122
123} /* namespace impl */
124
125} /* so_5 */
A base class for agents.
Definition agent.hpp:673
void so_initiate_agent_definition()
A correct initiation of so_define_agent method call.
Definition agent.cpp:829
void shutdown_agent() noexcept
Agent shutdown deriver.
Definition agent.cpp:1029
disp_binder_shptr_t m_disp_binder
Binder for this agent.
Definition agent.hpp:2936
void bind_to_coop(coop_t &coop)
Bind agent to the cooperation.
Definition agent.cpp:1023
Container for cooperation deregistration notificators.
Definition coop.hpp:197
std::vector< coop_dereg_notificator_t > m_notificators
Definition coop.hpp:215
void call_all(environment_t &env, const coop_handle_t &coop, const coop_dereg_reason_t &reason) const noexcept
Call all notificators.
Definition coop.cpp:38
It's a kind of strong typedef for coop's deregistration reason.
Definition coop.hpp:80
Type of smart handle for a cooperation.
Container for cooperation registration notificators.
Definition coop.hpp:129
void call_all(environment_t &env, const coop_handle_t &coop) const noexcept
Call all notificators.
Definition coop.cpp:26
std::vector< coop_reg_notificator_t > m_notificators
Definition coop.hpp:146
Agent cooperation.
Definition coop.hpp:389
coop_shptr_t m_first_child
The head of list of children coops.
Definition coop.hpp:1129
environment_t & environment() const noexcept
Access to SO Environment for which cooperation is bound.
Definition coop.hpp:453
registration_status_t m_registration_status
The registration status of cooperation.
Definition coop.hpp:1092
void decrement_usage_count() noexcept
Decrement usage count for the coop.
Definition coop.hpp:1224
exception_reaction_t exception_reaction() const noexcept
Get the current exception rection flag for that cooperation.
Definition coop.hpp:758
resource_deleter_vector_t m_resource_deleters
Container of user resource deleters.
Definition coop.hpp:1101
disp_binder_shptr_t m_coop_disp_binder
Default agent to the dispatcher binder.
Definition coop.hpp:1026
void deregister(int reason) noexcept
Deregister the cooperation with the specified reason.
Definition coop.hpp:907
void for_each_child(Lambda &&lambda) const
A helper method for doing some actions with children coops.
Definition coop.hpp:1285
exception_reaction_t m_exception_reaction
A reaction to non-handled exception.
Definition coop.hpp:1121
std::mutex m_lock
A lock for synchonization of some operations on coop.
Definition coop.hpp:1077
coop_handle_t m_parent
Parent coop.
Definition coop.hpp:1023
registration_status_t
Registration status.
Definition coop.hpp:956
@ deregistration_in_final_stage
Deregistration of the coop is in the final stage.
@ coop_registered
Cooperation is registered.
@ coop_deregistering
Cooperation is in deregistration process.
atomic_counter_t m_reference_count
Count for entities.
Definition coop.hpp:1043
void remove_child(coop_t &child) noexcept
Remove a child from the parent coop.
Definition coop.hpp:1267
coop_dereg_reason_t m_dereg_reason
Deregistration reason.
Definition coop.hpp:1110
void increment_usage_count() noexcept
Increment usage count for the coop.
Definition coop.hpp:1196
coop_reg_notificators_container_ref_t m_reg_notificators
Notificators for registration event.
Definition coop.hpp:1050
coop_shptr_t m_prev_sibling
The previous coop in sibling's chain.
Definition coop.hpp:1141
void add_child(coop_shptr_t child)
Add a new child to the parent coop.
Definition coop.hpp:1242
agent_array_t m_agent_array
Cooperation agents.
Definition coop.hpp:1029
outliving_reference_t< environment_t > m_env
SObjectizer Environment for which cooperation is created.
Definition coop.hpp:1032
coop_dereg_notificators_container_ref_t m_dereg_notificators
Notificators for deregistration event.
Definition coop.hpp:1057
coop_shptr_t m_next_sibling
The next coop in sibling's chain.
Definition coop.hpp:1153
Interface for dispatcher binders.
virtual void bind(agent_t &agent) noexcept=0
Bind agent to dispatcher.
virtual void unbind(agent_t &agent) noexcept=0
Unbind agent from dispatcher.
virtual void preallocate_resources(agent_t &agent)=0
Allocate resources in dispatcher for new agent.
virtual void undo_preallocation(agent_t &agent) noexcept=0
Undo resources allocation.
SObjectizer Environment.
exception_reaction_t exception_reaction() const noexcept
An exception reaction for the whole SO Environment.
The base class for all SObjectizer exceptions.
Definition exception.hpp:34
A helper for coop's deregistration procedure.
Definition coop.cpp:415
deregistration_performer_t(coop_t &coop, coop_dereg_reason_t reason) noexcept
Definition coop.cpp:465
registration_performer_t(coop_t &coop) noexcept
Definition coop.cpp:387
An internal class with real implementation of coop's logic.
Definition coop.hpp:249
static void destroy_content(coop_t &coop) noexcept
Perform all necessary cleanup actions for coop.
Definition coop.cpp:54
static void do_add_agent(coop_t &coop, agent_ref_t agent_ref, disp_binder_shptr_t disp_binder)
Add agent to the cooperation with the dispatcher binding.
Definition coop.cpp:95
static void do_final_deregistration_actions(coop_t &coop)
Perform final deregistration actions for an coop.
Definition coop.cpp:501
static void do_add_child(coop_t &parent, coop_shptr_t child)
Perform addition of a new child coop.
Definition coop.cpp:521
static void add_dereg_notificator(coop_t &coop, coop_dereg_notificator_t notificator)
Add notificator about cooperation deregistration event.
Definition coop.cpp:146
static exception_reaction_t exception_reaction(const coop_t &coop) noexcept
Get exception reaction for coop.
Definition coop.cpp:157
static void do_remove_child(coop_t &parent, coop_t &child) noexcept
Perform removement of a child coop.
Definition coop.cpp:560
static void add_reg_notificator(coop_t &coop, coop_reg_notificator_t notificator)
Add notificator about cooperation registration event.
Definition coop.cpp:136
static void do_decrement_reference_count(coop_t &coop) noexcept
Do decrement reference count for a coop.
Definition coop.cpp:174
static void do_deregistration_specific_actions(coop_t &coop, coop_dereg_reason_t reason) noexcept
Perform actions related to the deregistration of coop.
Definition coop.cpp:493
static void do_registration_specific_actions(coop_t &coop)
Perform actions related to the registration of coop.
Definition coop.cpp:405
static void do_add_agent(coop_t &coop, agent_ref_t agent_ref)
Add agent to cooperation.
Definition coop.cpp:79
internal_agent_iface_t(agent_t &agent) noexcept
disp_binder_t & query_disp_binder() const
Getter for disp_binder.
void drop_disp_binder() noexcept
Helper method that drops pointer to disp_binder.
void set_disp_binder(disp_binder_shptr_t binder)
Setter for disp_binder.
A helper class for accessing the functionality of environment-class which is specific for SObjectizer...
internal_env_iface_t(environment_t &env)
Initializing constructor.
void ready_to_deregister_notify(coop_shptr_t coop) noexcept
Notification about readiness to the deregistration.
Template class for smart reference wrapper on the atomic_refcounted_t.
T & operator*() const noexcept
T & get() const noexcept
#define SO_5_THROW_EXCEPTION(error_code, desc)
Definition exception.hpp:74
Enumeration of cooperation deregistration reasons.
Definition coop.hpp:39
const int parent_deregistration
Deregistration because parent cooperation deregistration.
Definition coop.hpp:52
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.
auto invoke_noexcept_code(L lambda) noexcept -> decltype(lambda())
void do_add_notificator_to(intrusive_ptr_t< C > &to, N notificator)
Helper function for notificator addition.
Definition coop.cpp:121
Details of SObjectizer run-time implementations.
Definition agent.cpp:780
coop_shptr_t to_shptr_noexcept(const coop_handle_t &) noexcept
A helper function for unsafe extraction of shared_ptr to coop from coop_handle instance.
coop_shptr_t to_shptr(const coop_handle_t &)
A helper function for safe extraction of shared_ptr to coop from coop_handle instance.
Private part of message limit implementation.
Definition agent.cpp:33
const int rc_coop_define_agent_failed
Cooperation couldn't be registered.
Definition ret_code.hpp:74
const int rc_coop_is_not_in_registered_state
An attempt to do something with coop that is not in registered state.
Definition ret_code.hpp:395
exception_reaction_t
A reaction of SObjectizer to an exception from agent event.
Definition agent.hpp:65
@ inherit_exception_reaction
Exception reaction should be inherited from SO Environment.
Definition agent.hpp:81
const int rc_agent_to_disp_binding_failed
Binding of agent to dispatcher failed.
Definition ret_code.hpp:81
const int rc_disp_binder_already_set_for_agent
The dispatcher binder is already set for the agent.
Definition ret_code.hpp:492
const int rc_no_disp_binder_for_agent
The dispatcher binder is not set for the agent yet.
Definition ret_code.hpp:505