1#include <fc/rpc/state.hpp>
5namespace fc {
namespace rpc {
13 _methods.emplace(std::pair<std::string,method>(
name,fc::move(m)));
21variant state::local_call(
const string& method_name,
const variants& 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 state::handle_reply(
const response& response )
32 auto await = _awaiting.find( response.id );
33 FC_ASSERT( await != _awaiting.end(),
"Unknown Response ID: ${id}", (
"id",response.id)(
"response",response) );
35 await->second->set_value( *response.result );
36 else if( response.error )
38 await->second->set_exception( std::make_exception_ptr(
FC_EXCEPTION( exception,
"${error}", (
"error",response.error->message)(
"data",response) ) ) );
42 _awaiting.erase(await);
45request state::start_remote_call(
const string& method_name,
variants args )
47 request request{ _next_id++, method_name, std::move(args) };
48 _awaiting[*request.id].reset(
new boost::fibers::promise<fc::variant>() );
51variant state::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 state::on_unhandled(
const std::function<variant(
const string&,
const variants&)>& unhandled )
66 _unhandled = unhandled;
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
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)
std::vector< fc::variant > variants
unsigned __int64 uint64_t