diff --git a/include/fc/json_rpc_connection.hpp b/include/fc/json_rpc_connection.hpp index a968211..4bc6f4c 100644 --- a/include/fc/json_rpc_connection.hpp +++ b/include/fc/json_rpc_connection.hpp @@ -39,12 +39,38 @@ namespace fc { namespace json { ~pending_result_impl(){} }; + template + struct named_param { + typedef fc::false_type type; + static T cast( const value& v ) { return fc::value_cast(v); } + + template + static value to_value( X&& x ) { return value(fc::forward(x)); } + }; + + #define FC_JSON_NAMED_PARAMS( T ) \ + namespace fc { namespace json {namespace detail { \ + template \ + struct named_param< fc::tuple > { \ + typedef fc::true_type type; \ + static tuple cast( const value& v ) { return make_tuple(fc::value_cast(v)); } \ + template \ + static value to_value( X&& x ) { return value( x.a0 ); }\ + }; \ + template \ + struct named_param< fc::tuple > { \ + typedef fc::true_type type; \ + static tuple cast( const value& v ) { return make_tuple(fc::value_cast(v)); } \ + template \ + static value to_value( X&& x ) { return value( x.a0 ); }\ + }; \ + } } } template struct rpc_server_method_impl : public rpc_server_method { rpc_server_method_impl( const std::function& f ):func(f){} virtual value call( const value& v ) { - return value( call_fused(func, fc::value_cast( v ) ) ); + return value( call_fused(func, named_param::cast(v) ) ); } std::function func; }; @@ -89,7 +115,8 @@ namespace fc { namespace json { future invoke( const fc::string& method, Args&& a = nullptr ){ auto r = new detail::pending_result_impl(); typename promise::ptr rtn( r, true ); - invoke( detail::pending_result::ptr(r), method, value(fc::forward(a)) ); + invoke( detail::pending_result::ptr(r), method, + value(detail::named_param::type>::to_value(a)) ); return rtn; } diff --git a/include/fc/utility.hpp b/include/fc/utility.hpp index f7be959..2fb5994 100644 --- a/include/fc/utility.hpp +++ b/include/fc/utility.hpp @@ -13,9 +13,14 @@ namespace std { namespace fc { template struct remove_reference { typedef T type; }; template struct remove_reference { typedef T type; }; - template struct remove_reference { typedef const T type; }; template struct remove_reference { typedef T type; }; + template struct deduce { typedef T type; }; + template struct deduce { typedef T type; }; + template struct deduce { typedef T type; }; + template struct deduce { typedef T type; }; + template struct deduce{ typedef T type; }; + template typename fc::remove_reference::type&& move( T&& t ) { return static_cast::type&&>(t); } diff --git a/tests/json_rpc_test.cpp b/tests/json_rpc_test.cpp index f54522c..fc448c1 100644 --- a/tests/json_rpc_test.cpp +++ b/tests/json_rpc_test.cpp @@ -5,10 +5,19 @@ #include #include +struct namep { + fc::string a; + double b; +}; + +FC_REFLECT( namep, (a)(b) ) +FC_JSON_NAMED_PARAMS( namep ) + struct test { int add(int x){ return x+1; } int sub(int x){ return x-1; } int sub1(int x){ return 3; } + int namep_test(namep x){ return 3; } int sub2(float x){ return 3; } int sub3(double x, int y){ return x-y; } int sub4(uint16_t x){ return 3; } @@ -19,7 +28,7 @@ struct test { int sub9(int x){ return 3; } }; -FC_STUB( test, (add)(sub)(sub1)(sub2)(sub3)(sub4)(sub5)(sub6)(sub7)(sub8)(sub9) ) +FC_STUB( test, (add)(namep_test)(sub)(sub1)(sub2)(sub3)(sub4)(sub5)(sub6)(sub7)(sub8)(sub9) ) int main( int argc, char** argv ) { try { @@ -27,6 +36,7 @@ int main( int argc, char** argv ) { fc::json::rpc_tcp_server serv; serv.add_interface( t ); serv.listen(8001); + slog( "%s", fc::json::to_string( fc::json::detail::named_param >::to_value(fc::tuple() ) ).c_str() ); slog("..."); { wlog( "create new connection" ); @@ -38,6 +48,7 @@ int main( int argc, char** argv ) { fc::json::rpc_client rpcc( con ); slog( "5+1=%d", rpcc->add(5).wait() ); slog( "sub3 4-5=%d", rpcc->sub3(4,5).wait() ); + slog( "namep=%d", rpcc->namep_test(namep()).wait() ); } slog( "exit serv" ); /* diff --git a/tests/ssh.cpp b/tests/ssh.cpp index e02ae39..c21e949 100644 --- a/tests/ssh.cpp +++ b/tests/ssh.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +//#include int main( int argc, char** argv ) { try { @@ -11,10 +11,10 @@ int main( int argc, char** argv ) { // return -1; // } fc::cout<<"password: "; - std::string pw; - std::cin>>pw; +// fc::string pw; +// std::cin>>pw; fc::ssh::client c; - c.connect( "dlarimer", pw, "localhost" ); + c.connect( "dlarimer", "yyRK@$p9", "localhost" ); fc::ssh::process proc = c.exec( "/bin/ls" ); while( !proc.out_stream().eof() ) { fc::string line;