Chris@16: // Boost.Signals2 library Chris@16: Chris@16: // Copyright Frank Mori Hess 2007-2008. Chris@16: // Use, modification and Chris@16: // distribution is subject to the Boost Software License, Version Chris@16: // 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // For more information, see http://www.boost.org Chris@16: Chris@16: #ifndef BOOST_SIGNALS2_SHARED_CONNECTION_BLOCK_HPP Chris@16: #define BOOST_SIGNALS2_SHARED_CONNECTION_BLOCK_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost Chris@16: { Chris@16: namespace signals2 Chris@16: { Chris@16: class shared_connection_block Chris@16: { Chris@16: public: Chris@16: shared_connection_block(const signals2::connection &conn = signals2::connection(), Chris@16: bool initially_blocked = true): Chris@16: _weak_connection_body(conn._weak_connection_body) Chris@16: { Chris@16: if(initially_blocked) block(); Chris@16: } Chris@16: void block() Chris@16: { Chris@16: if(blocking()) return; Chris@16: boost::shared_ptr connection_body(_weak_connection_body.lock()); Chris@16: if(connection_body == 0) Chris@16: { Chris@16: // Make _blocker non-empty so the blocking() method still returns the correct value Chris@16: // after the connection has expired. Chris@16: _blocker.reset(static_cast(0)); Chris@16: return; Chris@16: } Chris@16: _blocker = connection_body->get_blocker(); Chris@16: } Chris@16: void unblock() Chris@16: { Chris@16: _blocker.reset(); Chris@16: } Chris@16: bool blocking() const Chris@16: { Chris@16: shared_ptr empty; Chris@16: return _blocker < empty || empty < _blocker; Chris@16: } Chris@16: signals2::connection connection() const Chris@16: { Chris@16: return signals2::connection(_weak_connection_body); Chris@16: } Chris@16: private: Chris@16: boost::weak_ptr _weak_connection_body; Chris@16: shared_ptr _blocker; Chris@16: }; Chris@16: } Chris@16: } // end namespace boost Chris@16: Chris@16: #endif // BOOST_SIGNALS2_SHARED_CONNECTION_BLOCK_HPP