#pragma once #include #include namespace fc { namespace json { namespace detail { struct rpc_member { // TODO: expand for all method arity and constness.... template static fc::function,A1> functor( P, R (C::*mem_func)(A1), const rpc_connection& c = rpc_connection(), const char* name = nullptr ) { return [=](A1 a1)->fc::future{ return c.invoke( name, make_tuple(a1) ); }; } }; struct vtable_visitor { vtable_visitor( rpc_connection& c ):_con(c){} template void operator()( const char* name, Function& memb, MemberPtr m )const { memb = rpc_member::functor( nullptr, m, _con, name ); } rpc_connection& _con; }; }; template class rpc_client : public ptr { public: rpc_client(){} rpc_client( const rpc_connection& c ):_con(c){ init(); } rpc_client( const rpc_client& c ):_con(c._con){} void set_connection( const rpc_connection& c ) { _con = c; init(); } const rpc_connection& connection()const { return _con; } private: void init() { this->_vtable.reset(new fc::detail::vtable() ); this->_vtable->template visit( fc::json::detail::vtable_visitor(_con) ); } rpc_connection _con; }; } } // fc::json