SObjectizer  5.8
Loading...
Searching...
No Matches
so_5::coop_handle_t Class Reference

Type of smart handle for a cooperation. More...

#include <coop_handle.hpp>

Public Member Functions

 coop_handle_t ()
 
 operator bool () const noexcept
 Is this handle empty?
 
bool operator! () const noexcept
 Is this non-empty handle?
 
auto id () const noexcept
 Get the ID of the coop.
 

Static Public Attributes

static constexpr const coop_id_t invalid_coop_id = 0u
 

Private Member Functions

 coop_handle_t (coop_id_t id, std::shared_ptr< coop_t > coop)
 Initializing constructor.
 

Private Attributes

coop_id_t m_id
 ID of cooperation.
 
std::weak_ptr< coop_tm_coop
 Pointer for cooperation.
 

Friends

class so_5::coop_t
 
coop_shptr_t low_level_api::to_shptr (const coop_handle_t &)
 
coop_shptr_t low_level_api::to_shptr_noexcept (const coop_handle_t &) noexcept
 
std::ostream & operator<< (std::ostream &to, const coop_handle_t &what)
 A tool for dumping coop_handle to ostream.
 
bool operator== (const coop_handle_t &a, const coop_handle_t &b) noexcept
 
bool operator!= (const coop_handle_t &a, const coop_handle_t &b) noexcept
 
bool operator< (const coop_handle_t &a, const coop_handle_t &b) noexcept
 
bool operator<= (const coop_handle_t &a, const coop_handle_t &b) noexcept
 
bool operator> (const coop_handle_t &a, const coop_handle_t &b) noexcept
 
bool operator>= (const coop_handle_t &a, const coop_handle_t &b) noexcept
 

Detailed Description

Type of smart handle for a cooperation.

Type coop_handle_t is used for references to registered coops. Before v.5.6 coops in SObjectizer-5 were identified via strings. Every coop had its own name.

Since v.5.6.0 names are no more used for identificators of coops. SObjectizer's environment_t returns instances of coop_handle_t for every registered coop. This handle can be used for deregistration of the coop at the appropriate time. For example:

class request_manager_t final : public so_5::agent_t {
std::map<request_id_t, so_5::coop_handle_t> active_requests_;
...
void on_new_request(mhood_t<request_t> cmd) {
// Create a new coop for handling that request.
auto coop = so_5::create_child_coop( *this );
...; // Fill the coop with agents.
// Register coop and store its handle in the map of actual requests.
active_requests_[cmd->request_id()] = so_environment().register_coop(std::move(coop));
}
...
void on_cancel_request(mhood_t<cancel_request_t> cmd) {
auto it = active_requests_.find(cmd->request_id());
if(it != active_requests_.end())
// Deregister coop for this request.
}
};
A base class for agents.
Definition agent.hpp:673
environment_t & so_environment() const noexcept
Access to the SObjectizer Environment which this agent is belong.
Definition agent.cpp:987
coop_handle_t register_coop(coop_unique_holder_t agent_coop)
Register a cooperation.
void deregister_coop(coop_handle_t coop, int reason) noexcept
Deregister the cooperation.
A message wrapped to be used as type of argument for event handlers.
Definition mhood.hpp:570
coop_unique_holder_t create_child_coop(agent_t &owner, Args &&... args)
A simple way for creating child cooperation.

Note that coop_handle_t is somewhat like (smart)pointer. It can be empty, e.g. do not point to any coop. Or it can be not-empty. In that case coop_handle_t is very similar to std::weak_ptr.

Since
v.5.6.0
Examples
so_5/child_soenv/main.cpp, so_5/coop_listener/main.cpp, so_5/custom_work_thread_factory/main.cpp, so_5/exception_logger/main.cpp, so_5/make_agent_ref/main.cpp, and so_5/ping_pong_with_owner/main.cpp.

Definition at line 86 of file coop_handle.hpp.

Constructor & Destructor Documentation

◆ coop_handle_t() [1/2]

so_5::coop_handle_t::coop_handle_t ( coop_id_t id,
std::shared_ptr< coop_t > coop )
inlineprivate

Initializing constructor.

Definition at line 108 of file coop_handle.hpp.

◆ coop_handle_t() [2/2]

so_5::coop_handle_t::coop_handle_t ( )
inline

Definition at line 115 of file coop_handle.hpp.

Member Function Documentation

◆ id()

auto so_5::coop_handle_t::id ( ) const
inlinenoexcept

Get the ID of the coop.

Definition at line 135 of file coop_handle.hpp.

◆ operator bool()

so_5::coop_handle_t::operator bool ( ) const
inlinenoexcept

Is this handle empty?

Handle is empty if there is no underlying coop.

Return values
trueif handle is not empty

Definition at line 124 of file coop_handle.hpp.

◆ operator!()

bool so_5::coop_handle_t::operator! ( ) const
inlinenoexcept

Is this non-empty handle?

Handle is empty if there is no underlying coop.

Return values
trueif handle is empty

Definition at line 132 of file coop_handle.hpp.

Friends And Related Symbol Documentation

◆ low_level_api::to_shptr

◆ low_level_api::to_shptr_noexcept

◆ operator!=

bool operator!= ( const coop_handle_t & a,
const coop_handle_t & b )
friend

Definition at line 154 of file coop_handle.hpp.

◆ operator<

bool operator< ( const coop_handle_t & a,
const coop_handle_t & b )
friend

Definition at line 159 of file coop_handle.hpp.

◆ operator<<

std::ostream & operator<< ( std::ostream & to,
const coop_handle_t & what )
friend

A tool for dumping coop_handle to ostream.

Definition at line 138 of file coop_handle.hpp.

◆ operator<=

bool operator<= ( const coop_handle_t & a,
const coop_handle_t & b )
friend

Definition at line 165 of file coop_handle.hpp.

◆ operator==

bool operator== ( const coop_handle_t & a,
const coop_handle_t & b )
friend

Definition at line 148 of file coop_handle.hpp.

◆ operator>

bool operator> ( const coop_handle_t & a,
const coop_handle_t & b )
friend

Definition at line 172 of file coop_handle.hpp.

◆ operator>=

bool operator>= ( const coop_handle_t & a,
const coop_handle_t & b )
friend

Definition at line 178 of file coop_handle.hpp.

◆ so_5::coop_t

friend class so_5::coop_t
friend

Definition at line 88 of file coop_handle.hpp.

Member Data Documentation

◆ invalid_coop_id

const coop_id_t so_5::coop_handle_t::invalid_coop_id = 0u
staticconstexpr

Definition at line 113 of file coop_handle.hpp.

◆ m_coop

std::weak_ptr< coop_t > so_5::coop_handle_t::m_coop
private

Pointer for cooperation.

Attention
This is a weak pointer. It means that it can refer to already destroyed cooperation.

Definition at line 105 of file coop_handle.hpp.

◆ m_id

coop_id_t so_5::coop_handle_t::m_id
private

ID of cooperation.

Definition at line 97 of file coop_handle.hpp.


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