#include <iostream>
class example_guard final
, public std::enable_shared_from_this< example_guard >
{
public :
example_guard(
{}
void stop()
noexcept override
{
}
private :
};
{
state_t st_normal{ this }, st_shutdown{ this };
public:
worker( context_t ctx ) :
so_5::agent_t(
std::move(ctx) )
{
this >>= st_normal;
st_normal
.event( &worker::on_timer_normal )
.event( &worker::on_shutdown_started );
st_shutdown
.event( &worker::on_timer_shutdown )
.event( &worker::on_terminate );
}
{
std::chrono::milliseconds(125),
std::chrono::milliseconds(125) );
}
private :
void on_timer_normal( mhood_t<timer> )
{
std::cout << "working in normal mode..." << std::endl;
}
void on_timer_shutdown( mhood_t<timer> )
{
std::cout << "working in shutdown mode..." << std::endl;
}
void on_shutdown_started( mhood_t<example_guard::shutdown_started> )
{
std::cout << "shutdown is in progress!" << std::endl;
this >>= st_shutdown;
std::chrono::milliseconds(300) );
}
void on_terminate( mhood_t<terminate_work> )
{
std::cout << "terminate work." << std::endl;
}
};
{
public :
work_stopper( context_t ctx ) :
so_5::agent_t(
std::move(ctx) )
{
} );
}
{
std::chrono::milliseconds(400) );
}
};
int main()
{
try
{
{
} );
} );
}
catch( const std::exception & ex )
{
std::cerr << "Error: " << ex.what() << std::endl;
return 1;
}
return 0;
}
A helper header file for including all public SObjectizer stuff.
subscription_bind_t so_subscribe_self()
Initiate subscription to agent's direct mbox.
const mbox_t & so_direct_mbox() const
Get the agent's direct mbox.
environment_t & so_environment() const noexcept
Access to the SObjectizer Environment which this agent is belong.
virtual void so_evt_start()
Hook on agent start inside SObjectizer.
Agent * make_agent(Args &&... args)
Helper method for simplification of agents creation.
void stop() noexcept
Send a shutdown signal to the Run-Time.
decltype(auto) introduce_coop(Args &&... args)
Helper method for simplification of cooperation creation and registration.
void remove_stop_guard(stop_guard_shptr_t guard)
Remove stop_guard and complete the stop operation if necessary.
stop_guard_t::setup_result_t setup_stop_guard(stop_guard_shptr_t guard, stop_guard_t::what_if_stop_in_progress_t reaction_on_stop_in_progress=stop_guard_t::what_if_stop_in_progress_t::throw_exception)
Set up a new stop_guard.
A base class for agent signals.
An interface of stop_guard entity.
virtual void stop() noexcept=0
Perform stop-related actions.
std::enable_if< details::is_agent_method_pointer< details::method_arity::unary, Method_Pointer >::value, subscription_bind_t & >::type event(Method_Pointer pfn, thread_safety_t thread_safety=not_thread_safe)
Make subscription to the message.
An indentificator for the timer.
Private part of message limit implementation.
void launch(Init_Routine &&init_routine)
Launch a SObjectizer Environment with default parameters.
std::shared_ptr< stop_guard_t > stop_guard_shptr_t
An alias of shared_ptr for stop_guard.
timer_id_t send_periodic(Target &&target, std::chrono::steady_clock::duration pause, std::chrono::steady_clock::duration period, Args &&... args)
A utility function for creating and delivering a periodic message to the specified destination.
void send(Target &&to, Args &&... args)
A utility function for creating and delivering a message or a signal.
void send_delayed(Target &&target, std::chrono::steady_clock::duration pause, Args &&... args)
A utility function for creating and delivering a delayed message to the specified destination.