Skip to content

Commit 4947602

Browse files
committed
make add_torrent_params::flags_t an enum class and move it out into its own header
1 parent 00655d5 commit 4947602

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+906
-889
lines changed

bindings/python/client.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ def main():
237237
atp = {}
238238
atp["save_path"] = options.save_path
239239
atp["storage_mode"] = lt.storage_mode_t.storage_mode_sparse
240-
atp["flags"] = lt.add_torrent_params_flags_t.flag_duplicate_is_error \
241-
| lt.add_torrent_params_flags_t.flag_auto_managed
240+
atp["flags"] = lt.torrent_flags.duplicate_is_error \
241+
| lt.torrent_flags.auto_managed
242242
if f.startswith('magnet:') or f.startswith(
243243
'http://') or f.startswith('https://'):
244244
atp["url"] = f

bindings/python/src/converters.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "libtorrent/error_code.hpp"
99
#include "libtorrent/session_stats.hpp" // for stats_metric
1010
#include "libtorrent/time.hpp"
11+
#include "libtorrent/torrent_flags.hpp"
1112
#include "libtorrent/units.hpp"
1213
#include "libtorrent/sha1_hash.hpp"
1314
#include "libtorrent/disk_interface.hpp" // for open_file_state
@@ -229,6 +230,43 @@ struct to_strong_typedef
229230
}
230231
};
231232

233+
template<class T>
234+
struct from_bitfield_flag
235+
{
236+
using underlying_type = typename T::underlying_type;
237+
238+
static PyObject* convert(T const v)
239+
{
240+
object o(static_cast<underlying_type>(v));
241+
return incref(o.ptr());
242+
}
243+
};
244+
245+
template<typename T>
246+
struct to_bitfield_flag
247+
{
248+
using underlying_type = typename T::underlying_type;
249+
250+
to_bitfield_flag()
251+
{
252+
converter::registry::push_back(
253+
&convertible, &construct, type_id<T>()
254+
);
255+
}
256+
257+
static void* convertible(PyObject* x)
258+
{
259+
return PyNumber_Check(x) ? x : nullptr;
260+
}
261+
262+
static void construct(PyObject* x, converter::rvalue_from_python_stage1_data* data)
263+
{
264+
void* storage = ((converter::rvalue_from_python_storage<T>*)data)->storage.bytes;
265+
new (storage) T(extract<underlying_type>(object(borrowed(x))));
266+
data->convertible = storage;
267+
}
268+
};
269+
232270
void bind_converters()
233271
{
234272
// C++ -> python conversions
@@ -251,6 +289,7 @@ void bind_converters()
251289

252290
to_python_converter<lt::piece_index_t, from_strong_typedef<lt::piece_index_t>>();
253291
to_python_converter<lt::file_index_t, from_strong_typedef<lt::file_index_t>>();
292+
to_python_converter<lt::torrent_flags_t, from_bitfield_flag<lt::torrent_flags_t>>();
254293

255294
// work-around types
256295
to_python_converter<lt::aux::noexcept_movable<lt::address>, address_to_tuple<
@@ -293,4 +332,5 @@ void bind_converters()
293332

294333
to_strong_typedef<lt::piece_index_t>();
295334
to_strong_typedef<lt::file_index_t>();
335+
to_bitfield_flag<lt::torrent_flags_t>();
296336
}

bindings/python/src/module.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ BOOST_PYTHON_MODULE(libtorrent)
3434
Py_Initialize();
3535
PyEval_InitThreads();
3636

37+
bind_converters();
3738
bind_error_code();
3839
bind_utility();
3940
bind_fingerprint();
@@ -51,6 +52,5 @@ BOOST_PYTHON_MODULE(libtorrent)
5152
bind_peer_info();
5253
bind_ip_filter();
5354
bind_magnet_uri();
54-
bind_converters();
5555
bind_create_torrent();
5656
}

bindings/python/src/session.cpp

+46-22
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ namespace
229229
object const value = item[1];
230230
// torrent_info objects are always held by a shared_ptr in the
231231
// python binding, skip it if it is a object
232-
if(key == "ti" && value != boost::python::object())
232+
if (key == "ti" && value != boost::python::object())
233233
{
234234
// make a copy here. We don't want to end up holding a python-owned
235235
// object inside libtorrent. If the last reference goes out of scope
@@ -308,7 +308,7 @@ namespace
308308
}
309309
else if(key == "flags")
310310
{
311-
p.flags = extract<std::uint64_t>(value);
311+
p.flags = extract<lt::torrent_flags_t>(value);
312312
continue;
313313
}
314314
else if(key == "trackerid")
@@ -560,6 +560,10 @@ namespace
560560

