added a userdata parameter to add_torrent that is passed in to plugins

This commit is contained in:
Arvid Norberg
2007-09-14 00:11:33 +00:00
parent 8cbc53074d
commit 7bbfb3bd4b
8 changed files with 30 additions and 22 deletions

View File

@@ -185,7 +185,7 @@ namespace libtorrent
~session_impl(); ~session_impl();
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
void add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent*)> ext); void add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> ext);
#endif #endif
void operator()(); void operator()();
@@ -246,7 +246,8 @@ namespace libtorrent
, entry const& resume_data , entry const& resume_data
, bool compact_mode , bool compact_mode
, storage_constructor_type sc , storage_constructor_type sc
, bool paused); , bool paused
, void* userdata);
torrent_handle add_torrent( torrent_handle add_torrent(
char const* tracker_url char const* tracker_url
@@ -256,7 +257,8 @@ namespace libtorrent
, entry const& resume_data , entry const& resume_data
, bool compact_mode , bool compact_mode
, storage_constructor_type sc , storage_constructor_type sc
, bool paused); , bool paused
, void* userdata);
void remove_torrent(torrent_handle const& h); void remove_torrent(torrent_handle const& h);
@@ -519,7 +521,7 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
typedef std::list<boost::function<boost::shared_ptr< typedef std::list<boost::function<boost::shared_ptr<
torrent_plugin>(torrent*)> > extension_list_t; torrent_plugin>(torrent*, void*)> > extension_list_t;
extension_list_t m_extensions; extension_list_t m_extensions;
#endif #endif

View File

@@ -48,7 +48,7 @@ namespace libtorrent
{ {
struct torrent_plugin; struct torrent_plugin;
class torrent; class torrent;
TORRENT_EXPORT boost::shared_ptr<torrent_plugin> create_metadata_plugin(torrent*); TORRENT_EXPORT boost::shared_ptr<torrent_plugin> create_metadata_plugin(torrent*, void*);
} }
#endif // TORRENT_METADATA_TRANSFER_HPP_INCLUDED #endif // TORRENT_METADATA_TRANSFER_HPP_INCLUDED

View File

@@ -48,7 +48,7 @@ namespace libtorrent
{ {
struct torrent_plugin; struct torrent_plugin;
class torrent; class torrent;
TORRENT_EXPORT boost::shared_ptr<torrent_plugin> create_ut_pex_plugin(torrent*); TORRENT_EXPORT boost::shared_ptr<torrent_plugin> create_ut_pex_plugin(torrent*, void*);
} }
#endif // TORRENT_UT_PEX_EXTENSION_HPP_INCLUDED #endif // TORRENT_UT_PEX_EXTENSION_HPP_INCLUDED

View File

@@ -150,7 +150,8 @@ namespace libtorrent
, entry const& resume_data = entry() , entry const& resume_data = entry()
, bool compact_mode = true , bool compact_mode = true
, bool paused = false , bool paused = false
, storage_constructor_type sc = default_storage_constructor); , storage_constructor_type sc = default_storage_constructor
, void* userdata = 0);
torrent_handle add_torrent( torrent_handle add_torrent(
char const* tracker_url char const* tracker_url
@@ -160,7 +161,8 @@ namespace libtorrent
, entry const& resume_data = entry() , entry const& resume_data = entry()
, bool compact_mode = true , bool compact_mode = true
, bool paused = false , bool paused = false
, storage_constructor_type sc = default_storage_constructor); , storage_constructor_type sc = default_storage_constructor
, void* userdata = 0);
session_proxy abort() { return session_proxy(m_impl); } session_proxy abort() { return session_proxy(m_impl); }
@@ -181,7 +183,7 @@ namespace libtorrent
#endif #endif
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
void add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent*)> ext); void add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> ext);
#endif #endif
void set_ip_filter(ip_filter const& f); void set_ip_filter(ip_filter const& f);

View File

