1 #ifndef H_CAN_DISPATCHER 2 #define H_CAN_DISPATCHER 6 #include <boost/thread/mutex.hpp> 7 #include <boost/unordered_map.hpp> 8 #include <boost/utility.hpp> 9 #include <boost/foreach.hpp> 10 #include <boost/weak_ptr.hpp> 24 boost::weak_ptr<DispatcherBase>
guard_;
28 DispatcherBaseSharedPtr d = guard_.lock();
40 for(
typename std::list<const Listener* >::const_iterator it=listeners_.begin(); it != listeners_.end(); ++it){
45 boost::mutex::scoped_lock lock(mutex_);
49 boost::mutex::scoped_lock lock(mutex_);
50 return listeners_.size();
53 static ListenerConstSharedPtr
createListener(DispatcherBaseSharedPtr dispatcher,
const Callable &callable){
55 dispatcher->listeners_.push_back(l.get());
64 boost::mutex::scoped_lock lock(mutex_);
68 boost::mutex::scoped_lock lock(mutex_);
69 dispatcher_->dispatch_nolock(obj);
72 return dispatcher_->numListeners();
79 boost::unordered_map<K, typename BaseClass::DispatcherBaseSharedPtr, Hash>
filtered_;
81 using BaseClass::createListener;
83 boost::mutex::scoped_lock lock(BaseClass::mutex_);
85 if(!ptr) ptr.reset(
new typename BaseClass::DispatcherBase(BaseClass::mutex_));
86 return BaseClass::DispatcherBase::createListener(ptr, callable);
89 boost::mutex::scoped_lock lock(BaseClass::mutex_);
91 if(ptr) ptr->dispatch_nolock(obj);
92 BaseClass::dispatcher_->dispatch_nolock(obj);
virtual ~GuardedListener()
boost::unordered_map< K, typename BaseClass::DispatcherBaseSharedPtr, Hash > filtered_
void dispatch(const typename BaseClass::Type &obj)
boost::weak_ptr< DispatcherBase > guard_
static ListenerConstSharedPtr createListener(DispatcherBaseSharedPtr dispatcher, const Callable &callable)
DispatcherBase(boost::mutex &mutex)
boost::shared_ptr< DispatcherBase > DispatcherBaseSharedPtr
Listener::ListenerConstSharedPtr ListenerConstSharedPtr
void dispatch(const Type &obj)
DispatcherBaseSharedPtr dispatcher_
Listener::Callable Callable
void dispatch_nolock(const Type &obj) const
boost::shared_ptr< const Listener > ListenerConstSharedPtr
BaseClass::ListenerConstSharedPtr createListener(const K &key, const typename BaseClass::Callable &callable)
ListenerConstSharedPtr createListener(const Callable &callable)
SimpleDispatcher< Listener > BaseClass
GuardedListener(DispatcherBaseSharedPtr g, const Callable &callable)
std::list< const Listener * > listeners_