561561
} // namespace unnamed
562562

563+
struct dummy1 {};
564+
#ifndef TORRENT_NO_DEPRECATE
565+
struct dummy2 {};
566+
#endif
563567

564568
void bind_session()
565569
{
@@ -706,28 +710,48 @@ void bind_session()
706710
.value("start_default_features", lt::session::start_default_features)
707711
;
708712

709-
enum_<add_torrent_params::flags_t>("add_torrent_params_flags_t")
710-
.value("flag_seed_mode", add_torrent_params::flag_seed_mode)
711-
.value("flag_upload_mode", add_torrent_params::flag_upload_mode)
712-
.value("flag_share_mode", add_torrent_params::flag_share_mode)
713-
.value("flag_apply_ip_filter", add_torrent_params::flag_apply_ip_filter)
714-
.value("flag_paused", add_torrent_params::flag_paused)
715-
.value("flag_auto_managed", add_torrent_params::flag_auto_managed)
716-
.value("flag_duplicate_is_error", add_torrent_params::flag_duplicate_is_error)
717-
.value("flag_update_subscribe", add_torrent_params::flag_update_subscribe)
718-
.value("flag_super_seeding", add_torrent_params::flag_super_seeding)
719-
.value("flag_sequential_download", add_torrent_params::flag_sequential_download)
720-
.value("flag_stop_when_ready", add_torrent_params::flag_stop_when_ready)
721-
.value("flag_override_trackers", add_torrent_params::flag_override_trackers)
722-
.value("flag_override_web_seeds", add_torrent_params::flag_override_web_seeds)
713+
714+
{
715+
scope s = class_<dummy1>("torrent_flags");
716+
s.attr("seed_mode") = torrent_flags::seed_mode;
717+
s.attr("upload_mode") = torrent_flags::upload_mode;
718+
s.attr("share_mode") = torrent_flags::share_mode;
719+
s.attr("apply_ip_filter") = torrent_flags::apply_ip_filter;
720+
s.attr("paused") = torrent_flags::paused;
721+
s.attr("auto_managed") = torrent_flags::auto_managed;
722+
s.attr("duplicate_is_error") = torrent_flags::duplicate_is_error;
723+
s.attr("update_subscribe") = torrent_flags::update_subscribe;
724+
s.attr("super_seeding") = torrent_flags::super_seeding;
725+
s.attr("sequential_download") = torrent_flags::sequential_download;
726+
s.attr("stop_when_ready") = torrent_flags::stop_when_ready;
727+
s.attr("override_trackers") = torrent_flags::override_trackers;
728+
s.attr("override_web_seeds") = torrent_flags::override_web_seeds;
729+
}
730+
723731
#ifndef TORRENT_NO_DEPRECATE
724-
.value("flag_pinned", add_torrent_params::flag_pinned)
725-
.value("flag_override_resume_data", add_torrent_params::flag_override_resume_data)
726-
.value("flag_merge_resume_trackers", add_torrent_params::flag_merge_resume_trackers)
727-
.value("flag_use_resume_save_path", add_torrent_params::flag_use_resume_save_path)
728-
.value("flag_merge_resume_http_seeds", add_torrent_params::flag_merge_resume_http_seeds)
732+
{
733+
scope s = class_<dummy2>("add_torrent_params_flags_t");
734+
s.attr("flag_seed_mode") = add_torrent_params::flag_seed_mode;
735+
s.attr("flag_upload_mode") = add_torrent_params::flag_upload_mode;
736+
s.attr("flag_share_mode") = add_torrent_params::flag_share_mode;
737+
s.attr("flag_apply_ip_filter") = add_torrent_params::flag_apply_ip_filter;
738+
s.attr("flag_paused") = add_torrent_params::flag_paused;
739+
s.attr("flag_auto_managed") = add_torrent_params::flag_auto_managed;
740+
s.attr("flag_duplicate_is_error") = add_torrent_params::flag_duplicate_is_error;
741+
s.attr("flag_update_subscribe") = add_torrent_params::flag_update_subscribe;
742+
s.attr("flag_super_seeding") = add_torrent_params::flag_super_seeding;
743+
s.attr("flag_sequential_download") = add_torrent_params::flag_sequential_download;
744+
s.attr("flag_stop_when_ready") = add_torrent_params::flag_stop_when_ready;
745+
s.attr("flag_override_trackers") = add_torrent_params::flag_override_trackers;
746+
s.attr("flag_override_web_seeds") = add_torrent_params::flag_override_web_seeds;
747+
s.attr("flag_pinned") = add_torrent_params::flag_pinned;
748+
s.attr("flag_override_resume_data") = add_torrent_params::flag_override_resume_data;
749+
s.attr("flag_merge_resume_trackers") = add_torrent_params::flag_merge_resume_trackers;
750+
s.attr("flag_use_resume_save_path") = add_torrent_params::flag_use_resume_save_path;
751+
s.attr("flag_merge_resume_http_seeds") = add_torrent_params::flag_merge_resume_http_seeds;
752+
}
729753
#endif
730-
;
754+
731755
class_<cache_status>("cache_status")
732756
.add_property("pieces", cache_status_pieces)
733757
#ifndef TORRENT_NO_DEPRECATE

bindings/python/src/torrent_handle.cpp

+30-49
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,8 @@ void bind_torrent_handle()
437437
bool (torrent_handle::*super_seeding0)() const = &torrent_handle::super_seeding;
438438
void (torrent_handle::*super_seeding1)(bool) const = &torrent_handle::super_seeding;
439439
#endif
440-
void (torrent_handle::*set_flags0)(boost::uint64_t) const = &torrent_handle::set_flags;
441-
void (torrent_handle::*set_flags1)(boost::uint64_t, boost::uint64_t) const = &torrent_handle::set_flags;
440+
void (torrent_handle::*set_flags0)(torrent_flags_t) const = &torrent_handle::set_flags;
441+
void (torrent_handle::*set_flags1)(torrent_flags_t, torrent_flags_t) const = &torrent_handle::set_flags;
442442

443443
int (torrent_handle::*piece_priority0)(piece_index_t) const = &torrent_handle::piece_priority;
444444
void (torrent_handle::*piece_priority1)(piece_index_t, int) const = &torrent_handle::piece_priority;
@@ -491,39 +491,13 @@ void bind_torrent_handle()
491491
.def("is_valid", _(&torrent_handle::is_valid))
492492
.def("pause", _(&torrent_handle::pause), arg("flags") = 0)
493493
.def("resume", _(&torrent_handle::resume))
494-
#ifndef TORRENT_NO_DEPRECATE
495-
.def("stop_when_ready", _(&torrent_handle::stop_when_ready))
496-
#endif
497494
.def("clear_error", _(&torrent_handle::clear_error))
498-
#ifndef TORRENT_NO_DEPRECATE
499-
.def("super_seeding", super_seeding1)
500-
501-
.def("auto_managed", _(&torrent_handle::auto_managed))
502-
#endif
503495
.def("queue_position", _(&torrent_handle::queue_position))
504496
.def("queue_position_up", _(&torrent_handle::queue_position_up))
505497
.def("queue_position_down", _(&torrent_handle::queue_position_down))
506498
.def("queue_position_top", _(&torrent_handle::queue_position_top))
507499
.def("queue_position_bottom", _(&torrent_handle::queue_position_bottom))
508500

509-
// deprecated
510-
#ifndef TORRENT_NO_DEPRECATE
511-
.def("set_priority", _(&torrent_handle::set_priority))
512-
.def("get_torrent_info", &get_torrent_info)
513-
#ifndef TORRENT_NO_DEPRECATE
514-
.def("super_seeding", super_seeding0)
515-
#endif
516-
.def("write_resume_data", _(&torrent_handle::write_resume_data))
517-
.def("is_seed", _(&torrent_handle::is_seed))
518-
.def("is_finished", _(&torrent_handle::is_finished))
519-
#ifndef TORRENT_NO_DEPRECATE
520-
.def("is_paused", _(&torrent_handle::is_paused))
521-
.def("is_auto_managed", _(&torrent_handle::is_auto_managed))
522-
#endif
523-
.def("has_metadata", _(&torrent_handle::has_metadata))
524-
.def("use_interface", &torrent_handle::use_interface)
525-
.def("name", _(&torrent_handle::name))
526-
#endif
527501
.def("add_piece", add_piece)
528502
.def("read_piece", _(&torrent_handle::read_piece))
529503
.def("have_piece", _(&torrent_handle::have_piece))
@@ -549,46 +523,53 @@ void bind_torrent_handle()
549523
.def("force_dht_announce", _(&torrent_handle::force_dht_announce))
550524
#endif
551525
.def("scrape_tracker", _(&torrent_handle::scrape_tracker), arg("index") = -1)
552-
#ifndef TORRENT_NO_DEPRECATE
553-
.def("set_upload_mode", _(&torrent_handle::set_upload_mode))
554-
.def("set_share_mode", _(&torrent_handle::set_share_mode))
555-
#endif
556526
.def("flush_cache", &torrent_handle::flush_cache)
557-
#ifndef TORRENT_NO_DEPRECATE
558-
.def("apply_ip_filter", &torrent_handle::apply_ip_filter)
559-
#endif
560527
.def("set_upload_limit", _(&torrent_handle::set_upload_limit))
561528
.def("upload_limit", _(&torrent_handle::upload_limit))
562529
.def("set_download_limit", _(&torrent_handle::set_download_limit))
563530
.def("download_limit", _(&torrent_handle::download_limit))
564-
#ifndef TORRENT_NO_DEPRECATE
565-
.def("set_sequential_download", _(&torrent_handle::set_sequential_download))
566-
.def("set_peer_upload_limit", &torrent_handle::set_peer_upload_limit)
567-
.def("set_peer_download_limit", &torrent_handle::set_peer_download_limit)
568-
.def("set_ratio", _(&torrent_handle::set_ratio))
569-
.def("save_path", _(&torrent_handle::save_path))
570-
#endif
571531
.def("connect_peer", &torrent_handle::connect_peer, (arg("endpoint"), arg("source")=0, arg("flags")=0xd))
572532
.def("set_max_uploads", &torrent_handle::set_max_uploads)
573533
.def("max_uploads", _(&torrent_handle::max_uploads))
574534
.def("set_max_connections", &torrent_handle::set_max_connections)
575535
.def("max_connections", _(&torrent_handle::max_connections))
576-
#ifndef TORRENT_NO_DEPRECATE
577-
.def("set_tracker_login", &torrent_handle::set_tracker_login)
578-
#endif
579536
.def("move_storage", _(move_storage0), (arg("path"), arg("flags") = move_flags_t::always_replace_files))
580537
.def("info_hash", _(&torrent_handle::info_hash))
581538
.def("force_recheck", _(&torrent_handle::force_recheck))
582539
.def("rename_file", _(rename_file0))
583540
.def("set_ssl_certificate", &torrent_handle::set_ssl_certificate, (arg("cert"), arg("private_key"), arg("dh_params"), arg("passphrase")=""))
584-
#if !defined TORRENT_NO_DEPRECATE
585-
.def("move_storage", _(move_storage1), (arg("path"), arg("flags") = always_replace_files))
586-
.def("rename_file", _(rename_file1))
587-
#endif
588541
.def("flags", _(&torrent_handle::flags))
589542
.def("set_flags", _(set_flags0))
590543
.def("set_flags", _(set_flags1))
591544
.def("unset_flags", _(&torrent_handle::unset_flags))
545+
// deprecated
546+
#ifndef TORRENT_NO_DEPRECATE
547+
.def("stop_when_ready", _(&torrent_handle::stop_when_ready))
548+
.def("super_seeding", super_seeding1)
549+
.def("auto_managed", _(&torrent_handle::auto_managed))
550+
.def("set_priority", _(&torrent_handle::set_priority))
551+
.def("get_torrent_info", &get_torrent_info)
552+
.def("super_seeding", super_seeding0)
553+
.def("write_resume_data", _(&torrent_handle::write_resume_data))
554+
.def("is_seed", _(&torrent_handle::is_seed))
555+
.def("is_finished", _(&torrent_handle::is_finished))
556+
.def("has_metadata", _(&torrent_handle::has_metadata))
557+
.def("use_interface", &torrent_handle::use_interface)
558+
.def("name", _(&torrent_handle::name))
559+
.def("is_paused", _(&torrent_handle::is_paused))
560+
.def("is_auto_managed", _(&torrent_handle::is_auto_managed))
561+
.def("set_upload_mode", _(&torrent_handle::set_upload_mode))
562+
.def("set_share_mode", _(&torrent_handle::set_share_mode))
563+
.def("apply_ip_filter", &torrent_handle::apply_ip_filter)
564+
.def("set_sequential_download", _(&torrent_handle::set_sequential_download))
565+
.def("set_peer_upload_limit", &torrent_handle::set_peer_upload_limit)
566+
.def("set_peer_download_limit", &torrent_handle::set_peer_download_limit)
567+
.def("set_ratio", _(&torrent_handle::set_ratio))
568+
.def("save_path", _(&torrent_handle::save_path))
569+
.def("set_tracker_login", &torrent_handle::set_tracker_login)
570+
.def("move_storage", _(move_storage1), (arg("path"), arg("flags") = always_replace_files))
571+
.def("rename_file", _(rename_file1))
572+
#endif
592573
;
593574

594575
class_<open_file_state>("open_file_state")

docs/hunspell/libtorrent.dic

-1
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,3 @@ crypto
201201
uri
202202
infohashes
203203
rw
204-
0xffffffffffffffff

0 commit comments

Comments
 (0)