update callback signature for async_move_storage and async_release_files

This commit is contained in:
arvidn 2016-11-22 01:48:14 -05:00 committed by Arvid Norberg
parent fc9dabe1ab
commit d8662533d5
7 changed files with 44 additions and 26 deletions

View File

@ -69,10 +69,9 @@ namespace libtorrent
virtual void async_hash(storage_interface* storage, int piece, int flags
, std::function<void(int, int, sha1_hash const&, storage_error const&)> handler, void* requester) = 0;
virtual void async_move_storage(storage_interface* storage, std::string const& p, int flags
, std::function<void(disk_io_job const*)> handler) = 0;
, std::function<void(int, std::string const&, storage_error const&)> handler) = 0;
virtual void async_release_files(storage_interface* storage
, std::function<void(disk_io_job const*)> handler
= std::function<void(disk_io_job const*)>()) = 0;
, std::function<void()> handler = std::function<void()>()) = 0;
virtual void async_check_files(storage_interface* storage
, add_torrent_params const* resume_data
, std::vector<std::string>& links

View File

@ -157,9 +157,16 @@ namespace libtorrent
, char* block, int flags, storage_error const& se)>;
using write_handler = std::function<void(storage_error const&)>;
using hash_handler = std::function<void(int, int, sha1_hash const&, storage_error const&)>;
using move_handler = std::function<void(int, std::string const&, storage_error const&)>;
using release_handler = std::function<void()>;
using generic_handler = std::function<void(disk_io_job const*)>;
boost::variant<read_handler, write_handler, hash_handler, generic_handler> callback;
boost::variant<read_handler
, write_handler
, hash_handler
, move_handler
, release_handler
, generic_handler> callback;
// the error code from the file operation
// on error, this also contains the path of the

View File

@ -301,10 +301,9 @@ namespace libtorrent
void async_hash(storage_interface* storage, int piece, int flags
, std::function<void(int, int, sha1_hash const&, storage_error const&)> handler, void* requester) override;
void async_move_storage(storage_interface* storage, std::string const& p, int flags
, std::function<void(disk_io_job const*)> handler) override;
, std::function<void(int, std::string const&, storage_error const&)> handler) override;
void async_release_files(storage_interface* storage
, std::function<void(disk_io_job const*)> handler
= std::function<void(disk_io_job const*)>()) override;
, std::function<void()> handler = std::function<void()>()) override;
void async_delete_files(storage_interface* storage, int options
, std::function<void(disk_io_job const*)> handler) override;
void async_check_files(storage_interface* storage

View File

@ -1118,9 +1118,10 @@ namespace libtorrent
void on_files_deleted(disk_io_job const* j);
void on_torrent_paused(disk_io_job const* j);
void on_storage_moved(disk_io_job const* j);
void on_storage_moved(int status, std::string const& path
, storage_error const& error);
void on_file_renamed(disk_io_job const* j);
void on_cache_flushed(disk_io_job const* j);
void on_cache_flushed();
// upload and download rate limits for the torrent
void set_limit_impl(int limit, int channel, bool state_update = true);

View File

@ -58,6 +58,18 @@ namespace libtorrent
h(m_job.ret, m_job.piece, sha1_hash(m_job.d.piece_hash), m_job.error);
}
void operator()(disk_io_job::move_handler& h) const
{
if (!h) return;
h(m_job.ret, std::string(m_job.buffer.string), m_job.error);
}
void operator()(disk_io_job::release_handler& h) const
{
if (!h) return;
h();
}
void operator()(disk_io_job::generic_handler& h) const
{
if (!h) return;

View File

@ -1761,7 +1761,7 @@ namespace libtorrent
}
void disk_io_thread::async_move_storage(storage_interface* storage, std::string const& p, int flags
, std::function<void(disk_io_job const*)> handler)
, std::function<void(int, std::string const&, storage_error const&)> handler)
{
disk_io_job* j = allocate_job(disk_io_job::move_storage);
j->storage = storage->shared_from_this();
@ -1773,7 +1773,7 @@ namespace libtorrent
}
void disk_io_thread::async_release_files(storage_interface* storage
, std::function<void(disk_io_job const*)> handler)
, std::function<void()> handler)
{
disk_io_job* j = allocate_job(disk_io_job::release_files);
j->storage = storage->shared_from_this();

View File

@ -2154,8 +2154,7 @@ namespace libtorrent
// now.
leave_seed_mode(true);
m_ses.disk_thread().async_release_files(m_storage.get()
, std::function<void(disk_io_job const*)>());
m_ses.disk_thread().async_release_files(m_storage.get());
// forget that we have any pieces
m_have_all = false;
@ -4321,7 +4320,7 @@ namespace libtorrent
if (m_storage.get())
{
m_ses.disk_thread().async_stop_torrent(m_storage.get()
, std::bind(&torrent::on_cache_flushed, shared_from_this(), _1));
, std::bind(&torrent::on_cache_flushed, shared_from_this()));
}
else
{
@ -7426,7 +7425,7 @@ namespace libtorrent
{
// we need to keep the object alive during this operation
m_ses.disk_thread().async_release_files(m_storage.get()
, std::bind(&torrent::on_cache_flushed, shared_from_this(), _1));
, std::bind(&torrent::on_cache_flushed, shared_from_this()));
}
// this torrent just completed downloads, which means it will fall
@ -7761,7 +7760,7 @@ namespace libtorrent
std::string const& path = save_path;
#endif
m_ses.disk_thread().async_move_storage(m_storage.get(), path, flags
, std::bind(&torrent::on_storage_moved, shared_from_this(), _1));
, std::bind(&torrent::on_storage_moved, shared_from_this(), _1, _2, _3));
m_moving_storage = true;
}
else
@ -7781,26 +7780,27 @@ namespace libtorrent
}
}
void torrent::on_storage_moved(disk_io_job const* j) try
void torrent::on_storage_moved(int const status, std::string const& path
, storage_error const& error) try
{
TORRENT_ASSERT(is_single_thread());
m_moving_storage = false;
if (j->ret == disk_interface::no_error
|| j->ret == disk_interface::need_full_check)
if (status == disk_interface::no_error
|| status == disk_interface::need_full_check)
{
if (alerts().should_post<storage_moved_alert>())
alerts().emplace_alert<storage_moved_alert>(get_handle(), j->buffer.string);
m_save_path = j->buffer.string;
alerts().emplace_alert<storage_moved_alert>(get_handle(), path);
m_save_path = path;
set_need_save_resume();
if (j->ret == disk_interface::need_full_check)
if (status == disk_interface::need_full_check)
force_recheck();
}
else
{
if (alerts().should_post<storage_moved_failed_alert>())
alerts().emplace_alert<storage_moved_failed_alert>(get_handle(), j->error.ec
, resolve_filename(j->error.file), j->error.operation_str());
alerts().emplace_alert<storage_moved_failed_alert>(get_handle(), error.ec
, resolve_filename(error.file), error.operation_str());
}
}
catch (...) { handle_exception(); }
@ -8533,10 +8533,10 @@ namespace libtorrent
return;
}
m_ses.disk_thread().async_release_files(m_storage.get()
, std::bind(&torrent::on_cache_flushed, shared_from_this(), _1));
, std::bind(&torrent::on_cache_flushed, shared_from_this()));
}
void torrent::on_cache_flushed(disk_io_job const*) try
void torrent::on_cache_flushed() try
{
TORRENT_ASSERT(is_single_thread());