[WIP] refactor in file_progress to avoid dependency of alert_manager
This commit is contained in:
parent
adeceb4b92
commit
bcda184e59
|
@ -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<void(file_index_t)> const& completed_cb);
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -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<void(file_index_t)> 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<file_completed_alert>())
|
||||
{
|
||||
// this file just completed, post alert
|
||||
alerts->emplace_alert<file_completed_alert>(h, file_index);
|
||||
}
|
||||
}
|
||||
completed_cb(file_index);
|
||||
}
|
||||
size -= add;
|
||||
off += add;
|
||||
|
|
|
@ -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<file_completed_alert>())
|
||||
{
|
||||
// this file just completed, post alert
|
||||
m_ses.alerts().emplace_alert<file_completed_alert>(
|
||||
get_handle(), file_index);
|
||||
}
|
||||
});
|
||||
|
||||
remove_time_critical_piece(index, true);
|
||||
|
||||
|
|
Loading…
Reference in New Issue