SObjectizer 5.8
Loading...
Searching...
No Matches
so_5/nohandler_msg_tracing/main.cpp
/*
* An example to show custom msg_tracing filter.
* Only trace message for cases when no event handler found will be printed.
*/
#include <iostream>
#include <time.h>
// Main SObjectizer header file.
#include <so_5/all.hpp>
// Main example agent.
class a_example_t final : public so_5::agent_t
{
// Several signals for demonstration.
struct first final : public so_5::signal_t {};
struct second final : public so_5::signal_t {};
struct third final : public so_5::signal_t {};
// Signal for finishing the example.
struct finish final : public so_5::signal_t {};
// Several agent's states.
const state_t st_first{ this, "first" };
const state_t st_second{ this, "second" };
const state_t st_third{ this, "third" };
public :
a_example_t( context_t ctx )
: so_5::agent_t( std::move(ctx) )
{
st_first.event( &a_example_t::on_first );
st_first.event( &a_example_t::on_finish );
st_second.event( &a_example_t::on_second );
st_third.event( &a_example_t::on_third );
}
void so_evt_start() override
{
// Change the state of the agent.
this >>= st_first;
// Send a serie of messages.
}
private :
void on_first( mhood_t<first> ) {}
void on_second( mhood_t<first> ) {}
void on_third( mhood_t<first> ) {}
void on_finish( mhood_t<finish> )
{
}
};
int main()
{
try
{
env.introduce_coop( []( so_5::coop_t & coop ) {
coop.make_agent< a_example_t >();
} );
},
[]( so_5::environment_params_t & params ) {
// Turn message delivery tracing on.
params.message_delivery_tracer(
// Setup filter which enables only messages with
// null event_handler_data_ptr.
params.message_delivery_tracer_filter(
const auto h = td.event_handler_data_ptr();
return h && (nullptr == *h);
} ) );
} );
}
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.
A base class for agents.
Definition agent.hpp:673
void so_deregister_agent_coop_normally()
A helper method for deregistering agent's coop in case of normal deregistration.
Definition agent.cpp:982
virtual void so_evt_start()
Hook on agent start inside SObjectizer.
Definition agent.cpp:701
Agent cooperation.
Definition coop.hpp:389
Agent * make_agent(Args &&... args)
Helper method for simplification of agents creation.
Definition coop.hpp:792
Parameters for the SObjectizer Environment initialization.
SObjectizer Environment.
decltype(auto) introduce_coop(Args &&... args)
Helper method for simplification of cooperation creation and registration.
An interface of object for accessing trace details.
virtual optional< const so_5::impl::event_handler_data_t * > event_handler_data_ptr() const noexcept=0
Get pointer to event handler.
A base class for agent signals.
Definition message.hpp:275
SO_5_FUNC tracer_unique_ptr_t std_cout_tracer()
Factory for tracer which uses std::cout stream.
filter_shptr_t make_filter(L &&lambda)
A helper function for creation of new filter from lambda-function.
void launch(Init_Routine &&init_routine)
Launch a SObjectizer Environment with default parameters.
Definition api.hpp:142
void send(Target &&to, Args &&... args)
A utility function for creating and delivering a message or a signal.