add_extension on torrent_handle, to add an extension on an already running torrent

This commit is contained in:
Arvid Norberg 2007-11-08 01:45:35 +00:00
parent 8868469f2f
commit 80e8aa0a18
4 changed files with 47 additions and 0 deletions

View File

@ -128,6 +128,8 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_EXTENSIONS
void add_extension(boost::shared_ptr<torrent_plugin>);
void add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> const& ext
, void* userdata);
#endif
// this is called when the torrent has metadata.

View File

@ -64,6 +64,8 @@ namespace libtorrent
struct checker_impl;
}
struct torrent_plugin;
struct TORRENT_EXPORT duplicate_torrent: std::exception
{
virtual const char* what() const throw()
@ -279,6 +281,11 @@ namespace libtorrent
void remove_url_seed(std::string const& url) const;
std::set<std::string> url_seeds() const;
#ifndef TORRENT_DISABLE_EXTENSIONS
void add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> const& ext
, void* userdata = 0);
#endif
bool has_metadata() const;
const torrent_info& get_torrent_info() const;
bool is_valid() const;

View File

@ -346,10 +346,34 @@ namespace libtorrent
}
#ifndef TORRENT_DISABLE_EXTENSIONS
void torrent::add_extension(boost::shared_ptr<torrent_plugin> ext)
{
m_extensions.push_back(ext);
}
void torrent::add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> const& ext
, void* userdata)
{
boost::shared_ptr<torrent_plugin> tp(ext(this, userdata));
if (!tp) return;
add_extension(tp);
for (peer_iterator i = m_connections.begin();
i != m_connections.end(); ++i)
{
peer_connection* p = *i;
boost::shared_ptr<peer_plugin> pp(tp->new_connection(p));
if (pp) p->add_extension(pp);
}
// if files are checked for this torrent, call the extension
// to let it initialize itself
if (m_connections_initialized)
tp->on_files_checked();
}
#endif
// this may not be called from a constructor because of the call to

View File

@ -247,6 +247,20 @@ namespace libtorrent
find_torrent(m_ses, m_chk, m_info_hash)->move_storage(save_path);
}
void torrent_handle::add_extension(
boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> const& ext
, void* userdata)
{
INVARIANT_CHECK;
if (m_ses == 0) throw_invalid_handle();
TORRENT_ASSERT(m_chk);
session_impl::mutex_t::scoped_lock l1(m_ses->m_mutex);
mutex::scoped_lock l2(m_chk->m_mutex);
return find_torrent(m_ses, m_chk, m_info_hash)->add_extension(ext, userdata);
}
bool torrent_handle::has_metadata() const
{
INVARIANT_CHECK;