mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-10 16:19:23 +00:00
* Moved various Download related stuff from core::Manager to
core::DownloadList. * SVN didn't properly commit changes to view.h, fixed. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@678 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+89
-30
@@ -56,6 +56,14 @@
|
|||||||
|
|
||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
|
inline void
|
||||||
|
DownloadList::check_contains(Download* d) {
|
||||||
|
#ifdef USE_EXTRA_DEBUG
|
||||||
|
if (std::find(begin(), end(), d) == end())
|
||||||
|
throw torrent::internal_error("DownloadList::check_contains(...) failed.");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
struct download_list_call {
|
struct download_list_call {
|
||||||
download_list_call(Download* d) : m_download(d) {}
|
download_list_call(Download* d) : m_download(d) {}
|
||||||
|
|
||||||
@@ -95,11 +103,11 @@ DownloadList::create(std::istream* str, bool printLog) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DownloadList::iterator
|
DownloadList::iterator
|
||||||
DownloadList::insert(Download* d) {
|
DownloadList::insert(Download* download) {
|
||||||
iterator itr = base_type::insert(end(), d);
|
iterator itr = base_type::insert(end(), download);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
(*itr)->download()->signal_download_done(sigc::bind(sigc::mem_fun(*this, &DownloadList::received_finished), d));
|
(*itr)->download()->signal_download_done(sigc::bind(sigc::mem_fun(*this, &DownloadList::received_finished), download));
|
||||||
std::for_each(m_slotMapInsert.begin(), m_slotMapInsert.end(), download_list_call(*itr));
|
std::for_each(m_slotMapInsert.begin(), m_slotMapInsert.end(), download_list_call(*itr));
|
||||||
|
|
||||||
} catch (torrent::local_error& e) {
|
} catch (torrent::local_error& e) {
|
||||||
@@ -112,8 +120,10 @@ DownloadList::insert(Download* d) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DownloadList::erase(Download* d) {
|
DownloadList::erase(Download* download) {
|
||||||
erase(std::find(begin(), end(), d));
|
check_contains(download);
|
||||||
|
|
||||||
|
erase(std::find(begin(), end(), download));
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadList::iterator
|
DownloadList::iterator
|
||||||
@@ -123,7 +133,7 @@ DownloadList::erase(iterator itr) {
|
|||||||
|
|
||||||
// Make safe to erase active downloads.
|
// Make safe to erase active downloads.
|
||||||
if ((*itr)->download()->is_active())
|
if ((*itr)->download()->is_active())
|
||||||
throw std::logic_error("DownloadList::erase(...) called on an active download.");
|
throw torrent::internal_error("DownloadList::erase(...) called on an active download.");
|
||||||
|
|
||||||
std::for_each(m_slotMapErase.begin(), m_slotMapErase.end(), download_list_call(*itr));
|
std::for_each(m_slotMapErase.begin(), m_slotMapErase.end(), download_list_call(*itr));
|
||||||
|
|
||||||
@@ -134,11 +144,10 @@ DownloadList::erase(iterator itr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DownloadList::open(Download* d) {
|
DownloadList::open(Download* download) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (!d->download()->is_open())
|
open_throw(download);
|
||||||
std::for_each(m_slotMapOpen.begin(), m_slotMapOpen.end(), download_list_call(d));
|
|
||||||
|
|
||||||
} catch (torrent::local_error& e) {
|
} catch (torrent::local_error& e) {
|
||||||
control->core()->push_log(e.what());
|
control->core()->push_log(e.what());
|
||||||
@@ -146,14 +155,22 @@ DownloadList::open(Download* d) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DownloadList::close(Download* d) {
|
DownloadList::open_throw(Download* download) {
|
||||||
|
check_contains(download);
|
||||||
|
|
||||||
|
if (download->download()->is_open())
|
||||||
|
return;
|
||||||
|
|
||||||
|
download->download()->open();
|
||||||
|
|
||||||
|
std::for_each(m_slotMapOpen.begin(), m_slotMapOpen.end(), download_list_call(download));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DownloadList::close(Download* download) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (d->download()->is_active())
|
close_throw(download);
|
||||||
std::for_each(m_slotMapStop.begin(), m_slotMapStop.end(), download_list_call(d));
|
|
||||||
|
|
||||||
if (d->download()->is_open())
|
|
||||||
std::for_each(m_slotMapClose.begin(), m_slotMapClose.end(), download_list_call(d));
|
|
||||||
|
|
||||||
} catch (torrent::local_error& e) {
|
} catch (torrent::local_error& e) {
|
||||||
control->core()->push_log(e.what());
|
control->core()->push_log(e.what());
|
||||||
@@ -161,25 +178,49 @@ DownloadList::close(Download* d) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DownloadList::start(Download* d) {
|
DownloadList::close_throw(Download* download) {
|
||||||
d->variable()->set("state", (int64_t)1);
|
check_contains(download);
|
||||||
|
|
||||||
resume(d);
|
if (!download->download()->is_open())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (download->download()->is_active())
|
||||||
|
pause(download);
|
||||||
|
|
||||||
|
control->core()->hash_queue()->remove(download);
|
||||||
|
download->download()->close();
|
||||||
|
|
||||||
|
std::for_each(m_slotMapClose.begin(), m_slotMapClose.end(), download_list_call(download));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DownloadList::stop(Download* d) {
|
DownloadList::start(Download* download) {
|
||||||
d->variable()->set("state", (int64_t)0);
|
check_contains(download);
|
||||||
|
|
||||||
pause(d);
|
download->variable()->set("state", (int64_t)1);
|
||||||
|
|
||||||
|
resume(download);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DownloadList::stop(Download* download) {
|
||||||
|
check_contains(download);
|
||||||
|
|
||||||
|
download->variable()->set("state", (int64_t)0);
|
||||||
|
|
||||||
|
pause(download);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DownloadList::resume(Download* download) {
|
DownloadList::resume(Download* download) {
|
||||||
|
check_contains(download);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (!download->download()->is_open())
|
if (download->download()->is_active())
|
||||||
std::for_each(m_slotMapOpen.begin(), m_slotMapOpen.end(), download_list_call(download));
|
return;
|
||||||
|
|
||||||
|
open_throw(download);
|
||||||
|
|
||||||
if (download->download()->is_hash_checked()) {
|
if (download->download()->is_hash_checked()) {
|
||||||
|
|
||||||
@@ -209,13 +250,17 @@ DownloadList::resume(Download* download) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
DownloadList::pause(Download* download) {
|
DownloadList::pause(Download* download) {
|
||||||
|
check_contains(download);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
if (!download->download()->is_active())
|
||||||
|
return;
|
||||||
|
|
||||||
download->download()->stop();
|
download->download()->stop();
|
||||||
download->download()->hash_resume_save();
|
download->download()->hash_resume_save();
|
||||||
|
|
||||||
if (download->download()->is_active())
|
std::for_each(m_slotMapStop.begin(), m_slotMapStop.end(), download_list_call(download));
|
||||||
std::for_each(m_slotMapStop.begin(), m_slotMapStop.end(), download_list_call(download));
|
|
||||||
|
|
||||||
download->variable()->set("state_changed", cachedTime.seconds());
|
download->variable()->set("state_changed", cachedTime.seconds());
|
||||||
|
|
||||||
@@ -236,16 +281,26 @@ DownloadList::clear() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DownloadList::check_hash(Download* d) {
|
DownloadList::check_hash(Download* download) {
|
||||||
close(d);
|
check_contains(download);
|
||||||
d->download()->hash_resume_clear();
|
|
||||||
open(d);
|
|
||||||
|
|
||||||
control->core()->hash_queue()->insert(d);
|
try {
|
||||||
|
|
||||||
|
close_throw(download);
|
||||||
|
download->download()->hash_resume_clear();
|
||||||
|
open_throw(download);
|
||||||
|
|
||||||
|
control->core()->hash_queue()->insert(download);
|
||||||
|
|
||||||
|
} catch (torrent::local_error& e) {
|
||||||
|
control->core()->push_log(e.what());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DownloadList::hash_done(Download* download) {
|
DownloadList::hash_done(Download* download) {
|
||||||
|
check_contains(download);
|
||||||
|
|
||||||
if (!download->download()->is_hash_checked() || download->download()->is_hash_checking())
|
if (!download->download()->is_hash_checked() || download->download()->is_hash_checking())
|
||||||
throw torrent::internal_error("DownloadList::hash_done(...) download in invalid state.");
|
throw torrent::internal_error("DownloadList::hash_done(...) download in invalid state.");
|
||||||
|
|
||||||
@@ -274,6 +329,8 @@ DownloadList::hash_done(Download* download) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
DownloadList::received_finished(Download* download) {
|
DownloadList::received_finished(Download* download) {
|
||||||
|
check_contains(download);
|
||||||
|
|
||||||
if (control->variable()->get_value("check_hash")) {
|
if (control->variable()->get_value("check_hash")) {
|
||||||
// Set some 'checking_finished_thingie' variable to make hash_done
|
// Set some 'checking_finished_thingie' variable to make hash_done
|
||||||
// trigger correctly, also so it can bork on missing data.
|
// trigger correctly, also so it can bork on missing data.
|
||||||
@@ -287,6 +344,8 @@ DownloadList::received_finished(Download* download) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
DownloadList::confirm_finished(Download* download) {
|
DownloadList::confirm_finished(Download* download) {
|
||||||
|
check_contains(download);
|
||||||
|
|
||||||
// FIXME
|
// FIXME
|
||||||
//torrent::download_set_priority(m_download, 2);
|
//torrent::download_set_priority(m_download, 2);
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,10 @@ public:
|
|||||||
iterator erase(iterator itr);
|
iterator erase(iterator itr);
|
||||||
|
|
||||||
void open(Download* d);
|
void open(Download* d);
|
||||||
|
void open_throw(Download* d);
|
||||||
|
|
||||||
void close(Download* d);
|
void close(Download* d);
|
||||||
|
void close_throw(Download* d);
|
||||||
|
|
||||||
void start(Download* d);
|
void start(Download* d);
|
||||||
void stop(Download* d);
|
void stop(Download* d);
|
||||||
@@ -124,6 +127,8 @@ public:
|
|||||||
bool has_slot_finished(const std::string& key) const { return m_slotMapFinished.find(key) != m_slotMapFinished.end(); }
|
bool has_slot_finished(const std::string& key) const { return m_slotMapFinished.find(key) != m_slotMapFinished.end(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
inline void check_contains(Download* d);
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
void received_finished(Download* d);
|
void received_finished(Download* d);
|
||||||
|
|||||||
+8
-9
@@ -155,13 +155,6 @@ Manager::initialize_second() {
|
|||||||
m_downloadList->slot_map_erase()["1_hash_queue_remove"] = sigc::mem_fun(m_hashQueue, &HashQueue::remove);
|
m_downloadList->slot_map_erase()["1_hash_queue_remove"] = sigc::mem_fun(m_hashQueue, &HashQueue::remove);
|
||||||
m_downloadList->slot_map_erase()["1_store_remove"] = sigc::mem_fun(m_downloadStore, &DownloadStore::remove);
|
m_downloadList->slot_map_erase()["1_store_remove"] = sigc::mem_fun(m_downloadStore, &DownloadStore::remove);
|
||||||
m_downloadList->slot_map_erase()["1_delete_tied"] = sigc::ptr_fun(&delete_tied);
|
m_downloadList->slot_map_erase()["1_delete_tied"] = sigc::ptr_fun(&delete_tied);
|
||||||
|
|
||||||
m_downloadList->slot_map_open()["1_download_open"] = sigc::mem_fun(&Download::call<void, &torrent::Download::open>);
|
|
||||||
|
|
||||||
// Currently does not call stop, might want to add a function that
|
|
||||||
// checks if we're running, and if so stop?
|
|
||||||
m_downloadList->slot_map_close()["1_hash_queue_remove"] = sigc::mem_fun(m_hashQueue, &HashQueue::remove);
|
|
||||||
m_downloadList->slot_map_close()["2_download_close"] = sigc::mem_fun(&Download::call<void, &torrent::Download::close>);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -177,10 +170,16 @@ Manager::cleanup() {
|
|||||||
|
|
||||||
void
|
void
|
||||||
Manager::shutdown(bool force) {
|
Manager::shutdown(bool force) {
|
||||||
|
// This doesn't trigger a compiler error on gcc-3.4.5 for some reason.
|
||||||
|
// if (!force)
|
||||||
|
// std::for_each(m_downloadList->begin(), m_downloadList->end(), std::bind1st(std::mem_fun(&DownloadList::pause), &m_downloadList));
|
||||||
|
// else
|
||||||
|
// std::for_each(m_downloadList->begin(), m_downloadList->end(), std::bind1st(std::mem_fun(&DownloadList::close), &m_downloadList));
|
||||||
|
|
||||||
if (!force)
|
if (!force)
|
||||||
std::for_each(m_downloadList->begin(), m_downloadList->end(), std::bind1st(std::mem_fun(&DownloadList::pause), &m_downloadList));
|
std::for_each(m_downloadList->begin(), m_downloadList->end(), std::bind1st(std::mem_fun(&DownloadList::pause), m_downloadList));
|
||||||
else
|
else
|
||||||
std::for_each(m_downloadList->begin(), m_downloadList->end(), std::bind1st(std::mem_fun(&DownloadList::close), &m_downloadList));
|
std::for_each(m_downloadList->begin(), m_downloadList->end(), std::bind1st(std::mem_fun(&DownloadList::close), m_downloadList));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
+6
-6
@@ -41,7 +41,7 @@
|
|||||||
// elements get accessed often but not modified, better with cache
|
// elements get accessed often but not modified, better with cache
|
||||||
// locality.
|
// locality.
|
||||||
//
|
//
|
||||||
// ViewDownloads::m_size indicates the number of Download's that
|
// View::m_size indicates the number of Download's that
|
||||||
// remain visible, e.g. has not been filtered out. The Download's that
|
// remain visible, e.g. has not been filtered out. The Download's that
|
||||||
// were filtered are still in the underlying vector, but cannot be
|
// were filtered are still in the underlying vector, but cannot be
|
||||||
// accessed through the normal stl container functions.
|
// accessed through the normal stl container functions.
|
||||||
@@ -64,7 +64,7 @@ class DownloadList;
|
|||||||
class ViewSort;
|
class ViewSort;
|
||||||
class ViewFilter;
|
class ViewFilter;
|
||||||
|
|
||||||
class ViewDownloads : public std::vector<core::Download*> {
|
class View : public std::vector<core::Download*> {
|
||||||
public:
|
public:
|
||||||
typedef std::vector<core::Download*> base_type;
|
typedef std::vector<core::Download*> base_type;
|
||||||
typedef sigc::signal0<void> signal_type;
|
typedef sigc::signal0<void> signal_type;
|
||||||
@@ -81,8 +81,8 @@ public:
|
|||||||
using base_type::begin;
|
using base_type::begin;
|
||||||
using base_type::rbegin;
|
using base_type::rbegin;
|
||||||
|
|
||||||
ViewDownloads() {}
|
View() {}
|
||||||
~ViewDownloads();
|
~View();
|
||||||
|
|
||||||
void initialize(const std::string& name, core::DownloadList* list);
|
void initialize(const std::string& name, core::DownloadList* list);
|
||||||
|
|
||||||
@@ -130,8 +130,8 @@ public:
|
|||||||
signal_type& signal_changed() { return m_signalChanged; }
|
signal_type& signal_changed() { return m_signalChanged; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ViewDownloads(const ViewDownloads&);
|
View(const View&);
|
||||||
void operator = (const ViewDownloads&);
|
void operator = (const View&);
|
||||||
|
|
||||||
void received_insert(core::Download* d);
|
void received_insert(core::Download* d);
|
||||||
void received_erase(core::Download* d);
|
void received_erase(core::Download* d);
|
||||||
|
|||||||
@@ -45,7 +45,6 @@
|
|||||||
|
|
||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
class View;
|
|
||||||
class ViewSort;
|
class ViewSort;
|
||||||
|
|
||||||
class ViewManager : public rak::unordered_vector<View*> {
|
class ViewManager : public rak::unordered_vector<View*> {
|
||||||
|
|||||||
Reference in New Issue
Block a user