make torrent status flags be type safe

This commit is contained in:
arvidn 2017-07-26 16:50:46 -07:00 committed by Arvid Norberg
parent 5222d92e9f
commit 24e4263bae
12 changed files with 67 additions and 55 deletions

View File

@ -298,6 +298,7 @@ void bind_converters()
to_python_converter<lt::bandwidth_state_flags_t, from_bitfield_flag<lt::bandwidth_state_flags_t>>();
to_python_converter<lt::file_open_mode_t, from_bitfield_flag<lt::file_open_mode_t>>();
to_python_converter<lt::picker_flags_t, from_bitfield_flag<lt::picker_flags_t>>();
to_python_converter<lt::status_flags_t, from_bitfield_flag<lt::status_flags_t>>();
to_python_converter<lt::alert_category_t, from_bitfield_flag<lt::alert_category_t>>();
to_python_converter<lt::resume_data_flags_t, from_bitfield_flag<lt::resume_data_flags_t>>();
@ -348,6 +349,7 @@ void bind_converters()
to_bitfield_flag<lt::bandwidth_state_flags_t>();
to_bitfield_flag<lt::file_open_mode_t>();
to_bitfield_flag<lt::picker_flags_t>();
to_bitfield_flag<lt::status_flags_t>();
to_bitfield_flag<lt::alert_category_t>();
to_bitfield_flag<lt::resume_data_flags_t>();
}

View File

@ -427,6 +427,7 @@ void add_piece(torrent_handle& th, piece_index_t piece, char const *data, int fl
th.add_piece(piece, data, flags);
}
class dummy5 {};
class dummy {};
class dummy4 {};
@ -615,13 +616,14 @@ void bind_torrent_handle()
.value("alert_when_available", torrent_handle::alert_when_available)
;
enum_<torrent_handle::status_flags_t>("status_flags_t")
.value("query_distributed_copies", torrent_handle::query_distributed_copies)
.value("query_accurate_download_counters", torrent_handle::query_accurate_download_counters)
.value("query_last_seen_complete", torrent_handle::query_last_seen_complete)
.value("query_pieces", torrent_handle::query_pieces)
.value("query_verified_pieces", torrent_handle::query_verified_pieces)
;
{
scope s = class_<dummy5>("status_flags_t");
s.attr("query_distributed_copies") = torrent_handle::query_distributed_copies;
s.attr("query_accurate_download_counters") = torrent_handle::query_accurate_download_counters;
s.attr("query_last_seen_complete") = torrent_handle::query_last_seen_complete;
s.attr("query_pieces") = torrent_handle::query_pieces;
s.attr("query_verified_pieces") = torrent_handle::query_verified_pieces;
}
}

View File

@ -207,3 +207,4 @@ RC4
Hellman
html
namespace
dn

View File

@ -1517,7 +1517,7 @@ MAGNETURL is a magnet link
// save resume data for all torrents
std::vector<torrent_status> torr;
ses.get_torrent_status(&torr, [](torrent_status const& st)
{ return st.need_save_resume; }, 0);
{ return st.need_save_resume; }, {});
for (torrent_status const& st : torr)
{
st.handle.save_resume_data(torrent_handle::save_info_dict);
@ -1968,7 +1968,7 @@ COLUMN OPTIONS
if (!st.has_metadata) return false;
if (!st.need_save_resume) return false;
return true;
}, 0);
}, {});
int idx = 0;
for (auto const& st : temp)

View File

@ -504,10 +504,10 @@ namespace aux {
void get_torrent_status(std::vector<torrent_status>* ret
, std::function<bool(torrent_status const&)> const& pred
, std::uint32_t flags) const;
, status_flags_t flags) const;
void refresh_torrent_status(std::vector<torrent_status>* ret
, std::uint32_t flags) const;
void post_torrent_updates(std::uint32_t flags);
, status_flags_t flags) const;
void post_torrent_updates(status_flags_t flags);
void post_session_stats();
void post_dht_stats();

View File

