diff --git a/include/fc/actor.hpp b/include/fc/actor.hpp deleted file mode 100644 index 920d74276..000000000 --- a/include/fc/actor.hpp +++ /dev/null @@ -1,65 +0,0 @@ -#pragma once -#include -#include - -namespace fc { - - namespace detail { - struct actor_member { - #if 1 // BOOST_NO_VARIADIC_TEMPLATES - #define RPC_MEMBER_FUNCTOR(z,n,IS_CONST) \ - template \ - static std::function( BOOST_PP_ENUM_PARAMS(n,A) ) > \ - functor( P p, R (C::*mem_func)(BOOST_PP_ENUM_PARAMS(n,A)) IS_CONST, fc::thread* c = 0) { \ - return [=](BOOST_PP_ENUM_BINARY_PARAMS(n,A,a))->fc::future{ \ - return c->async( [=](){ return (p->*mem_func)(BOOST_PP_ENUM_PARAMS(n,a)); } ); }; \ - } - BOOST_PP_REPEAT( 8, RPC_MEMBER_FUNCTOR, const ) - BOOST_PP_REPEAT( 8, RPC_MEMBER_FUNCTOR, BOOST_PP_EMPTY() ) - #undef RPC_MEMBER_FUNCTOR - - #else // g++ has a bug that prevents lambdas and varidic templates from working together (G++ Bug 41933) - - template - static std::function(Args...)> functor( P&& p, R (C::*mem_func)(Args...), fc::thread* c ) { - return [=](Args... args)->fc::future{ c->async( [=]()->R { return p->*mem_func( fc::forward(args)... ); } ) }; - } - template - static std::function(Args...)> functor( P&& p, R (C::*mem_func)(Args...)const, fc::thread* c ){ - return [=](Args... args)->fc::future{ c->async( [=]()->R { return p->*mem_func( fc::forward(args)... ); } ) }; - } - #endif - }; - - template - struct actor_vtable_visitor { - template - actor_vtable_visitor( fc::thread* t, U&& u ):_thread(t),_this( fc::forward(u) ){} - - template - void operator()( const char* name, Function& memb, MemberPtr m )const { - memb = actor_member::functor( _this, m, _thread ); - } - fc::thread* _thread; - ThisPtr _this; - }; - } - - /** - * Posts all method calls to another thread and - * returns a future. - */ - template - class actor : public api { - public: - actor(){} - - template - actor( InterfaceType* p, fc::thread* t = &fc::thread::current() ) - { - this->_vtable.reset(new detail::vtable() ); - this->_vtable->template visit( detail::actor_vtable_visitor(t, p) ); - } - }; - -} // namespace fc diff --git a/include/fc/api.hpp b/include/fc/api.hpp index 06414b114..f4ce36759 100644 --- a/include/fc/api.hpp +++ b/include/fc/api.hpp @@ -1,5 +1,4 @@ -#pragma once -#include +#pragma once #include #include #include diff --git a/include/fc/fc.hpp b/include/fc/fc.hpp new file mode 100644 index 000000000..10b889015 --- /dev/null +++ b/include/fc/fc.hpp @@ -0,0 +1,124 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/include/fc/interprocess/iprocess.hpp b/include/fc/interprocess/iprocess.hpp deleted file mode 100644 index c7f8c4e2a..000000000 --- a/include/fc/interprocess/iprocess.hpp +++ /dev/null @@ -1,67 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include - -namespace fc -{ - /** - * @brief abstract interface for interacting with external processes - * - * At the very least we have ssh::process and direct child processes, and - * there may be other processes that need to implement this protocol. - */ - class iprocess - { - public: - enum exec_opts { - open_none = 0, - open_stdin = 0x01, - open_stdout = 0x02, - open_stderr = 0x04, - open_all = open_stdin|open_stdout|open_stderr, - suppress_console = 0x08 - }; - - virtual ~iprocess(){} - - /** - * - * @return *this - */ - virtual iprocess& exec( const path& exe, std::vector args, - const path& work_dir = path(), int opts = open_all ) = 0; - - /** - * @return blocks until the process exits - */ - virtual int result(const microseconds& timeout = microseconds::maximum()) = 0; - - - /** - * Forcefully kills the process. - */ - virtual void kill() = 0; - - /** - * @brief returns a stream that writes to the process' stdin - */ - virtual buffered_ostream_ptr in_stream() = 0; - - /** - * @brief returns a stream that reads from the process' stdout - */ - virtual buffered_istream_ptr out_stream() = 0; - /** - * @brief returns a stream that reads from the process' stderr - */ - virtual buffered_istream_ptr err_stream() = 0; - - }; - - typedef std::shared_ptr iprocess_ptr; - - -} // namespace fc diff --git a/include/fc/interprocess/process.hpp b/include/fc/interprocess/process.hpp deleted file mode 100644 index 777c154a7..000000000 --- a/include/fc/interprocess/process.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once -#include - -namespace fc { - - fc::path find_executable_in_path( const fc::string name ); - - /** - * @brief start and manage an local process - * @note this class implements reference semantics. - */ - class process : public iprocess - { - public: - process(); - ~process(); - - virtual iprocess& exec( const fc::path& exe, - std::vector args, - const fc::path& work_dir = fc::path(), - int opts = open_all ); - - - virtual int result(const microseconds& timeout = microseconds::maximum()); - virtual void kill(); - virtual fc::buffered_ostream_ptr in_stream(); - virtual fc::buffered_istream_ptr out_stream(); - virtual fc::buffered_istream_ptr err_stream(); - - class impl; - private: - std::unique_ptr my; - }; - - typedef std::shared_ptr process_ptr; - -} // namespace fc diff --git a/include/fc/io/iobuffer.hpp b/include/fc/io/iobuffer.hpp deleted file mode 100644 index 02f919b06..000000000 --- a/include/fc/io/iobuffer.hpp +++ /dev/null @@ -1,81 +0,0 @@ -#pragma once -#include -#include - -namespace fc -{ - /** - * Records the size, but discards the data. - */ - class size_stream : public virtual fc::ostream - { - public: - size_stream( size_t s = 0):_size(s){} - - size_t size()const { return _size; } - size_t seek( size_t pos ) { return _size = pos; } - - virtual size_t writesome( const char* /*ignored buf*/, size_t len ) - { - _size += len; - return len; - } - - virtual void close(){} - virtual void flush(){} - - private: - size_t _size; - }; - - - class iobuffer : public virtual fc::iostream - { - public: - iobuffer( size_t s ) - :_data(s){} - - size_t size()const { return _data.size(); } - size_t pos()const { return _pos; } - size_t seek( size_t pos ) - { - return _pos = std::min(_data.size(),pos); - } - - virtual size_t readsome( char* buf, size_t len ) - { - auto avail = std::min( _data.size()-_pos, len ); - if( avail == 0 ) throw fc::eof_exception(); - memcpy( buf, _data.data()+_pos, avail ); - _pos += avail; - return avail; - } - /** - * This method may block until at least 1 character is - * available. - */ - char peek()const - { - if( _pos == _data.size() ) throw fc::eof_exception(); - return _data[_pos]; - } - - virtual size_t writesome( const char* buf, size_t len ) - { - auto avail = std::max( _data.size(), _pos + len ); - _data.resize(avail); - memcpy( _data.data()+_pos, buf, len ); - _pos += avail; - return avail; - } - char* data() { return _data.data(); } - - virtual void close(){} - virtual void flush(){} - - private: - std::vector _data; - size_t _pos; - }; - -} diff --git a/include/fc/make_fused.hpp b/include/fc/make_fused.hpp deleted file mode 100644 index acbf90107..000000000 --- a/include/fc/make_fused.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include -#include - -namespace fc { - template - std::function > make_fused( const std::function& f ) { - return [=]( fc::tuple<> ){ return f(); }; - } - template - std::function) > make_fused( const std::function& f ) { - return [f]( fc::tuple t){ return f(t.a); }; - } - template - std::function) > make_fused( const std::function& f ) { - return [f]( fc::tuple t){ return f(t.a,t.b); }; - } - template - std::function) > make_fused( const std::function& f ) { - return [f]( fc::tuple t){ return f(t.a,t.b,t.c); }; - } - template - std::function) > make_fused( const std::function& f ) { - return [f]( fc::tuple t){ return f(t.a,t.b,t.c,t.d); }; - } -} diff --git a/include/fc/rpc/api_connection.hpp b/include/fc/rpc/api_connection.hpp deleted file mode 100644 index c2268ea72..000000000 --- a/include/fc/rpc/api_connection.hpp +++ /dev/null @@ -1,518 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include - -namespace fc { - class api_connection; - - namespace detail { - template - class callback_functor - { - public: - typedef typename std::function::result_type result_type; - - callback_functor( std::weak_ptr< fc::api_connection > con, uint64_t id ) - :_callback_id(id),_api_connection(con){} - - template - result_type operator()( Args... args )const; - - private: - uint64_t _callback_id; - std::weak_ptr< fc::api_connection > _api_connection; - }; - - template - std::function bind_first_arg( const std::function& f, Arg0 a0 ) - { - return [=]( Args... args ) { return f( a0, args... ); }; - } - template - R call_generic( const std::function& f, variants::const_iterator a0, variants::const_iterator e ) - { - return f(); - } - - template - R call_generic( const std::function& f, variants::const_iterator a0, variants::const_iterator e ) - { - FC_ASSERT( a0 != e ); - return call_generic( bind_first_arg( f, a0->as< typename std::decay::type >() ), a0+1, e ); - } - - template - std::function to_generic( const std::function& f ) - { - return [=]( const variants& args ) { - return variant( call_generic( f, args.begin(), args.end() ) ); - }; - } - - template - std::function to_generic( const std::function& f ) - { - return [=]( const variants& args ) { - call_generic( f, args.begin(), args.end() ); - return variant(); - }; - } - - /** - * If api is returned from a remote method, the API is eagerly bound to api of - * the correct type in api_visitor::from_variant(). This binding [1] needs a reference - * to the api_connection, which is made available to from_variant() as a parameter. - * - * However, in the case of a remote method which returns api_base which can subsequently - * be cast by the caller with as, we need to keep track of the connection because - * the binding is done later (when the client code actually calls as). - * - * [1] The binding actually happens in get_remote_api(). - */ - class any_api : public api_base - { - public: - any_api( api_id_type api_id, const std::shared_ptr& con ) - : _api_id(api_id), _api_connection(con) {} - - virtual uint64_t get_handle()const override - { return _api_id; } - - virtual api_id_type register_api( api_connection& conn )const override - { FC_ASSERT( false ); return api_id_type(); } - - api_id_type _api_id; - std::weak_ptr _api_connection; - }; - - } // namespace detail - - class generic_api - { - public: - template - generic_api( const Api& a, const std::shared_ptr& c ); - - generic_api( const generic_api& cpy ) = delete; - - variant call( const string& name, const variants& args ) - { - auto itr = _by_name.find(name); - FC_ASSERT( itr != _by_name.end(), "no method with name '${name}'", ("name",name)("api",_by_name) ); - return call( itr->second, args ); - } - - variant call( uint32_t method_id, const variants& args ) - { - FC_ASSERT( method_id < _methods.size() ); - return _methods[method_id](args); - } - - std::weak_ptr< fc::api_connection > get_connection() - { - return _api_connection; - } - - std::vector get_method_names()const - { - std::vector result; - result.reserve( _by_name.size() ); - for( auto& m : _by_name ) result.push_back(m.first); - return result; - } - - private: - friend struct api_visitor; - - template - std::function bind_first_arg( const std::function& f, Arg0 a0 )const - { - return [=]( Args... args ) { return f( a0, args... ); }; - } - - template - R call_generic( const std::function& f, variants::const_iterator a0, variants::const_iterator e )const - { - return f(); - } - - template - R call_generic( const std::function,Args...)>& f, variants::const_iterator a0, variants::const_iterator e ) - { - FC_ASSERT( a0 != e, "too few arguments passed to method" ); - detail::callback_functor arg0( get_connection(), a0->as() ); - return call_generic( this->bind_first_arg,Args...>( f, std::function(arg0) ), a0+1, e ); - } - template - R call_generic( const std::function&,Args...)>& f, variants::const_iterator a0, variants::const_iterator e ) - { - FC_ASSERT( a0 != e, "too few arguments passed to method" ); - detail::callback_functor arg0( get_connection(), a0->as() ); - return call_generic( this->bind_first_arg&,Args...>( f, arg0 ), a0+1, e ); - } - - template - R call_generic( const std::function& f, variants::const_iterator a0, variants::const_iterator e ) - { - FC_ASSERT( a0 != e, "too few arguments passed to method" ); - return call_generic( this->bind_first_arg( f, a0->as< typename std::decay::type >() ), a0+1, e ); - } - - struct api_visitor - { - api_visitor( generic_api& a, const std::weak_ptr& s ):_api(a),_api_con(s){ } - - template - std::function to_generic( const std::function(Args...)>& f )const; - - template - std::function to_generic( const std::function>(Args...)>& f )const; - - template - std::function to_generic( const std::function& f )const; - - template - std::function to_generic( const std::function& f )const; - - template - std::function to_generic( const std::function& f )const; - - template - void operator()( const char* name, std::function& memb )const { - _api._methods.emplace_back( to_generic( memb ) ); - _api._by_name[name] = _api._methods.size() - 1; - } - - generic_api& _api; - const std::weak_ptr& _api_con; - }; - - - std::weak_ptr _api_connection; - fc::any _api; - std::map< std::string, uint32_t > _by_name; - std::vector< std::function > _methods; - }; // class generic_api - - - - class api_connection : public std::enable_shared_from_this - { - public: - api_connection(){} - virtual ~api_connection(){}; - - - template - api get_remote_api( api_id_type api_id = 0 ) - { - api result; - result->visit( api_visitor( api_id, this->shared_from_this() ) ); - return result; - } - - /** makes calls to the remote server */ - virtual variant send_call( api_id_type api_id, string method_name, variants args = variants() ) = 0; - virtual variant send_callback( uint64_t callback_id, variants args = variants() ) = 0; - virtual void send_notice( uint64_t callback_id, variants args = variants() ) = 0; - - variant receive_call( api_id_type api_id, const string& method_name, const variants& args = variants() )const - { - FC_ASSERT( _local_apis.size() > api_id ); - return _local_apis[api_id]->call( method_name, args ); - } - variant receive_callback( uint64_t callback_id, const variants& args = variants() )const - { - FC_ASSERT( _local_callbacks.size() > callback_id ); - return _local_callbacks[callback_id]( args ); - } - void receive_notice( uint64_t callback_id, const variants& args = variants() )const - { - FC_ASSERT( _local_callbacks.size() > callback_id ); - _local_callbacks[callback_id]( args ); - } - - template - api_id_type register_api( const Interface& a ) - { - auto handle = a.get_handle(); - auto itr = _handle_to_id.find(handle); - if( itr != _handle_to_id.end() ) return itr->second; - - _local_apis.push_back( std::unique_ptr( new generic_api(a, shared_from_this() ) ) ); - _handle_to_id[handle] = _local_apis.size() - 1; - return _local_apis.size() - 1; - } - - template - uint64_t register_callback( const std::function& cb ) - { - _local_callbacks.push_back( detail::to_generic( cb ) ); - return _local_callbacks.size() - 1; - } - - std::vector get_method_names( api_id_type local_api_id = 0 )const { return _local_apis[local_api_id]->get_method_names(); } - - fc::signal closed; - private: - std::vector< std::unique_ptr > _local_apis; - std::map< uint64_t, api_id_type > _handle_to_id; - std::vector< std::function > _local_callbacks; - - - struct api_visitor - { - uint32_t _api_id; - std::shared_ptr _connection; - - api_visitor( uint32_t api_id, std::shared_ptr con ) - :_api_id(api_id),_connection(std::move(con)) - { - } - - api_visitor() = delete; - - template - static Result from_variant( const variant& v, Result*, const std::shared_ptr& ) - { - return v.as(); - } - - template - static fc::api from_variant( const variant& v, - fc::api* /*used for template deduction*/, - const std::shared_ptr& con - ) - { - return con->get_remote_api( v.as_uint64() ); - } - - static fc::api_ptr from_variant( - const variant& v, - fc::api_ptr* /* used for template deduction */, - const std::shared_ptr& con - ) - { - return fc::api_ptr( new detail::any_api( v.as_uint64(), con ) ); - } - - template - static fc::variant convert_callbacks( const std::shared_ptr&, const T& v ) - { - return fc::variant(v); - } - - template - static fc::variant convert_callbacks( const std::shared_ptr& con, const std::function& v ) - { - return con->register_callback( v ); - } - - template - void operator()( const char* name, std::function& memb )const - { - auto con = _connection; - auto api_id = _api_id; - memb = [con,api_id,name]( Args... args ) { - auto var_result = con->send_call( api_id, name, { convert_callbacks(con,args)...} ); - return from_variant( var_result, (Result*)nullptr, con ); - }; - } - template - void operator()( const char* name, std::function& memb )const - { - auto con = _connection; - auto api_id = _api_id; - memb = [con,api_id,name]( Args... args ) { - con->send_call( api_id, name, { convert_callbacks(con,args)...} ); - }; - } - }; - }; - - class local_api_connection : public api_connection - { - public: - /** makes calls to the remote server */ - virtual variant send_call( api_id_type api_id, string method_name, variants args = variants() ) override - { - FC_ASSERT( _remote_connection ); - return _remote_connection->receive_call( api_id, method_name, std::move(args) ); - } - virtual variant send_callback( uint64_t callback_id, variants args = variants() ) override - { - FC_ASSERT( _remote_connection ); - return _remote_connection->receive_callback( callback_id, args ); - } - virtual void send_notice( uint64_t callback_id, variants args = variants() ) override - { - FC_ASSERT( _remote_connection ); - _remote_connection->receive_notice( callback_id, args ); - } - - - void set_remote_connection( const std::shared_ptr& rc ) - { - FC_ASSERT( !_remote_connection ); - FC_ASSERT( rc != this->shared_from_this() ); - _remote_connection = rc; - } - const std::shared_ptr& remote_connection()const { return _remote_connection; } - - std::shared_ptr _remote_connection; - }; - - template - generic_api::generic_api( const Api& a, const std::shared_ptr& c ) - :_api_connection(c),_api(a) - { - boost::any_cast(a)->visit( api_visitor( *this, c ) ); - } - - template - std::function generic_api::api_visitor::to_generic( - const std::function(Args...)>& f )const - { - auto api_con = _api_con; - auto gapi = &_api; - return [=]( const variants& args ) { - auto con = api_con.lock(); - FC_ASSERT( con, "not connected" ); - - auto api_result = gapi->call_generic( f, args.begin(), args.end() ); - return con->register_api( api_result ); - }; - } - template - std::function generic_api::api_visitor::to_generic( - const std::function>(Args...)>& f )const - { - auto api_con = _api_con; - auto gapi = &_api; - return [=]( const variants& args )-> fc::variant { - auto con = api_con.lock(); - FC_ASSERT( con, "not connected" ); - - auto api_result = gapi->call_generic( f, args.begin(), args.end() ); - if( api_result ) - return con->register_api( *api_result ); - return variant(); - }; - } - - template - std::function generic_api::api_visitor::to_generic( - const std::function& f )const - { - auto api_con = _api_con; - auto gapi = &_api; - return [=]( const variants& args ) -> fc::variant { - auto con = api_con.lock(); - FC_ASSERT( con, "not connected" ); - - auto api_result = gapi->call_generic( f, args.begin(), args.end() ); - if( !api_result ) - return variant(); - return api_result->register_api( *con ); - }; - } - - template - std::function generic_api::api_visitor::to_generic( const std::function& f )const - { - generic_api* gapi = &_api; - return [f,gapi]( const variants& args ) { - return variant( gapi->call_generic( f, args.begin(), args.end() ) ); - }; - } - - template - std::function generic_api::api_visitor::to_generic( const std::function& f )const - { - generic_api* gapi = &_api; - return [f,gapi]( const variants& args ) { - gapi->call_generic( f, args.begin(), args.end() ); - return variant(); - }; - } - - /** - * It is slightly unclean tight coupling to have this method in the api class. - * It breaks encapsulation by requiring an api class method to have a pointer - * to an api_connection. The reason this is necessary is we have a goal of being - * able to call register_api() on an api through its base class api_base. But - * register_api() must know the template parameters! - * - * The only reasonable way to achieve the goal is to implement register_api() - * as a method in api (which obviously knows the template parameter T), - * then make the implementation accessible through the base class (by making - * it a pure virtual method in the base class which is overridden by the subclass's - * implementation). - */ - template< typename Interface, typename Transform > - api_id_type api< Interface, Transform >::register_api( api_connection& conn )const - { - return conn.register_api( *this ); - } - - template< typename T > - api api_base::as() - { - // TODO: this method should probably be const (if it is not too hard) - api* maybe_requested_type = dynamic_cast< api* >(this); - if( maybe_requested_type != nullptr ) - return *maybe_requested_type; - - detail::any_api* maybe_any = dynamic_cast< detail::any_api* >(this); - FC_ASSERT( maybe_any != nullptr ); - std::shared_ptr< api_connection > api_conn = maybe_any->_api_connection.lock(); - FC_ASSERT( api_conn ); - return api_conn->get_remote_api( maybe_any->_api_id ); - } - - namespace detail { - template - template - typename callback_functor::result_type callback_functor::operator()( Args... args )const - { - std::shared_ptr< fc::api_connection > locked = _api_connection.lock(); - // TODO: make new exception type for this instead of recycling eof_exception - if( !locked ) - throw fc::eof_exception(); - locked->send_callback( _callback_id, fc::variants{ args... } ).template as< result_type >(); - } - - - template - class callback_functor - { - public: - typedef void result_type; - - callback_functor( std::weak_ptr< fc::api_connection > con, uint64_t id ) - :_callback_id(id),_api_connection(con){} - - void operator()( Args... args )const - { - std::shared_ptr< fc::api_connection > locked = _api_connection.lock(); - // TODO: make new exception type for this instead of recycling eof_exception - if( !locked ) - throw fc::eof_exception(); - locked->send_notice( _callback_id, fc::variants{ args... } ); - } - - private: - uint64_t _callback_id; - std::weak_ptr< fc::api_connection > _api_connection; - }; - } // namespace detail - -} // fc diff --git a/include/fc/rpc/binary_api_connection.hpp b/include/fc/rpc/binary_api_connection.hpp deleted file mode 100644 index 9c9ce2f7d..000000000 --- a/include/fc/rpc/binary_api_connection.hpp +++ /dev/null @@ -1,532 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include - -namespace fc { - class binary_api_connection; - - namespace detail { - template - class callback_functor - { - public: - typedef typename std::function::result_type result_type; - - callback_functor( std::weak_ptr< fc::binary_api_connection > con, uint64_t id ) - :_callback_id(id),_binary_api_connection(con){} - - template - result_type operator()( Args... args )const; - - private: - uint64_t _callback_id; - std::weak_ptr< fc::binary_api_connection > _binary_api_connection; - }; - - template - std::function bind_first_arg( const std::function& f, Arg0 a0 ) - { - return [=]( Args... args ) { return f( a0, args... ); }; - } - template - R call_generic( const std::function& f, variants::const_iterator a0, variants::const_iterator e ) - { - return f(); - } - - template - R call_generic( const std::function& f, variants::const_iterator a0, variants::const_iterator e ) - { - FC_ASSERT( a0 != e ); - return call_generic( bind_first_arg( f, a0->as< typename std::decay::type >() ), a0+1, e ); - } - - template - std::function to_generic( const std::function& f ) - { - return [=]( const variants& args ) { - return variant( call_generic( f, args.begin(), args.end() ) ); - }; - } - - template - std::function to_generic( const std::function& f ) - { - return [=]( const variants& args ) { - call_generic( f, args.begin(), args.end() ); - return variant(); - }; - } - - /** - * If api is returned from a remote method, the API is eagerly bound to api of - * the correct type in api_visitor::from_variant(). This binding [1] needs a reference - * to the binary_api_connection, which is made available to from_variant() as a parameter. - * - * However, in the case of a remote method which returns api_base which can subsequently - * be cast by the caller with as, we need to keep track of the connection because - * the binding is done later (when the client code actually calls as). - * - * [1] The binding actually happens in get_remote_api(). - */ - class any_api : public api_base - { - public: - any_api( api_id_type api_id, const std::shared_ptr& con ) - : _api_id(api_id), _binary_api_connection(con) {} - - virtual uint64_t get_handle()const override - { return _api_id; } - - virtual api_id_type register_api( binary_api_connection& conn )const override - { FC_ASSERT( false ); return api_id_type(); } - - api_id_type _api_id; - std::weak_ptr _binary_api_connection; - }; - - } // namespace detail - - class generic_api - { - public: - template - generic_api( const Api& a, const std::shared_ptr& c ); - - generic_api( const generic_api& cpy ) = delete; - - vector call( const string& name, const vector& args ) - { - auto itr = _by_name.find(name); - FC_ASSERT( itr != _by_name.end(), "no method with name '${name}'", ("name",name)("api",_by_name) ); - return call( itr->second, args ); - } - - vector call( uint32_t method_id, const vector& args ) - { - FC_ASSERT( method_id < _methods.size() ); - return _methods[method_id](args); - } - - std::weak_ptr< fc::binary_api_connection > get_connection() - { - return _binary_api_connection; - } - - std::vector get_method_names()const - { - std::vector result; - result.reserve( _by_name.size() ); - for( auto& m : _by_name ) result.push_back(m.first); - return result; - } - - private: - friend struct api_visitor; - - template - std::function bind_first_arg( const std::function& f, Arg0 a0 )const - { - return [=]( Args... args ) { return f( a0, args... ); }; - } - - template - R call_generic( const std::function& f, datastream& ds )const - { - return f(); - } - - template - R call_generic( const std::function,Args...)>& f, datastream& ds ) - { - uint64_t callback_id = 0; - fc::raw::unpack( ds, callback_id ); - detail::callback_functor arg0( get_connection(), callback_id ); - return call_generic( this->bind_first_arg,Args...>( f, std::function(arg0) ), ds ); - } - template - R call_generic( const std::function&,Args...)>& f, fc::datastream& ds ) - { - uint64_t callback_id = 0; - fc::raw::unpack( ds, callback_id ); - detail::callback_functor arg0( get_connection(), callback_id ); - return call_generic( this->bind_first_arg&,Args...>( f, arg0 ), ds ); - } - - template - R call_generic( const std::function& f, fc::datastream& ds ) - { - std::decay::type a0; - fc::raw::unpack( ds, a0 ); - return call_generic( this->bind_first_arg( f, a0 ), ds ); - } - - struct api_visitor - { - api_visitor( generic_api& a, const std::weak_ptr& s ):api(a),_api_con(s){ } - - template - std::function to_generic( const std::function(Args...)>& f )const; - - template - std::function to_generic( const std::function>(Args...)>& f )const; - - template - std::function to_generic( const std::function& f )const; - - template - std::function to_generic( const std::function& f )const; - - template - std::function to_generic( const std::function& f )const; - - template - void operator()( const char* name, std::function& memb )const { - api._methods.emplace_back( to_generic( memb ) ); - api._by_name[name] = api._methods.size() - 1; - } - - generic_api& api; - const std::weak_ptr& _api_con; - }; - - - std::weak_ptr _binary_api_connection; - fc::any _api; - std::map< std::string, uint32_t > _by_name; - std::vector< std::function(const vector&)> > _methods; - }; // class generic_api - - - - class binary_api_connection : public std::enable_shared_from_this - { - public: - typedef std::vector params_type; - typedef std::vector result_type; - - binary_api_connection(){} - virtual ~binary_api_connection(){}; - - - template - api get_remote_api( api_id_type api_id = 0 ) - { - api result; - result->visit( api_visitor( api_id, this->shared_from_this() ) ); - return result; - } - - /** makes calls to the remote server */ - virtual result_type send_call( api_id_type api_id, string method_name, params_type args = params_type() ) = 0; - virtual result_type send_callback( uint64_t callback_id, params_type args = params_type() ) = 0; - virtual void send_notice( uint64_t callback_id, params_type args = params_type() ) = 0; - - result_type receive_call( api_id_type api_id, const string& method_name, const params_type& args = params_type() )const - { - FC_ASSERT( _local_apis.size() > api_id ); - return _local_apis[api_id]->call( method_name, args ); - } - result_type receive_callback( uint64_t callback_id, const params_type& args = params_type() )const - { - FC_ASSERT( _local_callbacks.size() > callback_id ); - return _local_callbacks[callback_id]( args ); - } - void receive_notice( uint64_t callback_id, const params_type& args = params_type() )const - { - FC_ASSERT( _local_callbacks.size() > callback_id ); - _local_callbacks[callback_id]( args ); - } - - template - api_id_type register_api( const Interface& a ) - { - auto handle = a.get_handle(); - auto itr = _handle_to_id.find(handle); - if( itr != _handle_to_id.end() ) return itr->second; - - _local_apis.push_back( std::unique_ptr( new generic_api(a, shared_from_this() ) ) ); - _handle_to_id[handle] = _local_apis.size() - 1; - return _local_apis.size() - 1; - } - - template - uint64_t register_callback( const std::function& cb ) - { - _local_callbacks.push_back( detail::to_generic( cb ) ); - return _local_callbacks.size() - 1; - } - - std::vector get_method_names( api_id_type local_api_id = 0 )const { return _local_apis[local_api_id]->get_method_names(); } - - fc::signal closed; - private: - std::vector< std::unique_ptr > _local_apis; - std::map< uint64_t, api_id_type > _handle_to_id; - std::vector< std::function > _local_callbacks; - - - struct api_visitor - { - uint32_t _api_id; - std::shared_ptr _connection; - - api_visitor( uint32_t api_id, std::shared_ptr con ) - :_api_id(api_id),_connection(std::move(con)) - { - } - - api_visitor() = delete; - - template - static Result from_vector( const vector& v, Result*, const std::shared_ptr& ) - { - return fc::raw::unpack( v ); - } - - template - static fc::api from_vector( const vector& v, - fc::api* /*used for template deduction*/, - const std::shared_ptr& con - ) - { - return con->get_remote_api( fc::raw::unpack( v ) ); - } - - static fc::api_ptr from_vector( - const vector& v, - fc::api_ptr* /* used for template deduction */, - const std::shared_ptr& con - ) - { - return fc::api_ptr( new detail::any_api( fc::raw::unpack(v), con ) ); - } - - template - static result_type convert_callbacks( const std::shared_ptr&, const T& v ) - { - return fc::raw::pack(v); - } - - template - static result_type convert_callbacks( const std::shared_ptr& con, const std::function& v ) - { - return con->register_callback( v ); - } - - template - void operator()( const char* name, std::function& memb )const - { - auto con = _connection; - auto api_id = _api_id; - memb = [con,api_id,name]( Args... args ) { - auto var_result = con->send_call( api_id, name, { convert_callbacks(con,args)...} ); - return from_vector( var_result, (Result*)nullptr, con ); - }; - } - template - void operator()( const char* name, std::function& memb )const - { - auto con = _connection; - auto api_id = _api_id; - memb = [con,api_id,name]( Args... args ) { - con->send_call( api_id, name, { convert_callbacks(con,args)...} ); - }; - } - }; - }; - - class local_binary_api_connection : public binary_api_connection - { - public: - /** makes calls to the remote server */ - virtual result_type send_call( api_id_type api_id, string method_name, params_type args = params_type() ) override - { - FC_ASSERT( _remote_connection ); - return _remote_connection->receive_call( api_id, method_name, std::move(args) ); - } - virtual result_type send_callback( uint64_t callback_id, params_type args = params_type() ) override - { - FC_ASSERT( _remote_connection ); - return _remote_connection->receive_callback( callback_id, args ); - } - virtual void send_notice( uint64_t callback_id, params_type args = params_type() ) override - { - FC_ASSERT( _remote_connection ); - _remote_connection->receive_notice( callback_id, args ); - } - - - void set_remote_connection( const std::shared_ptr& rc ) - { - FC_ASSERT( !_remote_connection ); - FC_ASSERT( rc != this->shared_from_this() ); - _remote_connection = rc; - } - const std::shared_ptr& remote_connection()const { return _remote_connection; } - - std::shared_ptr _remote_connection; - }; - - template - generic_api::generic_api( const Api& a, const std::shared_ptr& c ) - :_binary_api_connection(c),_api(a) - { - boost::any_cast(a)->visit( api_visitor( *this, c ) ); - } - - template - std::function generic_api::api_visitor::to_generic( - const std::function(Args...)>& f )const - { - auto api_con = _api_con; - auto gapi = &api; - return [=]( const params_type& args ) { - auto con = api_con.lock(); - FC_ASSERT( con, "not connected" ); - - fc::raw::datastream ds( args.data(), args.size() ); - auto api_result = gapi->call_generic( f, args ); - return con->register_api( api_result ); - }; - } - template - std::function generic_api::api_visitor::to_generic( - const std::function>(Args...)>& f )const - { - auto api_con = _api_con; - auto gapi = &api; - return [=]( const params_type& args )-> fc::variant { - auto con = api_con.lock(); - FC_ASSERT( con, "not connected" ); - - fc::raw::datastream ds( args.data(), args.size() ); - auto api_result = gapi->call_generic( f, ds ); - if( api_result ) - return con->register_api( *api_result ); - return result_type(); - }; - } - - template - std::function generic_api::api_visitor::to_generic( - const std::function& f )const - { - auto api_con = _api_con; - auto gapi = &api; - return [=]( const variants& args ) -> fc::variant { - auto con = api_con.lock(); - FC_ASSERT( con, "not connected" ); - - fc::raw::datastream ds( args.data(), args.size() ); - auto api_result = gapi->call_generic( f, ds ); - if( !api_result ) - return result_type(); - return api_result->register_api( *con ); - }; - } - - template - std::function generic_api::api_visitor::to_generic( const std::function& f )const - { - generic_api* gapi = &api; - return [f,gapi]( const params_type& args ) { - fc::raw::datastream ds( args.data(), args.size() ); - return fc::raw::pack(gapi->call_generic( f, ds )); - }; - } - - template - std::function generic_api::api_visitor::to_generic( const std::function& f )const - { - generic_api* gapi = &api; - return [f,gapi]( const params_type& args ) { - fc::raw::datastream ds( args.data(), args.size() ); - gapi->call_generic( f, ds ); - return result_type(); - }; - } - - /** - * It is slightly unclean tight coupling to have this method in the api class. - * It breaks encapsulation by requiring an api class method to have a pointer - * to an binary_api_connection. The reason this is necessary is we have a goal of being - * able to call register_api() on an api through its base class api_base. But - * register_api() must know the template parameters! - * - * The only reasonable way to achieve the goal is to implement register_api() - * as a method in api (which obviously knows the template parameter T), - * then make the implementation accessible through the base class (by making - * it a pure virtual method in the base class which is overridden by the subclass's - * implementation). - */ - template< typename Interface, typename Transform > - api_id_type api< Interface, Transform >::register_api( binary_api_connection& conn )const - { - return conn.register_api( *this ); - } - - template< typename T > - api api_base::as() - { - // TODO: this method should probably be const (if it is not too hard) - api* maybe_requested_type = dynamic_cast< api* >(this); - if( maybe_requested_type != nullptr ) - return *maybe_requested_type; - - detail::any_api* maybe_any = dynamic_cast< detail::any_api* >(this); - FC_ASSERT( maybe_any != nullptr ); - std::shared_ptr< binary_api_connection > api_conn = maybe_any->_binary_api_connection.lock(); - FC_ASSERT( api_conn ); - return api_conn->get_remote_api( maybe_any->_api_id ); - } - - namespace detail { - template - template - typename callback_functor::result_type callback_functor::operator()( Args... args )const - { - std::shared_ptr< fc::binary_api_connection > locked = _binary_api_connection.lock(); - // TODO: make new exception type for this instead of recycling eof_exception - if( !locked ) - throw fc::eof_exception(); - - /// TODO------------->>> pack args... - locked->send_callback( _callback_id, fc::raw::pack( args... ) ).template as< result_type >(); - } - - - template - class callback_functor - { - public: - typedef void result_type; - - callback_functor( std::weak_ptr< fc::binary_api_connection > con, uint64_t id ) - :_callback_id(id),_binary_api_connection(con){} - - void operator()( Args... args )const - { - std::shared_ptr< fc::binary_api_connection > locked = _binary_api_connection.lock(); - // TODO: make new exception type for this instead of recycling eof_exception - if( !locked ) - throw fc::eof_exception(); - locked->send_notice( _callback_id, fc::variants{ args... } ); - } - - private: - uint64_t _callback_id; - std::weak_ptr< fc::binary_api_connection > _binary_api_connection; - }; - } // namespace detail - -} // fc diff --git a/include/fc/rpc/cli.hpp b/include/fc/rpc/cli.hpp deleted file mode 100644 index bb4975fe6..000000000 --- a/include/fc/rpc/cli.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include - -#include - -namespace fc { namespace rpc { - - /** - * Provides a simple wrapper for RPC calls to a given interface. - */ - class cli : public api_connection - { - public: - ~cli(); - - virtual variant send_call( api_id_type api_id, string method_name, variants args = variants() ); - virtual variant send_callback( uint64_t callback_id, variants args = variants() ); - virtual void send_notice( uint64_t callback_id, variants args = variants() ); - - void start(); - void stop(); - void wait(); - void format_result( const string& method, std::function formatter); - - virtual void getline( const fc::string& prompt, fc::string& line ); - - void set_prompt( const string& prompt ); - - private: - void run(); - - std::string _prompt = ">>>"; - std::map > _result_formatters; - fc::future _run_complete; - }; -} } diff --git a/include/fc/rpc/http_api.hpp b/include/fc/rpc/http_api.hpp deleted file mode 100644 index 47eb289fe..000000000 --- a/include/fc/rpc/http_api.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include - -namespace fc { namespace rpc { - - class http_api_connection : public api_connection - { - public: - http_api_connection(); - ~http_api_connection(); - - virtual variant send_call( - api_id_type api_id, - string method_name, - variants args = variants() ) override; - virtual variant send_callback( - uint64_t callback_id, - variants args = variants() ) override; - virtual void send_notice( - uint64_t callback_id, - variants args = variants() ) override; - - void on_request( - const fc::http::request& req, - const fc::http::server::response& resp ); - - fc::rpc::state _rpc_state; - }; - -} } // namespace fc::rpc diff --git a/include/fc/rpc/json_connection.hpp b/include/fc/rpc/json_connection.hpp deleted file mode 100644 index 04cd041b0..000000000 --- a/include/fc/rpc/json_connection.hpp +++ /dev/null @@ -1,315 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include - -namespace fc { namespace rpc { - - namespace detail { class json_connection_impl; } - - /** - * @brief Implements JSON-RPC 2.0 over a set of io streams - * - * Each JSON RPC message is expected to be on its own line, violators - * will be prosecuted to the fullest extent of the law. - */ - class json_connection - { - public: - typedef std::function method; - typedef std::function named_param_method; - - json_connection( fc::buffered_istream_ptr in, fc::buffered_ostream_ptr out ); - ~json_connection(); - - /** - * Starts processing messages from input - */ - future exec(); - - bool is_open(); - void close(); - - void set_on_disconnected_callback(std::function callback); - - logger get_logger()const; - void set_logger( const logger& l ); - - /** - * @name server interface - * - * Adding methods to the interface allows the remote side - * to call them. - */ - ///@{ - void add_method( const fc::string& name, method ); - void add_named_param_method( const fc::string& name, named_param_method ); - void remove_method( const fc::string& name ); - //@} - - /** - * @name client interface - */ - ///@{ - void notice( const fc::string& method ); - void notice( const fc::string& method, const variants& args ); - void notice( const fc::string& method, const variant_object& named_args ); - - /// args will be handled as named params - future async_call( const fc::string& method, - const variant_object& args ); - - future async_call( const fc::string& method, mutable_variant_object args ); - - /// Sending in an array of variants will be handled as positional arguments - future async_call( const fc::string& method, - const variants& args ); - - future async_call( const fc::string& method ); - - future async_call( const fc::string& method, - const variant& a1 ); - - future async_call( const fc::string& method, - const variant& a1, - const variant& a2 ); - - future async_call( const fc::string& method, - const variant& a1, - const variant& a2, - const variant& a3 ); - - future async_call( const fc::string& method, - const variant& a1, - const variant& a2, - const variant& a3, - const variant& a4 ); - - future async_call( const fc::string& method, - const variant& a1, - const variant& a2, - const variant& a3, - const variant& a4, - const variant& a5 ); - - future async_call( const fc::string& method, - const variant& a1, - const variant& a2, - const variant& a3, - const variant& a4, - const variant& a5, - const variant& a6 ); - - future async_call( const fc::string& method, - const variant& a1, - const variant& a2, - const variant& a3, - const variant& a4, - const variant& a5, - const variant& a6, - const variant& a7 - ); - - future async_call( const fc::string& method, - const variant& a1, - const variant& a2, - const variant& a3, - const variant& a4, - const variant& a5, - const variant& a6, - const variant& a7, - const variant& a8 - ); - future async_call( const fc::string& method, - const variant& a1, - const variant& a2, - const variant& a3, - const variant& a4, - const variant& a5, - const variant& a6, - const variant& a7, - const variant& a8, - const variant& a9 - ); - future async_call( const fc::string& method, - const variant& a1, - const variant& a2, - const variant& a3, - const variant& a4, - const variant& a5, - const variant& a6, - const variant& a7, - const variant& a8, - const variant& a9, - const variant& a10 - ); - - template - Result call( const fc::string& method, - const variants& args, - microseconds timeout = microseconds::maximum()) - { - return async_call( method, args ).wait(timeout).as(); - } - - template - Result call( const fc::string& method, - const variant& a1, - const variant& a2, - const variant& a3, - microseconds timeout = microseconds::maximum()) - { - return async_call( method, a1, a2, a3 ).wait(timeout).as(); - } - - template - Result call( const fc::string& method, - const variant& a1, - const variant& a2, - const variant& a3, - const variant& a4, - microseconds timeout = microseconds::maximum()) - { - return async_call( method, a1, a2, a3, a4).wait(timeout).as(); - } - - template - Result call( const fc::string& method, - const variant& a1, - const variant& a2, - const variant& a3, - const variant& a4, - const variant& a5, - microseconds timeout = microseconds::maximum()) - { - return async_call( method, a1, a2, a3, a4, a5).wait(timeout).as(); - } - - template - Result call( const fc::string& method, - const variant& a1, - const variant& a2, - const variant& a3, - const variant& a4, - const variant& a5, - const variant& a6, - microseconds timeout = microseconds::maximum()) - { - return async_call( method, a1, a2, a3, a4, a5, a6).wait(timeout).as(); - } - template - Result call( const fc::string& method, - const variant& a1, - const variant& a2, - const variant& a3, - const variant& a4, - const variant& a5, - const variant& a6, - const variant& a7, - microseconds timeout = microseconds::maximum()) - { - return async_call( method, a1, a2, a3, a4, a5, a6, a7).wait(timeout).as(); - } - - template - Result call( const fc::string& method, - const variant& a1, - const variant& a2, - const variant& a3, - const variant& a4, - const variant& a5, - const variant& a6, - const variant& a7, - const variant& a8, - microseconds timeout = microseconds::maximum()) - { - return async_call( method, a1, a2, a3, a4, a5, a6, a7, a8).wait(timeout).as(); - } - - template - Result call( const fc::string& method, - const variant& a1, - const variant& a2, - const variant& a3, - const variant& a4, - const variant& a5, - const variant& a6, - const variant& a7, - const variant& a8, - const variant& a9, - microseconds timeout = microseconds::maximum()) - { - return async_call( method, a1, a2, a3, a4, a5, a6, a7, a8, a9).wait(timeout).as(); - } - - template - Result call( const fc::string& method, - const variant& a1, - const variant& a2, - const variant& a3, - const variant& a4, - const variant& a5, - const variant& a6, - const variant& a7, - const variant& a8, - const variant& a9, - const variant& a10, - microseconds timeout = microseconds::maximum()) - { - return async_call( method, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10).wait(timeout).as(); - } - - template - Result call( const fc::string& method, - const variant& a1, - const variant& a2, - microseconds timeout = microseconds::maximum()) - { - return async_call( method, a1, a2 ).wait(timeout).as(); - } - - template - Result call( const fc::string& method, - const variant& a1, - microseconds timeout = microseconds::maximum()) - { - return async_call( method, a1 ).wait(timeout).as(); - } - - template - Result call( const fc::string& method, - variant_object a1, - microseconds timeout = microseconds::maximum()) - { - return async_call( method, fc::move(a1) ).wait(timeout).as(); - } - template - Result call( const fc::string& method, - mutable_variant_object a1, - microseconds timeout = microseconds::maximum()) - { - return async_call( method, variant_object( fc::move(a1) ) ).wait(timeout).as(); - } - - - template - Result call( const fc::string& method, microseconds timeout = microseconds::maximum() ) - { - return async_call( method ).wait(timeout).as(); - } - - /// Sending in a variant_object will be issued as named parameters - variant call( const fc::string& method, const variant_object& named_args ); - ///@} - - private: - std::unique_ptr my; - }; - typedef std::shared_ptr json_connection_ptr; - -}} // fc::rpc - - - diff --git a/include/fc/rpc/variant_connection.hpp b/include/fc/rpc/variant_connection.hpp deleted file mode 100644 index 93cb29b1e..000000000 --- a/include/fc/rpc/variant_connection.hpp +++ /dev/null @@ -1,140 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include - -namespace fc { namespace rpc { - - namespace detail { class variant_connection_impl; } - - /** - * @brief Implements JSON-RPC 2.0 over a set of io streams - * - * Each JSON RPC message is expected to be on its own line, violators - * will be prosecuted to the fullest extent of the law. - */ - class variant_connection - { - public: - typedef std::function method; - typedef std::function named_param_method; - - variant_connection( fc::variant_stream::ptr in, fc::variant_stream::ptr out ); - ~variant_connection(); - - /** - * Starts processing messages from input - */ - future exec(); - - logger get_logger()const; - void set_logger( const logger& l ); - - /** - * @name server interface - * - * Adding methods to the interface allows the remote side - * to call them. - */ - ///@{ - void add_method( const fc::string& name, method ); - void add_named_param_method( const fc::string& name, named_param_method ); - void remove_method( const fc::string& name ); - //@} - - /** - * @name client interface - */ - ///@{ - void notice( const fc::string& method ); - void notice( const fc::string& method, const variants& args ); - void notice( const fc::string& method, const variant_object& named_args ); - - /// args will be handled as named params - future async_call( const fc::string& method, - const variant_object& args ); - - future async_call( const fc::string& method, mutable_variant_object args ); - - /// Sending in an array of variants will be handled as positional arguments - future async_call( const fc::string& method, - const variants& args ); - - future async_call( const fc::string& method ); - - future async_call( const fc::string& method, - const variant& a1 ); - - future async_call( const fc::string& method, - const variant& a1, - const variant& a2 ); - - future async_call( const fc::string& method, - const variant& a1, - const variant& a2, - const variant& a3 ); - - template - Result call( const fc::string& method, - const variant& a1, - const variant& a2, - const variant& a3, - microseconds timeout = microseconds::maximum()) - { - return async_call( method, a1, a2, a3 ).wait(timeout).as(); - } - - template - Result call( const fc::string& method, - const variant& a1, - const variant& a2, - microseconds timeout = microseconds::maximum()) - { - return async_call( method, a1, a2 ).wait(timeout).as(); - } - - template - Result call( const fc::string& method, - const variant& a1, - microseconds timeout = microseconds::maximum()) - { - return async_call( method, a1 ).wait(timeout).as(); - } - - template - Result call( const fc::string& method, - variant_object a1, - microseconds timeout = microseconds::maximum()) - { - return async_call( method, fc::move(a1) ).wait(timeout).as(); - } - template - Result call( const fc::string& method, - mutable_variant_object a1, - microseconds timeout = microseconds::maximum()) - { - return async_call( method, variant_object( fc::move(a1) ) ).wait(timeout).as(); - } - - - template - Result call( const fc::string& method, microseconds timeout = microseconds::maximum() ) - { - return async_call( method ).wait(timeout).as(); - } - - /// Sending in a variant_object will be issued as named parameters - variant call( const fc::string& method, const variant_object& named_args ); - ///@} - - private: - std::unique_ptr my; - }; - typedef std::shared_ptr variant_connection_ptr; - -}} // fc::rpc - - - diff --git a/include/fc/rpc/websocket_api.hpp b/include/fc/rpc/websocket_api.hpp deleted file mode 100644 index 92d7f2eb5..000000000 --- a/include/fc/rpc/websocket_api.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include - -namespace fc { namespace rpc { - - class websocket_api_connection : public api_connection - { - public: - websocket_api_connection( fc::http::websocket_connection& c ); - ~websocket_api_connection(); - - virtual variant send_call( - api_id_type api_id, - string method_name, - variants args = variants() ) override; - virtual variant send_callback( - uint64_t callback_id, - variants args = variants() ) override; - virtual void send_notice( - uint64_t callback_id, - variants args = variants() ) override; - - protected: - std::string on_message( - const std::string& message, - bool send_message = true ); - - fc::http::websocket_connection& _connection; - fc::rpc::state _rpc_state; - }; - -} } // namespace fc::rpc