SObjectizer-5 Extra
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
so_5::extra::mboxes::proxy::simple_t Class Reference

A simple proxy that delegates all calls to underlying actual mbox. More...

#include <proxy.hpp>

Inheritance diagram for so_5::extra::mboxes::proxy::simple_t:

Public Member Functions

 simple_t (::so_5::mbox_t underlying_mbox)
 Initializing constructor. More...
 

Protected Member Functions

::so_5::abstract_message_box_t & underlying_mbox () const noexcept
 An accessor to actual mbox. More...
 

Private Member Functions

::so_5::mbox_t ensure_underlying_mbox_not_null (::so_5::mbox_t mbox)
 Ensure that underlying mbox is not nullptr. More...
 

Private Attributes

const ::so_5::mbox_t m_underlying_mbox
 Actual underlying mbox to be used for all calls. More...
 

Simple implementation of inherited methods.

void do_deliver_message_from_timer (const std::type_index &msg_type, const ::so_5::message_ref_t &message) override
 
mbox_id_t id () const override
 
void subscribe_event_handler (const std::type_index &type_index, const ::so_5::message_limit::control_block_t *limit, ::so_5::agent_t &subscriber) override
 
void unsubscribe_event_handlers (const std::type_index &type_index, ::so_5::agent_t &subscriber) override
 
std::string query_name () const override
 
mbox_type_t type () const override
 
void do_deliver_message (const std::type_index &msg_type, const ::so_5::message_ref_t &message, unsigned int overlimit_reaction_deep) override
 
void set_delivery_filter (const std::type_index &msg_type, const ::so_5::delivery_filter_t &filter, ::so_5::agent_t &subscriber) override
 
void drop_delivery_filter (const std::type_index &msg_type, ::so_5::agent_t &subscriber) noexcept override
 
so_5::environment_t & environment () const noexcept override
 

Detailed Description

A simple proxy that delegates all calls to underlying actual mbox.

Sometimes it is necessary to create an own mbox that does some specific task. For example, counts the number of message of some specific type. Something like:

class my_mbox final : public so_5::abstract_message_box_t
{
bool is_appropriate_message_type(
const std::type_index & msg_type ) const { ... }
std::size_t counter_{};
...
const std::type_index & msg_type,
const so_5::message_ref_t & message,
unsigned int overlimit_reaction_deep ) override {
if(is_appropriate_message_type(msg_type))
++counter_;
... // Actual message delivery.
}
};

But it is hard to create a full implementation of so_5::abstract_message_box_t from the ground up. An existing mbox can be used for doing actual work:

class my_mbox final : public so_5::abstract_message_box_t
{
bool is_appropriate_message_type(
const std::type_index & msg_type ) const { ... }
const so_5::mbox_t mbox_;
std::size_t counter_{};
...
public:
my_mbox(so_5::mbox_t mbox) : mbox_{std::move(mbox)} {}
...
const std::type_index & msg_type,
const so_5::message_ref_t & message,
unsigned int overlimit_reaction_deep ) override {
if(is_appropriate_message_type(msg_type))
++counter_;
// Use actual mbox for message delivery.
mbox_->do_deliver_message(
msg_type, message, overlimit_reaction_deep);
}
};

But there is a small problem with this approach: so_5::abstract_message_box_t has a rich interface with a lot of pure virtual methods. It is a boring task to reimplement all of them.

In such cases simple_t can be used to reduce amount of developer's work:

class my_mbox final : public so_5::extra::mboxes::proxy::simple_t
{
bool is_appropriate_message_type(
const std::type_index & msg_type ) const { ... }
std::size_t counter_{};
public:
my_mbox(so_5::mbox_t mbox) : base_type{std::move(mbox)} {}
const std::type_index & msg_type,
const so_5::message_ref_t & message,
unsigned int overlimit_reaction_deep ) override {
if(is_appropriate_message_type(msg_type))
++counter_;
// Use actual mbox for message delivery.
base_type::do_deliver_message(
msg_type, message, overlimit_reaction_deep);
}
}

And that's all.

Since
v.5.5.23

Definition at line 128 of file proxy.hpp.

Constructor & Destructor Documentation

◆ simple_t()