@ -162,9 +162,9 @@ namespace libtorrent {
// a valid torrent are ignored.
void get_torrent_status(std::vector<torrent_status>* ret
, std::function<bool(torrent_status const&)> const& pred
, std::uint32_t flags = 0) const;
, status_flags_t flags = {}) const;
void refresh_torrent_status(std::vector<torrent_status>* ret
, std::uint32_t flags = 0) const;
, status_flags_t flags = {}) const;
// This functions instructs the session to post the state_update_alert,
// containing the status of all torrents whose state changed since the
@ -174,7 +174,7 @@ namespace libtorrent {
// included. This flag is on by default. See add_torrent_params.
// the ``flags`` argument is the same as for torrent_handle::status().
// see torrent_handle::status_flags_t.
void post_torrent_updates(std::uint32_t flags = 0xffffffff);
void post_torrent_updates(status_flags_t flags = status_flags_t{0x7fffffff});
// This function will post a session_stats_alert object, containing a
// snapshot of the performance counters from the internals of libtorrent.

View File

@ -574,7 +574,7 @@ namespace libtorrent {
void clear_time_critical();
void update_piece_priorities();
void status(torrent_status* st, std::uint32_t flags);
void status(torrent_status* st, status_flags_t flags);
// this torrent changed state, if the user is subscribing to
// it, add it to the m_state_updates list in session_impl

View File

@ -78,6 +78,9 @@ namespace aux {
struct storage_interface;
class torrent;
struct status_flags_tag;
using status_flags_t = flags::bitfield_flag<std::uint32_t, status_flags_tag>;
#ifndef BOOST_NO_EXCEPTIONS
void TORRENT_NO_RETURN throw_invalid_handle();
#endif
@ -315,35 +318,30 @@ namespace aux {
// information about that particular peer. See peer_info.
void get_peer_info(std::vector<peer_info>& v) const;
// flags to pass in to status() to specify which properties of the
// torrent to query for. By default all flags are set.
enum status_flags_t
{
// calculates ``distributed_copies``, ``distributed_full_copies`` and
// ``distributed_fraction``.
query_distributed_copies = 1,
// includes partial downloaded blocks in ``total_done`` and
// ``total_wanted_done``.
query_accurate_download_counters = 2,
// includes ``last_seen_complete``.
query_last_seen_complete = 4,
// populate the ``pieces`` field in torrent_status.
query_pieces = 8,
// includes ``verified_pieces`` (only applies to torrents in *seed
// mode*).
query_verified_pieces = 16,
// includes ``torrent_file``, which is all the static information from
// the .torrent file.
query_torrent_file = 32,
// includes ``name``, the name of the torrent. This is either derived
// from the .torrent file, or from the ``&dn=`` magnet link argument
// or possibly some other source. If the name of the torrent is not
// known, this is an empty string.
query_name = 64,
// includes ``save_path``, the path to the directory the files of the
// torrent are saved to.
query_save_path = 128
};
// calculates ``distributed_copies``, ``distributed_full_copies`` and
// ``distributed_fraction``.
static constexpr status_flags_t query_distributed_copies{1};
// includes partial downloaded blocks in ``total_done`` and
// ``total_wanted_done``.
static constexpr status_flags_t query_accurate_download_counters{2};
// includes ``last_seen_complete``.
static constexpr status_flags_t query_last_seen_complete{4};
// populate the ``pieces`` field in torrent_status.
static constexpr status_flags_t query_pieces{8};
// includes ``verified_pieces`` (only applies to torrents in *seed
// mode*).
static constexpr status_flags_t query_verified_pieces{16};
// includes ``torrent_file``, which is all the static information from
// the .torrent file.
static constexpr status_flags_t query_torrent_file{32};
// includes ``name``, the name of the torrent. This is either derived
// from the .torrent file, or from the ``&dn=`` magnet link argument
// or possibly some other source. If the name of the torrent is not
// known, this is an empty string.
static constexpr status_flags_t query_name{64};
// includes ``save_path``, the path to the directory the files of the
// torrent are saved to.
static constexpr status_flags_t query_save_path{128};
// ``status()`` will return a structure with information about the status
// of this torrent. If the torrent_handle is invalid, it will throw
@ -355,7 +353,7 @@ namespace aux {
//
// By default everything is included. The flags you can use to decide
// what to *include* are defined in the status_flags_t enum.
torrent_status status(std::uint32_t flags = 0xffffffff) const;
torrent_status status(status_flags_t flags = status_flags_t{0x7fffffff}) const;
// ``get_download_queue()`` takes a non-const reference to a vector which
// it will fill with information about pieces that are partially

View File

@ -155,18 +155,18 @@ namespace libtorrent {
void session_handle::get_torrent_status(std::vector<torrent_status>* ret
, std::function<bool(torrent_status const&)> const& pred
, std::uint32_t const flags) const
, status_flags_t const flags) const
{
sync_call(&session_impl::get_torrent_status, ret, pred, flags);
}
void session_handle::refresh_torrent_status(std::vector<torrent_status>* ret
, std::uint32_t flags) const
, status_flags_t const flags) const
{
sync_call(&session_impl::refresh_torrent_status, ret, flags);
}
void session_handle::post_torrent_updates(std::uint32_t flags)
void session_handle::post_torrent_updates(status_flags_t const flags)
{
async_call(&session_impl::post_torrent_updates, flags);
}

View File

@ -4574,7 +4574,7 @@ namespace {
void session_impl::get_torrent_status(std::vector<torrent_status>* ret
, std::function<bool(torrent_status const&)> const& pred
, std::uint32_t const flags) const
, status_flags_t const flags) const
{
for (auto const& t : m_torrents)
{
@ -4587,7 +4587,7 @@ namespace {
}
void session_impl::refresh_torrent_status(std::vector<torrent_status>* ret
, std::uint32_t const flags) const
, status_flags_t const flags) const
{
for (auto& st : *ret)
{
@ -4597,7 +4597,7 @@ namespace {
}
}
void session_impl::post_torrent_updates(std::uint32_t const flags)
void session_impl::post_torrent_updates(status_flags_t const flags)
{
INVARIANT_CHECK;

View File

@ -10546,7 +10546,7 @@ namespace {
m_links[aux::session_interface::torrent_state_updates].insert(list, this);
}
void torrent::status(torrent_status* st, std::uint32_t flags)
void torrent::status(torrent_status* st, status_flags_t flags)
{
INVARIANT_CHECK;
@ -10656,7 +10656,7 @@ namespace {
st->super_seeding = m_super_seeding;
#endif
st->has_metadata = valid_metadata();
bytes_done(*st, (flags & torrent_handle::query_accurate_download_counters) != 0);
bytes_done(*st, bool(flags & torrent_handle::query_accurate_download_counters));
TORRENT_ASSERT(st->total_wanted_done >= 0);
TORRENT_ASSERT(st->total_done >= st->total_wanted_done);

View File

@ -62,6 +62,15 @@ namespace libtorrent {
constexpr resume_data_flags_t torrent_handle::save_info_dict;
constexpr resume_data_flags_t torrent_handle::only_if_modified;
constexpr status_flags_t torrent_handle::query_distributed_copies;
constexpr status_flags_t torrent_handle::query_accurate_download_counters;
constexpr status_flags_t torrent_handle::query_last_seen_complete;
constexpr status_flags_t torrent_handle::query_pieces;
constexpr status_flags_t torrent_handle::query_verified_pieces;
constexpr status_flags_t torrent_handle::query_torrent_file;
constexpr status_flags_t torrent_handle::query_name;
constexpr status_flags_t torrent_handle::query_save_path;
#ifndef BOOST_NO_EXCEPTIONS
void TORRENT_NO_RETURN throw_invalid_handle()
{
@ -430,7 +439,7 @@ namespace libtorrent {
sync_call(&torrent::file_progress, std::ref(arg), flags);
}
torrent_status torrent_handle::status(std::uint32_t flags) const
torrent_status torrent_handle::status(status_flags_t const flags) const
{
torrent_status st;
sync_call(&torrent::status, &st, flags);