#include <iostream>
#include <string>
{
public :
{
.
event< ping >( &demo_agent::evt_ping );
}
{
}
{
}
private :
std::string evt_ping()
{
}
};
template< typename Lambda >
void do_action(
const std::string & action_name,
Lambda && lambda )
{
try
{
lambda();
}
catch( const std::exception & x )
{
std::cerr << "Error during '" << action_name << "': " << x.what() << std::endl;
}
}
void demo()
{
auto ask_coop_name = [] {
std::cout << "Coop name: " << std::flush;
std::string name;
std::cin >> name;
return name;
};
while( true )
{
std::cout << "Enter command (reg,dereg,ping,exit): " << std::flush;
std::string choice;
std::cin >> choice;
if( "reg" == choice )
{
const auto name = ask_coop_name();
do_action( "registering coop '" + name + "'",
[&] {
} );
} );
}
else if( "dereg" == choice )
{
const auto name = ask_coop_name();
do_action( "deregistering coop '" + name + "'",
[&] {
} );
}
else if( "ping" == choice )
{
const auto name = ask_coop_name();
do_action( "pinging '" + name + "'",
[&] {
auto reply = so_5::request_value< std::string, demo_agent::ping >(
std::cout << "ping reply: " << reply << std::endl;
} );
}
else if( "exit" == choice || "quit" == choice )
break;
}
}
int main()
{
try
{
demo();
}
catch( const std::exception & x )
{
std::cerr << "Exception: " << x.what() << std::endl;
return 2;
}
return 0;
}