From 17117bc6bfc76b027d14c68b4206b0ffb91b4e8e Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Fri, 6 Jun 2014 22:46:28 -0400 Subject: [PATCH] adding support for 7 arg rpc calls --- include/fc/exception/exception.hpp | 10 ++++++---- include/fc/rpc/json_connection.hpp | 23 +++++++++++++++++++++++ src/rpc/json_connection.cpp | 30 ++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/include/fc/exception/exception.hpp b/include/fc/exception/exception.hpp index fc291c3..10f9c9e 100644 --- a/include/fc/exception/exception.hpp +++ b/include/fc/exception/exception.hpp @@ -326,17 +326,19 @@ do { if( !(TEST) ) { FC_THROW_EXCEPTION( fc::assert_exception, #TEST ": " __VA_ FC_LOG_MESSAGE( LOG_LEVEL, FORMAT,__VA_ARGS__), \ std::current_exception() ); \ } -#define FC_CAPTURE_AND_RETHROW( SEQ ) \ + +#define FC_CAPTURE_AND_RETHROW( __VA_ARGS__ ) \ catch( fc::exception& er ) { \ - FC_RETHROW_EXCEPTION( er, fc::log_level::warn, "", FC_FORMAT_ARG_PARAMS(SEQ) ); \ + FC_RETHROW_EXCEPTION( er, warn, "", FC_FORMAT_ARG_PARAMS(__VA_ARGS__) ); \ } catch( const std::exception& e ) { \ fc::exception fce( \ - FC_LOG_MESSAGE( fc::log_level::warn, "${what}",FC_FORMAT_ARG_PARAMS(SEQ)("what",e.what())), \ + FC_LOG_MESSAGE( warn, "${what}",FC_FORMAT_ARG_PARAMS(__VA_ARGS__)("what",e.what())), \ fc::std_exception_code,\ typeid(e).name(), \ e.what() ) ; throw fce;\ } catch( ... ) { \ throw fc::unhandled_exception( \ - FC_LOG_MESSAGE( fc::log_level::warn, "",FC_FORMAT_ARG_PARAMS(SEQ)), \ + FC_LOG_MESSAGE( warn, "",FC_FORMAT_ARG_PARAMS(__VA_ARGS__)), \ std::current_exception() ); \ } + diff --git a/include/fc/rpc/json_connection.hpp b/include/fc/rpc/json_connection.hpp index 88c46a6..b666a74 100644 --- a/include/fc/rpc/json_connection.hpp +++ b/include/fc/rpc/json_connection.hpp @@ -97,6 +97,16 @@ namespace fc { namespace rpc { 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 + ); + template Result call( const fc::string& method, const variant& a1, @@ -142,6 +152,19 @@ namespace fc { namespace rpc { { 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,7).wait(timeout).as(); + } template Result call( const fc::string& method, diff --git a/src/rpc/json_connection.cpp b/src/rpc/json_connection.cpp index 37da39b..226d145 100644 --- a/src/rpc/json_connection.cpp +++ b/src/rpc/json_connection.cpp @@ -488,6 +488,36 @@ namespace fc { namespace rpc { my->_out->flush(); return my->_awaiting[id]; } + future json_connection::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 ) + { + auto id = my->_next_id++; + my->_awaiting[id] = fc::promise::ptr( new fc::promise() ); + + { + fc::scoped_lock lock(my->_write_mutex); + *my->_out << "{\"id\":"; + *my->_out << id; + *my->_out << ",\"method\":"; + json::to_stream( *my->_out, method ); + *my->_out << ",\"params\":["; + fc::json::to_stream( *my->_out, a1 ); + *my->_out << ","; + fc::json::to_stream( *my->_out, a2 ); + *my->_out << ","; + fc::json::to_stream( *my->_out, a3 ); + *my->_out << ","; + fc::json::to_stream( *my->_out, a4 ); + *my->_out << ","; + fc::json::to_stream( *my->_out, a5 ); + *my->_out << ","; + fc::json::to_stream( *my->_out, a6 ); + *my->_out << ","; + fc::json::to_stream( *my->_out, a7 ); + *my->_out << "]}\n"; + } + my->_out->flush(); + return my->_awaiting[id]; + } future json_connection::async_call( const fc::string& method, mutable_variant_object named_args ) {