forked from premiere/premiere-libtorrent
[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 piece_picker;
|
||||||
class file_storage;
|
class file_storage;
|
||||||
class alert_manager;
|
|
||||||
struct torrent_handle;
|
|
||||||
|
|
||||||
namespace aux {
|
namespace aux {
|
||||||
|
|
||||||
|
@ -72,7 +70,7 @@ namespace aux {
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
void update(file_storage const& fs, piece_index_t index
|
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:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -32,9 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include "libtorrent/piece_picker.hpp"
|
#include "libtorrent/piece_picker.hpp"
|
||||||
#include "libtorrent/file_storage.hpp"
|
#include "libtorrent/file_storage.hpp"
|
||||||
#include "libtorrent/alert_manager.hpp"
|
|
||||||
#include "libtorrent/aux_/file_progress.hpp"
|
#include "libtorrent/aux_/file_progress.hpp"
|
||||||
#include "libtorrent/alert_types.hpp"
|
|
||||||
#include "libtorrent/invariant_check.hpp"
|
#include "libtorrent/invariant_check.hpp"
|
||||||
|
|
||||||
namespace libtorrent { namespace aux {
|
namespace libtorrent { namespace aux {
|
||||||
|
@ -131,7 +129,7 @@ namespace libtorrent { namespace aux {
|
||||||
// update the file progress now that we just completed downloading piece
|
// update the file progress now that we just completed downloading piece
|
||||||
// 'index'
|
// 'index'
|
||||||
void file_progress::update(file_storage const& fs, piece_index_t const 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;
|
INVARIANT_CHECK;
|
||||||
if (m_file_progress.empty()) return;
|
if (m_file_progress.empty()) return;
|
||||||
|
@ -160,17 +158,10 @@ namespace libtorrent { namespace aux {
|
||||||
TORRENT_ASSERT(m_file_progress[file_index]
|
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) && completed_cb)
|
||||||
if (m_file_progress[file_index] >= fs.file_size(file_index) && alerts)
|
|
||||||
{
|
{
|
||||||
if (!fs.pad_file_at(file_index))
|
if (!fs.pad_file_at(file_index))
|
||||||
{
|
completed_cb(file_index);
|
||||||
if (alerts->should_post<file_completed_alert>())
|
|
||||||
{
|
|
||||||
// this file just completed, post alert
|
|
||||||
alerts->emplace_alert<file_completed_alert>(h, file_index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
size -= add;
|
size -= add;
|
||||||
off += add;
|
off += add;
|
||||||
|
|
|
@ -3819,7 +3819,15 @@ bool is_downloading_state(int const st)
|
||||||
|
|
||||||
// update m_file_progress (if we have one)
|
// update m_file_progress (if we have one)
|
||||||
m_file_progress.update(m_torrent_file->files(), index
|
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);
|
remove_time_critical_piece(index, true);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue