#include <iostream>
#include <exception>
#include <sstream>
void define_hello_service(
{
[]() -> std::string {
std::cout << "svc_hello called" << std::endl;
return "Hello, World!";
} );
}
struct msg_convert
{
int m_value;
};
void define_convert_service(
{
[]( const msg_convert & msg ) -> std::string {
std::cout << "svc_convert called: value=" << msg.m_value << std::endl;
std::ostringstream s;
s << msg.m_value;
return s.str();
} );
}
void define_shutdown_service(
{
[&env]() {
std::cout << "svc_shutdown called" << std::endl;
env.stop();
} );
}
{
public :
, m_svc_mbox( svc_mbox )
{}
{
std::cout << "hello_svc: "
<< so_5::request_future< std::string, msg_hello_svc >(
m_svc_mbox ).get()
<< std::endl;
std::cout << "convert_svc: "
<< so_5::request_future< std::string, msg_convert >(
m_svc_mbox, 42 ).get()
<< std::endl;
std::cout << "sync_convert_svc: "
<< so_5::request_value< std::string, msg_convert >(
<< std::endl;
auto svc_proxy = m_svc_mbox->get_one< std::string >();
auto c1 = svc_proxy.make_async< msg_convert >( 1 );
auto c2 = svc_proxy.make_async< msg_convert >( 2 );
std::cout << "sync_convert_svc: "
<< svc_proxy.wait_forever().make_sync_get< msg_convert >(3)
<< std::endl;
std::cout << "convert_svc: c2=" << c2.get() << std::endl;
std::cout << "convert_svc: c1=" << c1.get() << std::endl;
m_svc_mbox->run_one().wait_forever().sync_get< msg_shutdown >();
}
private :
};
{
{
define_hello_service( coop, svc_mbox );
define_convert_service( coop, svc_mbox );
define_shutdown_service( coop, svc_mbox );
} );
}
int main()
{
try
{
}
catch( const std::exception & ex )
{
std::cerr << "Error: " << ex.what() << std::endl;
return 1;
}
return 0;
}