From 16975b44a0f1812f18caa6132873db2c07bbf4b8 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sat, 12 Jul 2008 13:38:22 +0000 Subject: [PATCH] changed the definition of file_progress and deprecated the old function. Python bindings only exposes the new one git-svn-id: http://libtorrent.svn.sourceforge.net/svnroot/libtorrent/trunk@2532 a83610d8-ad2a-0410-a6ab-fc0612d85776 --- bindings/python/src/torrent_handle.cpp | 4 ++-- docs/manual.rst | 13 +++++++------ include/libtorrent/torrent.hpp | 4 +++- include/libtorrent/torrent_handle.hpp | 3 ++- src/torrent.cpp | 34 +++++++++++++++++++++++++--------- src/torrent_handle.cpp | 8 +++++++- 6 files changed, 46 insertions(+), 20 deletions(-) diff --git a/bindings/python/src/torrent_handle.cpp b/bindings/python/src/torrent_handle.cpp index 9980e940..09e6d8d1 100644 --- a/bindings/python/src/torrent_handle.cpp +++ b/bindings/python/src/torrent_handle.cpp @@ -74,7 +74,7 @@ namespace list file_progress(torrent_handle& handle) { - std::vector p; + std::vector p; { allow_threading_guard guard; @@ -84,7 +84,7 @@ list file_progress(torrent_handle& handle) list result; - for (std::vector::iterator i(p.begin()), e(p.end()); i != e; ++i) + for (std::vector::iterator i(p.begin()), e(p.end()); i != e; ++i) result.append(*i); return result; diff --git a/docs/manual.rst b/docs/manual.rst index fbc2ecb4..aa4f04ca 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -1517,7 +1517,7 @@ Its declaration looks like this:: torrent_handle(); torrent_status status(); - void file_progress(std::vector& fp); + void file_progress(std::vector& fp); void get_download_queue(std::vector& queue) const; void get_peer_info(std::vector& v) const; torrent_info const& get_torrent_info() const; @@ -1659,12 +1659,13 @@ file_progress() :: - void file_progress(std::vector& fp); + void file_progress(std::vector& fp); -This function fills in the supplied vector with the progress (a value in the -range [0, 1]) describing the download progress of each file in this torrent. -The progress values are ordered the same as the files in the `torrent_info`_. -This operation is not very cheap. +This function fills in the supplied vector with the the number of bytes downloaded +of each file in this torrent. The progress values are ordered the same as the files +in the `torrent_info`_. This operation is not very cheap. Its complexity is *O(n + m*j)*. +Where *n * is the number of files, *m * is the number of downloading pieces and *j * +is the number of blocks in a piece. save_path() diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index b7d45e36..eebd9ae7 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -222,6 +222,7 @@ namespace libtorrent bool is_piece_filtered(int index) const; void filtered_pieces(std::vector& bitmask) const; void filter_files(std::vector const& files); + void file_progress(std::vector& fp) const; // ============ end deprecation ============= void piece_availability(std::vector& avail) const; @@ -235,7 +236,8 @@ namespace libtorrent void prioritize_files(std::vector const& files); torrent_status status() const; - void file_progress(std::vector& fp) const; + + void file_progress(std::vector& fp) const; void use_interface(const char* net_interface); tcp::endpoint const& get_interface() const { return m_net_interface; } diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 25e9bbf2..29e1e93f 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -322,7 +322,8 @@ namespace libtorrent // fills the specified vector with the download progress [0, 1] // of each file in the torrent. The files are ordered as in // the torrent_info. - void file_progress(std::vector& progress); + void file_progress(std::vector& progress) const TORRENT_DEPRECATED; + void file_progress(std::vector& progress) const; std::vector const& trackers() const; void replace_trackers(std::vector const&) const; diff --git a/src/torrent.cpp b/src/torrent.cpp index 57717288..a66fd69f 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -4039,17 +4039,33 @@ namespace libtorrent void torrent::file_progress(std::vector& fp) const { + fp.clear(); + fp.resize(m_torrent_file->num_files(), 1.f); + if (is_seed()) return; + + std::vector progress; + file_progress(progress); + for (int i = 0; i < m_torrent_file->num_files(); ++i) + { + file_entry const& f = m_torrent_file->file_at(i); + if (f.size == 0) fp[i] = 1.f; + else fp[i] = float(progress[i]) / f.size; + } + } + + void torrent::file_progress(std::vector& fp) const + { TORRENT_ASSERT(valid_metadata()); - fp.clear(); + fp.resize(m_torrent_file->num_files(), 0); + TORRENT_ASSERT(has_picker()); + if (is_seed()) { - fp.resize(m_torrent_file->num_files(), 1.f); + for (int i = 0; i < m_torrent_file->num_files(); ++i) + fp[i] = m_torrent_file->files().at(i).size; return; } - - TORRENT_ASSERT(has_picker()); - fp.resize(m_torrent_file->num_files(), 0.f); for (int i = 0; i < m_torrent_file->num_files(); ++i) { @@ -4060,7 +4076,7 @@ namespace libtorrent // 100% done all the time if (size == 0) { - fp[i] = 1.f; + fp[i] = 0; continue; } @@ -4076,7 +4092,7 @@ namespace libtorrent } TORRENT_ASSERT(size == 0); - fp[i] = static_cast(done) / m_torrent_file->files().at(i).size; + fp[i] = done; } const std::vector& q @@ -4130,7 +4146,7 @@ namespace libtorrent { TORRENT_ASSERT(offset <= file->offset + file->size); size_type slice = file->offset + file->size - offset; - fp[file_index] += float(slice) / file->size; + fp[file_index] += slice; offset += slice; block_size -= slice; ++file; @@ -4141,7 +4157,7 @@ namespace libtorrent } else { - fp[file_index] += float(block_size) / file->size; + fp[file_index] += block_size; offset += m_block_size; } } diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index 31e28e3a..8e8542c7 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -326,7 +326,13 @@ namespace libtorrent TORRENT_FORWARD(set_tracker_login(name, password)); } - void torrent_handle::file_progress(std::vector& progress) + void torrent_handle::file_progress(std::vector& progress) const + { + INVARIANT_CHECK; + TORRENT_FORWARD(file_progress(progress)); + } + + void torrent_handle::file_progress(std::vector& progress) const { INVARIANT_CHECK; TORRENT_FORWARD(file_progress(progress)); -- 2.11.4.GIT