so_5::extra::mboxes::proxy::simple_t::simple_t ( ::so_5::mbox_t  underlying_mbox)
inline

Initializing constructor.

Parameters
underlying_mboxActual underlying mbox to be used for all operations. Must not be nullptr.

Definition at line 181 of file proxy.hpp.

Member Function Documentation

◆ do_deliver_message()

void so_5::extra::mboxes::proxy::simple_t::do_deliver_message ( const std::type_index &  msg_type,
const ::so_5::message_ref_t &  message,
unsigned int  overlimit_reaction_deep 
)
inlineoverride

Definition at line 234 of file proxy.hpp.

◆ do_deliver_message_from_timer()

void so_5::extra::mboxes::proxy::simple_t::do_deliver_message_from_timer ( const std::type_index &  msg_type,
const ::so_5::message_ref_t &  message 
)
inlineoverrideprotected

Definition at line 275 of file proxy.hpp.

◆ drop_delivery_filter()

void so_5::extra::mboxes::proxy::simple_t::drop_delivery_filter ( const std::type_index &  msg_type,
::so_5::agent_t &  subscriber 
)
inlineoverridenoexcept

Definition at line 258 of file proxy.hpp.

◆ ensure_underlying_mbox_not_null()

::so_5::mbox_t so_5::extra::mboxes::proxy::simple_t::ensure_underlying_mbox_not_null ( ::so_5::mbox_t  mbox)
inlineprivate

Ensure that underlying mbox is not nullptr.

Exceptions
so_5::exception_tif mbox is nullptr.

Definition at line 141 of file proxy.hpp.

◆ environment()

so_5::environment_t& so_5::extra::mboxes::proxy::simple_t::environment ( ) const
inlineoverridenoexcept

Definition at line 268 of file proxy.hpp.

◆ id()

mbox_id_t so_5::extra::mboxes::proxy::simple_t::id ( ) const
inlineoverride

Definition at line 194 of file proxy.hpp.

◆ query_name()

std::string so_5::extra::mboxes::proxy::simple_t::query_name ( ) const
inlineoverride

Definition at line 222 of file proxy.hpp.

◆ set_delivery_filter()

void so_5::extra::mboxes::proxy::simple_t::set_delivery_filter ( const std::type_index &  msg_type,
const ::so_5::delivery_filter_t &  filter,
::so_5::agent_t &  subscriber 
)
inlineoverride

Definition at line 246 of file proxy.hpp.

◆ subscribe_event_handler()

void so_5::extra::mboxes::proxy::simple_t::subscribe_event_handler ( const std::type_index &  type_index,
const ::so_5::message_limit::control_block_t *  limit,
::so_5::agent_t &  subscriber 
)
inlineoverride

Definition at line 200 of file proxy.hpp.

◆ type()

mbox_type_t so_5::extra::mboxes::proxy::simple_t::type ( ) const
inlineoverride

Definition at line 228 of file proxy.hpp.

◆ underlying_mbox()

::so_5::abstract_message_box_t& so_5::extra::mboxes::proxy::simple_t::underlying_mbox ( ) const
inlineprotectednoexcept

An accessor to actual mbox.

This method is intended to be used in derived classes. For example:

class my_mbox : public so_5::extra::mboxes::proxy::simple_t {
public:
const std::type_index & msg_type,
const so_5::message_ref_t & message,
unsigned int overlimit_reaction_deep ) override {
... // Do some specific stuff.
// Use actual mbox for message delivery.
underlying_mbox().do_deliver_message(
msg_type, message, overlimit_reaction_deep);
}
...
};

Definition at line 174 of file proxy.hpp.

◆ unsubscribe_event_handlers()

void so_5::extra::mboxes::proxy::simple_t::unsubscribe_event_handlers ( const std::type_index &  type_index,
::so_5::agent_t &  subscriber 
)
inlineoverride

Definition at line 212 of file proxy.hpp.

Member Data Documentation

◆ m_underlying_mbox

const ::so_5::mbox_t so_5::extra::mboxes::proxy::simple_t::m_underlying_mbox
private

Actual underlying mbox to be used for all calls.

Attention
Should not be nullptr.

Definition at line 134 of file proxy.hpp.


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