@@ -556,7 +556,7 @@ namespace libtorrent { namespace
namespace libtorrent namespace libtorrent
{ {
boost::shared_ptr<torrent_plugin> create_metadata_plugin(torrent* t) boost::shared_ptr<torrent_plugin> create_metadata_plugin(torrent* t, void*)
{ {
return boost::shared_ptr<torrent_plugin>(new metadata_plugin(*t)); return boost::shared_ptr<torrent_plugin>(new metadata_plugin(*t));
} }

View File

@@ -132,7 +132,7 @@ namespace libtorrent
m_impl->abort(); m_impl->abort();
} }
void session::add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent*)> ext) void session::add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> ext)
{ {
m_impl->add_extension(ext); m_impl->add_extension(ext);
} }
@@ -185,7 +185,7 @@ namespace libtorrent
assert(!ti.m_half_metadata); assert(!ti.m_half_metadata);
boost::intrusive_ptr<torrent_info> tip(new torrent_info(ti)); boost::intrusive_ptr<torrent_info> tip(new torrent_info(ti));
return m_impl->add_torrent(tip, save_path, resume_data return m_impl->add_torrent(tip, save_path, resume_data
, compact_mode, sc, paused); , compact_mode, sc, paused, 0);
} }
torrent_handle session::add_torrent( torrent_handle session::add_torrent(
@@ -194,11 +194,12 @@ namespace libtorrent
, entry const& resume_data , entry const& resume_data
, bool compact_mode , bool compact_mode
, bool paused , bool paused
, storage_constructor_type sc) , storage_constructor_type sc
, void* userdata)
{ {
assert(!ti->m_half_metadata); assert(!ti->m_half_metadata);
return m_impl->add_torrent(ti, save_path, resume_data return m_impl->add_torrent(ti, save_path, resume_data
, compact_mode, sc, paused); , compact_mode, sc, paused, userdata);
} }
torrent_handle session::add_torrent( torrent_handle session::add_torrent(
@@ -209,10 +210,11 @@ namespace libtorrent
, entry const& e , entry const& e
, bool compact_mode , bool compact_mode
, bool paused , bool paused
, storage_constructor_type sc) , storage_constructor_type sc
, void* userdata)
{ {
return m_impl->add_torrent(tracker_url, info_hash, name, save_path, e return m_impl->add_torrent(tracker_url, info_hash, name, save_path, e
, compact_mode, sc, paused); , compact_mode, sc, paused, userdata);
} }
void session::remove_torrent(const torrent_handle& h) void session::remove_torrent(const torrent_handle& h)

View File

@@ -593,7 +593,7 @@ namespace detail
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
void session_impl::add_extension( void session_impl::add_extension(
boost::function<boost::shared_ptr<torrent_plugin>(torrent*)> ext) boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> ext)
{ {
m_extensions.push_back(ext); m_extensions.push_back(ext);
} }
@@ -1474,7 +1474,8 @@ namespace detail
, entry const& resume_data , entry const& resume_data
, bool compact_mode , bool compact_mode
, storage_constructor_type sc , storage_constructor_type sc
, bool paused) , bool paused
, void* userdata)
{ {
// if you get this assert, you haven't managed to // if you get this assert, you haven't managed to
// open a listen port. call listen_on() first. // open a listen port. call listen_on() first.
@@ -1514,7 +1515,7 @@ namespace detail
for (extension_list_t::iterator i = m_extensions.begin() for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i) , end(m_extensions.end()); i != end; ++i)
{ {
boost::shared_ptr<torrent_plugin> tp((*i)(torrent_ptr.get())); boost::shared_ptr<torrent_plugin> tp((*i)(torrent_ptr.get(), userdata));
if (tp) torrent_ptr->add_extension(tp); if (tp) torrent_ptr->add_extension(tp);
} }
#endif #endif
@@ -1554,7 +1555,8 @@ namespace detail
, entry const& , entry const&
, bool compact_mode , bool compact_mode
, storage_constructor_type sc , storage_constructor_type sc
, bool paused) , bool paused
, void* userdata)
{ {
// TODO: support resume data in this case // TODO: support resume data in this case
@@ -1593,7 +1595,7 @@ namespace detail
for (extension_list_t::iterator i = m_extensions.begin() for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i) , end(m_extensions.end()); i != end; ++i)
{ {
boost::shared_ptr<torrent_plugin> tp((*i)(torrent_ptr.get())); boost::shared_ptr<torrent_plugin> tp((*i)(torrent_ptr.get(), userdata));
if (tp) torrent_ptr->add_extension(tp); if (tp) torrent_ptr->add_extension(tp);
} }
#endif #endif

View File

@@ -347,7 +347,7 @@ namespace libtorrent { namespace
namespace libtorrent namespace libtorrent
{ {
boost::shared_ptr<torrent_plugin> create_ut_pex_plugin(torrent* t) boost::shared_ptr<torrent_plugin> create_ut_pex_plugin(torrent* t, void*)
{ {
if (t->torrent_file().priv()) if (t->torrent_file().priv())
{ {