From d4554ca029fc1a0caabc7bee7ed4a3d1fb4dbb36 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Mon, 29 Oct 2012 13:19:17 -0700 Subject: [PATCH 1/2] updates for arm --- CMakeLists.txt | 3 ++- include/fc/iostream.hpp | 9 --------- include/fc/lexical_cast.hpp | 2 +- include/fc/sha1.hpp | 2 +- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e3c6157..8628aa9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,7 @@ option( UNITY_BUILD OFF ) include_directories( vendor/boost/process/include ) include_directories( ${Boost_INCLUDE_DIR} ) +include_directories( ${OPENSSL_INCLUDE_DIR} ) include_directories( include ) set( sources @@ -82,7 +83,7 @@ set( sources ) setup_library( fc SOURCES ${sources} ) -setup_executable( json_rpc_test SOURCES tests/json_rpc_test.cpp LIBRARIES fc ${Boost_THREAD_LIBRARY} ${Boost_CONTEXT_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_CHRONO_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ) +setup_executable( json_rpc_test SOURCES tests/json_rpc_test.cpp LIBRARIES fc ${pthread_library} ${rt_library} ${Boost_THREAD_LIBRARY} ${Boost_CONTEXT_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_CHRONO_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${rt_library} ) #add_executable( test_vec tests/vector_test.cpp ) #target_link_libraries( test_vec fc ${Boost_SYSTEM_LIBRARY} ${Boost_CHRONO_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_CONTEXT_LIBRARY} ) diff --git a/include/fc/iostream.hpp b/include/fc/iostream.hpp index f0650d8..0e3829a 100644 --- a/include/fc/iostream.hpp +++ b/include/fc/iostream.hpp @@ -76,13 +76,4 @@ namespace fc { v = fc::lexical_cast(str); return o; } - - fc::cin_t& getline( fc::cin_t&, fc::string&, char delim = '\n' ); - template - cin_t& operator>>( cin_t& o, T& v ) { - fc::string str; - getline( o, str, ' ' ); - v = fc::lexical_cast(str); - return o; - } } diff --git a/include/fc/lexical_cast.hpp b/include/fc/lexical_cast.hpp index e0f491e..18b9f6f 100644 --- a/include/fc/lexical_cast.hpp +++ b/include/fc/lexical_cast.hpp @@ -28,7 +28,7 @@ namespace fc { fc::string to_string( int16_t d ); fc::string to_string( int8_t d ); fc::string to_string( char d ); - fc::string to_string( const char* d ); + inline fc::string to_string( const char* d ) { return d; } inline fc::string to_string( fc::string s ) { return s; } template diff --git a/include/fc/sha1.hpp b/include/fc/sha1.hpp index 34ddb7a..cef850f 100644 --- a/include/fc/sha1.hpp +++ b/include/fc/sha1.hpp @@ -34,7 +34,7 @@ namespace fc { private: struct impl; - fwd my; + fwd my; }; template From 9adbe96079413f1052e96f1953807fd3620a8ca4 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Mon, 29 Oct 2012 14:06:58 -0700 Subject: [PATCH 2/2] adding rpc server methods --- include/fc/json_rpc_connection.hpp | 54 ++++++++++++++++++++++++------ include/fc/reflect.hpp | 8 ----- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/include/fc/json_rpc_connection.hpp b/include/fc/json_rpc_connection.hpp index 375bcbb..6f357b6 100644 --- a/include/fc/json_rpc_connection.hpp +++ b/include/fc/json_rpc_connection.hpp @@ -3,8 +3,16 @@ #include #include #include +#include namespace fc { namespace json { + class rpc_connection; + + struct rpc_server_function : public fc::retainable { + typedef fc::shared_ptr ptr; + virtual value call( const value& v ) = 0; + }; + namespace detail { struct pending_result : virtual public promise_base { typedef shared_ptr ptr; @@ -31,6 +39,28 @@ namespace fc { namespace json { protected: ~pending_result_impl(){} }; + + + template + struct rpc_server_function_impl : public rpc_server_function { + rpc_server_function_impl( const fc::function& f ):func(f){} + virtual value call( const value& v ) { + return value( func( fc::value_cast( v ) ) ); + } + fc::function func; + }; + + template + struct add_method_visitor { + public: + add_method_visitor( const fc::ptr& p, fc::json::rpc_connection& c ):_ptr(p){} + + template + void operator()( const char* name, fc::function& meth, Type ); + + const fc::ptr& _ptr; + fc::json::rpc_connection& _con; + }; } /** @@ -55,32 +85,36 @@ namespace fc { namespace json { /** note the life of i and o must be longer than rpc_connection's life */ void init( istream& i, ostream& o ); - /* - template - future invoke( const fc::string& method ) { - auto r = new detail::pending_result_impl(); - invoke( detail::pending_result::ptr(r), method, value(make_tuple()) ); - return promise::ptr( r, true ); - } */ - template future invoke( const fc::string& method, Args&& a = nullptr )const { auto r = new detail::pending_result_impl(); - slog( "%p", r ); typename promise::ptr rtn( r, true ); invoke( detail::pending_result::ptr(r), method, value(fc::forward(a)) ); return rtn; } + template + void add_interface( const fc::ptr& it ) { + it->template visit( detail::add_method_visitor( it, *this ) ); + } + + void add_method( const fc::string& name, const fc::json::rpc_server_function::ptr& func ); + private: void invoke( detail::pending_result::ptr&& p, const fc::string& m, const value& param )const; class impl; fc::shared_ptr my; }; + namespace detail { + template + template + void add_method_visitor::operator()( const char* name, fc::function& meth, Type ) { + _con.add_method( name, rpc_server_function::ptr( new rpc_server_function_impl(meth) ) ); + } + } // namespace detail } } // fc::json - diff --git a/include/fc/reflect.hpp b/include/fc/reflect.hpp index 469ca28..219351a 100644 --- a/include/fc/reflect.hpp +++ b/include/fc/reflect.hpp @@ -9,20 +9,12 @@ #define _FC_REFLECT_HPP_ #include -#include -//#include -#include #include #include #include -//#include -//#include #include -//#include -//#include - namespace fc { /**