2014-06-21 20:12:25 +00:00
|
|
|
#pragma once
|
2014-09-07 22:02:39 +00:00
|
|
|
|
|
|
|
|
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
|
|
|
|
#pragma warning(push)
|
|
|
|
|
#pragma warning(disable:4996)
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-02-15 06:52:19 +00:00
|
|
|
#include <boost/signals2/signal.hpp>
|
2014-09-07 22:02:39 +00:00
|
|
|
|
|
|
|
|
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
|
|
|
|
#pragma warning(pop)
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-06-05 19:19:00 +00:00
|
|
|
#include <fc/thread/future.hpp>
|
|
|
|
|
#include <fc/thread/thread.hpp>
|
2012-09-09 04:25:43 +00:00
|
|
|
|
|
|
|
|
namespace fc {
|
2012-09-10 05:48:08 +00:00
|
|
|
#if !defined(BOOST_NO_TEMPLATE_ALIASES)
|
2012-09-09 04:25:43 +00:00
|
|
|
template<typename T>
|
2014-02-15 06:52:19 +00:00
|
|
|
using signal = boost::signals2::signal<T>;
|
2014-06-26 15:58:57 +00:00
|
|
|
|
|
|
|
|
using scoped_connection = boost::signals2::scoped_connection;
|
2012-09-10 05:48:08 +00:00
|
|
|
#else
|
2014-03-04 17:23:35 +00:00
|
|
|
/** Workaround for missing Template Aliases feature in the VS 2012.
|
|
|
|
|
\warning Class defined below cannot have defined constructor (even base class has it)
|
|
|
|
|
since it is impossible to reference directly template class arguments outside this class.
|
|
|
|
|
This code will work until someone will use non-default constructor as it is defined in
|
|
|
|
|
boost::signals2::signal.
|
|
|
|
|
*/
|
|
|
|
|
template <class T>
|
|
|
|
|
class signal : public boost::signals2::signal<T>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
};
|
2012-09-10 05:48:08 +00:00
|
|
|
#endif
|
2012-09-09 04:25:43 +00:00
|
|
|
|
|
|
|
|
template<typename T>
|
2014-02-15 06:52:19 +00:00
|
|
|
inline T wait( boost::signals2::signal<void(T)>& sig, const microseconds& timeout_us=microseconds::maximum() ) {
|
2014-07-27 21:37:21 +00:00
|
|
|
typename promise<T>::ptr p(new promise<T>("fc::signal::wait"));
|
2014-02-15 06:52:19 +00:00
|
|
|
boost::signals2::scoped_connection c( sig.connect( [=]( T t ) { p->set_value(t); } ));
|
2012-09-09 04:25:43 +00:00
|
|
|
return p->wait( timeout_us );
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-15 06:52:19 +00:00
|
|
|
inline void wait( boost::signals2::signal<void()>& sig, const microseconds& timeout_us=microseconds::maximum() ) {
|
2014-07-27 21:37:21 +00:00
|
|
|
promise<void>::ptr p(new promise<void>("fc::signal::wait"));
|
2014-02-15 06:52:19 +00:00
|
|
|
boost::signals2::scoped_connection c( sig.connect( [=]() { p->set_value(); } ));
|
2012-09-09 04:25:43 +00:00
|
|
|
p->wait( timeout_us );
|
|
|
|
|
}
|
|
|
|
|
}
|