Fix python bindings

This commit is contained in:
Andrew Resch 2008-06-02 17:39:11 +00:00
parent f12e1d26b7
commit 867e6c2009
4 changed files with 28 additions and 14 deletions

View File

@ -3,6 +3,7 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <libtorrent/peer_info.hpp>
#include <libtorrent/bitfield.hpp>
#include <boost/python.hpp>
#include <boost/python/iterator.hpp>
@ -35,7 +36,7 @@ list get_pieces(peer_info const& pi)
{
list ret;
for (std::vector<bool>::const_iterator i = pi.pieces.begin()
for (bitfield::const_iterator i = pi.pieces.begin()
, end(pi.pieces.end()); i != end; ++i)
{
ret.append(*i);

View File

@ -6,6 +6,7 @@
#include <libtorrent/entry.hpp>
#include <libtorrent/peer_request.hpp>
#include <libtorrent/disk_buffer_holder.hpp>
#include <libtorrent/bitfield.hpp>
#include <boost/python.hpp>
using namespace boost::python;
@ -119,17 +120,26 @@ namespace
return this->peer_plugin::on_have(index);
}
bool on_bitfield(std::vector<bool> const& bitfield)
bool on_bitfield(list _bf)
{
//Convert list to a bitfield
bitfield bf(len(_bf));
for (int i = 0; i < len(_bf); ++i)
{
if (_bf[i])
bf.set_bit(i);
else
bf.clear_bit(i);
}
if (override f = this->get_override("on_bitfield"))
return f(bitfield);
return f(bf);
else
return peer_plugin::on_bitfield(bitfield);
return peer_plugin::on_bitfield(bf);
}
bool default_on_bitfield(std::vector<bool> const& bitfield)
bool default_on_bitfield(const bitfield &bf)
{
return this->peer_plugin::on_bitfield(bitfield);
return this->peer_plugin::on_bitfield(bf);
}
bool on_request(peer_request const& req)

View File

@ -41,14 +41,14 @@ namespace
return result;
}
std::vector<file_entry>::const_iterator begin_files(torrent_info& i, bool storage)
file_storage::iterator begin_files(torrent_info& i)
{
return i.begin_files(storage);
return i.begin_files();
}
std::vector<file_entry>::const_iterator end_files(torrent_info& i, bool storage)
file_storage::iterator end_files(torrent_info& i)
{
return i.end_files(storage);
return i.end_files();
}
//list files(torrent_info const& ti, bool storage) {
@ -57,7 +57,7 @@ namespace
typedef std::vector<file_entry> list_type;
for (list_type::const_iterator i = ti.begin_files(storage); i != ti.end_files(storage); ++i)
for (list_type::const_iterator i = ti.begin_files(); i != ti.end_files(); ++i)
result.append(*i);
return result;
@ -70,10 +70,12 @@ void bind_torrent_info()
{
return_value_policy<copy_const_reference> copy;
class_<torrent_info, boost::intrusive_ptr<torrent_info> >("torrent_info")
class_<torrent_info, boost::intrusive_ptr<torrent_info> >("torrent_info", no_init)
.def(init<entry const&>())
.def(init<sha1_hash const&>())
.def(init<char const*, int>())
.def(init<char const*>())
.def("add_tracker", &torrent_info::add_tracker, (arg("url"), arg("tier")=0))
.def("add_url_seed", &torrent_info::add_url_seed)

View File

@ -4,6 +4,7 @@
#include <libtorrent/torrent_handle.hpp>
#include <boost/python.hpp>
#include <libtorrent/bitfield.hpp>
using namespace boost::python;
using namespace libtorrent;
@ -12,7 +13,7 @@ object pieces(torrent_status const& s)
{
list result;
for (std::vector<bool>::const_iterator i(s.pieces->begin()), e(s.pieces->end()); i != e; ++i)
for (bitfield::const_iterator i(s.pieces->begin()), e(s.pieces->end()); i != e; ++i)
result.append(*i);
return result;