1#include <fc/rpc/bstate.hpp>
5namespace fc {
namespace rpc {
13 _methods.emplace(std::pair<std::string,method>(
name,fc::move(m)));
21result_type bstate::local_call(
const string& method_name,
const params_type& args )
23 auto method_itr = _methods.find(method_name);
24 if( method_itr == _methods.end() && _unhandled )
25 return _unhandled( method_name, args );
26 FC_ASSERT( method_itr != _methods.end(),
"Unknown Method: ${name}", (
"name",method_name) );
27 return method_itr->second(args);
30void bstate::handle_reply(
const bresponse& bresponse )
32 auto await = _awaiting.find( bresponse.id );
33 FC_ASSERT( await != _awaiting.end(),
"Unknown Response ID: ${id}", (
"id",bresponse.id)(
"bresponse",bresponse) );
34 if( bresponse.result )
35 await->second->set_value( *bresponse.result );
36 else if( bresponse.error )
38 await->second->set_exception( std::make_exception_ptr(
FC_EXCEPTION( exception,
"${error}", (
"error",bresponse.error->message)(
"data",bresponse) ) ) );
41 await->second->set_value( params_type() );
42 _awaiting.erase(await);
45brequest bstate::start_remote_call(
const string& method_name, params_type args )
47 brequest brequest{ _next_id++, method_name, std::move(args) };
48 _awaiting[*brequest.id].reset(
new boost::fibers::promise<result_type>() );
51result_type bstate::wait_for_response(
uint64_t request_id )
53 auto itr = _awaiting.find(request_id);
55 auto fut = itr->second->get_future();
60 for(
auto& item : _awaiting )
61 item.second->set_exception( std::make_exception_ptr(
FC_EXCEPTION( eof_exception,
"connection closed" )) );
64void bstate::on_unhandled(
const std::function<result_type(
const string&,
const params_type&)>& unhandled )
66 _unhandled = unhandled;
Defines exception's used by fc.
#define FC_EXCEPTION(EXCEPTION_TYPE, FORMAT,...)
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
void close(T *e, websocketpp::connection_hdl hdl)
unsigned __int64 uint64_t