00001
00002
00003
00004
00005
00006
00007
00008 #include <libtorrent/extensions.hpp>
00009 #include <libtorrent/entry.hpp>
00010 #include <libtorrent/peer_request.hpp>
00011 #include <libtorrent/peer_connection.hpp>
00012 #include <boost/python.hpp>
00013 #include "gil.hpp"
00014
00015 using namespace boost::python;
00016 using namespace libtorrent;
00017
00018 namespace
00019 {
00020
00021 struct torrent_plugin_wrap : torrent_plugin, wrapper<torrent_plugin>
00022 {
00023 boost::shared_ptr<peer_plugin> new_connection(peer_connection* p)
00024 {
00025 lock_gil lock;
00026
00027 if (override f = this->get_override("new_connection"))
00028 return f(ptr(p));
00029 return torrent_plugin::new_connection(p);
00030 }
00031
00032 boost::shared_ptr<peer_plugin> default_new_connection(peer_connection* p)
00033 {
00034 return this->torrent_plugin::new_connection(p);
00035 }
00036
00037 void on_piece_pass(int index)
00038 {
00039 lock_gil lock;
00040
00041 if (override f = this->get_override("on_piece_pass"))
00042 f(index);
00043 else
00044 torrent_plugin::on_piece_pass(index);
00045 }
00046
00047 void default_on_piece_pass(int index)
00048 {
00049 this->torrent_plugin::on_piece_pass(index);
00050 }
00051
00052 void on_piece_failed(int index)
00053 {
00054 lock_gil lock;
00055
00056 if (override f = this->get_override("on_piece_failed"))
00057 f(index);
00058 else
00059 torrent_plugin::on_piece_failed(index);
00060 }
00061
00062 void default_on_piece_failed(int index)
00063 {
00064 return this->torrent_plugin::on_piece_failed(index);
00065 }
00066
00067 void tick()
00068 {
00069 lock_gil lock;
00070
00071 if (override f = this->get_override("tick"))
00072 f();
00073 else
00074 torrent_plugin::tick();
00075 }
00076
00077 void default_tick()
00078 {
00079 return this->torrent_plugin::tick();
00080 }
00081
00082 bool on_pause()
00083 {
00084 lock_gil lock;
00085
00086 if (override f = this->get_override("on_pause"))
00087 return f();
00088 return torrent_plugin::on_pause();
00089 }
00090
00091 bool default_on_pause()
00092 {
00093 return this->torrent_plugin::on_pause();
00094 }
00095
00096 bool on_resume()
00097 {
00098 lock_gil lock;
00099
00100 if (override f = this->get_override("on_resume"))
00101 return f();
00102 return torrent_plugin::on_resume();
00103 }
00104
00105 bool default_on_resume()
00106 {
00107 return this->torrent_plugin::on_resume();
00108 }
00109 };
00110
00111 }
00112
00113 void bind_extensions()
00114 {
00115 class_<
00116 torrent_plugin_wrap, boost::shared_ptr<torrent_plugin_wrap>, boost::noncopyable
00117 >("torrent_plugin")
00118 .def(
00119 "new_connection"
00120 , &torrent_plugin::new_connection, &torrent_plugin_wrap::default_new_connection
00121 )
00122 .def(
00123 "on_piece_pass"
00124 , &torrent_plugin::on_piece_pass, &torrent_plugin_wrap::default_on_piece_pass
00125 )
00126 .def(
00127 "on_piece_failed"
00128 , &torrent_plugin::on_piece_failed, &torrent_plugin_wrap::default_on_piece_failed
00129 )
00130 .def(
00131 "tick"
00132 , &torrent_plugin::tick, &torrent_plugin_wrap::default_tick
00133 )
00134 .def(
00135 "on_pause"
00136 , &torrent_plugin::on_pause, &torrent_plugin_wrap::default_on_pause
00137 )
00138 .def(
00139 "on_resume"
00140 , &torrent_plugin::on_resume, &torrent_plugin_wrap::default_on_resume
00141 );
00142
00143
00144 class_<peer_connection, boost::noncopyable>("peer_connection", no_init);
00145 }
00146