diff --git a/CMakeLists.txt b/CMakeLists.txt index 2750cbe..f605b64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,7 @@ endif() option( UNITY_BUILD OFF ) FIND_PACKAGE( OpenSSL ) +#FIND_PACKAGE( ZLIB ) include_directories( vendor/zlib-1.2.7/) include_directories( vendor/libssh2-1.4.2/include ) @@ -98,7 +99,7 @@ add_subdirectory(vendor) setup_library( fc SOURCES ${sources} ) -#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} ${Boost_DATE_TIME_LIBRARY}) +#setup_executable( json_rpc_test SOURCES tests/json_rpc_test.cpp LIBRARIES fc ${ZLIB_LIBRARY} ${pthread_library} ${rt_library} ${Boost_THREAD_LIBRARY} ${Boost_CONTEXT_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_CHRONO_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${rt_library} ${Boost_DATE_TIME_LIBRARY}) #setup_executable( ssh_test SOURCES tests/ssh.cpp LIBRARIES fc ${pthread_library} ${rt_library} ${Boost_THREAD_LIBRARY} ${Boost_CONTEXT_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_CHRONO_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${rt_library} ssh2 ${OPENSSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY} ${ZLIB_LIBRARY} ${ALL_OPENSSL_LIBRARIES} ${Boost_DATE_TIME_LIBRARY}) #add_executable( test_vec tests/vector_test.cpp ) diff --git a/include/fc/interprocess/file_mapping.hpp b/include/fc/interprocess/file_mapping.hpp index 8f01ab7..0610887 100644 --- a/include/fc/interprocess/file_mapping.hpp +++ b/include/fc/interprocess/file_mapping.hpp @@ -1,5 +1,4 @@ -#ifndef _FC_INTERPROCESS_FILEMAPPING_HPP_ -#define _FC_INTERPROCESS_FILEMAPPING_HPP_ +#pragma once #include #include @@ -35,4 +34,3 @@ namespace fc { fc::fwd my; }; } -#endif diff --git a/include/fc/signal.hpp b/include/fc/signal.hpp new file mode 100644 index 0000000..925ef4f --- /dev/null +++ b/include/fc/signal.hpp @@ -0,0 +1,48 @@ +#pragma once +#include +#include + + +namespace fc { + + template + class signal { + public: + typedef int64_t connection_id_type; + + template + connection_id_type connect( Functor&& f ) { + auto c = new std::function( fc::forward(f) ); + _handlers.push_back( c ); + return reinterpret_cast(c); + } + + template + void emit( Args&&... args ) { + for( size_t i = 0; i < _handlers.size(); ++i ) { + (*_handlers[i])( args... ); + } + } + template + void operator()( Args&&... args ) { + for( size_t i = 0; i < _handlers.size(); ++i ) { + (*_handlers[i])( args... ); + } + } + + void disconnect( connection_id_type cid ) { + auto itr = _handlers.begin(); + while( itr != _handlers.end() ) { + if( reinterpret_cast(*itr) == cid ) { + delete *itr; + _handlers.erase(itr); + } + ++itr; + } + } + + private: + fc::vector< std::function* > _handlers; + }; + +} diff --git a/include/fc/signals.hpp b/include/fc/signals.hpp index 105fdc4..97e3518 100644 --- a/include/fc/signals.hpp +++ b/include/fc/signals.hpp @@ -1,5 +1,3 @@ -#ifndef _FC_SIGNALS_HPP -#define _FC_SIGNALS_HPP #include #include #include @@ -27,4 +25,3 @@ namespace fc { } } -#endif diff --git a/include/fc/spin_lock.hpp b/include/fc/spin_lock.hpp index 489e9e6..6dfbd1a 100644 --- a/include/fc/spin_lock.hpp +++ b/include/fc/spin_lock.hpp @@ -1,6 +1,3 @@ -#ifndef _FC_SPIN_LOCK_HPP_ -#define _FC_SPIN_LOCK_HPP_ - namespace boost { template class atomic; } @@ -38,4 +35,3 @@ namespace fc { } // namespace fc -#endif // _FC_SPIN_LOCK_HPP_ diff --git a/src/lexical_cast.cpp b/src/lexical_cast.cpp index 7a8ba3a..142e200 100644 --- a/src/lexical_cast.cpp +++ b/src/lexical_cast.cpp @@ -13,6 +13,9 @@ namespace fc { return boost::lexical_cast(s.c_str()); } fc::string to_string( double d ){ return boost::lexical_cast(d); } + #ifdef __APPLE__ + fc::string to_string( size_t d ){ return boost::lexical_cast(d); } + #endif fc::string to_string( uint64_t d ){ return boost::lexical_cast(d); } fc::string to_string( uint32_t d ){ return boost::lexical_cast(d); } fc::string to_string( uint16_t d ){ return boost::lexical_cast(d); } diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt index b565b83..7b4140e 100644 --- a/vendor/CMakeLists.txt +++ b/vendor/CMakeLists.txt @@ -1,3 +1,3 @@ add_subdirectory( libssh2-1.4.2 ) add_subdirectory( zlib-1.2.7) -add_subdirectory( sigar ) +#add_subdirectory( sigar )