Updates from BitShares FC #22
133 changed files with 494 additions and 3007 deletions
|
|
@ -233,12 +233,9 @@ set( fc_sources
|
|||
src/io/sstream.cpp
|
||||
src/io/json.cpp
|
||||
src/io/varint.cpp
|
||||
src/io/console.cpp
|
||||
src/filesystem.cpp
|
||||
src/interprocess/signals.cpp
|
||||
src/interprocess/file_mapping.cpp
|
||||
src/interprocess/mmap_struct.cpp
|
||||
src/interprocess/file_mutex.cpp
|
||||
src/rpc/cli.cpp
|
||||
src/rpc/http_api.cpp
|
||||
src/rpc/json_connection.cpp
|
||||
|
|
|
|||
|
|
@ -31,12 +31,6 @@
|
|||
</Expand>
|
||||
</Type>
|
||||
|
||||
<Type Name="fc::string">
|
||||
<DisplayString>{my}</DisplayString>
|
||||
<Expand>
|
||||
<ExpandedItem>my</ExpandedItem>
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
<Type Name="fc::optional<*>">
|
||||
<DisplayString Condition="!_valid">invalid</DisplayString>
|
||||
|
|
@ -54,4 +48,4 @@
|
|||
</Expand>
|
||||
</Type>
|
||||
|
||||
</AutoVisualizer>
|
||||
</AutoVisualizer>
|
||||
|
|
|
|||
|
|
@ -1,65 +0,0 @@
|
|||
#pragma once
|
||||
#include <fc/api.hpp>
|
||||
#include <fc/thread/thread.hpp>
|
||||
|
||||
namespace fc {
|
||||
|
||||
namespace detail {
|
||||
struct actor_member {
|
||||
#if 1 // BOOST_NO_VARIADIC_TEMPLATES
|
||||
#define RPC_MEMBER_FUNCTOR(z,n,IS_CONST) \
|
||||
template<typename R, typename C, typename P BOOST_PP_ENUM_TRAILING_PARAMS( n, typename A)> \
|
||||
static std::function<fc::future<R>( 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<R>{ \
|
||||
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<typename R, typename C, typename P, typename... Args>
|
||||
static std::function<fc::future<R>(Args...)> functor( P&& p, R (C::*mem_func)(Args...), fc::thread* c ) {
|
||||
return [=](Args... args)->fc::future<R>{ c->async( [=]()->R { return p->*mem_func( fc::forward<Args>(args)... ); } ) };
|
||||
}
|
||||
template<typename R, typename C, typename P, typename... Args>
|
||||
static std::function<fc::future<R>(Args...)> functor( P&& p, R (C::*mem_func)(Args...)const, fc::thread* c ){
|
||||
return [=](Args... args)->fc::future<R>{ c->async( [=]()->R { return p->*mem_func( fc::forward<Args>(args)... ); } ) };
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
template<typename ThisPtr>
|
||||
struct actor_vtable_visitor {
|
||||
template<typename U>
|
||||
actor_vtable_visitor( fc::thread* t, U&& u ):_thread(t),_this( fc::forward<U>(u) ){}
|
||||
|
||||
template<typename Function, typename MemberPtr>
|
||||
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<typename Interface>
|
||||
class actor : public api<Interface, detail::actor_member> {
|
||||
public:
|
||||
actor(){}
|
||||
|
||||
template<typename InterfaceType>
|
||||
actor( InterfaceType* p, fc::thread* t = &fc::thread::current() )
|
||||
{
|
||||
this->_vtable.reset(new detail::vtable<Interface,detail::actor_member>() );
|
||||
this->_vtable->template visit<InterfaceType>( detail::actor_vtable_visitor<InterfaceType*>(t, p) );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace fc
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
#pragma once
|
||||
namespace fc {
|
||||
|
||||
template<unsigned int S, typename T=double>
|
||||
struct aligned {
|
||||
union {
|
||||
T _align;
|
||||
char _data[S];
|
||||
} _store;
|
||||
operator char*() { return _store._data; }
|
||||
operator const char*()const { return _store._data; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
#pragma once
|
||||
#include <boost/any.hpp>
|
||||
|
||||
namespace fc {
|
||||
// TODO: define this without using boost
|
||||
typedef boost::any any;
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
#include <fc/thread/future.hpp>
|
||||
#include <fc/any.hpp>
|
||||
#include <functional>
|
||||
#include <boost/any.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
// ms visual c++ (as of 2013) doesn't accept the standard syntax for calling a
|
||||
|
|
@ -75,7 +75,7 @@ namespace fc {
|
|||
api( const T& p )
|
||||
:_vtable( std::make_shared<vtable_type>() )
|
||||
{
|
||||
_data = std::make_shared<fc::any>(p);
|
||||
_data = std::make_shared<boost::any>(p);
|
||||
T& ptr = boost::any_cast<T&>(*_data);
|
||||
auto& pointed_at = *ptr;
|
||||
typedef typename std::remove_reference<decltype(pointed_at)>::type source_vtable_type;
|
||||
|
|
@ -95,7 +95,7 @@ namespace fc {
|
|||
|
||||
protected:
|
||||
std::shared_ptr<vtable_type> _vtable;
|
||||
std::shared_ptr<fc::any> _data;
|
||||
std::shared_ptr<boost::any> _data;
|
||||
};
|
||||
|
||||
} // namespace fc
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ namespace fc {
|
|||
std::vector<char> ve = v.as< std::vector<char> >( 1 );
|
||||
if( ve.size() )
|
||||
{
|
||||
memcpy(&bi, ve.data(), fc::min<size_t>(ve.size(),sizeof(bi)) );
|
||||
memcpy(&bi, ve.data(), std::min<size_t>(ve.size(),sizeof(bi)) );
|
||||
}
|
||||
else
|
||||
memset( &bi, char(0), sizeof(bi) );
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ namespace asio {
|
|||
{
|
||||
public:
|
||||
istream( std::shared_ptr<AsyncReadStream> str )
|
||||
:_stream( fc::move(str) ){}
|
||||
:_stream( std::move(str) ){}
|
||||
|
||||
virtual size_t readsome( char* buf, size_t len )
|
||||
{
|
||||
|
|
@ -302,7 +302,7 @@ namespace asio {
|
|||
{
|
||||
public:
|
||||
ostream( std::shared_ptr<AsyncWriteStream> str )
|
||||
:_stream( fc::move(str) ){}
|
||||
:_stream( std::move(str) ){}
|
||||
|
||||
virtual size_t writesome( const char* buf, size_t len )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <fc/string.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace fc
|
||||
{
|
||||
|
||||
string zlib_compress(const string& in);
|
||||
std::string zlib_compress(const std::string& in);
|
||||
|
||||
} // namespace fc
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <fc/config.hpp>
|
||||
#include <deque>
|
||||
|
||||
namespace fc {
|
||||
|
||||
namespace raw {
|
||||
template<typename Stream, typename T>
|
||||
void pack( Stream& s, const std::deque<T>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
template<typename Stream, typename T>
|
||||
void unpack( Stream& s, std::deque<T>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
}
|
||||
} // namespace fc
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
#pragma once
|
||||
#include <fc/vector.hpp>
|
||||
#include <fc/string.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace fc
|
||||
{
|
||||
std::vector<char> from_base36( const fc::string& b36 );
|
||||
fc::string to_base36( const std::vector<char>& vec );
|
||||
fc::string to_base36( const char* data, size_t len );
|
||||
std::vector<char> from_base36( const std::string& b36 );
|
||||
std::string to_base36( const std::vector<char>& vec );
|
||||
std::string to_base36( const char* data, size_t len );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
#include <fc/string.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace fc {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <fc/string.hpp>
|
||||
#include <fc/vector.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct bignum_st;
|
||||
typedef bignum_st BIGNUM;
|
||||
|
|
@ -55,7 +55,7 @@ namespace fc {
|
|||
bigint operator--(int);
|
||||
bigint& operator--();
|
||||
|
||||
operator fc::string()const;
|
||||
operator std::string()const;
|
||||
|
||||
// returns bignum as bigendian bytes
|
||||
operator std::vector<char>()const;
|
||||
|
|
|
|||
|
|
@ -153,9 +153,9 @@ namespace fc {
|
|||
|
||||
extended_key_data serialize_extended() const;
|
||||
static extended_public_key deserialize( const extended_key_data& data );
|
||||
fc::string str() const;
|
||||
fc::string to_base58() const { return str(); }
|
||||
static extended_public_key from_base58( const fc::string& base58 );
|
||||
std::string str() const;
|
||||
std::string to_base58() const { return str(); }
|
||||
static extended_public_key from_base58( const std::string& base58 );
|
||||
|
||||
private:
|
||||
sha256 c;
|
||||
|
|
@ -177,10 +177,10 @@ namespace fc {
|
|||
|
||||
extended_key_data serialize_extended() const;
|
||||
static extended_private_key deserialize( const extended_key_data& data );
|
||||
fc::string str() const;
|
||||
fc::string to_base58() const { return str(); }
|
||||
static extended_private_key from_base58( const fc::string& base58 );
|
||||
static extended_private_key generate_master( const fc::string& seed );
|
||||
std::string str() const;
|
||||
std::string to_base58() const { return str(); }
|
||||
static extended_private_key from_base58( const std::string& base58 );
|
||||
static extended_private_key generate_master( const std::string& seed );
|
||||
static extended_private_key generate_master( const char* seed, uint32_t seed_len );
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
#pragma once
|
||||
#include <fc/string.hpp>
|
||||
#include <fc/utility.hpp>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace fc {
|
||||
uint8_t from_hex( char c );
|
||||
fc::string to_hex( const char* d, uint32_t s );
|
||||
std::string to_hex( const char* d, uint32_t s );
|
||||
std::string to_hex( const std::vector<char>& data );
|
||||
|
||||
/**
|
||||
* @return the number of bytes decoded
|
||||
*/
|
||||
size_t from_hex( const fc::string& hex_str, char* out_data, size_t out_data_len );
|
||||
size_t from_hex( const std::string& hex_str, char* out_data, size_t out_data_len );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
#include <fc/fwd.hpp>
|
||||
#include <fc/string.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace fc{
|
||||
|
||||
|
|
@ -10,16 +10,16 @@ class sha1
|
|||
{
|
||||
public:
|
||||
sha1();
|
||||
explicit sha1( const string& hex_str );
|
||||
explicit sha1( const std::string& hex_str );
|
||||
|
||||
string str()const;
|
||||
operator string()const;
|
||||
std::string str()const;
|
||||
operator std::string()const;
|
||||
|
||||
char* data()const;
|
||||
size_t data_size()const { return 20; }
|
||||
|
||||
static sha1 hash( const char* d, uint32_t dlen );
|
||||
static sha1 hash( const string& );
|
||||
static sha1 hash( const std::string& );
|
||||
|
||||
template<typename T>
|
||||
static sha1 hash( const T& t )
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
#include <unordered_map>
|
||||
#include <fc/fwd.hpp>
|
||||
#include <fc/io/raw_fwd.hpp>
|
||||
#include <fc/string.hpp>
|
||||
|
||||
namespace fc
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
#include <fc/fwd.hpp>
|
||||
#include <fc/string.hpp>
|
||||
#include <fc/platform_independence.hpp>
|
||||
#include <fc/io/raw_fwd.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
#include <fc/fwd.hpp>
|
||||
#include <fc/string.hpp>
|
||||
|
||||
namespace fc
|
||||
{
|
||||
|
|
|
|||
|
|
@ -240,9 +240,9 @@ namespace fc
|
|||
TYPE( const std::string& what_value, const fc::log_messages& m ) \
|
||||
:BASE( m, CODE, BOOST_PP_STRINGIZE(TYPE), what_value ){} \
|
||||
TYPE( fc::log_message&& m ) \
|
||||
:BASE( fc::move(m), CODE, BOOST_PP_STRINGIZE(TYPE), WHAT ){}\
|
||||
:BASE( std::move(m), CODE, BOOST_PP_STRINGIZE(TYPE), WHAT ){}\
|
||||
TYPE( fc::log_messages msgs ) \
|
||||
:BASE( fc::move( msgs ), CODE, BOOST_PP_STRINGIZE(TYPE), WHAT ) {} \
|
||||
:BASE( std::move( msgs ), CODE, BOOST_PP_STRINGIZE(TYPE), WHAT ) {} \
|
||||
TYPE( const TYPE& c ) \
|
||||
:BASE(c){} \
|
||||
TYPE( const BASE& c ) \
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
#include <utility>
|
||||
#include <memory>
|
||||
|
||||
#include <fc/string.hpp>
|
||||
#include <fc/reflect/typename.hpp>
|
||||
#include <fc/optional.hpp>
|
||||
#include <fc/fwd.hpp>
|
||||
|
|
@ -228,37 +227,5 @@ namespace fc {
|
|||
temp_directory(const fc::path& tempFolder = fc::temp_directory_path());
|
||||
};
|
||||
|
||||
|
||||
#if !defined(__APPLE__)
|
||||
// this code is known to work on linux and windows. It may work correctly on mac,
|
||||
// or it may need slight tweaks or extra includes. It's disabled now to avoid giving
|
||||
// a false sense of security.
|
||||
# define FC_HAS_SIMPLE_FILE_LOCK
|
||||
#endif
|
||||
#ifdef FC_HAS_SIMPLE_FILE_LOCK
|
||||
/** simple class which only allows one process to open any given file.
|
||||
* approximate usage:
|
||||
* int main() {
|
||||
* fc::simple_file_lock instance_lock("~/.my_app/.lock");
|
||||
* if (!instance_lock.try_lock()) {
|
||||
* elog("my_app is already running");
|
||||
* return 1;
|
||||
* }
|
||||
* // do stuff here, file will be unlocked when instance_lock goes out of scope
|
||||
* }
|
||||
*/
|
||||
class simple_lock_file
|
||||
{
|
||||
public:
|
||||
simple_lock_file(const path& lock_file_path);
|
||||
~simple_lock_file();
|
||||
bool try_lock();
|
||||
void unlock();
|
||||
private:
|
||||
class impl;
|
||||
std::unique_ptr<impl> my;
|
||||
};
|
||||
#endif // FC_HAS_SIMPLE_FILE_LOCK
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,143 +0,0 @@
|
|||
#pragma once
|
||||
#include <fc/io/raw_fwd.hpp>
|
||||
|
||||
|
||||
namespace fc {
|
||||
|
||||
|
||||
/**
|
||||
* This class is designed to offer in-place memory allocation of a string up to Length equal to
|
||||
* sizeof(Storage).
|
||||
*
|
||||
* The string will serialize the same way as std::string for variant and raw formats
|
||||
* The string will sort according to the comparison operators defined for Storage, this enables effecient
|
||||
* sorting.
|
||||
*/
|
||||
template<typename Storage = std::pair<uint64_t,uint64_t> >
|
||||
class fixed_string {
|
||||
public:
|
||||
fixed_string(){}
|
||||
fixed_string( const fixed_string& c ):data(c.data){}
|
||||
|
||||
fixed_string( const std::string& str ) {
|
||||
if( str.size() <= sizeof(data) )
|
||||
memcpy( (char*)&data, str.c_str(), str.size() );
|
||||
else {
|
||||
memcpy( (char*)&data, str.c_str(), sizeof(data) );
|
||||
}
|
||||
}
|
||||
fixed_string( const char* str ) {
|
||||
auto l = strlen(str);
|
||||
if( l <= sizeof(data) )
|
||||
memcpy( (char*)&data, str, l );
|
||||
else {
|
||||
memcpy( (char*)&data, str, sizeof(data) );
|
||||
}
|
||||
}
|
||||
|
||||
operator std::string()const {
|
||||
const char* self = (const char*)&data;
|
||||
return std::string( self, self + size() );
|
||||
}
|
||||
|
||||
uint32_t size()const {
|
||||
if( *(((const char*)&data)+sizeof(data) - 1) )
|
||||
return sizeof(data);
|
||||
return strnlen( (const char*)&data, sizeof(data) );
|
||||
}
|
||||
uint32_t length()const { return size(); }
|
||||
|
||||
fixed_string& operator=( const fixed_string& str ) {
|
||||
data = str.data;
|
||||
return *this;
|
||||
}
|
||||
fixed_string& operator=( const char* str ) {
|
||||
return *this = fixed_string(str);
|
||||
}
|
||||
|
||||
fixed_string& operator=( const std::string& str ) {
|
||||
if( str.size() <= sizeof(data) ) {
|
||||
data = Storage();
|
||||
memcpy( (char*)&data, str.c_str(), str.size() );
|
||||
}
|
||||
else {
|
||||
memcpy( (char*)&data, str.c_str(), sizeof(data) );
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
friend std::string operator + ( const fixed_string& a, const std::string& b ) {
|
||||
return std::string(a) + b;
|
||||
}
|
||||
friend std::string operator + ( const std::string& a, const fixed_string& b ) {
|
||||
return a + std::string(b);
|
||||
}
|
||||
|
||||
friend bool operator < ( const fixed_string& a, const fixed_string& b ) {
|
||||
return a.data < b.data;
|
||||
}
|
||||
friend bool operator <= ( const fixed_string& a, const fixed_string& b ) {
|
||||
return a.data <= b.data;
|
||||
}
|
||||
friend bool operator > ( const fixed_string& a, const fixed_string& b ) {
|
||||
return a.data > b.data;
|
||||
}
|
||||
friend bool operator >= ( const fixed_string& a, const fixed_string& b ) {
|
||||
return a.data >= b.data;
|
||||
}
|
||||
friend bool operator == ( const fixed_string& a, const fixed_string& b ) {
|
||||
return a.data == b.data;
|
||||
}
|
||||
friend bool operator != ( const fixed_string& a, const fixed_string& b ) {
|
||||
return a.data != b.data;
|
||||
}
|
||||
//private:
|
||||
Storage data;
|
||||
};
|
||||
|
||||
namespace raw
|
||||
{
|
||||
template<typename Stream, typename Storage>
|
||||
inline void pack( Stream& s, const fc::fixed_string<Storage>& u, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) {
|
||||
FC_ASSERT( _max_depth > 0 );
|
||||
unsigned_int size = u.size();
|
||||
pack( s, size, _max_depth - 1 );
|
||||
s.write( (const char*)&u.data, size );
|
||||
}
|
||||
|
||||
template<typename Stream, typename Storage>
|
||||
inline void unpack( Stream& s, fc::fixed_string<Storage>& u, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) {
|
||||
FC_ASSERT( _max_depth > 0 );
|
||||
unsigned_int size;
|
||||
fc::raw::unpack( s, size, _max_depth - 1 );
|
||||
if( size.value > 0 ) {
|
||||
if( size.value > sizeof(Storage) ) {
|
||||
s.read( (char*)&u.data, sizeof(Storage) );
|
||||
char buf[1024];
|
||||
size_t left = size.value - sizeof(Storage);
|
||||
while( left >= 1024 )
|
||||
{
|
||||
s.read( buf, 1024 );
|
||||
left -= 1024;
|
||||
}
|
||||
s.read( buf, left );
|
||||
} else {
|
||||
s.read( (char*)&u.data, size.value );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <fc/variant.hpp>
|
||||
namespace fc {
|
||||
template<typename Storage>
|
||||
void to_variant( const fixed_string<Storage>& s, variant& v, uint32_t max_depth = 1 ) {
|
||||
v = std::string(s);
|
||||
}
|
||||
|
||||
template<typename Storage>
|
||||
void from_variant( const variant& v, fixed_string<Storage>& s, uint32_t max_depth = 1 ) {
|
||||
s = v.as_string();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
#pragma once
|
||||
#include <fc/aligned.hpp>
|
||||
|
||||
namespace fc {
|
||||
|
||||
|
|
@ -37,7 +36,7 @@ class fwd {
|
|||
~fwd();
|
||||
|
||||
private:
|
||||
aligned<S,Align> _store;
|
||||
alignas(Align) char _store[S];
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,31 +3,32 @@
|
|||
#include <fc/utility.hpp>
|
||||
#include <fc/fwd.hpp>
|
||||
#include <new>
|
||||
#include <type_traits>
|
||||
|
||||
namespace fc {
|
||||
|
||||
namespace detail {
|
||||
template<typename A, typename U>
|
||||
struct add {
|
||||
typedef decltype( *((A*)0) + *((typename fc::remove_reference<U>::type*)0) ) type;
|
||||
typedef decltype( *((A*)0) + *((typename std::remove_reference<U>::type*)0) ) type;
|
||||
};
|
||||
template<typename A, typename U>
|
||||
struct add_eq {
|
||||
typedef decltype( *((A*)0) += *((typename fc::remove_reference<U>::type*)0) ) type;
|
||||
typedef decltype( *((A*)0) += *((typename std::remove_reference<U>::type*)0) ) type;
|
||||
};
|
||||
|
||||
template<typename A, typename U>
|
||||
struct sub {
|
||||
typedef decltype( *((A*)0) - *((typename fc::remove_reference<U>::type*)0) ) type;
|
||||
typedef decltype( *((A*)0) - *((typename std::remove_reference<U>::type*)0) ) type;
|
||||
};
|
||||
|
||||
template<typename A, typename U>
|
||||
struct sub_eq {
|
||||
typedef decltype( *((A*)0) -= *((typename fc::remove_reference<U>::type*)0) ) type;
|
||||
typedef decltype( *((A*)0) -= *((typename std::remove_reference<U>::type*)0) ) type;
|
||||
};
|
||||
template<typename A, typename U>
|
||||
struct insert_op {
|
||||
typedef decltype( *((A*)0) << *((typename fc::remove_reference<U>::type*)0) ) type;
|
||||
typedef decltype( *((A*)0) << *((typename std::remove_reference<U>::type*)0) ) type;
|
||||
};
|
||||
template<typename A, typename U>
|
||||
struct extract_op {
|
||||
|
|
@ -91,7 +92,7 @@ namespace fc {
|
|||
template<typename T,unsigned int S,typename A>
|
||||
fwd<T,S,A>::fwd( fwd<T,S,A>&& f ){
|
||||
check_size<sizeof(T),sizeof(_store)>();
|
||||
new (this) T( fc::move(*f) );
|
||||
new (this) T( std::move(*f) );
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -124,7 +125,7 @@ namespace fc {
|
|||
|
||||
template<typename T,unsigned int S, typename A>
|
||||
T& fwd<T,S,A>::operator = ( fwd<T,S,A>&& u ) {
|
||||
return **this = fc::move(*u);
|
||||
return **this = std::move(*u);
|
||||
}
|
||||
template<typename T,unsigned int S, typename A>
|
||||
T& fwd<T,S,A>::operator = ( const fwd<T,S,A>& u ) {
|
||||
|
|
|
|||
|
|
@ -1,108 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <fc/variant.hpp>
|
||||
#include <boost/interprocess/allocators/allocator.hpp>
|
||||
#include <boost/interprocess/containers/string.hpp>
|
||||
#include <boost/interprocess/containers/vector.hpp>
|
||||
#include <boost/interprocess/containers/map.hpp>
|
||||
#include <boost/interprocess/containers/flat_map.hpp>
|
||||
#include <boost/interprocess/containers/set.hpp>
|
||||
#include <boost/interprocess/containers/deque.hpp>
|
||||
#include <fc/crypto/hex.hpp>
|
||||
#include <fc/exception/exception.hpp>
|
||||
#include <fc/io/raw_fwd.hpp>
|
||||
|
||||
namespace fc {
|
||||
|
||||
namespace bip = boost::interprocess;
|
||||
|
||||
template<typename... T >
|
||||
void to_variant( const bip::deque< T... >& t, fc::variant& v, uint32_t max_depth ) {
|
||||
FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
|
||||
--max_depth;
|
||||
std::vector<variant> vars(t.size());
|
||||
for( size_t i = 0; i < t.size(); ++i ) {
|
||||
to_variant( t[i], vars[i], max_depth );
|
||||
}
|
||||
v = std::move(vars);
|
||||
}
|
||||
|
||||
template<typename T, typename... A>
|
||||
void from_variant( const fc::variant& v, bip::deque< T, A... >& d, uint32_t max_depth ) {
|
||||
FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
|
||||
--max_depth;
|
||||
const variants& vars = v.get_array();
|
||||
d.clear();
|
||||
d.resize( vars.size() );
|
||||
for( uint32_t i = 0; i < vars.size(); ++i ) {
|
||||
from_variant( vars[i], d[i], max_depth );
|
||||
}
|
||||
}
|
||||
|
||||
template<typename K, typename V, typename... T >
|
||||
void to_variant( const bip::map< K, V, T... >& var, fc::variant& vo, uint32_t max_depth ) {
|
||||
FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
|
||||
--max_depth;
|
||||
std::vector< variant > vars(var.size());
|
||||
size_t i = 0;
|
||||
for( auto itr = var.begin(); itr != var.end(); ++itr, ++i )
|
||||
vars[i] = fc::variant( *itr, max_depth );
|
||||
vo = vars;
|
||||
}
|
||||
|
||||
template<typename... T >
|
||||
void to_variant( const bip::vector< T... >& t, fc::variant& v, uint32_t max_depth ) {
|
||||
FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
|
||||
--max_depth;
|
||||
std::vector<variant> vars(t.size());
|
||||
for( size_t i = 0; i < t.size(); ++i ) {
|
||||
to_variant( t[i], vars[i], max_depth );
|
||||
}
|
||||
v = std::move(vars);
|
||||
}
|
||||
|
||||
template<typename T, typename... A>
|
||||
void from_variant( const fc::variant& v, bip::vector< T, A... >& d, uint32_t max_depth ) {
|
||||
FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
|
||||
--max_depth;
|
||||
const variants& vars = v.get_array();
|
||||
d.clear();
|
||||
d.resize( vars.size() );
|
||||
for( uint32_t i = 0; i < vars.size(); ++i ) {
|
||||
from_variant( vars[i], d[i], max_depth );
|
||||
}
|
||||
}
|
||||
|
||||
template<typename... T >
|
||||
void to_variant( const bip::set< T... >& t, fc::variant& v, uint32_t max_depth ) {
|
||||
FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
|
||||
--max_depth;
|
||||
std::vector<variant> vars;
|
||||
vars.reserve(t.size());
|
||||
for( const auto& item : t ) {
|
||||
vars.emplace_back( variant( item, max_depth ) );
|
||||
}
|
||||
v = std::move(vars);
|
||||
}
|
||||
|
||||
template<typename... A>
|
||||
void to_variant( const bip::vector<char, A...>& t, fc::variant& v, uint32_t max_depth = 1 )
|
||||
{
|
||||
if( t.size() )
|
||||
v = variant(fc::to_hex(t.data(), t.size()));
|
||||
else
|
||||
v = "";
|
||||
}
|
||||
|
||||
template<typename... A>
|
||||
void from_variant( const fc::variant& v, bip::vector<char, A...>& d, uint32_t max_depth = 1 )
|
||||
{
|
||||
auto str = v.as_string();
|
||||
d.resize( str.size() / 2 );
|
||||
if( d.size() )
|
||||
{
|
||||
size_t r = fc::from_hex( str, d.data(), d.size() );
|
||||
FC_ASSERT( r == d.size() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include <fc/fwd.hpp>
|
||||
#include <fc/utility.hpp>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace boost {
|
||||
namespace interprocess {
|
||||
|
|
@ -24,7 +25,7 @@ namespace fc {
|
|||
#ifdef _WIN64
|
||||
fc::fwd<boost::interprocess::file_mapping,0x38> my;
|
||||
#else
|
||||
fc::fwd<boost::interprocess::file_mapping,0x24> my;
|
||||
fc::fwd<boost::interprocess::file_mapping,0x28> my;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,44 +0,0 @@
|
|||
#pragma once
|
||||
#include <fc/time.hpp>
|
||||
#include <fc/thread/spin_yield_lock.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace fc {
|
||||
class microseconds;
|
||||
class time_point;
|
||||
class path;
|
||||
struct context;
|
||||
|
||||
namespace detail { class file_mutex_impl; }
|
||||
|
||||
/**
|
||||
* The purpose of this class is to support synchronization of
|
||||
* processes, threads, and coop-threads.
|
||||
*
|
||||
* Before grabbing the lock for a thread or coop, a file_mutex will first
|
||||
* grab a process-level lock. After grabbing the process level lock, it will
|
||||
* synchronize in the same way as a local process lock.
|
||||
*/
|
||||
class file_mutex {
|
||||
public:
|
||||
file_mutex( const fc::path& filename );
|
||||
~file_mutex();
|
||||
|
||||
bool try_lock();
|
||||
bool try_lock_for( const microseconds& rel_time );
|
||||
bool try_lock_until( const time_point& abs_time );
|
||||
void lock();
|
||||
void unlock();
|
||||
|
||||
void lock_shared();
|
||||
void unlock_shared();
|
||||
bool try_lock_shared();
|
||||
|
||||
int readers()const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<detail::file_mutex_impl> my;
|
||||
};
|
||||
|
||||
} // namespace fc
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
#pragma once
|
||||
#include <fc/thread/future.hpp>
|
||||
#include <fc/io/buffered_iostream.hpp>
|
||||
#include <vector>
|
||||
#include <fc/string.hpp>
|
||||
#include <fc/filesystem.hpp>
|
||||
|
||||
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<std::string> 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> iprocess_ptr;
|
||||
|
||||
|
||||
} // namespace fc
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
#pragma once
|
||||
#include <fc/interprocess/file_mapping.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace fc
|
||||
{
|
||||
class path;
|
||||
namespace detail
|
||||
{
|
||||
/**
|
||||
* Base class used to hide common implementation details.
|
||||
*/
|
||||
class mmap_struct_base
|
||||
{
|
||||
public:
|
||||
size_t size()const;
|
||||
void flush();
|
||||
|
||||
protected:
|
||||
void open( const fc::path& file, size_t s, bool create );
|
||||
std::unique_ptr<fc::file_mapping> _file_mapping;
|
||||
std::unique_ptr<fc::mapped_region> _mapped_region;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @class mmap_struct
|
||||
* @brief A struct that has been mapped from a file.
|
||||
*
|
||||
* @note T must be POD
|
||||
*/
|
||||
template<typename T>
|
||||
class mmap_struct : public detail::mmap_struct_base
|
||||
{
|
||||
public:
|
||||
mmap_struct():_mapped_struct(nullptr){}
|
||||
/**
|
||||
* Create the file if it does not exist or is of the wrong size if create is true, then maps
|
||||
* the file to memory.
|
||||
*
|
||||
* @throw an exception if the file does not exist or is the wrong size and create is false
|
||||
*/
|
||||
void open( const fc::path& file, bool create = false )
|
||||
{
|
||||
detail::mmap_struct_base::open( file, sizeof(T), create );
|
||||
_mapped_struct = (T*)_mapped_region->get_address();
|
||||
}
|
||||
|
||||
T* operator->() { return _mapped_struct; }
|
||||
const T* operator->()const { return _mapped_struct; }
|
||||
|
||||
T& operator*() { return *_mapped_struct; }
|
||||
const T& operator*()const { return *_mapped_struct; }
|
||||
|
||||
private:
|
||||
T* _mapped_struct;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
#pragma once
|
||||
#include <fc/interprocess/iprocess.hpp>
|
||||
|
||||
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<std::string> 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<impl> my;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<process> process_ptr;
|
||||
|
||||
} // namespace fc
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
#pragma once
|
||||
namespace fc
|
||||
{
|
||||
/** enables / disables echoing of console input, useful for
|
||||
* entering passwords on the console.
|
||||
*/
|
||||
void set_console_echo( bool enable_echo );
|
||||
} // namespace fc
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
#pragma once
|
||||
#include <fc/io/iostream.hpp>
|
||||
#include <fc/exception/exception.hpp>
|
||||
|
||||
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<size_t>(_data.size(),pos);
|
||||
}
|
||||
|
||||
virtual size_t readsome( char* buf, size_t len )
|
||||
{
|
||||
auto avail = std::min<size_t>( _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<size_t>( _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<char> _data;
|
||||
size_t _pos;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
#pragma once
|
||||
#include <fc/utility.hpp>
|
||||
#include <fc/string.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace fc {
|
||||
|
|
@ -61,7 +59,7 @@ namespace fc {
|
|||
|
||||
class iostream : public virtual ostream, public virtual istream {};
|
||||
|
||||
fc::istream& getline( fc::istream&, fc::string&, char delim = '\n' );
|
||||
fc::istream& getline( fc::istream&, std::string&, char delim = '\n' );
|
||||
|
||||
template<size_t N>
|
||||
ostream& operator<<( ostream& o, char (&array)[N] )
|
||||
|
|
@ -72,7 +70,7 @@ namespace fc {
|
|||
ostream& operator<<( ostream& o, char );
|
||||
ostream& operator<<( ostream& o, const char* v );
|
||||
ostream& operator<<( ostream& o, const std::string& v );
|
||||
ostream& operator<<( ostream& o, const fc::string& v );
|
||||
ostream& operator<<( ostream& o, const std::string& v );
|
||||
ostream& operator<<( ostream& o, const double& v );
|
||||
ostream& operator<<( ostream& o, const float& v );
|
||||
ostream& operator<<( ostream& o, const int64_t& v );
|
||||
|
|
@ -88,7 +86,7 @@ namespace fc {
|
|||
#endif
|
||||
|
||||
istream& operator>>( istream& o, std::string& v );
|
||||
istream& operator>>( istream& o, fc::string& v );
|
||||
istream& operator>>( istream& o, std::string& v );
|
||||
istream& operator>>( istream& o, char& v );
|
||||
istream& operator>>( istream& o, double& v );
|
||||
istream& operator>>( istream& o, float& v );
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ namespace fc
|
|||
legacy_generator = 1
|
||||
};
|
||||
|
||||
static ostream& to_stream( ostream& out, const fc::string& );
|
||||
static ostream& to_stream( ostream& out, const std::string& );
|
||||
static ostream& to_stream( ostream& out, const variant& v, output_formatting format = stringify_large_ints_and_doubles, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH );
|
||||
static ostream& to_stream( ostream& out, const variants& v, output_formatting format = stringify_large_ints_and_doubles, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH );
|
||||
static ostream& to_stream( ostream& out, const variant_object& v, output_formatting format = stringify_large_ints_and_doubles, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH );
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@
|
|||
#include <fc/io/fstream.hpp>
|
||||
#include <fc/io/sstream.hpp>
|
||||
#include <fc/log/logger.hpp>
|
||||
#include <fc/string.hpp>
|
||||
//#include <utfcpp/utf8.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
|
@ -24,7 +23,7 @@ namespace fc { namespace json_relaxed
|
|||
variant variant_from_stream( T& in, uint32_t max_depth );
|
||||
|
||||
template<typename T>
|
||||
fc::string tokenFromStream( T& in )
|
||||
std::string tokenFromStream( T& in )
|
||||
{
|
||||
fc::stringstream token;
|
||||
try
|
||||
|
|
@ -81,7 +80,7 @@ namespace fc { namespace json_relaxed
|
|||
}
|
||||
|
||||
template<typename T, bool strict, bool allow_escape>
|
||||
fc::string quoteStringFromStream( T& in )
|
||||
std::string quoteStringFromStream( T& in )
|
||||
{
|
||||
fc::stringstream token;
|
||||
try
|
||||
|
|
@ -107,11 +106,11 @@ namespace fc { namespace json_relaxed
|
|||
try
|
||||
{
|
||||
if( in.peek() != q )
|
||||
return fc::string();
|
||||
return std::string();
|
||||
}
|
||||
catch( const fc::eof_exception& e )
|
||||
{
|
||||
return fc::string();
|
||||
return std::string();
|
||||
}
|
||||
|
||||
// triple quote processing
|
||||
|
|
@ -186,7 +185,7 @@ namespace fc { namespace json_relaxed
|
|||
}
|
||||
|
||||
template<typename T, bool strict>
|
||||
fc::string stringFromStream( T& in )
|
||||
std::string stringFromStream( T& in )
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -294,7 +293,7 @@ namespace fc { namespace json_relaxed
|
|||
};
|
||||
|
||||
template<uint8_t base>
|
||||
fc::variant parseInt( const fc::string& token, size_t start )
|
||||
fc::variant parseInt( const std::string& token, size_t start )
|
||||
{
|
||||
static const CharValueTable ctbl;
|
||||
static const uint64_t INT64_MAX_PLUS_ONE = static_cast<uint64_t>(INT64_MAX) + 1;
|
||||
|
|
@ -336,7 +335,7 @@ namespace fc { namespace json_relaxed
|
|||
}
|
||||
|
||||
template<bool strict, uint8_t base>
|
||||
fc::variant maybeParseInt( const fc::string& token, size_t start )
|
||||
fc::variant maybeParseInt( const std::string& token, size_t start )
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -352,7 +351,7 @@ namespace fc { namespace json_relaxed
|
|||
}
|
||||
|
||||
template<bool strict>
|
||||
fc::variant parseNumberOrStr( const fc::string& token )
|
||||
fc::variant parseNumberOrStr( const std::string& token )
|
||||
{ try {
|
||||
//ilog( (token) );
|
||||
size_t i = 0, n = token.length();
|
||||
|
|
@ -588,7 +587,7 @@ namespace fc { namespace json_relaxed
|
|||
template<typename T, bool strict>
|
||||
variant numberFromStream( T& in )
|
||||
{ try {
|
||||
fc::string token = tokenFromStream(in);
|
||||
std::string token = tokenFromStream(in);
|
||||
variant result = json_relaxed::parseNumberOrStr<strict>( token );
|
||||
if( strict && !(result.is_int64() || result.is_uint64() || result.is_double()) )
|
||||
FC_THROW_EXCEPTION( parse_error_exception, "expected: number" );
|
||||
|
|
@ -598,7 +597,7 @@ namespace fc { namespace json_relaxed
|
|||
template<typename T, bool strict>
|
||||
variant wordFromStream( T& in )
|
||||
{
|
||||
fc::string token = tokenFromStream(in);
|
||||
std::string token = tokenFromStream(in);
|
||||
|
||||
FC_ASSERT( token.length() > 0 );
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ namespace fc {
|
|||
fc::raw::unpack( s, what, _max_depth );
|
||||
fc::raw::unpack( s, msgs, _max_depth );
|
||||
|
||||
e = fc::exception( fc::move(msgs), code, name, what );
|
||||
e = fc::exception( std::move(msgs), code, name, what );
|
||||
}
|
||||
|
||||
template<typename Stream>
|
||||
|
|
@ -206,7 +206,7 @@ namespace fc {
|
|||
template<typename Stream> inline void pack( Stream& s, const char* v, uint32_t _max_depth )
|
||||
{
|
||||
FC_ASSERT( _max_depth > 0 );
|
||||
fc::raw::pack( s, fc::string(v), _max_depth - 1 );
|
||||
fc::raw::pack( s, std::string(v), _max_depth - 1 );
|
||||
}
|
||||
|
||||
template<typename Stream, typename T>
|
||||
|
|
@ -270,18 +270,18 @@ namespace fc {
|
|||
}
|
||||
|
||||
// fc::string
|
||||
template<typename Stream> inline void pack( Stream& s, const fc::string& v, uint32_t _max_depth ) {
|
||||
template<typename Stream> inline void pack( Stream& s, const std::string& v, uint32_t _max_depth ) {
|
||||
FC_ASSERT( _max_depth > 0 );
|
||||
fc::raw::pack( s, unsigned_int(v.size()), _max_depth - 1 );
|
||||
if( v.size() ) s.write( v.c_str(), v.size() );
|
||||
}
|
||||
|
||||
template<typename Stream> inline void unpack( Stream& s, fc::string& v, uint32_t _max_depth ) {
|
||||
template<typename Stream> inline void unpack( Stream& s, std::string& v, uint32_t _max_depth ) {
|
||||
FC_ASSERT( _max_depth > 0 );
|
||||
std::vector<char> tmp; fc::raw::unpack( s, tmp, _max_depth - 1 );
|
||||
if( tmp.size() )
|
||||
v = fc::string( tmp.data(), tmp.data()+tmp.size() );
|
||||
else v = fc::string();
|
||||
v = std::string( tmp.data(), tmp.data()+tmp.size() );
|
||||
else v = std::string();
|
||||
}
|
||||
|
||||
// bool
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
#include <fc/config.hpp>
|
||||
#include <fc/container/flat_fwd.hpp>
|
||||
#include <fc/container/deque_fwd.hpp>
|
||||
#include <fc/io/varint.hpp>
|
||||
#include <fc/array.hpp>
|
||||
#include <fc/safe.hpp>
|
||||
|
|
@ -31,15 +30,11 @@ namespace fc {
|
|||
namespace ip { class endpoint; }
|
||||
|
||||
namespace ecc { class public_key; class private_key; }
|
||||
template<typename Storage> class fixed_string;
|
||||
|
||||
namespace raw {
|
||||
template<typename T>
|
||||
inline size_t pack_size( const T& v );
|
||||
|
||||
template<typename Stream, typename Storage> inline void pack( Stream& s, const fc::fixed_string<Storage>& u, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
template<typename Stream, typename Storage> inline void unpack( Stream& s, fc::fixed_string<Storage>& u, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
|
||||
template<typename Stream, typename IntType, typename EnumType>
|
||||
inline void pack( Stream& s, const fc::enum_type<IntType,EnumType>& tp, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
template<typename Stream, typename IntType, typename EnumType>
|
||||
|
|
@ -58,8 +53,8 @@ namespace fc {
|
|||
//template<typename Stream, typename T> inline void pack( Stream& s, const flat_set<T>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
//template<typename Stream, typename T> inline void unpack( Stream& s, flat_set<T>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
|
||||
//template<typename Stream, typename T> inline void pack( Stream& s, const std::deque<T>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
//template<typename Stream, typename T> inline void unpack( Stream& s, std::deque<T>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
template<typename Stream, typename T> inline void pack( Stream& s, const std::deque<T>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
template<typename Stream, typename T> inline void unpack( Stream& s, std::deque<T>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
|
||||
template<typename Stream, typename K, typename V> inline void pack( Stream& s, const std::unordered_map<K,V>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
template<typename Stream, typename K, typename V> inline void unpack( Stream& s, std::unordered_map<K,V>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
|
|
|
|||
|
|
@ -1,24 +0,0 @@
|
|||
#pragma once
|
||||
#include <fc/io/raw.hpp>
|
||||
#include <fc/interprocess/file_mapping.hpp>
|
||||
#include <fc/filesystem.hpp>
|
||||
#include <fc/exception/exception.hpp>
|
||||
|
||||
namespace fc
|
||||
{
|
||||
namespace raw
|
||||
{
|
||||
template<typename T>
|
||||
void unpack_file( const fc::path& filename, T& obj )
|
||||
{
|
||||
try {
|
||||
fc::file_mapping fmap( filename.generic_string().c_str(), fc::read_only);
|
||||
fc::mapped_region mapr( fmap, fc::read_only, 0, fc::file_size(filename) );
|
||||
auto cs = (const char*)mapr.get_address();
|
||||
|
||||
fc::datastream<const char*> ds( cs, mapr.get_size() );
|
||||
fc::raw::unpack(ds,obj);
|
||||
} FC_RETHROW_EXCEPTIONS( info, "unpacking file ${file}", ("file",filename) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -100,23 +100,23 @@ namespace fc { namespace raw {
|
|||
}
|
||||
case variant::string_type:
|
||||
{
|
||||
fc::string val;
|
||||
std::string val;
|
||||
raw::unpack( s, val, _max_depth );
|
||||
v = fc::move(val);
|
||||
v = std::move(val);
|
||||
return;
|
||||
}
|
||||
case variant::array_type:
|
||||
{
|
||||
variants val;
|
||||
raw::unpack( s, val, _max_depth );
|
||||
v = fc::move(val);
|
||||
v = std::move(val);
|
||||
return;
|
||||
}
|
||||
case variant::object_type:
|
||||
{
|
||||
variant_object val;
|
||||
raw::unpack( s, val, _max_depth );
|
||||
v = fc::move(val);
|
||||
v = std::move(val);
|
||||
return;
|
||||
}
|
||||
default:
|
||||
|
|
@ -148,13 +148,13 @@ namespace fc { namespace raw {
|
|||
mvo.reserve( std::min( vs.value, static_cast<uint64_t>(FC_MAX_PREALLOC_SIZE) ) );
|
||||
for( uint32_t i = 0; i < vs.value; ++i )
|
||||
{
|
||||
fc::string key;
|
||||
std::string key;
|
||||
fc::variant value;
|
||||
fc::raw::unpack( s, key, _max_depth );
|
||||
fc::raw::unpack( s, value, _max_depth );
|
||||
mvo.set( fc::move(key), fc::move(value) );
|
||||
mvo.set( std::move(key), std::move(value) );
|
||||
}
|
||||
v = fc::move(mvo);
|
||||
v = std::move(mvo);
|
||||
}
|
||||
|
||||
} } // fc::raw
|
||||
|
|
|
|||
|
|
@ -7,12 +7,12 @@ namespace fc {
|
|||
class stringstream : virtual public iostream {
|
||||
public:
|
||||
stringstream();
|
||||
stringstream( fc::string& s);
|
||||
stringstream( const fc::string& s);
|
||||
stringstream( std::string& s);
|
||||
stringstream( const std::string& s);
|
||||
~stringstream();
|
||||
|
||||
fc::string str();
|
||||
void str(const fc::string& s);
|
||||
std::string str();
|
||||
void str(const std::string& s);
|
||||
|
||||
void clear();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
#include <fc/shared_ptr.hpp>
|
||||
#include <fc/string.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace fc {
|
||||
class appender;
|
||||
|
|
@ -30,13 +30,13 @@ namespace fc {
|
|||
typedef fc::shared_ptr<appender> ptr;
|
||||
|
||||
template<typename T>
|
||||
static bool register_appender(const fc::string& type) {
|
||||
static bool register_appender(const std::string& type) {
|
||||
return register_appender( type, new detail::appender_factory_impl<T>() );
|
||||
}
|
||||
|
||||
static appender::ptr create( const fc::string& name, const fc::string& type, const variant& args );
|
||||
static appender::ptr get( const fc::string& name );
|
||||
static bool register_appender( const fc::string& type, const appender_factory::ptr& f );
|
||||
static appender::ptr create( const std::string& name, const std::string& type, const variant& args );
|
||||
static appender::ptr get( const std::string& name );
|
||||
static bool register_appender( const std::string& type, const appender_factory::ptr& f );
|
||||
|
||||
virtual void log( const log_message& m ) = 0;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ namespace fc
|
|||
:format( "${timestamp} ${thread_name} ${context} ${file}:${line} ${method} ${level}] ${message}" ),
|
||||
stream(console_appender::stream::std_error),max_object_depth(FC_MAX_LOG_OBJECT_DEPTH),flush(true){}
|
||||
|
||||
fc::string format;
|
||||
std::string format;
|
||||
console_appender::stream::type stream;
|
||||
std::vector<level_color> level_colors;
|
||||
uint32_t max_object_depth;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class file_appender : public appender {
|
|||
struct config {
|
||||
config( const fc::path& p = "log.txt" );
|
||||
|
||||
fc::string format;
|
||||
std::string format;
|
||||
fc::path filename;
|
||||
bool flush = true;
|
||||
bool rotate = false;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include <fc/variant_object.hpp>
|
||||
#include <fc/shared_ptr.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace fc
|
||||
{
|
||||
|
|
@ -65,19 +66,19 @@ namespace fc
|
|||
explicit log_context( const variant& v, uint32_t max_depth );
|
||||
variant to_variant( uint32_t max_depth )const;
|
||||
|
||||
string get_file()const;
|
||||
std::string get_file()const;
|
||||
uint64_t get_line_number()const;
|
||||
string get_method()const;
|
||||
string get_thread_name()const;
|
||||
string get_task_name()const;
|
||||
string get_host_name()const;
|
||||
std::string get_method()const;
|
||||
std::string get_thread_name()const;
|
||||
std::string get_task_name()const;
|
||||
std::string get_host_name()const;
|
||||
time_point get_timestamp()const;
|
||||
log_level get_log_level()const;
|
||||
string get_context()const;
|
||||
std::string get_context()const;
|
||||
|
||||
void append_context( const fc::string& c );
|
||||
void append_context( const std::string& c );
|
||||
|
||||
string to_string()const;
|
||||
std::string to_string()const;
|
||||
private:
|
||||
std::shared_ptr<detail::log_context_impl> my;
|
||||
};
|
||||
|
|
@ -116,10 +117,10 @@ namespace fc
|
|||
log_message( const variant& v, uint32_t max_depth );
|
||||
variant to_variant(uint32_t max_depth)const;
|
||||
|
||||
string get_message()const;
|
||||
std::string get_message()const;
|
||||
|
||||
log_context get_context()const;
|
||||
string get_format()const;
|
||||
std::string get_format()const;
|
||||
variant_object get_data()const;
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
#include <fc/config.hpp>
|
||||
#include <fc/string.hpp>
|
||||
#include <fc/time.hpp>
|
||||
#include <fc/shared_ptr.hpp>
|
||||
#include <fc/log/log_message.hpp>
|
||||
|
|
@ -23,7 +22,7 @@ namespace fc
|
|||
class logger
|
||||
{
|
||||
public:
|
||||
static logger get( const fc::string& name = "default");
|
||||
static logger get( const std::string& name = "default");
|
||||
|
||||
logger();
|
||||
logger( const string& name, const logger& parent = nullptr );
|
||||
|
|
@ -41,8 +40,8 @@ namespace fc
|
|||
logger& set_parent( const logger& l );
|
||||
logger get_parent()const;
|
||||
|
||||
void set_name( const fc::string& n );
|
||||
const fc::string& name()const;
|
||||
void set_name( const std::string& n );
|
||||
const std::string& name()const;
|
||||
|
||||
void add_appender( const fc::shared_ptr<appender>& a );
|
||||
std::vector<fc::shared_ptr<appender> > get_appenders()const;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace fc {
|
|||
variant args = variant()) :
|
||||
name(name),
|
||||
type(type),
|
||||
args(fc::move(args)),
|
||||
args(std::move(args)),
|
||||
enabled(true)
|
||||
{}
|
||||
string name;
|
||||
|
|
@ -19,7 +19,7 @@ namespace fc {
|
|||
};
|
||||
|
||||
struct logger_config {
|
||||
logger_config(const fc::string& name = ""):name(name),enabled(true),additivity(false){}
|
||||
logger_config(const std::string& name = ""):name(name),enabled(true),additivity(false){}
|
||||
string name;
|
||||
ostring parent;
|
||||
/// if not set, then parents level is used.
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
#pragma once
|
||||
#include <fc/tuple.hpp>
|
||||
#include <fc/function.hpp>
|
||||
|
||||
namespace fc {
|
||||
template<typename R>
|
||||
std::function<R, fc::tuple<> > make_fused( const std::function<R>& f ) {
|
||||
return [=]( fc::tuple<> ){ return f(); };
|
||||
}
|
||||
template<typename R,typename A>
|
||||
std::function<R(fc::tuple<A>) > make_fused( const std::function<R(A)>& f ) {
|
||||
return [f]( fc::tuple<A> t){ return f(t.a); };
|
||||
}
|
||||
template<typename R,typename A,typename B>
|
||||
std::function<R(fc::tuple<A,B>) > make_fused( const std::function<R(A,B)>& f ) {
|
||||
return [f]( fc::tuple<A,B> t){ return f(t.a,t.b); };
|
||||
}
|
||||
template<typename R,typename A,typename B,typename C>
|
||||
std::function<R(fc::tuple<A,B,C>) > make_fused( const std::function<R(A,B,C)>& f ) {
|
||||
return [f]( fc::tuple<A,B,C> t){ return f(t.a,t.b,t.c); };
|
||||
}
|
||||
template<typename R,typename A,typename B,typename C,typename D>
|
||||
std::function<R(fc::tuple<A,B,C,D>) > make_fused( const std::function<R(A,B,C,D)>& f ) {
|
||||
return [f]( fc::tuple<A,B,C> t){ return f(t.a,t.b,t.c,t.d); };
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
#include <fc/vector.hpp>
|
||||
#include <fc/string.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace fc {
|
||||
namespace ip { class endpoint; }
|
||||
|
|
@ -11,11 +10,11 @@ namespace fc {
|
|||
|
||||
struct header
|
||||
{
|
||||
header( fc::string k, fc::string v )
|
||||
:key(fc::move(k)),val(fc::move(v)){}
|
||||
header( std::string k, std::string v )
|
||||
:key(std::move(k)),val(std::move(v)){}
|
||||
header(){}
|
||||
fc::string key;
|
||||
fc::string val;
|
||||
std::string key;
|
||||
std::string val;
|
||||
};
|
||||
|
||||
typedef std::vector<header> headers;
|
||||
|
|
@ -39,16 +38,16 @@ namespace fc {
|
|||
|
||||
struct request
|
||||
{
|
||||
fc::string get_header( const fc::string& key )const;
|
||||
fc::string remote_endpoint;
|
||||
fc::string method;
|
||||
fc::string domain;
|
||||
fc::string path;
|
||||
std::string get_header( const std::string& key )const;
|
||||
std::string remote_endpoint;
|
||||
std::string method;
|
||||
std::string domain;
|
||||
std::string path;
|
||||
std::vector<header> headers;
|
||||
std::vector<char> body;
|
||||
};
|
||||
|
||||
std::vector<header> parse_urlencoded_params( const fc::string& f );
|
||||
std::vector<header> parse_urlencoded_params( const std::string& f );
|
||||
|
||||
/**
|
||||
* Connections have reference semantics, all copies refer to the same
|
||||
|
|
@ -61,7 +60,7 @@ namespace fc {
|
|||
~connection();
|
||||
// used for clients
|
||||
void connect_to( const fc::ip::endpoint& ep );
|
||||
http::reply request( const fc::string& method, const fc::string& url, const fc::string& body = std::string(), const headers& = headers());
|
||||
http::reply request( const std::string& method, const std::string& url, const std::string& body = std::string(), const headers& = headers());
|
||||
|
||||
// used for servers
|
||||
fc::tcp_socket& get_socket()const;
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ namespace fc { namespace http {
|
|||
response& operator=(const response& );
|
||||
response& operator=( response&& );
|
||||
|
||||
void add_header( const fc::string& key, const fc::string& val )const;
|
||||
void add_header( const std::string& key, const std::string& val )const;
|
||||
void set_status( const http::reply::status_code& s )const;
|
||||
void set_length( uint64_t s )const;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <fc/any.hpp>
|
||||
#include <boost/any.hpp>
|
||||
#include <fc/network/ip.hpp>
|
||||
#include <fc/signals.hpp>
|
||||
|
||||
|
|
@ -26,14 +26,14 @@ namespace fc { namespace http {
|
|||
void on_message_handler( const std::function<void(const std::string&)>& h ) { _on_message = h; }
|
||||
void on_http_handler( const std::function<std::string(const std::string&)>& h ) { _on_http = h; }
|
||||
|
||||
void set_session_data( fc::any d ){ _session_data = std::move(d); }
|
||||
fc::any& get_session_data() { return _session_data; }
|
||||
void set_session_data( boost::any d ){ _session_data = std::move(d); }
|
||||
boost::any& get_session_data() { return _session_data; }
|
||||
|
||||
virtual std::string get_request_header(const std::string& key) = 0;
|
||||
|
||||
fc::signal<void()> closed;
|
||||
private:
|
||||
fc::any _session_data;
|
||||
boost::any _session_data;
|
||||
std::function<void(const std::string&)> _on_message;
|
||||
std::function<string(const std::string&)> _on_http;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#pragma once
|
||||
#include <fc/string.hpp>
|
||||
#include <fc/crypto/sha1.hpp>
|
||||
#include <fc/io/raw_fwd.hpp>
|
||||
#include <fc/crypto/city.hpp>
|
||||
|
|
@ -11,10 +10,10 @@ namespace fc {
|
|||
class address {
|
||||
public:
|
||||
address( uint32_t _ip = 0 );
|
||||
address( const fc::string& s );
|
||||
address( const std::string& s );
|
||||
|
||||
address& operator=( const fc::string& s );
|
||||
operator fc::string()const;
|
||||
address& operator=( const std::string& s );
|
||||
operator std::string()const;
|
||||
operator uint32_t()const;
|
||||
|
||||
friend bool operator==( const address& a, const address& b );
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#pragma once
|
||||
#include <fc/vector.hpp>
|
||||
#include <fc/network/ip.hpp>
|
||||
|
||||
namespace fc
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#pragma once
|
||||
#include <fc/utility.hpp>
|
||||
#include <fc/fwd.hpp>
|
||||
#include <fc/io/iostream.hpp>
|
||||
#include <fc/time.hpp>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#pragma once
|
||||
#include <fc/utility.hpp>
|
||||
#include <fc/shared_ptr.hpp>
|
||||
#include <memory>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#pragma once
|
||||
#include <fc/string.hpp>
|
||||
#include <fc/optional.hpp>
|
||||
#include <stdint.h>
|
||||
#include <fc/filesystem.hpp>
|
||||
|
|
@ -8,7 +7,7 @@
|
|||
|
||||
namespace fc {
|
||||
|
||||
typedef fc::optional<fc::string> ostring;
|
||||
typedef fc::optional<std::string> ostring;
|
||||
typedef fc::optional<fc::path> opath;
|
||||
typedef fc::optional<fc::variant_object> ovariant_object;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
namespace fc
|
||||
{
|
||||
class noncopyable
|
||||
{
|
||||
public:
|
||||
noncopyable(){}
|
||||
private:
|
||||
noncopyable( const noncopyable& ) = delete;
|
||||
noncopyable& operator=( const noncopyable& ) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ namespace fc {
|
|||
optional( optional&& o )
|
||||
:_valid(false)
|
||||
{
|
||||
if( o._valid ) new (ptr()) T( fc::move(*o) );
|
||||
if( o._valid ) new (ptr()) T( std::move(*o) );
|
||||
_valid = o._valid;
|
||||
o.reset();
|
||||
}
|
||||
|
|
@ -71,7 +71,7 @@ namespace fc {
|
|||
optional( optional<U>&& o )
|
||||
:_valid(false)
|
||||
{
|
||||
if( o._valid ) new (ptr()) T( fc::move(*o) );
|
||||
if( o._valid ) new (ptr()) T( std::move(*o) );
|
||||
_valid = o._valid;
|
||||
o.reset();
|
||||
}
|
||||
|
|
@ -156,10 +156,10 @@ namespace fc {
|
|||
{
|
||||
if( _valid && o._valid )
|
||||
{
|
||||
ref() = fc::move(*o);
|
||||
ref() = std::move(*o);
|
||||
o.reset();
|
||||
} else if ( !_valid && o._valid ) {
|
||||
*this = fc::move(*o);
|
||||
*this = std::move(*o);
|
||||
} else if (_valid) {
|
||||
reset();
|
||||
}
|
||||
|
|
@ -173,10 +173,10 @@ namespace fc {
|
|||
{
|
||||
if( _valid && o._valid )
|
||||
{
|
||||
ref() = fc::move(*o);
|
||||
ref() = std::move(*o);
|
||||
o.reset();
|
||||
} else if ( !_valid && o._valid ) {
|
||||
*this = fc::move(*o);
|
||||
*this = std::move(*o);
|
||||
} else if (_valid) {
|
||||
reset();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <fc/string.hpp>
|
||||
#include <fc/utility.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/preprocessor/seq/for_each.hpp>
|
||||
|
|
@ -126,7 +127,7 @@ void fc::reflector<TYPE>::visit( const Visitor& v ) { \
|
|||
#define FC_REFLECT_ENUM_TO_STRING( r, enum_type, elem ) \
|
||||
case enum_type::elem: return BOOST_PP_STRINGIZE(elem);
|
||||
#define FC_REFLECT_ENUM_TO_FC_STRING( r, enum_type, elem ) \
|
||||
case enum_type::elem: return fc::string(BOOST_PP_STRINGIZE(elem));
|
||||
case enum_type::elem: return std::string(BOOST_PP_STRINGIZE(elem));
|
||||
|
||||
#define FC_REFLECT_ENUM_FROM_STRING( r, enum_type, elem ) \
|
||||
if( strcmp( s, BOOST_PP_STRINGIZE(elem) ) == 0 ) return enum_type::elem;
|
||||
|
|
@ -149,13 +150,13 @@ template<> struct reflector<ENUM> { \
|
|||
static const char* to_string(int64_t i) { \
|
||||
return to_string(ENUM(i)); \
|
||||
} \
|
||||
static fc::string to_fc_string(ENUM elem) { \
|
||||
static std::string to_fc_string(ENUM elem) { \
|
||||
switch( elem ) { \
|
||||
BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_ENUM_TO_FC_STRING, ENUM, FIELDS ) \
|
||||
} \
|
||||
return fc::to_string(int64_t(elem)); \
|
||||
} \
|
||||
static fc::string to_fc_string(int64_t i) { \
|
||||
static std::string to_fc_string(int64_t i) { \
|
||||
return to_fc_string(ENUM(i)); \
|
||||
} \
|
||||
static ENUM from_int(int64_t i) { \
|
||||
|
|
|
|||
|
|
@ -3,13 +3,12 @@
|
|||
#include <deque>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <fc/string.hpp>
|
||||
#include <fc/optional.hpp>
|
||||
|
||||
#include <fc/container/flat_fwd.hpp>
|
||||
#include <fc/container/deque_fwd.hpp>
|
||||
|
||||
namespace fc {
|
||||
class value;
|
||||
|
|
@ -30,8 +29,8 @@ namespace fc {
|
|||
template<> struct get_typename<bool> { static const char* name() { return "bool"; } };
|
||||
template<> struct get_typename<char> { static const char* name() { return "char"; } };
|
||||
template<> struct get_typename<void> { static const char* name() { return "char"; } };
|
||||
template<> struct get_typename<string> { static const char* name() { return "string"; } };
|
||||
template<> struct get_typename<value> { static const char* name() { return "value"; } };
|
||||
template<> struct get_typename<std::string> { static const char* name() { return "string"; } };
|
||||
template<> struct get_typename<fc::exception> { static const char* name() { return "fc::exception"; } };
|
||||
template<> struct get_typename<std::vector<char>> { static const char* name() { return "std::vector<char>"; } };
|
||||
template<typename T> struct get_typename<std::vector<T>>
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ namespace fc
|
|||
{
|
||||
mutable_variant_object mvo;
|
||||
fc::reflector<T>::visit( to_variant_visitor<T>( mvo, v, max_depth ) );
|
||||
vo = fc::move(mvo);
|
||||
vo = std::move(mvo);
|
||||
}
|
||||
template<typename T>
|
||||
static inline void from_variant( const fc::variant& v, T& o, uint32_t max_depth )
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#include <fc/variant.hpp>
|
||||
#include <fc/optional.hpp>
|
||||
#include <fc/api.hpp>
|
||||
#include <fc/any.hpp>
|
||||
#include <boost/any.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
|
@ -202,7 +202,7 @@ namespace fc {
|
|||
|
||||
|
||||
std::weak_ptr<fc::api_connection> _api_connection;
|
||||
fc::any _api;
|
||||
boost::any _api;
|
||||
std::map< std::string, uint32_t > _by_name;
|
||||
std::vector< std::function<variant(const variants&)> > _methods;
|
||||
}; // class generic_api
|
||||
|
|
|
|||
|
|
@ -1,532 +0,0 @@
|
|||
#pragma once
|
||||
#include <fc/variant.hpp>
|
||||
#include <fc/io/raw.hpp>
|
||||
#include <fc/optional.hpp>
|
||||
#include <fc/api.hpp>
|
||||
#include <fc/any.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <fc/signals.hpp>
|
||||
//#include <fc/rpc/json_connection.hpp>
|
||||
|
||||
namespace fc {
|
||||
class binary_api_connection;
|
||||
|
||||
namespace detail {
|
||||
template<typename Signature>
|
||||
class callback_functor
|
||||
{
|
||||
public:
|
||||
typedef typename std::function<Signature>::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<typename... Args>
|
||||
result_type operator()( Args... args )const;
|
||||
|
||||
private:
|
||||
uint64_t _callback_id;
|
||||
std::weak_ptr< fc::binary_api_connection > _binary_api_connection;
|
||||
};
|
||||
|
||||
template<typename R, typename Arg0, typename ... Args>
|
||||
std::function<R(Args...)> bind_first_arg( const std::function<R(Arg0,Args...)>& f, Arg0 a0 )
|
||||
{
|
||||
return [=]( Args... args ) { return f( a0, args... ); };
|
||||
}
|
||||
template<typename R>
|
||||
R call_generic( const std::function<R()>& f, variants::const_iterator a0, variants::const_iterator e )
|
||||
{
|
||||
return f();
|
||||
}
|
||||
|
||||
template<typename R, typename Arg0, typename ... Args>
|
||||
R call_generic( const std::function<R(Arg0,Args...)>& f, variants::const_iterator a0, variants::const_iterator e )
|
||||
{
|
||||
FC_ASSERT( a0 != e );
|
||||
return call_generic<R,Args...>( bind_first_arg<R,Arg0,Args...>( f, a0->as< typename std::decay<Arg0>::type >() ), a0+1, e );
|
||||
}
|
||||
|
||||
template<typename R, typename ... Args>
|
||||
std::function<variant(const fc::variants&)> to_generic( const std::function<R(Args...)>& f )
|
||||
{
|
||||
return [=]( const variants& args ) {
|
||||
return variant( call_generic( f, args.begin(), args.end() ) );
|
||||
};
|
||||
}
|
||||
|
||||
template<typename ... Args>
|
||||
std::function<variant(const fc::variants&)> to_generic( const std::function<void(Args...)>& f )
|
||||
{
|
||||
return [=]( const variants& args ) {
|
||||
call_generic( f, args.begin(), args.end() );
|
||||
return variant();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* If api<T> is returned from a remote method, the API is eagerly bound to api<T> 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<T>, we need to keep track of the connection because
|
||||
* the binding is done later (when the client code actually calls as<T>).
|
||||
*
|
||||
* [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<fc::binary_api_connection>& 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<fc::binary_api_connection> _binary_api_connection;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
class generic_api
|
||||
{
|
||||
public:
|
||||
template<typename Api>
|
||||
generic_api( const Api& a, const std::shared_ptr<fc::binary_api_connection>& c );
|
||||
|
||||
generic_api( const generic_api& cpy ) = delete;
|
||||
|
||||
vector<char> call( const string& name, const vector<char>& 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<char> call( uint32_t method_id, const vector<char>& 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<std::string> get_method_names()const
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
result.reserve( _by_name.size() );
|
||||
for( auto& m : _by_name ) result.push_back(m.first);
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
friend struct api_visitor;
|
||||
|
||||
template<typename R, typename Arg0, typename ... Args>
|
||||
std::function<R(Args...)> bind_first_arg( const std::function<R(Arg0,Args...)>& f, Arg0 a0 )const
|
||||
{
|
||||
return [=]( Args... args ) { return f( a0, args... ); };
|
||||
}
|
||||
|
||||
template<typename R>
|
||||
R call_generic( const std::function<R()>& f, datastream<const char*>& ds )const
|
||||
{
|
||||
return f();
|
||||
}
|
||||
|
||||
template<typename R, typename Signature, typename ... Args>
|
||||
R call_generic( const std::function<R(std::function<Signature>,Args...)>& f, datastream<const char*>& ds )
|
||||
{
|
||||
uint64_t callback_id = 0;
|
||||
fc::raw::unpack( ds, callback_id );
|
||||
detail::callback_functor<Signature> arg0( get_connection(), callback_id );
|
||||
return call_generic<R,Args...>( this->bind_first_arg<R,std::function<Signature>,Args...>( f, std::function<Signature>(arg0) ), ds );
|
||||
}
|
||||
template<typename R, typename Signature, typename ... Args>
|
||||
R call_generic( const std::function<R(const std::function<Signature>&,Args...)>& f, fc::datastream<const char*>& ds )
|
||||
{
|
||||
uint64_t callback_id = 0;
|
||||
fc::raw::unpack( ds, callback_id );
|
||||
detail::callback_functor<Signature> arg0( get_connection(), callback_id );
|
||||
return call_generic<R,Args...>( this->bind_first_arg<R,const std::function<Signature>&,Args...>( f, arg0 ), ds );
|
||||
}
|
||||
|
||||
template<typename R, typename Arg0, typename ... Args>
|
||||
R call_generic( const std::function<R(Arg0,Args...)>& f, fc::datastream<const char*>& ds )
|
||||
{
|
||||
std::decay<Arg0>::type a0;
|
||||
fc::raw::unpack( ds, a0 );
|
||||
return call_generic<R,Args...>( this->bind_first_arg<R,Arg0,Args...>( f, a0 ), ds );
|
||||
}
|
||||
|
||||
struct api_visitor
|
||||
{
|
||||
api_visitor( generic_api& a, const std::weak_ptr<fc::binary_api_connection>& s ):api(a),_api_con(s){ }
|
||||
|
||||
template<typename Interface, typename Adaptor, typename ... Args>
|
||||
std::function<variant(const fc::variants&)> to_generic( const std::function<api<Interface,Adaptor>(Args...)>& f )const;
|
||||
|
||||
template<typename Interface, typename Adaptor, typename ... Args>
|
||||
std::function<variant(const fc::variants&)> to_generic( const std::function<fc::optional<api<Interface,Adaptor>>(Args...)>& f )const;
|
||||
|
||||
template<typename ... Args>
|
||||
std::function<variant(const fc::variants&)> to_generic( const std::function<fc::api_ptr(Args...)>& f )const;
|
||||
|
||||
template<typename R, typename ... Args>
|
||||
std::function<variant(const fc::variants&)> to_generic( const std::function<R(Args...)>& f )const;
|
||||
|
||||
template<typename ... Args>
|
||||
std::function<variant(const fc::variants&)> to_generic( const std::function<void(Args...)>& f )const;
|
||||
|
||||
template<typename Result, typename... Args>
|
||||
void operator()( const char* name, std::function<Result(Args...)>& memb )const {
|
||||
api._methods.emplace_back( to_generic( memb ) );
|
||||
api._by_name[name] = api._methods.size() - 1;
|
||||
}
|
||||
|
||||
generic_api& api;
|
||||
const std::weak_ptr<fc::binary_api_connection>& _api_con;
|
||||
};
|
||||
|
||||
|
||||
std::weak_ptr<fc::binary_api_connection> _binary_api_connection;
|
||||
fc::any _api;
|
||||
std::map< std::string, uint32_t > _by_name;
|
||||
std::vector< std::function<vector<char>(const vector<char>&)> > _methods;
|
||||
}; // class generic_api
|
||||
|
||||
|
||||
|
||||
class binary_api_connection : public std::enable_shared_from_this<fc::binary_api_connection>
|
||||
{
|
||||
public:
|
||||
typedef std::vector<char> params_type;
|
||||
typedef std::vector<char> result_type;
|
||||
|
||||
binary_api_connection(){}
|
||||
virtual ~binary_api_connection(){};
|
||||
|
||||
|
||||
template<typename T>
|
||||
api<T> get_remote_api( api_id_type api_id = 0 )
|
||||
{
|
||||
api<T> 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<typename Interface>
|
||||
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<generic_api>( new generic_api(a, shared_from_this() ) ) );
|
||||
_handle_to_id[handle] = _local_apis.size() - 1;
|
||||
return _local_apis.size() - 1;
|
||||
}
|
||||
|
||||
template<typename Signature>
|
||||
uint64_t register_callback( const std::function<Signature>& cb )
|
||||
{
|
||||
_local_callbacks.push_back( detail::to_generic( cb ) );
|
||||
return _local_callbacks.size() - 1;
|
||||
}
|
||||
|
||||
std::vector<std::string> get_method_names( api_id_type local_api_id = 0 )const { return _local_apis[local_api_id]->get_method_names(); }
|
||||
|
||||
fc::signal<void()> closed;
|
||||
private:
|
||||
std::vector< std::unique_ptr<generic_api> > _local_apis;
|
||||
std::map< uint64_t, api_id_type > _handle_to_id;
|
||||
std::vector< std::function<variant(const variants&)> > _local_callbacks;
|
||||
|
||||
|
||||
struct api_visitor
|
||||
{
|
||||
uint32_t _api_id;
|
||||
std::shared_ptr<fc::binary_api_connection> _connection;
|
||||
|
||||
api_visitor( uint32_t api_id, std::shared_ptr<fc::binary_api_connection> con )
|
||||
:_api_id(api_id),_connection(std::move(con))
|
||||
{
|
||||
}
|
||||
|
||||
api_visitor() = delete;
|
||||
|
||||
template<typename Result>
|
||||
static Result from_vector( const vector<char>& v, Result*, const std::shared_ptr<fc::binary_api_connection>& )
|
||||
{
|
||||
return fc::raw::unpack<Result>( v );
|
||||
}
|
||||
|
||||
template<typename ResultInterface>
|
||||
static fc::api<ResultInterface> from_vector( const vector<char>& v,
|
||||
fc::api<ResultInterface>* /*used for template deduction*/,
|
||||
const std::shared_ptr<fc::binary_api_connection>& con
|
||||
)
|
||||
{
|
||||
return con->get_remote_api<ResultInterface>( fc::raw::unpack<uint64_t>( v ) );
|
||||
}
|
||||
|
||||
static fc::api_ptr from_vector(
|
||||
const vector<char>& v,
|
||||
fc::api_ptr* /* used for template deduction */,
|
||||
const std::shared_ptr<fc::binary_api_connection>& con
|
||||
)
|
||||
{
|
||||
return fc::api_ptr( new detail::any_api( fc::raw::unpack<uint64_t>(v), con ) );
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static result_type convert_callbacks( const std::shared_ptr<fc::binary_api_connection>&, const T& v )
|
||||
{
|
||||
return fc::raw::pack(v);
|
||||
}
|
||||
|
||||
template<typename Signature>
|
||||
static result_type convert_callbacks( const std::shared_ptr<fc::binary_api_connection>& con, const std::function<Signature>& v )
|
||||
{
|
||||
return con->register_callback( v );
|
||||
}
|
||||
|
||||
template<typename Result, typename... Args>
|
||||
void operator()( const char* name, std::function<Result(Args...)>& 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<typename... Args>
|
||||
void operator()( const char* name, std::function<void(Args...)>& 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<fc::binary_api_connection>& rc )
|
||||
{
|
||||
FC_ASSERT( !_remote_connection );
|
||||
FC_ASSERT( rc != this->shared_from_this() );
|
||||
_remote_connection = rc;
|
||||
}
|
||||
const std::shared_ptr<fc::binary_api_connection>& remote_connection()const { return _remote_connection; }
|
||||
|
||||
std::shared_ptr<fc::binary_api_connection> _remote_connection;
|
||||
};
|
||||
|
||||
template<typename Api>
|
||||
generic_api::generic_api( const Api& a, const std::shared_ptr<fc::binary_api_connection>& c )
|
||||
:_binary_api_connection(c),_api(a)
|
||||
{
|
||||
boost::any_cast<const Api&>(a)->visit( api_visitor( *this, c ) );
|
||||
}
|
||||
|
||||
template<typename Interface, typename Adaptor, typename ... Args>
|
||||
std::function<result_type(const params_type&)> generic_api::api_visitor::to_generic(
|
||||
const std::function<fc::api<Interface,Adaptor>(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<const char*> ds( args.data(), args.size() );
|
||||
auto api_result = gapi->call_generic( f, args );
|
||||
return con->register_api( api_result );
|
||||
};
|
||||
}
|
||||
template<typename Interface, typename Adaptor, typename ... Args>
|
||||
std::function<result_type(const params_type&)> generic_api::api_visitor::to_generic(
|
||||
const std::function<fc::optional<fc::api<Interface,Adaptor>>(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<const char*> 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<typename ... Args>
|
||||
std::function<result_type(const params_type&)> generic_api::api_visitor::to_generic(
|
||||
const std::function<fc::api_ptr(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" );
|
||||
|
||||
fc::raw::datastream<const char*> 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<typename R, typename ... Args>
|
||||
std::function<result_type(const params_type&)> generic_api::api_visitor::to_generic( const std::function<R(Args...)>& f )const
|
||||
{
|
||||
generic_api* gapi = &api;
|
||||
return [f,gapi]( const params_type& args ) {
|
||||
fc::raw::datastream<const char*> ds( args.data(), args.size() );
|
||||
return fc::raw::pack(gapi->call_generic( f, ds ));
|
||||
};
|
||||
}
|
||||
|
||||
template<typename ... Args>
|
||||
std::function<result_type(const params_type&)> generic_api::api_visitor::to_generic( const std::function<void(Args...)>& f )const
|
||||
{
|
||||
generic_api* gapi = &api;
|
||||
return [f,gapi]( const params_type& args ) {
|
||||
fc::raw::datastream<const char*> 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<T> 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<T> (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<T> api_base::as()
|
||||
{
|
||||
// TODO: this method should probably be const (if it is not too hard)
|
||||
api<T>* maybe_requested_type = dynamic_cast< api<T>* >(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<T>( maybe_any->_api_id );
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
template<typename Signature>
|
||||
template<typename... Args>
|
||||
typename callback_functor<Signature>::result_type callback_functor<Signature>::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<typename... Args>
|
||||
class callback_functor<void(Args...)>
|
||||
{
|
||||
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
|
||||
|
|
@ -32,8 +32,8 @@ namespace fc { namespace rpc {
|
|||
typedef std::function<result_type(const params_type&)> method;
|
||||
~bstate();
|
||||
|
||||
void add_method( const fc::string& name, method m );
|
||||
void remove_method( const fc::string& name );
|
||||
void add_method( const std::string& name, method m );
|
||||
void remove_method( const std::string& name );
|
||||
|
||||
result_type local_call( const string& method_name, const params_type& args );
|
||||
void handle_reply( const bresponse& response );
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ namespace fc { namespace rpc {
|
|||
void wait();
|
||||
void format_result( const string& method, std::function<string(variant,const variants&)> formatter);
|
||||
|
||||
virtual void getline( const fc::string& prompt, fc::string& line );
|
||||
virtual void getline( const std::string& prompt, std::string& line );
|
||||
|
||||
void set_prompt( const string& prompt );
|
||||
|
||||
|
|
|
|||
|
|
@ -44,57 +44,57 @@ namespace fc { namespace rpc {
|
|||
* 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 );
|
||||
void add_method( const std::string& name, method );
|
||||
void add_named_param_method( const std::string& name, named_param_method );
|
||||
void remove_method( const std::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 );
|
||||
void notice( const std::string& method );
|
||||
void notice( const std::string& method, const variants& args );
|
||||
void notice( const std::string& method, const variant_object& named_args );
|
||||
|
||||
/// args will be handled as named params
|
||||
future<variant> async_call( const fc::string& method,
|
||||
future<variant> async_call( const std::string& method,
|
||||
const variant_object& args );
|
||||
|
||||
future<variant> async_call( const fc::string& method, mutable_variant_object args );
|
||||
future<variant> async_call( const std::string& method, mutable_variant_object args );
|
||||
|
||||
/// Sending in an array of variants will be handled as positional arguments
|
||||
future<variant> async_call( const fc::string& method,
|
||||
future<variant> async_call( const std::string& method,
|
||||
const variants& args );
|
||||
|
||||
future<variant> async_call( const fc::string& method );
|
||||
future<variant> async_call( const std::string& method );
|
||||
|
||||
future<variant> async_call( const fc::string& method,
|
||||
future<variant> async_call( const std::string& method,
|
||||
const variant& a1 );
|
||||
|
||||
future<variant> async_call( const fc::string& method,
|
||||
future<variant> async_call( const std::string& method,
|
||||
const variant& a1,
|
||||
const variant& a2 );
|
||||
|
||||
future<variant> async_call( const fc::string& method,
|
||||
future<variant> async_call( const std::string& method,
|
||||
const variant& a1,
|
||||
const variant& a2,
|
||||
const variant& a3 );
|
||||
|
||||
future<variant> async_call( const fc::string& method,
|
||||
future<variant> async_call( const std::string& method,
|
||||
const variant& a1,
|
||||
const variant& a2,
|
||||
const variant& a3,
|
||||
const variant& a4 );
|
||||
|
||||
future<variant> async_call( const fc::string& method,
|
||||
future<variant> async_call( const std::string& method,
|
||||
const variant& a1,
|
||||
const variant& a2,
|
||||
const variant& a3,
|
||||
const variant& a4,
|
||||
const variant& a5 );
|
||||
|
||||
future<variant> async_call( const fc::string& method,
|
||||
future<variant> async_call( const std::string& method,
|
||||
const variant& a1,
|
||||
const variant& a2,
|
||||
const variant& a3,
|
||||
|
|
@ -102,7 +102,7 @@ namespace fc { namespace rpc {
|
|||
const variant& a5,
|
||||
const variant& a6 );
|
||||
|
||||
future<variant> async_call( const fc::string& method,
|
||||
future<variant> async_call( const std::string& method,
|
||||
const variant& a1,
|
||||
const variant& a2,
|
||||
const variant& a3,
|
||||
|
|
@ -112,7 +112,7 @@ namespace fc { namespace rpc {
|
|||
const variant& a7
|
||||
);
|
||||
|
||||
future<variant> async_call( const fc::string& method,
|
||||
future<variant> async_call( const std::string& method,
|
||||
const variant& a1,
|
||||
const variant& a2,
|
||||
const variant& a3,
|
||||
|
|
@ -122,7 +122,7 @@ namespace fc { namespace rpc {
|
|||
const variant& a7,
|
||||
const variant& a8
|
||||
);
|
||||
future<variant> async_call( const fc::string& method,
|
||||
future<variant> async_call( const std::string& method,
|
||||
const variant& a1,
|
||||
const variant& a2,
|
||||
const variant& a3,
|
||||
|
|
@ -133,7 +133,7 @@ namespace fc { namespace rpc {
|
|||
const variant& a8,
|
||||
const variant& a9
|
||||
);
|
||||
future<variant> async_call( const fc::string& method,
|
||||
future<variant> async_call( const std::string& method,
|
||||
const variant& a1,
|
||||
const variant& a2,
|
||||
const variant& a3,
|
||||
|
|
@ -147,7 +147,7 @@ namespace fc { namespace rpc {
|
|||
);
|
||||
|
||||
template<typename Result>
|
||||
Result call( const fc::string& method,
|
||||
Result call( const std::string& method,
|
||||
const variants& args,
|
||||
microseconds timeout = microseconds::maximum())
|
||||
{
|
||||
|
|
@ -155,7 +155,7 @@ namespace fc { namespace rpc {
|
|||
}
|
||||
|
||||
template<typename Result>
|
||||
Result call( const fc::string& method,
|
||||
Result call( const std::string& method,
|
||||
const variant& a1,
|
||||
const variant& a2,
|
||||
const variant& a3,
|
||||
|
|
@ -165,7 +165,7 @@ namespace fc { namespace rpc {
|
|||
}
|
||||
|
||||
template<typename Result>
|
||||
Result call( const fc::string& method,
|
||||
Result call( const std::string& method,
|
||||
const variant& a1,
|
||||
const variant& a2,
|
||||
const variant& a3,
|
||||
|
|
@ -176,7 +176,7 @@ namespace fc { namespace rpc {
|
|||
}
|
||||
|
||||
template<typename Result>
|
||||
Result call( const fc::string& method,
|
||||
Result call( const std::string& method,
|
||||
const variant& a1,
|
||||
const variant& a2,
|
||||
const variant& a3,
|
||||
|
|
@ -188,7 +188,7 @@ namespace fc { namespace rpc {
|
|||
}
|
||||
|
||||
template<typename Result>
|
||||
Result call( const fc::string& method,
|
||||
Result call( const std::string& method,
|
||||
const variant& a1,
|
||||
const variant& a2,
|
||||
const variant& a3,
|
||||
|
|
@ -200,7 +200,7 @@ namespace fc { namespace rpc {
|
|||
return async_call( method, a1, a2, a3, a4, a5, a6).wait(timeout).as<Result>();
|
||||
}
|
||||
template<typename Result>
|
||||
Result call( const fc::string& method,
|
||||
Result call( const std::string& method,
|
||||
const variant& a1,
|
||||
const variant& a2,
|
||||
const variant& a3,
|
||||
|
|
@ -214,7 +214,7 @@ namespace fc { namespace rpc {
|
|||
}
|
||||
|
||||
template<typename Result>
|
||||
Result call( const fc::string& method,
|
||||
Result call( const std::string& method,
|
||||
const variant& a1,
|
||||
const variant& a2,
|
||||
const variant& a3,
|
||||
|
|
@ -229,7 +229,7 @@ namespace fc { namespace rpc {
|
|||
}
|
||||
|
||||
template<typename Result>
|
||||
Result call( const fc::string& method,
|
||||
Result call( const std::string& method,
|
||||
const variant& a1,
|
||||
const variant& a2,
|
||||
const variant& a3,
|
||||
|
|
@ -245,7 +245,7 @@ namespace fc { namespace rpc {
|
|||
}
|
||||
|
||||
template<typename Result>
|
||||
Result call( const fc::string& method,
|
||||
Result call( const std::string& method,
|
||||
const variant& a1,
|
||||
const variant& a2,
|
||||
const variant& a3,
|
||||
|
|
@ -262,7 +262,7 @@ namespace fc { namespace rpc {
|
|||
}
|
||||
|
||||
template<typename Result>
|
||||
Result call( const fc::string& method,
|
||||
Result call( const std::string& method,
|
||||
const variant& a1,
|
||||
const variant& a2,
|
||||
microseconds timeout = microseconds::maximum())
|
||||
|
|
@ -271,7 +271,7 @@ namespace fc { namespace rpc {
|
|||
}
|
||||
|
||||
template<typename Result>
|
||||
Result call( const fc::string& method,
|
||||
Result call( const std::string& method,
|
||||
const variant& a1,
|
||||
microseconds timeout = microseconds::maximum())
|
||||
{
|
||||
|
|
@ -279,29 +279,29 @@ namespace fc { namespace rpc {
|
|||
}
|
||||
|
||||
template<typename Result>
|
||||
Result call( const fc::string& method,
|
||||
Result call( const std::string& method,
|
||||
variant_object a1,
|
||||
microseconds timeout = microseconds::maximum())
|
||||
{
|
||||
return async_call( method, fc::move(a1) ).wait(timeout).as<Result>();
|
||||
return async_call( method, std::move(a1) ).wait(timeout).as<Result>();
|
||||
}
|
||||
template<typename Result>
|
||||
Result call( const fc::string& method,
|
||||
Result call( const std::string& method,
|
||||
mutable_variant_object a1,
|
||||
microseconds timeout = microseconds::maximum())
|
||||
{
|
||||
return async_call( method, variant_object( fc::move(a1) ) ).wait(timeout).as<Result>();
|
||||
return async_call( method, variant_object( std::move(a1) ) ).wait(timeout).as<Result>();
|
||||
}
|
||||
|
||||
|
||||
template<typename Result>
|
||||
Result call( const fc::string& method, microseconds timeout = microseconds::maximum() )
|
||||
Result call( const std::string& method, microseconds timeout = microseconds::maximum() )
|
||||
{
|
||||
return async_call( method ).wait(timeout).as<Result>();
|
||||
}
|
||||
|
||||
/// Sending in a variant_object will be issued as named parameters
|
||||
variant call( const fc::string& method, const variant_object& named_args );
|
||||
variant call( const std::string& method, const variant_object& named_args );
|
||||
///@}
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace fc { namespace rpc {
|
|||
response( int64_t i, fc::variant r, string j ):id(i),jsonrpc(j),result(r){}
|
||||
response( int64_t i, error_object r, string j ):id(i),jsonrpc(j),error(r){}
|
||||
int64_t id = 0;
|
||||
optional<fc::string> jsonrpc;
|
||||
optional<std::string> jsonrpc;
|
||||
optional<fc::variant> result;
|
||||
optional<error_object> error;
|
||||
};
|
||||
|
|
@ -37,8 +37,8 @@ namespace fc { namespace rpc {
|
|||
typedef std::function<variant(const variants&)> method;
|
||||
~state();
|
||||
|
||||
void add_method( const fc::string& name, method m );
|
||||
void remove_method( const fc::string& name );
|
||||
void add_method( const std::string& name, method m );
|
||||
void remove_method( const std::string& name );
|
||||
|
||||
variant local_call( const string& method_name, const variants& args );
|
||||
void handle_reply( const response& response );
|
||||
|
|
|
|||
|
|
@ -1,140 +0,0 @@
|
|||
#pragma once
|
||||
#include <fc/io/buffered_iostream.hpp>
|
||||
#include <fc/variant_object.hpp>
|
||||
#include <fc/thread/future.hpp>
|
||||
#include <fc/log/logger.hpp>
|
||||
#include <functional>
|
||||
|
||||
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<variant(const variants&)> method;
|
||||
typedef std::function<variant(const variant_object&)> named_param_method;
|
||||
|
||||
variant_connection( fc::variant_stream::ptr in, fc::variant_stream::ptr out );
|
||||
~variant_connection();
|
||||
|
||||
/**
|
||||
* Starts processing messages from input
|
||||
*/
|
||||
future<void> 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<variant> async_call( const fc::string& method,
|
||||
const variant_object& args );
|
||||
|
||||
future<variant> async_call( const fc::string& method, mutable_variant_object args );
|
||||
|
||||
/// Sending in an array of variants will be handled as positional arguments
|
||||
future<variant> async_call( const fc::string& method,
|
||||
const variants& args );
|
||||
|
||||
future<variant> async_call( const fc::string& method );
|
||||
|
||||
future<variant> async_call( const fc::string& method,
|
||||
const variant& a1 );
|
||||
|
||||
future<variant> async_call( const fc::string& method,
|
||||
const variant& a1,
|
||||
const variant& a2 );
|
||||
|
||||
future<variant> async_call( const fc::string& method,
|
||||
const variant& a1,
|
||||
const variant& a2,
|
||||
const variant& a3 );
|
||||
|
||||
template<typename Result>
|
||||
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<Result>();
|
||||
}
|
||||
|
||||
template<typename Result>
|
||||
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<Result>();
|
||||
}
|
||||
|
||||
template<typename Result>
|
||||
Result call( const fc::string& method,
|
||||
const variant& a1,
|
||||
microseconds timeout = microseconds::maximum())
|
||||
{
|
||||
return async_call( method, a1 ).wait(timeout).as<Result>();
|
||||
}
|
||||
|
||||
template<typename Result>
|
||||
Result call( const fc::string& method,
|
||||
variant_object a1,
|
||||
microseconds timeout = microseconds::maximum())
|
||||
{
|
||||
return async_call( method, fc::move(a1) ).wait(timeout).as<Result>();
|
||||
}
|
||||
template<typename Result>
|
||||
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<Result>();
|
||||
}
|
||||
|
||||
|
||||
template<typename Result>
|
||||
Result call( const fc::string& method, microseconds timeout = microseconds::maximum() )
|
||||
{
|
||||
return async_call( method ).wait(timeout).as<Result>();
|
||||
}
|
||||
|
||||
/// 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<detail::variant_connection_impl> my;
|
||||
};
|
||||
typedef std::shared_ptr<variant_connection> variant_connection_ptr;
|
||||
|
||||
}} // fc::rpc
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
namespace fc
|
||||
{
|
||||
|
||||
/**
|
||||
* Thread-safe, circular buffer for passing variants
|
||||
* between threads.
|
||||
*/
|
||||
class variant_stream
|
||||
{
|
||||
public:
|
||||
variant_stream( size_t s );
|
||||
~variant_stream();
|
||||
|
||||
/** producer api */
|
||||
int64_t free(); // number of spaces available
|
||||
int64_t claim( int64_t num );
|
||||
int64_t publish( int64_t pos );
|
||||
int64_t wait_free(); // wait for free space
|
||||
|
||||
// producer/consumer api
|
||||
variant& get( int64_t pos );
|
||||
|
||||
/** consumer api */
|
||||
int64_t begin(); // returns the first index ready to be read
|
||||
int64_t end(); // returns the first index that cannot be read
|
||||
int64_t wait(); // wait for variants to be posted
|
||||
|
||||
private:
|
||||
std::vector<variant> _variants;
|
||||
uint64_t _read_pos;
|
||||
uint64_t _write_pos;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
namespace fc {
|
||||
|
||||
template<typename Callback>
|
||||
class scoped_exit {
|
||||
public:
|
||||
template<typename C>
|
||||
scoped_exit( C&& c ):callback( std::forward<C>(c) ){}
|
||||
scoped_exit( scoped_exit&& mv ):callback( std::move( mv.callback ) ){}
|
||||
|
||||
~scoped_exit() {
|
||||
try { callback(); } catch( ... ) {}
|
||||
}
|
||||
|
||||
scoped_exit& operator = ( scoped_exit&& mv ) {
|
||||
callback = std::move(mv);
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
scoped_exit( const scoped_exit& );
|
||||
scoped_exit& operator=( const scoped_exit& );
|
||||
|
||||
Callback callback;
|
||||
};
|
||||
|
||||
template<typename Callback>
|
||||
scoped_exit<Callback> make_scoped_exit( Callback&& c ) {
|
||||
return scoped_exit<Callback>( std::forward<Callback>(c) );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
#include <fc/utility.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <utility>
|
||||
|
||||
namespace fc {
|
||||
|
||||
|
|
@ -62,7 +64,7 @@ namespace fc {
|
|||
return *this;
|
||||
}
|
||||
shared_ptr& operator=(shared_ptr&& p ) {
|
||||
fc_swap(_ptr,p._ptr);
|
||||
std::swap(_ptr,p._ptr);
|
||||
return *this;
|
||||
}
|
||||
T& operator* ()const { return *_ptr; }
|
||||
|
|
|
|||
|
|
@ -1,130 +0,0 @@
|
|||
#pragma once
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <fc/vector.hpp>
|
||||
#include <fc/log/logger.hpp>
|
||||
#include <fc/thread/mutex.hpp>
|
||||
#include <fc/thread/unique_lock.hpp>
|
||||
#ifdef emit
|
||||
#undef emit
|
||||
#endif
|
||||
|
||||
namespace fc {
|
||||
|
||||
template<typename Signature>
|
||||
class signal {
|
||||
private:
|
||||
typedef std::function<Signature> func_type;
|
||||
typedef std::vector<std::shared_ptr<func_type>> list_type;
|
||||
public:
|
||||
typedef void* connection_id_type;
|
||||
|
||||
template<typename Functor>
|
||||
connection_id_type connect( Functor&& f ) {
|
||||
fc::unique_lock<fc::mutex> lock(_mutex);
|
||||
//auto c = new std::function<Signature>( fc::forward<Functor>(f) );
|
||||
_handlers.push_back( std::make_shared<func_type>(f) );
|
||||
return reinterpret_cast<connection_id_type>(_handlers.back().get());
|
||||
}
|
||||
#ifdef WIN32
|
||||
template<typename Arg>
|
||||
void emit( Arg&& arg ) {
|
||||
list_type handlers = getHandlers();
|
||||
for( size_t i = 0; i < handlers.size(); ++i ) {
|
||||
(*handlers[i])( fc::forward<Arg>(arg) );
|
||||
}
|
||||
}
|
||||
void operator()() {
|
||||
list_type handlers = getHandlers();
|
||||
for( size_t i = 0; i < handlers.size(); ++i ) {
|
||||
(*handlers[i])();
|
||||
}
|
||||
}
|
||||
template<typename Arg>
|
||||
void operator()( Arg&& arg ) {
|
||||
list_type handlers = getHandlers();
|
||||
for( size_t i = 0; i < handlers.size(); ++i ) {
|
||||
(*handlers[i])( fc::forward<Arg>(arg) );
|
||||
}
|
||||
}
|
||||
template<typename Arg,typename Arg2>
|
||||
void emit( Arg&& arg, Arg2&& arg2 ) {
|
||||
list_type handlers = getHandlers();
|
||||
for( size_t i = 0; i < handlers.size(); ++i ) {
|
||||
(*handlers[i])( fc::forward<Arg>(arg), fc::forward<Arg2>(arg2) );
|
||||
}
|
||||
}
|
||||
template<typename Arg, typename Arg2>
|
||||
void operator()( Arg&& arg, Arg2&& arg2 ) {
|
||||
list_type handlers = getHandlers();
|
||||
for( size_t i = 0; i < handlers.size(); ++i ) {
|
||||
(*handlers[i])( fc::forward<Arg>(arg), fc::forward<Arg2>(arg2) );
|
||||
}
|
||||
}
|
||||
template<typename Arg, typename Arg2, typename Arg3>
|
||||
void emit( Arg&& arg, Arg2&& arg2, Arg3&& arg3 ) {
|
||||
list_type handlers = getHandlers();
|
||||
for( size_t i = 0; i < handlers.size(); ++i ) {
|
||||
(*handlers[i])( fc::forward<Arg>(arg), fc::forward<Arg2>(arg2), fc::forward<Arg3>(arg3) );
|
||||
}
|
||||
}
|
||||
template<typename Arg, typename Arg2, typename Arg3>
|
||||
void operator()( Arg&& arg, Arg2&& arg2, Arg3&& arg3 ) {
|
||||
list_type handlers = getHandlers();
|
||||
for( size_t i = 0; i < handlers.size(); ++i ) {
|
||||
(*handlers[i])( fc::forward<Arg>(arg), fc::forward<Arg2>(arg2), fc::forward<Arg3>(arg3) );
|
||||
}
|
||||
}
|
||||
#else
|
||||
template<typename... Args>
|
||||
void emit( Args&&... args ) {
|
||||
list_type handlers = getHandlers();
|
||||
for( size_t i = 0; i < handlers.size(); ++i ) {
|
||||
(*handlers[i])( fc::forward<Args>(args)... );
|
||||
}
|
||||
}
|
||||
template<typename... Args>
|
||||
void operator()( Args&&... args ) {
|
||||
list_type handlers = getHandlers();
|
||||
for( size_t i = 0; i < handlers.size(); ++i ) {
|
||||
(*handlers[i])( fc::forward<Args>(args)... );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void disconnect( connection_id_type cid ) {
|
||||
fc::unique_lock<fc::mutex> lock(_mutex);
|
||||
auto itr = _handlers.begin();
|
||||
while( itr != _handlers.end() ) {
|
||||
if( reinterpret_cast<connection_id_type>(itr->get()) == cid ) {
|
||||
_handlers.erase(itr);
|
||||
}
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
signal()
|
||||
{
|
||||
_handlers.reserve(4);
|
||||
}
|
||||
//~signal()
|
||||
//{
|
||||
// for( auto itr = _handlers.begin(); itr != _handlers.end(); ++itr )
|
||||
// {
|
||||
// delete *itr;
|
||||
// }
|
||||
// _handlers.clear();
|
||||
//}
|
||||
|
||||
private:
|
||||
fc::mutex _mutex;
|
||||
list_type _handlers;
|
||||
|
||||
list_type getHandlers()
|
||||
{
|
||||
fc::unique_lock<fc::mutex> lock(_mutex);
|
||||
list_type handlers(_handlers);
|
||||
return handlers;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -1,154 +1,32 @@
|
|||
#pragma once
|
||||
#include <fc/utility.hpp>
|
||||
#include <fc/fwd.hpp>
|
||||
#include <fc/optional.hpp>
|
||||
|
||||
#ifndef USE_FC_STRING
|
||||
#include <string>
|
||||
|
||||
namespace fc
|
||||
{
|
||||
typedef std::string string;
|
||||
using std::string;
|
||||
|
||||
int64_t to_int64( const fc::string& );
|
||||
uint64_t to_uint64( const fc::string& );
|
||||
double to_double( const fc::string& );
|
||||
fc::string to_string( double );
|
||||
fc::string to_string( uint64_t );
|
||||
fc::string to_string( int64_t );
|
||||
fc::string to_string( uint16_t );
|
||||
int64_t to_int64( const std::string& );
|
||||
uint64_t to_uint64( const std::string& );
|
||||
double to_double( const std::string& );
|
||||
std::string to_string( double );
|
||||
std::string to_string( uint64_t );
|
||||
std::string to_string( int64_t );
|
||||
std::string to_string( uint16_t );
|
||||
std::string to_pretty_string( int64_t );
|
||||
inline fc::string to_string( int32_t v ) { return to_string( int64_t(v) ); }
|
||||
inline fc::string to_string( uint32_t v ){ return to_string( uint64_t(v) ); }
|
||||
inline std::string to_string( int32_t v ) { return to_string( int64_t(v) ); }
|
||||
inline std::string to_string( uint32_t v ){ return to_string( uint64_t(v) ); }
|
||||
#ifdef __APPLE__
|
||||
inline fc::string to_string( size_t s) { return to_string(uint64_t(s)); }
|
||||
inline std::string to_string( size_t s) { return to_string(uint64_t(s)); }
|
||||
#endif
|
||||
|
||||
typedef fc::optional<fc::string> ostring;
|
||||
typedef fc::optional<std::string> ostring;
|
||||
class variant_object;
|
||||
fc::string format_string( const fc::string&, const variant_object&, uint32_t max_object_depth = 200 );
|
||||
fc::string trim( const fc::string& );
|
||||
fc::string to_lower( const fc::string& );
|
||||
std::string format_string( const std::string&, const variant_object&, uint32_t max_object_depth = 200 );
|
||||
std::string trim( const std::string& );
|
||||
std::string to_lower( const std::string& );
|
||||
string trim_and_normalize_spaces( const string& s );
|
||||
|
||||
uint64_t parse_size( const string& s );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/**
|
||||
* There is debate about whether doing this is 'standard conforming', but
|
||||
* it works everywhere and enables the purpose of this library which is to
|
||||
* accelerate compiles while maintaining compatability.
|
||||
*/
|
||||
namespace std {
|
||||
template<class Char>
|
||||
struct char_traits;
|
||||
|
||||
template<class T>
|
||||
class allocator;
|
||||
|
||||
template<class Char, class Traits, class Allocator>
|
||||
class basic_string;
|
||||
|
||||
typedef basic_string<char, char_traits<char>, allocator<char> > string;
|
||||
}
|
||||
|
||||
|
||||
namespace fc {
|
||||
/**
|
||||
* @brief wrapper on std::string
|
||||
*
|
||||
* Including <string> results in 4000 lines of code
|
||||
* that must be included to build your header. This
|
||||
* class hides all of those details while maintaining
|
||||
* compatability with std::string. Using fc::string
|
||||
* instead of std::string can accelerate compile times
|
||||
* 10x.
|
||||
*
|
||||
* The implementation of this class is std::string, this header simply
|
||||
* accelerates compile times. fc::string is automatically convertable to / from
|
||||
* std::string.
|
||||
*/
|
||||
class string {
|
||||
public:
|
||||
typedef char* iterator;
|
||||
typedef const char* const_iterator;
|
||||
enum { npos = size_t(-1) };
|
||||
// static const size_t npos;// = -1;
|
||||
|
||||
string();
|
||||
string( const std::string& s );
|
||||
string( std::string&& s );
|
||||
string( const string& c );
|
||||
string( string&& c );
|
||||
string( const char* c );
|
||||
string( const char* c, int s );
|
||||
string( const_iterator b, const_iterator e );
|
||||
~string();
|
||||
|
||||
operator std::string&();
|
||||
operator const std::string&()const;
|
||||
|
||||
iterator begin();
|
||||
iterator end();
|
||||
|
||||
const_iterator begin()const;
|
||||
const_iterator end()const;
|
||||
|
||||
char& operator[](size_t idx);
|
||||
const char& operator[](size_t idx)const;
|
||||
|
||||
string& operator =( const string& c );
|
||||
string& operator =( string&& c );
|
||||
|
||||
void reserve( size_t );
|
||||
size_t size()const;
|
||||
size_t find( char c, size_t pos = 0 )const;
|
||||
size_t find(const fc::string& str, size_t pos = 0) const;
|
||||
size_t find(const char* s, size_t pos = 0) const;
|
||||
size_t rfind( char c, size_t pos = npos )const;
|
||||
size_t rfind( const char* c, size_t pos = npos )const;
|
||||
size_t rfind( const fc::string& c, size_t pos = npos )const;
|
||||
size_t find_first_of (const fc::string& str, size_t pos = 0) const;
|
||||
size_t find_first_of (const char* s, size_t pos = 0) const;
|
||||
string& replace(size_t pos, size_t len, const fc::string& str);
|
||||
string& replace(size_t pos, size_t len, const char* s);
|
||||
|
||||
void resize( size_t s );
|
||||
void clear();
|
||||
|
||||
const char* c_str()const;
|
||||
char* data();
|
||||
|
||||
bool operator == ( const char* s )const;
|
||||
bool operator == ( const string& s )const;
|
||||
bool operator != ( const string& s )const;
|
||||
|
||||
friend bool operator < ( const string& a, const string& b );
|
||||
|
||||
string& operator+=( const string& s );
|
||||
string& operator+=( char c );
|
||||
|
||||
friend string operator + ( const string&, const string& );
|
||||
friend string operator + ( const string&, char c );
|
||||
|
||||
fc::string substr( size_t start, size_t len = fc::string::npos )const;
|
||||
|
||||
private:
|
||||
fc::fwd<std::string,32> my;
|
||||
};
|
||||
|
||||
int64_t to_int64( const fc::string& );
|
||||
uint64_t to_uint64( const fc::string& );
|
||||
double to_double( const fc::string& );
|
||||
fc::string to_string( double );
|
||||
fc::string to_string( uint64_t );
|
||||
fc::string to_string( int64_t );
|
||||
|
||||
typedef fc::optional<fc::string> ostring;
|
||||
class variant_object;
|
||||
fc::string format_string( const fc::string&, const variant_object& );
|
||||
|
||||
} // namespace fc
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#pragma once
|
||||
#include <fc/utility.hpp>
|
||||
#include <fc/time.hpp>
|
||||
#include <fc/shared_ptr.hpp>
|
||||
#include <fc/exception/exception.hpp>
|
||||
|
|
@ -35,7 +34,7 @@ namespace fc {
|
|||
template<typename Functor, typename T>
|
||||
class completion_handler_impl : public completion_handler {
|
||||
public:
|
||||
completion_handler_impl( Functor&& f ):_func(fc::move(f)){}
|
||||
completion_handler_impl( Functor&& f ):_func(std::move(f)){}
|
||||
completion_handler_impl( const Functor& f ):_func(f){}
|
||||
|
||||
virtual void on_complete( const void* v, const fc::exception_ptr& e ) {
|
||||
|
|
@ -47,7 +46,7 @@ namespace fc {
|
|||
template<typename Functor>
|
||||
class completion_handler_impl<Functor,void> : public completion_handler {
|
||||
public:
|
||||
completion_handler_impl( Functor&& f ):_func(fc::move(f)){}
|
||||
completion_handler_impl( Functor&& f ):_func(std::move(f)){}
|
||||
completion_handler_impl( const Functor& f ):_func(f){}
|
||||
virtual void on_complete( const void* v, const fc::exception_ptr& e ) {
|
||||
_func(e);
|
||||
|
|
@ -110,7 +109,7 @@ namespace fc {
|
|||
typedef fc::shared_ptr< promise<T> > ptr;
|
||||
promise( const char* desc FC_TASK_NAME_DEFAULT_ARG):promise_base(desc){}
|
||||
promise( const T& val ){ set_value(val); }
|
||||
promise( T&& val ){ set_value(fc::move(val) ); }
|
||||
promise( T&& val ){ set_value(std::move(val) ); }
|
||||
|
||||
const T& wait(const microseconds& timeout = microseconds::maximum() ){
|
||||
this->_wait( timeout );
|
||||
|
|
@ -127,7 +126,7 @@ namespace fc {
|
|||
}
|
||||
|
||||
void set_value( T&& v ) {
|
||||
result = fc::move(v);
|
||||
result = std::move(v);
|
||||
_set_value(&*result);
|
||||
}
|
||||
|
||||
|
|
@ -186,12 +185,12 @@ namespace fc {
|
|||
class future {
|
||||
public:
|
||||
future( const fc::shared_ptr<promise<T>>& p ):m_prom(p){}
|
||||
future( fc::shared_ptr<promise<T>>&& p ):m_prom(fc::move(p)){}
|
||||
future( fc::shared_ptr<promise<T>>&& p ):m_prom(std::move(p)){}
|
||||
future(const future<T>& f ) : m_prom(f.m_prom){}
|
||||
future(){}
|
||||
|
||||
future& operator=(future<T>&& f ) {
|
||||
fc_swap(m_prom,f.m_prom);
|
||||
std::swap(m_prom,f.m_prom);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -259,12 +258,12 @@ namespace fc {
|
|||
class future<void> {
|
||||
public:
|
||||
future( const fc::shared_ptr<promise<void>>& p ):m_prom(p){}
|
||||
future( fc::shared_ptr<promise<void>>&& p ):m_prom(fc::move(p)){}
|
||||
future( fc::shared_ptr<promise<void>>&& p ):m_prom(std::move(p)){}
|
||||
future(const future<void>& f ) : m_prom(f.m_prom){}
|
||||
future(){}
|
||||
|
||||
future& operator=(future<void>&& f ) {
|
||||
fc_swap(m_prom,f.m_prom);
|
||||
std::swap(m_prom,f.m_prom);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
#include <fc/thread/future.hpp>
|
||||
#include <fc/thread/priority.hpp>
|
||||
#include <fc/aligned.hpp>
|
||||
#include <fc/fwd.hpp>
|
||||
|
||||
namespace fc {
|
||||
|
|
@ -103,7 +102,7 @@ namespace fc {
|
|||
}
|
||||
virtual void cancel(const char* reason FC_CANCELATION_REASON_DEFAULT_ARG) override { task_base::cancel(reason); }
|
||||
|
||||
aligned<FunctorSize> _functor;
|
||||
alignas(double) char _functor[FunctorSize];
|
||||
private:
|
||||
~task(){}
|
||||
};
|
||||
|
|
@ -123,7 +122,7 @@ namespace fc {
|
|||
}
|
||||
virtual void cancel(const char* reason FC_CANCELATION_REASON_DEFAULT_ARG) override { task_base::cancel(reason); }
|
||||
|
||||
aligned<FunctorSize> _functor;
|
||||
alignas(double) char _functor[FunctorSize];
|
||||
private:
|
||||
~task(){}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
#define FC_CONTEXT_STACK_SIZE (2048*1024)
|
||||
|
||||
#include <fc/thread/task.hpp>
|
||||
#include <fc/vector.hpp>
|
||||
#include <fc/string.hpp>
|
||||
|
||||
namespace fc {
|
||||
class time_point;
|
||||
|
|
@ -75,7 +73,7 @@ namespace fc {
|
|||
* @note debug info is more useful if you provide a description for your
|
||||
* async tasks and promises.
|
||||
*/
|
||||
void debug( const fc::string& d );
|
||||
void debug( const std::string& d );
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -146,7 +144,7 @@ namespace fc {
|
|||
std::vector<fc::promise_base::ptr> proms(2);
|
||||
proms[0] = fc::static_pointer_cast<fc::promise_base>(f1.m_prom);
|
||||
proms[1] = fc::static_pointer_cast<fc::promise_base>(f2.m_prom);
|
||||
return wait_any_until(fc::move(proms), fc::time_point::now()+timeout_us );
|
||||
return wait_any_until(std::move(proms), fc::time_point::now()+timeout_us );
|
||||
}
|
||||
private:
|
||||
thread( class thread_d* ); // parameter is ignored, will create a new thread_d
|
||||
|
|
|
|||
|
|
@ -1,76 +0,0 @@
|
|||
#pragma once
|
||||
#include <fc/thread/future.hpp>
|
||||
#include <fc/thread/spin_yield_lock.hpp>
|
||||
#include <fc/thread/unique_lock.hpp>
|
||||
#include <deque>
|
||||
|
||||
namespace fc
|
||||
{
|
||||
/**
|
||||
* A thread-safe, fiber-aware condition variable that
|
||||
* can be used to signal/wait on a certain condition between
|
||||
* threads.
|
||||
*/
|
||||
template<typename T=void_t>
|
||||
class wait_condition
|
||||
{
|
||||
public:
|
||||
wait_condition(const char* name) : _name(name) {}
|
||||
|
||||
void wait( const microseconds& timeout = microseconds::maximum() )
|
||||
{
|
||||
typename fc::promise<T>::ptr p = new fc::promise<T>(_name);
|
||||
{ synchronized( _prom_lock )
|
||||
_promises.push_back( p );
|
||||
}
|
||||
p->wait(timeout);
|
||||
}
|
||||
|
||||
template<typename LockType>
|
||||
T wait( LockType& l, const microseconds& timeout = microseconds::maximum() )
|
||||
{
|
||||
typename fc::promise<T>::ptr p( new fc::promise<T>(_name));
|
||||
{ synchronized( _prom_lock )
|
||||
_promises.push_back( p );
|
||||
}
|
||||
l.unlock();
|
||||
struct relocker {
|
||||
LockType& _lock;
|
||||
relocker(LockType& l) : _lock(l) {}
|
||||
~relocker() { _lock.lock(); }
|
||||
} lock_on_exit(l);
|
||||
return p->wait(timeout);
|
||||
}
|
||||
|
||||
void notify_one( const T& t=T())
|
||||
{
|
||||
typename fc::promise<void_t>::ptr prom;
|
||||
{ synchronized( _prom_lock )
|
||||
if( _promises.size() )
|
||||
{
|
||||
prom = _promises.front();
|
||||
_promises.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
if( prom && prom->retain_count() > 1 )
|
||||
prom->set_value(t);
|
||||
}
|
||||
void notify_all(const T& t=T())
|
||||
{
|
||||
std::deque<typename fc::promise<T>::ptr> all;
|
||||
{ synchronized( _prom_lock )
|
||||
std::swap(all, _promises);
|
||||
}
|
||||
for( auto itr = all.begin(); itr != all.end(); ++itr )
|
||||
{
|
||||
if( (*itr)->retain_count() > 1 )
|
||||
(*itr)->set_value(t);
|
||||
}
|
||||
}
|
||||
private:
|
||||
fc::spin_yield_lock _prom_lock;
|
||||
std::deque<typename fc::promise<T>::ptr> _promises;
|
||||
const char *const _name;
|
||||
};
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <fc/string.hpp>
|
||||
#include <string>
|
||||
#include <fc/optional.hpp>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
|
@ -48,8 +48,8 @@ namespace fc {
|
|||
static time_point maximum() { return time_point( microseconds::maximum() ); }
|
||||
static time_point min() { return time_point(); }
|
||||
|
||||
operator fc::string()const;
|
||||
static time_point from_iso_string( const fc::string& s );
|
||||
operator std::string()const;
|
||||
static time_point from_iso_string( const std::string& s );
|
||||
|
||||
const microseconds& time_since_epoch()const { return elapsed; }
|
||||
uint32_t sec_since_epoch()const { return elapsed.count() / 1000000; }
|
||||
|
|
@ -112,11 +112,11 @@ namespace fc {
|
|||
friend microseconds operator - ( const time_point_sec& t, const time_point_sec& m ) { return time_point(t) - time_point(m); }
|
||||
friend microseconds operator - ( const time_point& t, const time_point_sec& m ) { return time_point(t) - time_point(m); }
|
||||
|
||||
fc::string to_non_delimited_iso_string()const;
|
||||
fc::string to_iso_string()const;
|
||||
std::string to_non_delimited_iso_string()const;
|
||||
std::string to_iso_string()const;
|
||||
|
||||
operator fc::string()const;
|
||||
static time_point_sec from_iso_string( const fc::string& s );
|
||||
operator std::string()const;
|
||||
static time_point_sec from_iso_string( const std::string& s );
|
||||
|
||||
private:
|
||||
uint32_t utc_seconds;
|
||||
|
|
@ -127,12 +127,12 @@ namespace fc {
|
|||
/** return a human-readable approximate time, relative to now()
|
||||
* e.g., "4 hours ago", "2 months ago", etc.
|
||||
*/
|
||||
string get_approximate_relative_time_string(const time_point_sec& event_time,
|
||||
const time_point_sec& relative_to_time = fc::time_point::now(),
|
||||
const std::string& ago = " ago");
|
||||
string get_approximate_relative_time_string(const time_point& event_time,
|
||||
const time_point& relative_to_time = fc::time_point::now(),
|
||||
const std::string& ago = " ago");
|
||||
std::string get_approximate_relative_time_string(const time_point_sec& event_time,
|
||||
const time_point_sec& relative_to_time = fc::time_point::now(),
|
||||
const std::string& ago = " ago");
|
||||
std::string get_approximate_relative_time_string(const time_point& event_time,
|
||||
const time_point& relative_to_time = fc::time_point::now(),
|
||||
const std::string& ago = " ago");
|
||||
}
|
||||
|
||||
#include <fc/reflect/reflect.hpp>
|
||||
|
|
|
|||
|
|
@ -1,136 +0,0 @@
|
|||
#pragma once
|
||||
#include <fc/utility.hpp>
|
||||
#include <boost/preprocessor/repeat.hpp>
|
||||
#include <boost/preprocessor/repeat_from_to.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum.hpp>
|
||||
#include <boost/preprocessor/facilities/empty.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
|
||||
|
||||
namespace fc {
|
||||
|
||||
/**
|
||||
* Provides a fast-compiling tuple that doesn't use fancy meta-programming
|
||||
* techniques. It is limited to 4 parameters which is sufficient for most
|
||||
* methods argument lists which is the primary use case for this tuple. Methods
|
||||
* that require more than 4 parameters are probably better served by defining
|
||||
* a struct.
|
||||
*
|
||||
* The members of the tuple are easily visited with a simple visitor functor
|
||||
* of the form:
|
||||
* @code
|
||||
* struct visitor {
|
||||
* template<typename MemberType>
|
||||
* void operator()( MemberType& m );
|
||||
*
|
||||
* template<typename MemberType>
|
||||
* void operator()( const MemberType& m );
|
||||
* };
|
||||
* @endcode
|
||||
template<typename A=void, typename B=void,typename C=void, typename D=void>
|
||||
struct tuple {
|
||||
tuple(){}
|
||||
enum size_enum { size = 4 };
|
||||
|
||||
template<typename AA, typename BB, typename CC, typename DD>
|
||||
tuple( AA&& aa, BB&& bb, CC&& cc, DD&& dd )
|
||||
:a( fc::forward<AA>(aa) ),
|
||||
b( fc::forward<BB>(bb) ),
|
||||
c( fc::forward<CC>(cc) ),
|
||||
d( fc::forward<DD>(dd) )
|
||||
{}
|
||||
|
||||
template<typename V>
|
||||
void visit( V&& v ) { v(a); v(b); v(c); v(d); }
|
||||
template<typename V>
|
||||
void visit( V&& v )const { v(a); v(b); v(c); v(d); }
|
||||
|
||||
A a;
|
||||
B b;
|
||||
C c;
|
||||
D d;
|
||||
};
|
||||
*/
|
||||
template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(9, typename A, void)> struct tuple{};
|
||||
|
||||
template<>
|
||||
struct tuple<> {
|
||||
enum size_enum { size = 0 };
|
||||
template<typename V>
|
||||
void visit( V&& v)const{};
|
||||
};
|
||||
template<typename Functor>
|
||||
auto call_fused( Functor f, const tuple<>& t ) -> decltype( f( ) ) {
|
||||
return f();
|
||||
}
|
||||
|
||||
inline tuple<> make_tuple(){ return tuple<>(); }
|
||||
|
||||
template<typename T>
|
||||
struct is_tuple {
|
||||
typedef fc::false_type type;
|
||||
};
|
||||
|
||||
#define RREF_PARAMS(z,n,data) BOOST_PP_CAT(AA,n)&& BOOST_PP_CAT(p,n)
|
||||
#define ILIST_PARAMS(z,n,data) BOOST_PP_CAT(a,n)( fc::forward<BOOST_PP_CAT(AA,n)>( BOOST_PP_CAT(p,n) ) )
|
||||
#define ILIST_PARAMS_COPY(z,n,data) BOOST_PP_CAT(a,n)( t.BOOST_PP_CAT(a,n) )
|
||||
#define VISIT_PARAMS(z,n,data) v(BOOST_PP_CAT(a,n));
|
||||
#define LIST_MEMBERS_ON(z,n,data) data.BOOST_PP_CAT(a,n)
|
||||
#define DEDUCE_MEMBERS(z,n,data) typename fc::deduce<BOOST_PP_CAT(AA,n)>::type
|
||||
#define FORWARD_PARAMS(z,n,data) fc::forward<BOOST_PP_CAT(AA,n)>(BOOST_PP_CAT(p,n))
|
||||
#define MEM_PARAMS(z,n,data) BOOST_PP_CAT(A,n) BOOST_PP_CAT(a,n);
|
||||
#define TUPLE(z,n,unused) \
|
||||
template<BOOST_PP_ENUM_PARAMS( n, typename A)> \
|
||||
struct tuple<BOOST_PP_ENUM_PARAMS(n,A)> { \
|
||||
enum size_enum { size = n }; \
|
||||
template<BOOST_PP_ENUM_PARAMS( n, typename AA)> \
|
||||
explicit tuple( BOOST_PP_ENUM(n, RREF_PARAMS, unused ) )BOOST_PP_IF(n,:,BOOST_PP_EMPTY())BOOST_PP_ENUM( n, ILIST_PARAMS,unused){} \
|
||||
tuple( const tuple& t )BOOST_PP_IF(n,:,BOOST_PP_EMPTY())BOOST_PP_ENUM( n, ILIST_PARAMS_COPY,unused){} \
|
||||
tuple( tuple&& t )BOOST_PP_IF(n,:,BOOST_PP_EMPTY())BOOST_PP_ENUM( n, ILIST_PARAMS_COPY,unused){} \
|
||||
tuple(){}\
|
||||
template<typename V>\
|
||||
void visit( V&& v ) { BOOST_PP_REPEAT(n,VISIT_PARAMS,a) }\
|
||||
template<typename V>\
|
||||
void visit( V&& v )const { BOOST_PP_REPEAT(n,VISIT_PARAMS,a) }\
|
||||
BOOST_PP_REPEAT(n,MEM_PARAMS,a) \
|
||||
}; \
|
||||
template<BOOST_PP_ENUM_PARAMS( n, typename AA)> \
|
||||
tuple<BOOST_PP_ENUM_PARAMS(n,AA)> make_tuple( BOOST_PP_ENUM( n, RREF_PARAMS, unused) ) { \
|
||||
return tuple<BOOST_PP_ENUM_PARAMS(n,AA)>( BOOST_PP_ENUM( n, FORWARD_PARAMS,unused ) ); \
|
||||
} \
|
||||
template<typename Functor, BOOST_PP_ENUM_PARAMS(n,typename AA)> \
|
||||
auto call_fused( Functor f, tuple<BOOST_PP_ENUM_PARAMS(n,AA)>& t ) \
|
||||
-> decltype( f( BOOST_PP_ENUM( n, LIST_MEMBERS_ON, t) ) ) { \
|
||||
return f( BOOST_PP_ENUM( n, LIST_MEMBERS_ON, t) ); \
|
||||
} \
|
||||
template<typename Functor, BOOST_PP_ENUM_PARAMS(n,typename AA)> \
|
||||
auto call_fused( Functor f, const tuple<BOOST_PP_ENUM_PARAMS(n,AA)>& t ) \
|
||||
-> decltype( f( BOOST_PP_ENUM( n, LIST_MEMBERS_ON, t) ) ) { \
|
||||
return f( BOOST_PP_ENUM( n, LIST_MEMBERS_ON, t) ); \
|
||||
} \
|
||||
template<BOOST_PP_ENUM_PARAMS( n, typename AA)> \
|
||||
struct is_tuple<fc::tuple<BOOST_PP_ENUM_PARAMS(n,AA)> > { \
|
||||
typedef fc::true_type type; \
|
||||
}; \
|
||||
template<BOOST_PP_ENUM_PARAMS( n, typename AA)> \
|
||||
struct deduce<fc::tuple<BOOST_PP_ENUM_PARAMS(n,AA)> > { \
|
||||
typedef fc::tuple<BOOST_PP_ENUM( n, DEDUCE_MEMBERS,unused)> type; \
|
||||
};
|
||||
|
||||
BOOST_PP_REPEAT_FROM_TO( 1, 5, TUPLE, unused )
|
||||
|
||||
|
||||
#undef FORWARD_PARAMS
|
||||
#undef DEDUCE_MEMBERS
|
||||
#undef RREF_PARAMS
|
||||
#undef LIST_MEMBERS_ON
|
||||
#undef ILIST_PARAMS
|
||||
#undef ILIST_PARAMS_COPY
|
||||
#undef VISIT_PARAMS
|
||||
#undef MEM_PARAMS
|
||||
#undef TUPLE
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
#pragma once
|
||||
#include <fc/utility.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace fc
|
||||
{
|
||||
template<typename T>
|
||||
class unique_ptr
|
||||
{
|
||||
public:
|
||||
typedef T* pointer;
|
||||
|
||||
explicit unique_ptr( pointer t = nullptr ):_p(t){}
|
||||
|
||||
unique_ptr( unique_ptr&& m )
|
||||
:_p(m._p){ m._p = nullptr; }
|
||||
|
||||
~unique_ptr() { delete _p; }
|
||||
|
||||
operator bool()const { return _p != nullptr; }
|
||||
friend bool operator==(const unique_ptr& p, nullptr_t)
|
||||
{
|
||||
return p._p == nullptr;
|
||||
}
|
||||
|
||||
friend bool operator!=(const unique_ptr& p, nullptr_t)
|
||||
{
|
||||
return p._p != nullptr;
|
||||
}
|
||||
|
||||
unique_ptr& operator=( nullptr_t )
|
||||
{
|
||||
delete _p; _p = nullptr;
|
||||
}
|
||||
|
||||
unique_ptr& operator=( unique_ptr&& o )
|
||||
{
|
||||
fc_swap( _p, o._p );
|
||||
return *this;
|
||||
}
|
||||
|
||||
pointer operator->()const { return _p; }
|
||||
T& operator*()const { return *_p; }
|
||||
|
||||
void reset( pointer v )
|
||||
{
|
||||
delete _p; _p = v;
|
||||
}
|
||||
pointer release()
|
||||
{
|
||||
auto tmp = _p;
|
||||
_p = nullptr;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
private:
|
||||
pointer _p;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -19,19 +19,12 @@ namespace fc {
|
|||
using std::size_t;
|
||||
typedef decltype(nullptr) nullptr_t;
|
||||
|
||||
template<typename T> struct remove_reference { typedef T type; };
|
||||
template<typename T> struct remove_reference<T&> { typedef T type; };
|
||||
template<typename T> struct remove_reference<T&&> { typedef T type; };
|
||||
|
||||
template<typename T> struct deduce { typedef T type; };
|
||||
template<typename T> struct deduce<T&> { typedef T type; };
|
||||
template<typename T> struct deduce<const T&> { typedef T type; };
|
||||
template<typename T> struct deduce<T&&> { typedef T type; };
|
||||
template<typename T> struct deduce<const T&&>{ typedef T type; };
|
||||
|
||||
template<typename T>
|
||||
typename fc::remove_reference<T>::type&& move( T&& t ) { return static_cast<typename fc::remove_reference<T>::type&&>(t); }
|
||||
|
||||
template<typename T, typename U>
|
||||
inline T&& forward( U&& u ) { return static_cast<T&&>(u); }
|
||||
|
||||
|
|
@ -45,21 +38,4 @@ namespace fc {
|
|||
|
||||
template<typename T>
|
||||
struct is_class { typedef decltype(detail::is_class_helper<T>(0)) type; enum value_enum { value = type::value }; };
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
template<typename T>
|
||||
const T& min( const T& a, const T& b ) { return a < b ? a: b; }
|
||||
|
||||
}
|
||||
// outside of namespace fc becuase of VC++ conflict with std::swap
|
||||
template<typename T>
|
||||
void fc_swap( T& a, T& b ) {
|
||||
T tmp = fc::move(a);
|
||||
a = fc::move(b);
|
||||
b = fc::move(tmp);
|
||||
}
|
||||
|
||||
#define LLCONST(constant) static_cast<int64_t>(constant##ll)
|
||||
#define ULLCONST(constant) static_cast<uint64_t>(constant##ull)
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@
|
|||
#include <string.h> // memset
|
||||
|
||||
#include <fc/optional.hpp>
|
||||
#include <fc/string.hpp>
|
||||
#include <fc/container/deque_fwd.hpp>
|
||||
#include <fc/container/flat_fwd.hpp>
|
||||
#include <boost/multi_index_container_fwd.hpp>
|
||||
|
||||
|
|
@ -217,7 +215,7 @@ namespace fc
|
|||
variant( double val, uint32_t max_depth = 1 );
|
||||
variant( bool val, uint32_t max_depth = 1 );
|
||||
variant( blob val, uint32_t max_depth = 1 );
|
||||
variant( fc::string val, uint32_t max_depth = 1 );
|
||||
variant( std::string val, uint32_t max_depth = 1 );
|
||||
variant( variant_object, uint32_t max_depth = 1 );
|
||||
variant( mutable_variant_object, uint32_t max_depth = 1 );
|
||||
variant( variants, uint32_t max_depth = 1 );
|
||||
|
|
@ -238,7 +236,7 @@ namespace fc
|
|||
virtual void handle( const uint64_t& v )const = 0;
|
||||
virtual void handle( const double& v )const = 0;
|
||||
virtual void handle( const bool& v )const = 0;
|
||||
virtual void handle( const string& v )const = 0;
|
||||
virtual void handle( const std::string& v )const = 0;
|
||||
virtual void handle( const variant_object& v)const = 0;
|
||||
virtual void handle( const variants& v)const = 0;
|
||||
};
|
||||
|
|
@ -277,10 +275,10 @@ namespace fc
|
|||
/** Convert's double, ints, bools, etc to a string
|
||||
* @throw if get_type() == array_type | get_type() == object_type
|
||||
*/
|
||||
string as_string()const;
|
||||
std::string as_string()const;
|
||||
|
||||
/// @pre get_type() == string_type
|
||||
const string& get_string()const;
|
||||
const std::string& get_string()const;
|
||||
|
||||
/// @throw if get_type() != array_type | null_type
|
||||
variants& get_array();
|
||||
|
|
@ -357,7 +355,7 @@ namespace fc
|
|||
typedef optional<variant> ovariant;
|
||||
|
||||
/** @ingroup Serializable */
|
||||
void from_variant( const variant& var, string& vo, uint32_t max_depth = 1 );
|
||||
void from_variant( const variant& var, std::string& vo, uint32_t max_depth = 1 );
|
||||
/** @ingroup Serializable */
|
||||
void from_variant( const variant& var, variants& vo, uint32_t max_depth );
|
||||
void from_variant( const variant& var, variant& vo, uint32_t max_depth );
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
#include <fc/variant.hpp>
|
||||
#include <fc/shared_ptr.hpp>
|
||||
#include <fc/unique_ptr.hpp>
|
||||
|
||||
namespace fc
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,2 +0,0 @@
|
|||
#pragma once
|
||||
#include <vector>
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
#ifndef _FC_VECTOR_FWD_HPP_
|
||||
#define _FC_VECTOR_FWD_HPP_
|
||||
#if 0
|
||||
#include <fc/vector.hpp>
|
||||
#else
|
||||
namespace fc {
|
||||
template<typename T> class vector;
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // _FC_VECTOR_FWD_HPP_
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
#pragma once
|
||||
#include <fc/vector.hpp>
|
||||
#include <fc/thread/thread.hpp>
|
||||
|
||||
namespace fc {
|
||||
template<typename T1, typename T2>
|
||||
int wait_any( fc::future<T1>& f1, fc::future<T2>& f2, const microseconds& timeout_us = microseconds::max() ) {
|
||||
fc::vector<promise_base::ptr> p(2);
|
||||
p[0] = static_pointer_cast<promise_base*>(f1.promise());
|
||||
p[1] = static_pointer_cast<promise_base*>(f2.promise());
|
||||
return wait( fc::move(p), timeout_us );
|
||||
}
|
||||
}
|
||||
|
|
@ -4,11 +4,11 @@
|
|||
|
||||
namespace fc
|
||||
{
|
||||
string zlib_compress(const string& in)
|
||||
std::string zlib_compress(const std::string& in)
|
||||
{
|
||||
size_t compressed_message_length;
|
||||
char* compressed_message = (char*)tdefl_compress_mem_to_heap(in.c_str(), in.size(), &compressed_message_length, TDEFL_WRITE_ZLIB_HEADER | TDEFL_DEFAULT_MAX_PROBES);
|
||||
string result(compressed_message, compressed_message_length);
|
||||
std::string result(compressed_message, compressed_message_length);
|
||||
free(compressed_message);
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
#include <fc/crypto/bigint.hpp>
|
||||
#include <fc/io/sstream.hpp>
|
||||
#include <fc/log/logger.hpp>
|
||||
|
||||
namespace fc
|
||||
{
|
||||
fc::string to_base36( const char* data, size_t len )
|
||||
std::string to_base36( const char* data, size_t len )
|
||||
{
|
||||
if( len == 0 ) return fc::string();
|
||||
if( len == 0 ) return std::string();
|
||||
|
||||
const char* src = data;
|
||||
int src_len = len;
|
||||
|
|
@ -34,15 +35,15 @@ namespace fc
|
|||
while (len-- > 0 && *data++ == 0) {
|
||||
out[--pos] = '0';
|
||||
}
|
||||
return &out[pos]; //fc::string( &out[pos], out.size() - pos);
|
||||
return &out[pos]; //std::string( &out[pos], out.size() - pos);
|
||||
}
|
||||
|
||||
fc::string to_base36( const std::vector<char>& vec )
|
||||
std::string to_base36( const std::vector<char>& vec )
|
||||
{
|
||||
return to_base36( (const char*)vec.data(), vec.size() );
|
||||
}
|
||||
|
||||
std::vector<char> from_base36( const fc::string& b36 )
|
||||
std::vector<char> from_base36( const std::string& b36 )
|
||||
{
|
||||
if ( b36.empty() ) {
|
||||
std::vector<char> empty;
|
||||
|
|
@ -63,7 +64,7 @@ namespace fc
|
|||
value = value + (_36.exp(pos) * fc::bigint(10+*itr - 'A'));
|
||||
else
|
||||
{
|
||||
wlog("unknown '${char}'", ("char",fc::string(&*itr,1)) );
|
||||
wlog("unknown '${char}'", ("char",std::string(&*itr,1)) );
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@
|
|||
#include <string.h>
|
||||
|
||||
#include <fc/log/logger.hpp>
|
||||
#include <fc/string.hpp>
|
||||
#include <fc/exception/exception.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#include <fc/crypto/bigint.hpp>
|
||||
#include <fc/utility.hpp>
|
||||
#include <openssl/bn.h>
|
||||
#include <fc/variant.hpp>
|
||||
#include <fc/crypto/base64.hpp>
|
||||
|
|
@ -145,7 +144,7 @@ namespace fc {
|
|||
BN_CTX* ctx = BN_CTX_new();
|
||||
bigint tmp;
|
||||
BN_div( tmp.n, NULL, n, a.n, ctx );
|
||||
fc_swap( tmp.n, n );
|
||||
std::swap( tmp.n, n );
|
||||
BN_CTX_free(ctx);
|
||||
return tmp;
|
||||
}
|
||||
|
|
@ -190,7 +189,7 @@ namespace fc {
|
|||
bigint& bigint::operator = ( bigint&& a ) {
|
||||
if( &a == this )
|
||||
return *this;
|
||||
fc_swap( a.n, n );
|
||||
std::swap( a.n, n );
|
||||
return *this;
|
||||
}
|
||||
bigint& bigint::operator = ( const bigint& a ) {
|
||||
|
|
@ -199,7 +198,7 @@ namespace fc {
|
|||
BN_copy( n, a.n );
|
||||
return *this;
|
||||
}
|
||||
bigint::operator fc::string()const {
|
||||
bigint::operator std::string()const {
|
||||
return BN_bn2dec(n);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ namespace fc { namespace ecc {
|
|||
return private_key( k );
|
||||
}
|
||||
|
||||
static fc::string _to_base58( const extended_key_data& key )
|
||||
static std::string _to_base58( const extended_key_data& key )
|
||||
{
|
||||
size_t buf_len = key.size() + 4;
|
||||
char *buffer = (char*)alloca(buf_len);
|
||||
|
|
@ -239,7 +239,7 @@ namespace fc { namespace ecc {
|
|||
return fc::to_base58( buffer, buf_len );
|
||||
}
|
||||
|
||||
static void _parse_extended_data( unsigned char* buffer, fc::string base58 )
|
||||
static void _parse_extended_data( unsigned char* buffer, std::string base58 )
|
||||
{
|
||||
memset( buffer, 0, 78 );
|
||||
std::vector<char> decoded = fc::from_base58( base58 );
|
||||
|
|
@ -276,12 +276,12 @@ namespace fc { namespace ecc {
|
|||
return from_base58( _to_base58( data ) );
|
||||
}
|
||||
|
||||
fc::string extended_public_key::str() const
|
||||
std::string extended_public_key::str() const
|
||||
{
|
||||
return _to_base58( serialize_extended() );
|
||||
}
|
||||
|
||||
extended_public_key extended_public_key::from_base58( const fc::string& base58 )
|
||||
extended_public_key extended_public_key::from_base58( const std::string& base58 )
|
||||
{
|
||||
unsigned char buffer[78];
|
||||
unsigned char* ptr = buffer;
|
||||
|
|
@ -344,12 +344,12 @@ namespace fc { namespace ecc {
|
|||
return from_base58( _to_base58( data ) );
|
||||
}
|
||||
|
||||
fc::string extended_private_key::str() const
|
||||
std::string extended_private_key::str() const
|
||||
{
|
||||
return _to_base58( serialize_extended() );
|
||||
}
|
||||
|
||||
extended_private_key extended_private_key::from_base58( const fc::string& base58 )
|
||||
extended_private_key extended_private_key::from_base58( const std::string& base58 )
|
||||
{
|
||||
unsigned char buffer[78];
|
||||
unsigned char* ptr = buffer;
|
||||
|
|
@ -366,7 +366,7 @@ namespace fc { namespace ecc {
|
|||
return extended_private_key( private_key::regenerate(key), chain, cn, fp, d );
|
||||
}
|
||||
|
||||
extended_private_key extended_private_key::generate_master( const fc::string& seed )
|
||||
extended_private_key extended_private_key::generate_master( const std::string& seed )
|
||||
{
|
||||
return generate_master( seed.c_str(), seed.size() );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace fc {
|
|||
return c - 'a' + 10;
|
||||
if( c >= 'A' && c <= 'F' )
|
||||
return c - 'A' + 10;
|
||||
FC_THROW_EXCEPTION( exception, "Invalid hex character '${c}'", ("c", fc::string(&c,1) ) );
|
||||
FC_THROW_EXCEPTION( exception, "Invalid hex character '${c}'", ("c", std::string(&c,1) ) );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -24,8 +24,8 @@ namespace fc {
|
|||
return r;
|
||||
}
|
||||
|
||||
size_t from_hex( const fc::string& hex_str, char* out_data, size_t out_data_len ) {
|
||||
fc::string::const_iterator i = hex_str.begin();
|
||||
size_t from_hex( const std::string& hex_str, char* out_data, size_t out_data_len ) {
|
||||
std::string::const_iterator i = hex_str.begin();
|
||||
uint8_t* out_pos = (uint8_t*)out_data;
|
||||
uint8_t* out_end = out_pos + out_data_len;
|
||||
while( i != hex_str.end() && out_end != out_pos ) {
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ namespace fc {
|
|||
out.resize(rtn);
|
||||
return out;
|
||||
}
|
||||
FC_THROW_EXCEPTION( exception, "openssl: ${message}", ("message",fc::string(ERR_error_string( ERR_get_error(),NULL))) );
|
||||
FC_THROW_EXCEPTION( exception, "openssl: ${message}", ("message",std::string(ERR_error_string( ERR_get_error(),NULL))) );
|
||||
}
|
||||
|
||||
bytes public_key::encrypt( const bytes& in )const
|
||||
|
|
@ -113,7 +113,7 @@ namespace fc {
|
|||
out.resize(rtn);
|
||||
return out;
|
||||
}
|
||||
FC_THROW_EXCEPTION( exception, "openssl: ${message}", ("message",fc::string(ERR_error_string( ERR_get_error(),NULL))) );
|
||||
FC_THROW_EXCEPTION( exception, "openssl: ${message}", ("message",std::string(ERR_error_string( ERR_get_error(),NULL))) );
|
||||
}
|
||||
bytes public_key::decrypt( const bytes& in )const
|
||||
{
|
||||
|
|
@ -127,7 +127,7 @@ namespace fc {
|
|||
out.resize(rtn);
|
||||
return out;
|
||||
}
|
||||
FC_THROW_EXCEPTION( exception, "openssl: ${message}", ("message",fc::string(ERR_error_string( ERR_get_error(),NULL))) );
|
||||
FC_THROW_EXCEPTION( exception, "openssl: ${message}", ("message",std::string(ERR_error_string( ERR_get_error(),NULL))) );
|
||||
}
|
||||
|
||||
bytes public_key::serialize()const
|
||||
|
|
@ -140,14 +140,14 @@ namespace fc {
|
|||
if( e != 1 )
|
||||
{
|
||||
BIO_free(mem);
|
||||
FC_THROW_EXCEPTION( exception, "openssl: ${message}", ("message",fc::string(ERR_error_string( ERR_get_error(),NULL))) );
|
||||
FC_THROW_EXCEPTION( exception, "openssl: ${message}", ("message",std::string(ERR_error_string( ERR_get_error(),NULL))) );
|
||||
}
|
||||
char* dat;
|
||||
uint32_t l = BIO_get_mem_data( mem, &dat );
|
||||
|
||||
fc::stringstream ss( string( dat, l ) );
|
||||
fc::stringstream key;
|
||||
fc::string tmp;
|
||||
std::string tmp;
|
||||
fc::getline( ss, tmp );
|
||||
fc::getline( ss, tmp );
|
||||
while( tmp.size() && tmp[0] != '-' )
|
||||
|
|
@ -210,7 +210,7 @@ namespace fc {
|
|||
if( 1 != RSA_sign( NID_sha1, (uint8_t*)&digest,
|
||||
20, (unsigned char*)&sig, &slen, my->rsa ) )
|
||||
{
|
||||
FC_THROW_EXCEPTION( exception, "rsa sign failed with ${message}", ("message",fc::string(ERR_error_string( ERR_get_error(),NULL))) );
|
||||
FC_THROW_EXCEPTION( exception, "rsa sign failed with ${message}", ("message",std::string(ERR_error_string( ERR_get_error(),NULL))) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -224,7 +224,7 @@ namespace fc {
|
|||
if( 1 != RSA_sign( NID_sha1, (uint8_t*)digest.data(),
|
||||
20, (unsigned char*)sig.data(), &slen, my->rsa ) )
|
||||
{
|
||||
FC_THROW_EXCEPTION( exception, "rsa sign failed with ${message}", ("message",fc::string(ERR_error_string( ERR_get_error(),NULL))) );
|
||||
FC_THROW_EXCEPTION( exception, "rsa sign failed with ${message}", ("message",std::string(ERR_error_string( ERR_get_error(),NULL))) );
|
||||
}
|
||||
return sig;
|
||||
}
|
||||
|
|
@ -238,7 +238,7 @@ namespace fc {
|
|||
if( 1 != RSA_sign( NID_sha256, (uint8_t*)digest.data(),
|
||||
32, (unsigned char*)sig.data(), &slen, my->rsa ) )
|
||||
{
|
||||
FC_THROW_EXCEPTION( exception, "rsa sign failed with ${message}", ("message",fc::string(ERR_error_string( ERR_get_error(),NULL))) );
|
||||
FC_THROW_EXCEPTION( exception, "rsa sign failed with ${message}", ("message",std::string(ERR_error_string( ERR_get_error(),NULL))) );
|
||||
}
|
||||
return sig;
|
||||
}
|
||||
|
|
@ -302,7 +302,7 @@ namespace fc {
|
|||
if( e != 1 )
|
||||
{
|
||||
BIO_free(mem);
|
||||
FC_THROW_EXCEPTION( exception, "Error writing private key, ${message}", ("message",fc::string(ERR_error_string( ERR_get_error(),NULL))) );
|
||||
FC_THROW_EXCEPTION( exception, "Error writing private key, ${message}", ("message",std::string(ERR_error_string( ERR_get_error(),NULL))) );
|
||||
}
|
||||
char* dat;
|
||||
uint32_t l = BIO_get_mem_data( mem, &dat );
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ bool operator == ( const ripemd160& h1, const ripemd160& h2 ) {
|
|||
std::vector<char> ve = v.as< std::vector<char> >( max_depth );
|
||||
memset( &bi, char(0), sizeof(bi) );
|
||||
if( ve.size() )
|
||||
memcpy( &bi, ve.data(), fc::min<size_t>(ve.size(),sizeof(bi)) );
|
||||
memcpy( &bi, ve.data(), std::min<size_t>(ve.size(),sizeof(bi)) );
|
||||
}
|
||||
|
||||
} // fc
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ bool operator == ( const sha1& h1, const sha1& h2 ) {
|
|||
std::vector<char> ve = v.as< std::vector<char> >( max_depth );
|
||||
memset( &bi, char(0), sizeof(bi) );
|
||||
if( ve.size() )
|
||||
memcpy( &bi, ve.data(), fc::min<size_t>(ve.size(),sizeof(bi)) );
|
||||
memcpy( &bi, ve.data(), std::min<size_t>(ve.size(),sizeof(bi)) );
|
||||
}
|
||||
|
||||
} // fc
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ namespace fc {
|
|||
std::vector<char> ve = v.as< std::vector<char> >( max_depth );
|
||||
memset( &bi, char(0), sizeof(bi) );
|
||||
if( ve.size() )
|
||||
memcpy( &bi, ve.data(), fc::min<size_t>(ve.size(),sizeof(bi)) );
|
||||
memcpy( &bi, ve.data(), std::min<size_t>(ve.size(),sizeof(bi)) );
|
||||
}
|
||||
|
||||
template<>
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ namespace fc {
|
|||
std::vector<char> ve = v.as< std::vector<char> >( max_depth );
|
||||
memset( &bi, char(0), sizeof(bi) );
|
||||
if( ve.size() )
|
||||
memcpy( &bi, ve.data(), fc::min<size_t>(ve.size(),sizeof(bi)) );
|
||||
memcpy( &bi, ve.data(), std::min<size_t>(ve.size(),sizeof(bi)) );
|
||||
}
|
||||
|
||||
uint64_t hash64(const char* buf, size_t len)
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ namespace fc {
|
|||
std::vector<char> ve = v.as< std::vector<char> >( max_depth );
|
||||
memset( &bi, char(0), sizeof(bi) );
|
||||
if( ve.size() )
|
||||
memcpy( &bi, ve.data(), fc::min<size_t>(ve.size(),sizeof(bi)) );
|
||||
memcpy( &bi, ve.data(), std::min<size_t>(ve.size(),sizeof(bi)) );
|
||||
}
|
||||
|
||||
template<>
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace fc
|
|||
my->_code = code;
|
||||
my->_what = what_value;
|
||||
my->_name = name_value;
|
||||
my->_elog = fc::move(msgs);
|
||||
my->_elog = std::move(msgs);
|
||||
}
|
||||
|
||||
exception::exception(
|
||||
|
|
@ -63,7 +63,7 @@ namespace fc
|
|||
}
|
||||
|
||||
unhandled_exception::unhandled_exception( log_message&& m, std::exception_ptr e )
|
||||
:exception( fc::move(m) )
|
||||
:exception( std::move(m) )
|
||||
{
|
||||
_inner = e;
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ namespace fc
|
|||
}
|
||||
unhandled_exception::unhandled_exception( log_messages m )
|
||||
:exception()
|
||||
{ my->_elog = fc::move(m); }
|
||||
{ my->_elog = std::move(m); }
|
||||
|
||||
std::exception_ptr unhandled_exception::get_inner_exception()const { return _inner; }
|
||||
|
||||
|
|
@ -109,13 +109,13 @@ namespace fc
|
|||
my->_code = code;
|
||||
my->_what = what_value;
|
||||
my->_name = name_value;
|
||||
my->_elog.push_back( fc::move( msg ) );
|
||||
my->_elog.push_back( std::move( msg ) );
|
||||
}
|
||||
exception::exception( const exception& c )
|
||||
:my( new detail::exception_impl(*c.my) )
|
||||
{ }
|
||||
exception::exception( exception&& c )
|
||||
:my( fc::move(c.my) ){}
|
||||
:my( std::move(c.my) ){}
|
||||
|
||||
const char* exception::name()const throw() { return my->_name.c_str(); }
|
||||
const char* exception::what()const throw() { return my->_what.c_str(); }
|
||||
|
|
@ -153,7 +153,7 @@ namespace fc
|
|||
const log_messages& exception::get_log()const { return my->_elog; }
|
||||
void exception::append_log( log_message m )
|
||||
{
|
||||
my->_elog.emplace_back( fc::move(m) );
|
||||
my->_elog.emplace_back( std::move(m) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -220,7 +220,7 @@ namespace fc
|
|||
return std::make_shared<exception>(*this);
|
||||
}
|
||||
|
||||
fc::string except_str()
|
||||
std::string except_str()
|
||||
{
|
||||
return boost::current_exception_diagnostic_information();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
#include <fc/filesystem.hpp>
|
||||
#include <fc/exception/exception.hpp>
|
||||
#include <fc/fwd_impl.hpp>
|
||||
#include <fc/utility.hpp>
|
||||
#include <fc/io/fstream.hpp>
|
||||
|
||||
#include <fc/utf8.hpp>
|
||||
|
|
@ -52,7 +51,7 @@ namespace fc {
|
|||
|
||||
path::path( const char* p )
|
||||
:_p(p){}
|
||||
path::path( const fc::string& p )
|
||||
path::path( const std::string& p )
|
||||
:_p(p.c_str()){}
|
||||
|
||||
path::path(const std::wstring& p)
|
||||
|
|
@ -69,7 +68,7 @@ namespace fc {
|
|||
return *this;
|
||||
}
|
||||
path& path::operator =( path&& p ) {
|
||||
*_p = fc::move( *p._p );
|
||||
*_p = std::move( *p._p );
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -93,11 +92,11 @@ namespace fc {
|
|||
path::operator const boost::filesystem::path& ()const {
|
||||
return *_p;
|
||||
}
|
||||
fc::string path::generic_string()const {
|
||||
std::string path::generic_string()const {
|
||||
return _p->generic_string();
|
||||
}
|
||||
|
||||
fc::string path::preferred_string() const
|
||||
std::string path::preferred_string() const
|
||||
{
|
||||
return boost::filesystem::path(*_p).make_preferred().string();
|
||||
}
|
||||
|
|
@ -140,13 +139,13 @@ namespace fc {
|
|||
* @todo use iterators instead of indexes for
|
||||
* faster performance
|
||||
*/
|
||||
fc::string path::windows_string()const {
|
||||
std::string path::windows_string()const {
|
||||
std::string result = _p->generic_string();
|
||||
std::replace(result.begin(), result.end(), '/', '\\');
|
||||
return result;
|
||||
}
|
||||
|
||||
fc::string path::string()const {
|
||||
std::string path::string()const {
|
||||
return _p->string();
|
||||
}
|
||||
fc::path path::filename()const {
|
||||
|
|
@ -502,101 +501,4 @@ namespace fc {
|
|||
return appCurrentPath;
|
||||
}
|
||||
|
||||
|
||||
#ifdef FC_HAS_SIMPLE_FILE_LOCK
|
||||
class simple_lock_file::impl
|
||||
{
|
||||
public:
|
||||
#ifdef _WIN32
|
||||
HANDLE file_handle;
|
||||
#else
|
||||
int file_handle;
|
||||
#endif
|
||||
bool is_locked;
|
||||
path lock_file_path;
|
||||
|
||||
impl(const path& lock_file_path);
|
||||
~impl();
|
||||
|
||||
bool try_lock();
|
||||
void unlock();
|
||||
};
|
||||
|
||||
simple_lock_file::impl::impl(const path& lock_file_path) :
|
||||
#ifdef _WIN32
|
||||
file_handle(INVALID_HANDLE_VALUE),
|
||||
#else
|
||||
file_handle(-1),
|
||||
#endif
|
||||
is_locked(false),
|
||||
lock_file_path(lock_file_path)
|
||||
{}
|
||||
|
||||
simple_lock_file::impl::~impl()
|
||||
{
|
||||
unlock();
|
||||
}
|
||||
|
||||
bool simple_lock_file::impl::try_lock()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
HANDLE fh = CreateFileA(lock_file_path.to_native_ansi_path().c_str(),
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
0, 0,
|
||||
OPEN_ALWAYS, 0, NULL);
|
||||
if (fh == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
is_locked = true;
|
||||
file_handle = fh;
|
||||
return true;
|
||||
#else
|
||||
int fd = open(lock_file_path.string().c_str(), O_RDWR|O_CREAT, 0644);
|
||||
if (fd < 0)
|
||||
return false;
|
||||
if (flock(fd, LOCK_EX|LOCK_NB) == -1)
|
||||
{
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
is_locked = true;
|
||||
file_handle = fd;
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void simple_lock_file::impl::unlock()
|
||||
{
|
||||
#ifdef WIN32
|
||||
CloseHandle(file_handle);
|
||||
file_handle = INVALID_HANDLE_VALUE;
|
||||
is_locked = false;
|
||||
#else
|
||||
flock(file_handle, LOCK_UN);
|
||||
close(file_handle);
|
||||
file_handle = -1;
|
||||
is_locked = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
simple_lock_file::simple_lock_file(const path& lock_file_path) :
|
||||
my(new impl(lock_file_path))
|
||||
{
|
||||
}
|
||||
|
||||
simple_lock_file::~simple_lock_file()
|
||||
{
|
||||
}
|
||||
|
||||
bool simple_lock_file::try_lock()
|
||||
{
|
||||
return my->try_lock();
|
||||
}
|
||||
|
||||
void simple_lock_file::unlock()
|
||||
{
|
||||
my->unlock();
|
||||
}
|
||||
#endif // FC_HAS_SIMPLE_FILE_LOCK
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,100 +0,0 @@
|
|||
#include <fc/interprocess/file_mutex.hpp>
|
||||
//#include <fc/thread/mutex.hpp>
|
||||
#include <fc/thread/mutex.hpp>
|
||||
#include <fc/filesystem.hpp>
|
||||
#include <boost/interprocess/sync/file_lock.hpp>
|
||||
#include <boost/interprocess/sync/scoped_lock.hpp>
|
||||
#include <boost/atomic.hpp>
|
||||
|
||||
#include <fc/thread/thread.hpp>
|
||||
#include <fc/log/logger.hpp>
|
||||
|
||||
namespace fc {
|
||||
namespace bip = boost::interprocess;
|
||||
|
||||
void yield();
|
||||
|
||||
namespace detail {
|
||||
class file_mutex_impl {
|
||||
public:
|
||||
file_mutex_impl( const char* f )
|
||||
:_file_mutex( f ),_reader_count(0){}
|
||||
|
||||
fc::mutex _write_lock;
|
||||
bip::file_lock _file_mutex;
|
||||
boost::atomic<int> _reader_count;
|
||||
};
|
||||
}
|
||||
|
||||
file_mutex::file_mutex( const fc::path& file )
|
||||
{
|
||||
my.reset( new detail::file_mutex_impl( file.generic_string().c_str() ) );
|
||||
}
|
||||
|
||||
file_mutex::~file_mutex() {
|
||||
}
|
||||
|
||||
int file_mutex::readers()const {
|
||||
return my->_reader_count.load();
|
||||
}
|
||||
|
||||
bool file_mutex::try_lock() {
|
||||
return false;
|
||||
if( my->_write_lock.try_lock() ) {
|
||||
if( my->_file_mutex.try_lock() )
|
||||
return true;
|
||||
}
|
||||
if( my->_file_mutex.try_lock() ) {
|
||||
if( my->_write_lock.try_lock() ) {
|
||||
return true;
|
||||
} else {
|
||||
my->_file_mutex.unlock();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool file_mutex::try_lock_for( const microseconds& rel_time ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool file_mutex::try_lock_until( const time_point& abs_time ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void file_mutex::lock() {
|
||||
my->_write_lock.lock();
|
||||
while( my->_reader_count.load() > 0 ) {
|
||||
fc::usleep( fc::microseconds(10) );
|
||||
}
|
||||
my->_file_mutex.lock();
|
||||
}
|
||||
|
||||
void file_mutex::unlock() {
|
||||
my->_file_mutex.unlock();
|
||||
my->_write_lock.unlock();
|
||||
}
|
||||
|
||||
void file_mutex::lock_shared() {
|
||||
bip::scoped_lock< fc::mutex > lock( my->_write_lock );
|
||||
if( 0 == my->_reader_count.fetch_add( 1, boost::memory_order_relaxed ) )
|
||||
my->_file_mutex.lock_sharable();
|
||||
}
|
||||
|
||||
void file_mutex::unlock_shared() {
|
||||
if( 1 == my->_reader_count.fetch_add( -1, boost::memory_order_relaxed ) )
|
||||
my->_file_mutex.unlock_sharable();
|
||||
}
|
||||
|
||||
bool file_mutex::try_lock_shared() {
|
||||
return false;
|
||||
if( my->_write_lock.try_lock() ) {
|
||||
if( my->_reader_count.load() == 0 && my->_file_mutex.try_lock_sharable() ) {
|
||||
my->_reader_count++;
|
||||
}
|
||||
my->_write_lock.unlock();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace fc
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue