fixes bug where priorities where lost when force-rechecking.
[libtorrent.git] / bindings / python / src / extensions.cpp
blobacb8f245785023195ae0eaa7526764d4850b1b76
1 // Copyright Daniel Wallin, Arvid Norberg 2007. Use, modification and distribution is
2 // subject to the Boost Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 #include <libtorrent/extensions.hpp>
6 #include <libtorrent/entry.hpp>
7 #include <libtorrent/peer_request.hpp>
8 #include <libtorrent/peer_connection.hpp>
9 #include <libtorrent/extensions/ut_pex.hpp>
10 #include <libtorrent/extensions/metadata_transfer.hpp>
11 #include <boost/python.hpp>
12 #include "gil.hpp"
14 using namespace boost::python;
15 using namespace libtorrent;
17 namespace
20 struct torrent_plugin_wrap : torrent_plugin, wrapper<torrent_plugin>
22 boost::shared_ptr<peer_plugin> new_connection(peer_connection* p)
24 lock_gil lock;
26 if (override f = this->get_override("new_connection"))
27 return f(ptr(p));
28 return torrent_plugin::new_connection(p);
31 boost::shared_ptr<peer_plugin> default_new_connection(peer_connection* p)
33 return this->torrent_plugin::new_connection(p);
36 void on_piece_pass(int index)
38 lock_gil lock;
40 if (override f = this->get_override("on_piece_pass"))
41 f(index);
42 else
43 torrent_plugin::on_piece_pass(index);
46 void default_on_piece_pass(int index)
48 this->torrent_plugin::on_piece_pass(index);
51 void on_piece_failed(int index)
53 lock_gil lock;
55 if (override f = this->get_override("on_piece_failed"))
56 f(index);
57 else
58 torrent_plugin::on_piece_failed(index);
61 void default_on_piece_failed(int index)
63 return this->torrent_plugin::on_piece_failed(index);
66 void tick()
68 lock_gil lock;
70 if (override f = this->get_override("tick"))
71 f();
72 else
73 torrent_plugin::tick();
76 void default_tick()
78 return this->torrent_plugin::tick();
81 bool on_pause()
83 lock_gil lock;
85 if (override f = this->get_override("on_pause"))
86 return f();
87 return torrent_plugin::on_pause();
90 bool default_on_pause()
92 return this->torrent_plugin::on_pause();
95 bool on_resume()
97 lock_gil lock;
99 if (override f = this->get_override("on_resume"))
100 return f();
101 return torrent_plugin::on_resume();
104 bool default_on_resume()
106 return this->torrent_plugin::on_resume();
110 } // namespace unnamed
113 boost::shared_ptr<torrent_plugin> create_metadata_plugin_wrapper(torrent* t) {
114 return create_metadata_plugin(t, NULL);
117 boost::shared_ptr<torrent_plugin> create_ut_pex_plugin_wrapper(torrent* t) {
118 return create_ut_pex_plugin(t, NULL);
121 void bind_extensions()
123 class_<
124 torrent_plugin_wrap, boost::shared_ptr<torrent_plugin_wrap>, boost::noncopyable
125 >("torrent_plugin")
126 .def(
127 "new_connection"
128 , &torrent_plugin::new_connection, &torrent_plugin_wrap::default_new_connection
130 .def(
131 "on_piece_pass"
132 , &torrent_plugin::on_piece_pass, &torrent_plugin_wrap::default_on_piece_pass
134 .def(
135 "on_piece_failed"
136 , &torrent_plugin::on_piece_failed, &torrent_plugin_wrap::default_on_piece_failed
138 .def(
139 "tick"
140 , &torrent_plugin::tick, &torrent_plugin_wrap::default_tick
142 .def(
143 "on_pause"
144 , &torrent_plugin::on_pause, &torrent_plugin_wrap::default_on_pause
146 .def(
147 "on_resume"
148 , &torrent_plugin::on_resume, &torrent_plugin_wrap::default_on_resume
151 // TODO move to it's own file
152 class_<peer_connection, boost::noncopyable>("peer_connection", no_init);
154 class_<torrent_plugin, boost::shared_ptr<torrent_plugin> >("torrent_plugin", no_init);
155 def("create_ut_pex_plugin", create_ut_pex_plugin_wrapper);
156 def("create_metadata_plugin", create_metadata_plugin_wrapper);