threads and monitor
This commit is contained in:
@@ -31,6 +31,8 @@
|
||||
#include <boost/signals2/signal.hpp>
|
||||
#include <boost/signals2/signal_type.hpp>
|
||||
#include <boost/signals2/slot.hpp>
|
||||
#include <boost/signals2/connection.hpp>
|
||||
#include <boost/signals2/shared_connection_block.hpp>
|
||||
|
||||
#include "Function.h"
|
||||
#include <boost/bind/bind.hpp>
|
||||
@@ -63,9 +65,11 @@ using namespace boost::placeholders;
|
||||
|
||||
#define _ULIB_DETAIL_SIGNAL_EMIT(_name, ...) \
|
||||
do { \
|
||||
BOOST_AUTO(sig, this->findOrAddSignal(&_name)); \
|
||||
if (sig) \
|
||||
sig->operator()(__VA_ARGS__); \
|
||||
if (!this->signalsBlocked()) { \
|
||||
BOOST_AUTO(sig, this->findOrAddSignal(&_name)); \
|
||||
if (sig) \
|
||||
sig->operator()(__VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
@@ -90,6 +94,7 @@ namespace uLib {
|
||||
// TODO ...
|
||||
|
||||
typedef boost::signals2::signal_base SignalBase;
|
||||
typedef boost::signals2::connection Connection;
|
||||
|
||||
template <typename T> struct Signal {
|
||||
typedef boost::signals2::signal<T> type;
|
||||
@@ -104,57 +109,57 @@ struct ConnectSignal {};
|
||||
|
||||
template <typename FuncT, typename SigSignature>
|
||||
struct ConnectSignal<FuncT, SigSignature, 0> {
|
||||
static void connect(SignalBase *sigb, FuncT slof,
|
||||
static Connection connect(SignalBase *sigb, FuncT slof,
|
||||
typename FunctionPointer<FuncT>::Object *receiver) {
|
||||
typedef typename Signal<SigSignature>::type SigT;
|
||||
reinterpret_cast<SigT *>(sigb)->connect(slof);
|
||||
return reinterpret_cast<SigT *>(sigb)->connect(slof);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename FuncT, typename SigSignature>
|
||||
struct ConnectSignal<FuncT, SigSignature, 1> {
|
||||
static void connect(SignalBase *sigb, FuncT slof,
|
||||
static Connection connect(SignalBase *sigb, FuncT slof,
|
||||
typename FunctionPointer<FuncT>::Object *receiver) {
|
||||
typedef typename Signal<SigSignature>::type SigT;
|
||||
reinterpret_cast<SigT *>(sigb)->connect(boost::bind(slof, receiver));
|
||||
return reinterpret_cast<SigT *>(sigb)->connect(boost::bind(slof, receiver));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename FuncT, typename SigSignature>
|
||||
struct ConnectSignal<FuncT, SigSignature, 2> {
|
||||
static void connect(SignalBase *sigb, FuncT slof,
|
||||
static Connection connect(SignalBase *sigb, FuncT slof,
|
||||
typename FunctionPointer<FuncT>::Object *receiver) {
|
||||
typedef typename Signal<SigSignature>::type SigT;
|
||||
reinterpret_cast<SigT *>(sigb)->connect(boost::bind(slof, receiver, _1));
|
||||
return reinterpret_cast<SigT *>(sigb)->connect(boost::bind(slof, receiver, _1));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename FuncT, typename SigSignature>
|
||||
struct ConnectSignal<FuncT, SigSignature, 3> {
|
||||
static void connect(SignalBase *sigb, FuncT slof,
|
||||
static Connection connect(SignalBase *sigb, FuncT slof,
|
||||
typename FunctionPointer<FuncT>::Object *receiver) {
|
||||
typedef typename Signal<SigSignature>::type SigT;
|
||||
reinterpret_cast<SigT *>(sigb)->connect(
|
||||
return reinterpret_cast<SigT *>(sigb)->connect(
|
||||
boost::bind(slof, receiver, _1, _2));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename FuncT, typename SigSignature>
|
||||
struct ConnectSignal<FuncT, SigSignature, 4> {
|
||||
static void connect(SignalBase *sigb, FuncT slof,
|
||||
static Connection connect(SignalBase *sigb, FuncT slof,
|
||||
typename FunctionPointer<FuncT>::Object *receiver) {
|
||||
typedef typename Signal<SigSignature>::type SigT;
|
||||
reinterpret_cast<SigT *>(sigb)->connect(
|
||||
return reinterpret_cast<SigT *>(sigb)->connect(
|
||||
boost::bind(slof, receiver, _1, _2, _3));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename FuncT, typename SigSignature>
|
||||
struct ConnectSignal<FuncT, SigSignature, 5> {
|
||||
static void connect(SignalBase *sigb, FuncT slof,
|
||||
static Connection connect(SignalBase *sigb, FuncT slof,
|
||||
typename FunctionPointer<FuncT>::Object *receiver) {
|
||||
typedef typename Signal<SigSignature>::type SigT;
|
||||
reinterpret_cast<SigT *>(sigb)->connect(
|
||||
return reinterpret_cast<SigT *>(sigb)->connect(
|
||||
boost::bind(slof, receiver, _1, _2, _3, _4));
|
||||
}
|
||||
};
|
||||
@@ -167,11 +172,11 @@ template <typename FuncT> SignalBase *NewSignal(FuncT f) {
|
||||
}
|
||||
|
||||
template <typename SigSignature, typename FuncT>
|
||||
void ConnectSignal(SignalBase *sigb, FuncT slof,
|
||||
Connection ConnectSignal(SignalBase *sigb, FuncT slof,
|
||||
typename FunctionPointer<FuncT>::Object *receiver) {
|
||||
detail::ConnectSignal<FuncT, SigSignature,
|
||||
FunctionPointer<FuncT>::arity>::connect(sigb, slof,
|
||||
receiver);
|
||||
return detail::ConnectSignal<FuncT, SigSignature,
|
||||
FunctionPointer<FuncT>::arity>::connect(sigb, slof,
|
||||
receiver);
|
||||
}
|
||||
|
||||
} // namespace uLib
|
||||
|
||||
Reference in New Issue
Block a user