void create_new_child_coop()
	{
		// The cooperation will use active_obj dispatcher.
		auto disp = so_5::disp::active_obj::create_private_disp(
				so_environment() );
		auto coop = so_5::create_child_coop(
				// This agent will be parent for new cooperation.
				*this,
				// Name for the cooperation will be generated automatically.
				so_5::autoname,
				// The main dispatcher for the new cooperation is
				// the private active_obj dispatcher.
				disp->binder() );
		// We should receive notification about complete
		// child cooperation deregistration.
		coop->add_dereg_notificator(
				so_5::make_coop_dereg_notificator( so_direct_mbox() ) );

		auto first_mbox = fill_coop( *coop );

		so_environment().register_coop( std::move( coop ) );

		// Initial message must be sent to the first chain's member.
		so_5::send< a_chain_member_t::msg_your_turn >( first_mbox );
	}
		void
		so_evt_start()
		{
			auto child_coop = so_environment().create_coop( "child" );
			child_coop->set_parent_coop_name( so_coop_name() );
			child_coop->add_reg_notificator( m_reg_notificator );
			child_coop->add_dereg_notificator( m_dereg_notificator );
			child_coop->add_dereg_notificator(
					[this]( so_5::environment_t &,
						const std::string &,
						const so_5::coop_dereg_reason_t &)
					{
						m_mbox->deliver_signal< msg_child_deregistered >();
					} );

			child_coop->add_agent( new a_child_t( so_environment() ) );

			so_environment().register_coop( std::move( child_coop ) );
		}
Example #3
0
		void
		try_start_new_iteration()
		{
			if( m_iterations_left <= 0 )
			{
				std::cout << "COMPLETED!" << std::endl;

				so_environment().stop();
				return;
			}

			std::cout << m_iterations_left << " iterations left...\r"
				<< std::flush;

			m_state = state_t::awaiting_creation;
			m_acks_received = 0;
			m_destroy_received = 0;

			m_child_mboxes = std::vector< so_5::rt::mbox_t >();
			m_child_mboxes.reserve( m_max_agents );

			auto coop = so_environment().create_coop( "child" );
			coop->set_parent_coop_name( so_coop_name() );
			coop->add_reg_notificator(
					so_5::rt::make_coop_reg_notificator( so_direct_mbox() ) );
			coop->add_dereg_notificator(
					so_5::rt::make_coop_dereg_notificator( so_direct_mbox() ) );

			for( std::size_t i = 0; i != m_max_agents; ++i )
			{
				std::unique_ptr< so_5::rt::agent_t > agent(
						new a_child_t(
								so_environment(),
								so_direct_mbox() ) );
				m_child_mboxes.push_back( agent->so_direct_mbox() );

				coop->add_agent( std::move( agent ) );
			}

			so_environment().register_coop( std::move( coop ) );
		}