From bcda184e59240d1926fbe8ff111e89f07da959d1 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Thu, 10 Jan 2019 20:56:50 -0500 Subject: [PATCH] [WIP] refactor in file_progress to avoid dependency of alert_manager --- include/libtorrent/aux_/file_progress.hpp | 4 +--- src/file_progress.cpp | 17 ++++------------- src/torrent.cpp | 10 +++++++++- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/include/libtorrent/aux_/file_progress.hpp b/include/libtorrent/aux_/file_progress.hpp index a63299c85..20101c1fb 100644 --- a/include/libtorrent/aux_/file_progress.hpp +++ b/include/libtorrent/aux_/file_progress.hpp @@ -54,8 +54,6 @@ namespace libtorrent { class piece_picker; class file_storage; -class alert_manager; -struct torrent_handle; namespace aux { @@ -72,7 +70,7 @@ namespace aux { void clear(); void update(file_storage const& fs, piece_index_t index - , alert_manager* alerts, torrent_handle const& h); + , std::function const& completed_cb); private: diff --git a/src/file_progress.cpp b/src/file_progress.cpp index 371273e58..a24b67a25 100644 --- a/src/file_progress.cpp +++ b/src/file_progress.cpp @@ -32,9 +32,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/piece_picker.hpp" #include "libtorrent/file_storage.hpp" -#include "libtorrent/alert_manager.hpp" #include "libtorrent/aux_/file_progress.hpp" -#include "libtorrent/alert_types.hpp" #include "libtorrent/invariant_check.hpp" namespace libtorrent { namespace aux { @@ -131,7 +129,7 @@ namespace libtorrent { namespace aux { // update the file progress now that we just completed downloading piece // 'index' void file_progress::update(file_storage const& fs, piece_index_t const index - , alert_manager* alerts, torrent_handle const& h) + , std::function const& completed_cb) { INVARIANT_CHECK; if (m_file_progress.empty()) return; @@ -158,19 +156,12 @@ namespace libtorrent { namespace aux { m_file_progress[file_index] += add; TORRENT_ASSERT(m_file_progress[file_index] - <= fs.file_size(file_index)); + <= fs.file_size(file_index)); - // TODO: it would be nice to not depend on alert_manager here - if (m_file_progress[file_index] >= fs.file_size(file_index) && alerts) + if (m_file_progress[file_index] >= fs.file_size(file_index) && completed_cb) { if (!fs.pad_file_at(file_index)) - { - if (alerts->should_post()) - { - // this file just completed, post alert - alerts->emplace_alert(h, file_index); - } - } + completed_cb(file_index); } size -= add; off += add; diff --git a/src/torrent.cpp b/src/torrent.cpp index cef3ae2c1..517377743 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -3819,7 +3819,15 @@ bool is_downloading_state(int const st) // update m_file_progress (if we have one) m_file_progress.update(m_torrent_file->files(), index - , &m_ses.alerts(), get_handle()); + , [this](file_index_t const file_index) + { + if (m_ses.alerts().should_post()) + { + // this file just completed, post alert + m_ses.alerts().emplace_alert( + get_handle(), file_index); + } + }); remove_time_critical_piece(index, true);