void emplace_alert(BOOST_PP_ENUM_BINARY_PARAMS(I, A, const& a) )
		{
			mutex::scoped_lock lock(m_mutex);
#ifndef TORRENT_NO_DEPRECATE
			if (m_dispatch)
			{
				m_dispatch(std::auto_ptr<alert>(new T(m_allocations[m_generation]
					BOOST_PP_COMMA_IF(I)
					BOOST_PP_ENUM_PARAMS(I, a))));
				return;
			}
#endif
			// don't add more than this number of alerts, unless it's a
			// high priority alert, in which case we try harder to deliver it
			// for high priority alerts, double the upper limit
			if (m_alerts[m_generation].size() >= m_queue_size_limit
				* (1 + T::priority))
				return;

			T alert(m_allocations[m_generation]
				BOOST_PP_COMMA_IF(I)
				BOOST_PP_ENUM_PARAMS(I, a));
			m_alerts[m_generation].push_back(alert);

			maybe_notify(&alert, lock);
		}
Beispiel #2
0
	bool alert_manager::maybe_dispatch(alert const& a)
	{
		if (m_dispatch)
		{
			m_dispatch(a.clone());
			return true;
		}
		return false;
	}
Beispiel #3
0
	void alert_manager::post_impl(std::auto_ptr<alert>& alert_)
	{
		if (m_dispatch)
		{
			TORRENT_ASSERT(m_alerts.empty());
			TORRENT_TRY {
				m_dispatch(alert_);
			} TORRENT_CATCH(std::exception&) {}
		}
		else if (m_alerts.size() < m_queue_size_limit || !alert_->discardable())
Beispiel #4
0
	void alert_manager::post_alert(const alert& alert_)
	{

		mutex::scoped_lock lock(m_mutex);

		if (m_dispatch)
		{
			TORRENT_ASSERT(m_alerts.empty());
			TORRENT_TRY {
				m_dispatch(std::auto_ptr<alert>(alert_.clone()));
			} TORRENT_CATCH(std::exception&) {}
		}
		else if (m_alerts.size() < m_queue_size_limit || !alert_.discardable())
Beispiel #5
0
	void alert_manager::set_dispatch_function(boost::function<void(std::auto_ptr<alert>)> const& fun)
	{
		mutex::scoped_lock lock(m_mutex);

		m_dispatch = fun;

		std::deque<alert*> alerts;
		m_alerts.swap(alerts);
		lock.unlock();

		while (!alerts.empty())
		{
			TORRENT_TRY {
				m_dispatch(std::auto_ptr<alert>(alerts.front()));
			} TORRENT_CATCH(std::exception&) {}
			alerts.pop_front();
		}
	}
Beispiel #6
0
	void alert_manager::set_dispatch_function(
		boost::function<void(std::auto_ptr<alert>)> const& fun)
	{
		mutex::scoped_lock lock(m_mutex);

		m_dispatch = fun;

		heterogeneous_queue<alert> storage;
		m_alerts[m_generation].swap(storage);
		lock.unlock();

		std::vector<alert*> alerts;
		storage.get_pointers(alerts);

		for (std::vector<alert*>::iterator i = alerts.begin()
			, end(alerts.end()); i != end; ++i)
		{
			m_dispatch((*i)->clone());
		}
	}
Beispiel #7
0
		void emplace_alert(Args&&... args)
		{
			std::unique_lock<std::mutex> lock(m_mutex);
#ifndef TORRENT_NO_DEPRECATE
			if (m_dispatch)
			{
				m_dispatch(std::auto_ptr<alert>(new T(m_allocations[m_generation]
					, std::forward<Args>(args)...)));
				return;
			}
#endif
			// don't add more than this number of alerts, unless it's a
			// high priority alert, in which case we try harder to deliver it
			// for high priority alerts, double the upper limit
			if (m_alerts[m_generation].size() >= m_queue_size_limit
				* (1 + T::priority))
				return;

			T& alert = m_alerts[m_generation].emplace_back<T>(
				m_allocations[m_generation], std::forward<Args>(args)...);

			maybe_notify(&alert, lock);
		}
 void doCommand() const {
     LOGD("Executing command '%s' (%s)", m_name, m_description);
     if (!m_dispatch(m_frame, m_connection))
         // XXX: Have useful failure messages
         m_connection->write("EPIC FAIL!\n", 11);
 }