forked from premiere/premiere-libtorrent
make file_status return the vector instead of taking an out-parameter (#1000)
make file_status return the vector instead of taking an out-parameter
This commit is contained in:
parent
a0095a6562
commit
bc8c49dc15
|
@ -2021,8 +2021,7 @@ int main(int argc, char* argv[])
|
|||
{
|
||||
std::vector<std::int64_t> file_progress;
|
||||
h.file_progress(file_progress);
|
||||
std::vector<pool_file_status> file_status;
|
||||
h.file_status(file_status);
|
||||
std::vector<pool_file_status> file_status = h.file_status();
|
||||
std::vector<int> file_prio = h.file_priorities();
|
||||
std::vector<pool_file_status>::iterator f = file_status.begin();
|
||||
boost::shared_ptr<const torrent_info> ti = h.torrent_file();
|
||||
|
|
|
@ -48,9 +48,6 @@ namespace libtorrent
|
|||
// file list of this torrent. This starts indexing at 0.
|
||||
int file_index;
|
||||
|
||||
// a (high precision) timestamp of when the file was last used.
|
||||
time_point last_use;
|
||||
|
||||
// ``open_mode`` is a bitmask of the file flags this file is currently opened with. These
|
||||
// are the flags used in the ``file::open()`` function. This enum is defined as a member
|
||||
// of the ``file`` class.
|
||||
|
@ -73,6 +70,9 @@ namespace libtorrent
|
|||
// Note that the read/write mode is not a bitmask. The two least significant bits are used
|
||||
// to represent the read/write mode. Those bits can be masked out using the ``rw_mask`` constant.
|
||||
int open_mode;
|
||||
|
||||
// a (high precision) timestamp of when the file was last used.
|
||||
time_point last_use;
|
||||
};
|
||||
|
||||
// this is an internal cache of open file handles. It's primarily used by
|
||||
|
@ -107,7 +107,7 @@ namespace libtorrent
|
|||
|
||||
// internal
|
||||
void set_low_prio_io(bool b) { m_low_prio_io = b; }
|
||||
void get_status(std::vector<pool_file_status>* files, void* st) const;
|
||||
std::vector<pool_file_status> get_status(void* st) const;
|
||||
|
||||
#if TORRENT_USE_ASSERTS
|
||||
bool assert_idle_files(void* st) const;
|
||||
|
@ -136,7 +136,7 @@ namespace libtorrent
|
|||
|
||||
// maps storage pointer, file index pairs to the
|
||||
// lru entry for the file
|
||||
typedef std::map<std::pair<void*, int>, lru_file_entry> file_set;
|
||||
using file_set = std::map<std::pair<void*, int>, lru_file_entry>;
|
||||
|
||||
file_set m_files;
|
||||
#if TORRENT_USE_ASSERTS
|
||||
|
|
|
@ -404,7 +404,7 @@ namespace libtorrent
|
|||
// every interested peer on a high priority torrent will be unchoked
|
||||
// before any other, lower priority, torrents have any peers unchoked.
|
||||
void set_priority(int prio) const;
|
||||
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
#if !TORRENT_NO_FPU
|
||||
// fills the specified vector with the download progress [0, 1]
|
||||
|
@ -413,6 +413,9 @@ namespace libtorrent
|
|||
TORRENT_DEPRECATED
|
||||
void file_progress(std::vector<float>& progress) const;
|
||||
#endif
|
||||
|
||||
TORRENT_DEPRECATED
|
||||
void file_status(std::vector<pool_file_status>& status) const;
|
||||
#endif
|
||||
|
||||
// flags to be passed in file_progress().
|
||||
|
@ -442,14 +445,14 @@ namespace libtorrent
|
|||
// already keeps track of this internally and no calculation is required.
|
||||
void file_progress(std::vector<std::int64_t>& progress, int flags = 0) const;
|
||||
|
||||
// This function fills in the passed in vector with status about files
|
||||
// that are open for this torrent. Any file that is not open in this
|
||||
// torrent, will not be reported in the vector, i.e. it's possible that
|
||||
// This function returns a vector with status about files
|
||||
// that are open for this torrent. Any file that is not open
|
||||
// will not be reported in the vector, i.e. it's possible that
|
||||
// the vector is empty when returning, if none of the files in the
|
||||
// torrent are currently open.
|
||||
//
|
||||
// see pool_file_status.
|
||||
void file_status(std::vector<pool_file_status>& status) const;
|
||||
std::vector<pool_file_status> file_status() const;
|
||||
|
||||
// If the torrent is in an error state (i.e. ``torrent_status::error`` is
|
||||
// non-empty), this will clear the error and start the torrent again.
|
||||
|
|
|
@ -221,22 +221,22 @@ namespace libtorrent
|
|||
return file_ptr;
|
||||
}
|
||||
|
||||
void file_pool::get_status(std::vector<pool_file_status>* files, void* st) const
|
||||
std::vector<pool_file_status> file_pool::get_status(void* st) const
|
||||
{
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
file_set::const_iterator start = m_files.lower_bound(std::make_pair(st, 0));
|
||||
file_set::const_iterator end = m_files.upper_bound(std::make_pair(st
|
||||
, std::numeric_limits<int>::max()));
|
||||
|
||||
for (file_set::const_iterator i = start; i != end; ++i)
|
||||
std::vector<pool_file_status> ret;
|
||||
{
|
||||
pool_file_status s;
|
||||
s.file_index = i->first.second;
|
||||
s.open_mode = i->second.mode;
|
||||
s.last_use = i->second.last_use;
|
||||
files->push_back(s);
|
||||
std::unique_lock<std::mutex> l(m_mutex);
|
||||
|
||||
auto start = m_files.lower_bound(std::make_pair(st, 0));
|
||||
auto end = m_files.upper_bound(std::make_pair(st
|
||||
, std::numeric_limits<int>::max()));
|
||||
|
||||
for (file_set::const_iterator i = start; i != end; ++i)
|
||||
{
|
||||
ret.push_back({i->first.second, i->second.mode, i->second.last_use});
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void file_pool::remove_oldest(std::unique_lock<std::mutex>& l)
|
||||
|
|
|
@ -648,6 +648,16 @@ namespace libtorrent
|
|||
async_call(&torrent::force_tracker_request, aux::time_now()
|
||||
+ seconds(duration.total_seconds()), -1);
|
||||
}
|
||||
|
||||
void torrent_handle::file_status(std::vector<pool_file_status>& status) const
|
||||
{
|
||||
status.clear();
|
||||
|
||||
boost::shared_ptr<torrent> t = m_torrent.lock();
|
||||
if (!t || !t->has_storage()) return;
|
||||
session_impl& ses = static_cast<session_impl&>(t->session());
|
||||
status = ses.disk_thread().files().get_status(&t->storage());
|
||||
}
|
||||
#endif
|
||||
|
||||
void torrent_handle::force_dht_announce() const
|
||||
|
@ -662,14 +672,12 @@ namespace libtorrent
|
|||
async_call(&torrent::force_tracker_request, aux::time_now() + seconds(s), idx);
|
||||
}
|
||||
|
||||
void torrent_handle::file_status(std::vector<pool_file_status>& status) const
|
||||
std::vector<pool_file_status> torrent_handle::file_status() const
|
||||
{
|
||||
status.clear();
|
||||
|
||||
boost::shared_ptr<torrent> t = m_torrent.lock();
|
||||
if (!t || !t->has_storage()) return;
|
||||
if (!t || !t->has_storage()) return {};
|
||||
session_impl& ses = static_cast<session_impl&>(t->session());
|
||||
ses.disk_thread().files().get_status(&status, &t->storage());
|
||||
return ses.disk_thread().files().get_status(&t->storage());
|
||||
}
|
||||
|
||||
void torrent_handle::scrape_tracker(int idx) const
|
||||
|
|
Loading…
Reference in New Issue