From 910ccc528f20cd735cec1407b4f3ef361625a3df Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 26 Mar 2017 19:19:20 -0400 Subject: [PATCH] deprecate torrent_added_alert in favor of add_torrent_alert --- ChangeLog | 1 + bindings/python/src/alert.cpp | 2 ++ include/libtorrent/alert_types.hpp | 6 +++++- simulation/test_swarm.cpp | 2 +- simulation/test_torrent_status.cpp | 2 +- simulation/test_transfer.cpp | 2 +- src/alert.cpp | 2 ++ src/session_impl.cpp | 2 ++ test/test_alert_manager.cpp | 34 +++++++++++++++--------------- 9 files changed, 32 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 19c4acb5e..84217751a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * deprecate torrent_added_alert (in favor of add_torrent_alert) * fix python binding for parse_magnet_uri * fix minor robustness issue in DHT bootstrap logic * fix issue where torrent_status::num_seeds could be negative diff --git a/bindings/python/src/alert.cpp b/bindings/python/src/alert.cpp index 9dc16fc9e..8572c7e63 100644 --- a/bindings/python/src/alert.cpp +++ b/bindings/python/src/alert.cpp @@ -243,9 +243,11 @@ void bind_alert() .def("tracker_url", &tracker_alert::tracker_url) ; +#ifndef TORRENT_NO_DEPRECATE class_, noncopyable>( "torrent_added_alert", no_init) ; +#endif class_, noncopyable>( "torrent_removed_alert", no_init) diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 027b2c8ce..93af05996 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -195,11 +195,14 @@ namespace libtorrent #define TORRENT_DEFINE_ALERT_PRIO(name, seq) \ TORRENT_DEFINE_ALERT_IMPL(name, seq, 1) +#ifndef TORRENT_NO_DEPRECATE // The ``torrent_added_alert`` is posted once every time a torrent is successfully // added. It doesn't contain any members of its own, but inherits the torrent handle // from its base class. // It's posted when the ``status_notification`` bit is set in the alert_mask. - struct TORRENT_EXPORT torrent_added_alert TORRENT_FINAL : torrent_alert + // deprecated in 1.1.3 + // use add_torrent_alert instead + struct TORRENT_DEPRECATED_EXPORT torrent_added_alert TORRENT_FINAL : torrent_alert { // internal torrent_added_alert(aux::stack_allocator& alloc, torrent_handle const& h); @@ -208,6 +211,7 @@ namespace libtorrent static const int static_category = alert::status_notification; virtual std::string message() const TORRENT_OVERRIDE; }; +#endif // The ``torrent_removed_alert`` is posted whenever a torrent is removed. Since // the torrent handle in its base class will always be invalid (since the torrent diff --git a/simulation/test_swarm.cpp b/simulation/test_swarm.cpp index c2e94cb4e..378061d29 100644 --- a/simulation/test_swarm.cpp +++ b/simulation/test_swarm.cpp @@ -195,7 +195,7 @@ void test_stop_start_download(swarm_test type, bool graceful) // on alert , [&](lt::alert const* a, lt::session& ses) { - if (lt::alert_cast(a)) + if (lt::alert_cast(a)) add_extra_peers(ses); if (auto tp = lt::alert_cast(a)) diff --git a/simulation/test_torrent_status.cpp b/simulation/test_torrent_status.cpp index c5e979d51..763404b36 100644 --- a/simulation/test_torrent_status.cpp +++ b/simulation/test_torrent_status.cpp @@ -54,7 +54,7 @@ TORRENT_TEST(status_timers) , [](lt::add_torrent_params& params) {} // on alert , [&](lt::alert const* a, lt::session& ses) { - if (auto ta = alert_cast(a)) + if (auto ta = alert_cast(a)) { TEST_CHECK(!handle.is_valid()); start_time = lt::clock_type::now(); diff --git a/simulation/test_transfer.cpp b/simulation/test_transfer.cpp index 5b732e170..3752faedc 100644 --- a/simulation/test_transfer.cpp +++ b/simulation/test_transfer.cpp @@ -110,7 +110,7 @@ void run_test( // only monitor alerts for session 0 (the downloader) print_alerts(*ses[0], [=](lt::session& ses, lt::alert const* a) { - if (auto ta = alert_cast(a)) + if (auto ta = alert_cast(a)) { ta->handle.connect_peer(lt::tcp::endpoint( (flags & connect_socks) ? proxy : peer1, 6881)); diff --git a/src/alert.cpp b/src/alert.cpp index 5d9129da4..e7b7a2521 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -1202,6 +1202,7 @@ namespace libtorrent { return m_alloc.ptr(m_file_idx); } +#ifndef TORRENT_NO_DEPRECATE torrent_added_alert::torrent_added_alert(aux::stack_allocator& alloc , torrent_handle const& h) : torrent_alert(alloc, h) @@ -1211,6 +1212,7 @@ namespace libtorrent { { return torrent_alert::message() + " added"; } +#endif torrent_removed_alert::torrent_removed_alert(aux::stack_allocator& alloc , torrent_handle const& h, sha1_hash const& ih) diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 077c8a218..f74867ce6 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -4856,8 +4856,10 @@ retry: } #endif +#ifndef TORRENT_NO_DEPRECATE if (m_alerts.should_post()) m_alerts.emplace_alert(handle); +#endif // if this was an existing torrent, we can't start it again, or add // another set of plugins etc. we're done diff --git a/test/test_alert_manager.cpp b/test/test_alert_manager.cpp index bf0c28f4d..32a6532a5 100644 --- a/test/test_alert_manager.cpp +++ b/test/test_alert_manager.cpp @@ -54,7 +54,7 @@ TORRENT_TEST(limit) // try add 600 torrent_add_alert to make sure we honor the limit of 500 // alerts. for (int i = 0; i < 600; ++i) - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle()); TEST_EQUAL(mgr.pending(), true); @@ -71,7 +71,7 @@ TORRENT_TEST(limit) mgr.set_alert_queue_size_limit(200); for (int i = 0; i < 600; ++i) - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle()); TEST_EQUAL(mgr.pending(), true); @@ -89,7 +89,7 @@ TORRENT_TEST(priority_limit) // this should only add 100 because of the limit for (int i = 0; i < 200; ++i) - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle(), add_torrent_params(), error_code()); // the limit is twice as high for priority alerts for (int i = 0; i < 200; ++i) @@ -119,7 +119,7 @@ TORRENT_TEST(dispatch_function) TEST_EQUAL(mgr.pending(), false); for (int i = 0; i < 20; ++i) - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle(), add_torrent_params(), error_code()); TEST_EQUAL(mgr.pending(), true); @@ -130,7 +130,7 @@ TORRENT_TEST(dispatch_function) TEST_EQUAL(cnt, 20); for (int i = 0; i < 200; ++i) - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle(), add_torrent_params(), error_code()); TEST_EQUAL(mgr.pending(), false); TEST_EQUAL(cnt, 220); @@ -151,7 +151,7 @@ TORRENT_TEST(notify_function) TEST_EQUAL(mgr.pending(), false); for (int i = 0; i < 20; ++i) - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle(), add_torrent_params(), error_code()); TEST_EQUAL(mgr.pending(), true); @@ -165,7 +165,7 @@ TORRENT_TEST(notify_function) // subsequent posted alerts will not cause an edge (because there are // already alerts queued) for (int i = 0; i < 20; ++i) - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle(), add_torrent_params(), error_code()); TEST_EQUAL(mgr.pending(), true); TEST_EQUAL(cnt, 1); @@ -179,7 +179,7 @@ TORRENT_TEST(notify_function) TEST_EQUAL(mgr.pending(), false); for (int i = 0; i < 20; ++i) - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle(), add_torrent_params(), error_code()); TEST_EQUAL(mgr.pending(), true); TEST_EQUAL(cnt, 2); @@ -211,14 +211,14 @@ TORRENT_TEST(extensions) mgr.add_extension(boost::make_shared(2)); for (int i = 0; i < 53; ++i) - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle(), add_torrent_params(), error_code()); TEST_EQUAL(plugin_alerts[0], 53); TEST_EQUAL(plugin_alerts[1], 53); TEST_EQUAL(plugin_alerts[2], 53); for (int i = 0; i < 17; ++i) - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle(), add_torrent_params(), error_code()); TEST_EQUAL(plugin_alerts[0], 70); TEST_EQUAL(plugin_alerts[1], 70); @@ -229,7 +229,7 @@ TORRENT_TEST(extensions) void post_torrent_added(alert_manager* mgr) { test_sleep(10); - mgr->emplace_alert(torrent_handle()); + mgr->emplace_alert(torrent_handle(), add_torrent_params(), error_code()); } TORRENT_TEST(wait_for_alert) @@ -247,7 +247,7 @@ TORRENT_TEST(wait_for_alert) TEST_CHECK(end - start > milliseconds(900)); TEST_CHECK(end - start < milliseconds(1100)); - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle(), add_torrent_params(), error_code()); start = clock_type::now(); a = mgr.wait_for_alert(seconds(1)); @@ -255,7 +255,7 @@ TORRENT_TEST(wait_for_alert) fprintf(stderr, "delay: %d ms\n", int(total_milliseconds(end - start))); TEST_CHECK(end - start < milliseconds(1)); - TEST_CHECK(a->type() == torrent_added_alert::alert_type); + TEST_CHECK(a->type() == add_torrent_alert::alert_type); std::vector alerts; int num_resume = 0; @@ -269,7 +269,7 @@ TORRENT_TEST(wait_for_alert) fprintf(stderr, "delay: %d ms\n", int(total_milliseconds(end - start))); TEST_CHECK(end - start < milliseconds(500)); - TEST_CHECK(a->type() == torrent_added_alert::alert_type); + TEST_CHECK(a->type() == add_torrent_alert::alert_type); posting_thread.join(); } @@ -281,7 +281,7 @@ TORRENT_TEST(queued_resume) TEST_EQUAL(mgr.num_queued_resume(), 0); for (int i = 0; i < 17; ++i) - mgr.emplace_alert(torrent_handle()); + mgr.emplace_alert(torrent_handle(), add_torrent_params(), error_code()); TEST_EQUAL(mgr.num_queued_resume(), 0); @@ -312,12 +312,12 @@ TORRENT_TEST(alert_mask) { alert_manager mgr(100, 0xffffffff); - TEST_CHECK(mgr.should_post()); + TEST_CHECK(mgr.should_post()); TEST_CHECK(mgr.should_post()); mgr.set_alert_mask(0); - TEST_CHECK(!mgr.should_post()); + TEST_CHECK(!mgr.should_post()); TEST_CHECK(!mgr.should_post()); }