#include <iostream>
#include <sstream>
struct task_result
{
unsigned int m_id;
};
{
public:
a_child_t(
context_t ctx,
unsigned int task_id )
, m_result_mbox(
std::move(result_mbox) )
, m_task_id( task_id )
{}
~a_child_t() override
{
std::cout << "Child: agent of the task " << m_task_id
<< " has destroyed." << std::endl;
}
{
}
{
std::cout << "Child: has started to do task " << m_task_id << std::endl;
}
{
std::cout << "Child: has finished, task " << m_task_id << std::endl;
}
void evt_task_completed( mhood_t< task_completed > )
{
std::cout << "Child: has completed his task " << m_task_id << std::endl;
}
private:
const unsigned int m_task_id;
};
{
public:
~a_parent_t() override
{
std::cout << "Parent: agent has destroyed." << std::endl;
}
{
}
{
std::cout << "Parent: agent has started." << std::endl;
start_child( 0 );
}
{
std::cout << "Parent: agent has finished." << std::endl;
}
void evt_task_result( const task_result & evt )
{
std::cout << "Parent: task result " << evt.m_id << " is received." << std::endl;
start_child( evt.m_id + 1 );
}
private:
void start_child( unsigned int id )
{
std::cout << "Parent: starting a child to do task " << id << std::endl;
} );
}
};
int main()
{
try
{
{
std::this_thread::sleep_for( std::chrono::seconds( 3 ) );
} );
}
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.
virtual void so_define_agent()
Hook on define agent for SObjectizer.
subscription_bind_t so_subscribe_self()
Initiate subscription to agent's direct mbox.
agent_t(environment_t &env)
Constructor.
void so_deregister_agent_coop_normally()
A helper method for deregistering agent's coop in case of normal deregistration.
virtual void so_evt_finish()
Hook of agent finish in SObjectizer.
const mbox_t & so_direct_mbox() const
Get the agent's direct mbox.
virtual void so_evt_start()
Hook on agent start inside SObjectizer.
Agent * make_agent(Args &&... args)
Helper method for simplification of agents creation.
coop_handle_t register_agent_as_coop(std::unique_ptr< A > agent)
Register single agent as a cooperation.
std::unique_ptr< Agent > make_agent(Args &&... args)
Helper method for simplification of agents creation.
void stop() noexcept
Send a shutdown signal to the Run-Time.
A base class for agent signals.
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.
Private part of message limit implementation.
void launch(Init_Routine &&init_routine)
Launch a SObjectizer Environment with default parameters.
decltype(auto) introduce_child_coop(agent_t &owner, Args &&... args)
A simple way for creating and registering child cooperation.
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.