diff --git a/bindings/python/src/converters.cpp b/bindings/python/src/converters.cpp index 5cea412c1..05a034991 100644 --- a/bindings/python/src/converters.cpp +++ b/bindings/python/src/converters.cpp @@ -298,6 +298,7 @@ void bind_converters() to_python_converter>(); to_python_converter>(); to_python_converter>(); + to_python_converter>(); to_python_converter>(); to_python_converter>(); @@ -348,6 +349,7 @@ void bind_converters() to_bitfield_flag(); to_bitfield_flag(); to_bitfield_flag(); + to_bitfield_flag(); to_bitfield_flag(); to_bitfield_flag(); } diff --git a/bindings/python/src/torrent_handle.cpp b/bindings/python/src/torrent_handle.cpp index d1407ead5..78b671d56 100644 --- a/bindings/python/src/torrent_handle.cpp +++ b/bindings/python/src/torrent_handle.cpp @@ -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_("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_("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; + } } diff --git a/docs/hunspell/libtorrent.dic b/docs/hunspell/libtorrent.dic index 742d1a5ac..3ad80010f 100644 --- a/docs/hunspell/libtorrent.dic +++ b/docs/hunspell/libtorrent.dic @@ -207,3 +207,4 @@ RC4 Hellman html namespace +dn diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 423c00f16..f56e32f6c 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -1517,7 +1517,7 @@ MAGNETURL is a magnet link // save resume data for all torrents std::vector 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) diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index bff217231..7a3884ad9 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -504,10 +504,10 @@ namespace aux { void get_torrent_status(std::vector* ret , std::function const& pred - , std::uint32_t flags) const; + , status_flags_t flags) const; void refresh_torrent_status(std::vector* 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(); diff --git a/include/libtorrent/session_handle.hpp b/include/libtorrent/session_handle.hpp index ea718d2b8..c9d7862b5 100644 --- a/include/libtorrent/session_handle.hpp +++ b/include/libtorrent/session_handle.hpp @@ -162,9 +162,9 @@ namespace libtorrent { // a valid torrent are ignored. void get_torrent_status(std::vector* ret , std::function const& pred - , std::uint32_t flags = 0) const; + , status_flags_t flags = {}) const; void refresh_torrent_status(std::vector* 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. diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 22e193e11..3f4b7ea2d 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -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 diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 09481cf04..6c2f93d4c 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -78,6 +78,9 @@ namespace aux { struct storage_interface; class torrent; + struct status_flags_tag; + using status_flags_t = flags::bitfield_flag; + #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& 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 diff --git a/src/session_handle.cpp b/src/session_handle.cpp index 6d62de5bb..bc3ba63f4 100644 --- a/src/session_handle.cpp +++ b/src/session_handle.cpp @@ -155,18 +155,18 @@ namespace libtorrent { void session_handle::get_torrent_status(std::vector* ret , std::function 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* 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); } diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 9a3a4c3b6..3642527e0 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -4574,7 +4574,7 @@ namespace { void session_impl::get_torrent_status(std::vector* ret , std::function 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* 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; diff --git a/src/torrent.cpp b/src/torrent.cpp index 008b7d42e..9c9a74efd 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -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); diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index 19198e2c8..a4534b464 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -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);