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>
14 using namespace boost::python
;
15 using namespace libtorrent
;
20 struct torrent_plugin_wrap
: torrent_plugin
, wrapper
<torrent_plugin
>
22 boost::shared_ptr
<peer_plugin
> new_connection(peer_connection
* p
)
26 if (override f
= this->get_override("new_connection"))
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
)
40 if (override f
= this->get_override("on_piece_pass"))
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
)
55 if (override f
= this->get_override("on_piece_failed"))
58 torrent_plugin::on_piece_failed(index
);
61 void default_on_piece_failed(int index
)
63 return this->torrent_plugin::on_piece_failed(index
);
70 if (override f
= this->get_override("tick"))
73 torrent_plugin::tick();
78 return this->torrent_plugin::tick();
85 if (override f
= this->get_override("on_pause"))
87 return torrent_plugin::on_pause();
90 bool default_on_pause()
92 return this->torrent_plugin::on_pause();
99 if (override f
= this->get_override("on_resume"))
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()
124 torrent_plugin_wrap
, boost::shared_ptr
<torrent_plugin_wrap
>, boost::noncopyable
128 , &torrent_plugin::new_connection
, &torrent_plugin_wrap::default_new_connection
132 , &torrent_plugin::on_piece_pass
, &torrent_plugin_wrap::default_on_piece_pass
136 , &torrent_plugin::on_piece_failed
, &torrent_plugin_wrap::default_on_piece_failed
140 , &torrent_plugin::tick
, &torrent_plugin_wrap::default_tick
144 , &torrent_plugin::on_pause
, &torrent_plugin_wrap::default_on_pause
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
);