* Added some more download commands that replace some of the

start/stop/close wrapper functions in DownloadList.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1049 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2008-03-28 16:47:17 +00:00
parent a6045c9ea5
commit 03c544d07d
9 changed files with 74 additions and 124 deletions
-2
View File
@@ -156,8 +156,6 @@ Download::receive_chunk_failed(__UNUSED uint32_t idx) {
void
Download::set_root_directory(const std::string& path) {
control->core()->push_log_std("Pushed " + path);
torrent::FileList* fileList = m_download.file_list();
control->core()->download_list()->close_directly(this);
+1 -1
View File
@@ -273,7 +273,7 @@ DownloadFactory::receive_success() {
} else {
// Use the state thingie here, move below.
if (m_start)
m_manager->download_list()->start_normal(download);
rpc::parse_command_single(rpc::make_target(download), "d.start=");
m_manager->download_store()->save(download);
}
-86
View File
@@ -245,26 +245,6 @@ DownloadList::close(Download* download) {
}
}
bool
DownloadList::close_try(Download* download) {
try {
if (rpc::call_command_value("d.get_ignore_commands", rpc::make_target(download)) != 0)
return false;
rpc::call_command("d.set_state", (int64_t)0, rpc::make_target(download));
(*control->view_manager()->find_throw("started"))->set_not_visible(download);
(*control->view_manager()->find_throw("stopped"))->set_visible(download);
close_throw(download);
return true;
} catch (torrent::local_error& e) {
control->core()->push_log(e.what());
return false;
}
}
void
DownloadList::close_directly(Download* download) {
if (download->download()->is_active()) {
@@ -318,72 +298,6 @@ DownloadList::close_throw(Download* download) {
std::for_each(slot_map_close().begin(), slot_map_close().end(), download_list_call(download));
}
void
DownloadList::start_normal(Download* download) {
check_contains(download);
// Clear hash failed as we're doing a manual start and want to try
// hashing again.
download->set_hash_failed(false);
rpc::call_command("d.set_state", (int64_t)1, rpc::make_target(download));
(*control->view_manager()->find_throw("stopped"))->set_not_visible(download);
(*control->view_manager()->find_throw("started"))->set_visible(download);
// try {
// rpc::parse_command_multiple(rpc::make_target(download), "d.set_state=1 ;view.set_not_visible=stopped ;view.set_visible=started");
// } catch (torrent::local_error& e) {
// control->core()->push_log(e.what());
// }
}
bool
DownloadList::start_try(Download* download) {
check_contains(download);
// Also don't start if the state is one of those that indicate we
// were manually stopped?
if (download->is_hash_failed() || rpc::call_command_value("d.get_ignore_commands", rpc::make_target(download)) != 0)
return false;
// Don't clear the hash failed as this function is used by scripts,
// etc.
rpc::call_command("d.set_state", (int64_t)1, rpc::make_target(download));
(*control->view_manager()->find_throw("stopped"))->set_not_visible(download);
(*control->view_manager()->find_throw("started"))->set_visible(download);
// rpc::parse_command_multiple(rpc::make_target(download), "d.set_state=1 ;view.set_not_visible=stopped ;view.set_visible=started");
return true;
}
void
DownloadList::stop_normal(Download* download) {
check_contains(download);
rpc::call_command("d.set_state", (int64_t)0, rpc::make_target(download));
(*control->view_manager()->find_throw("started"))->set_not_visible(download);
(*control->view_manager()->find_throw("stopped"))->set_visible(download);
}
bool
DownloadList::stop_try(Download* download) {
check_contains(download);
if (rpc::call_command_value("d.get_ignore_commands", rpc::make_target(download)) != 0)
return false;
rpc::call_command("d.set_state", (int64_t)0, rpc::make_target(download));
(*control->view_manager()->find_throw("started"))->set_not_visible(download);
(*control->view_manager()->find_throw("stopped"))->set_visible(download);
return true;
}
void
DownloadList::resume(Download* download, int flags) {
check_contains(download);
-7
View File
@@ -102,17 +102,10 @@ public:
void open_throw(Download* d);
void close(Download* d);
bool close_try(Download* d);
void close_directly(Download* d);
void close_quick(Download* d);
void close_throw(Download* d);
void start_normal(Download* d);
bool start_try(Download* d);
void stop_normal(Download* d);
bool stop_try(Download* d);
void resume(Download* d, int flags = 0);
void pause(Download* d, int flags = 0);
+20 -20
View File
@@ -71,37 +71,37 @@ Scheduler::active() const {
void
Scheduler::update() {
size_type curActive = active();
// size_type curActive = active();
// size_type curInactive = m_view->size() - curActive;
// Hmm... Perhaps we should use a more complex sorting thingie.
m_view->sort();
// m_view->sort();
// Just a hack for now, need to take into consideration how many
// inactive we can switch with.
size_type target = m_maxActive - std::min(m_cycle, m_maxActive);
// size_type target = m_maxActive - std::min(m_cycle, m_maxActive);
for (View::iterator itr = m_view->begin_visible(), last = m_view->end_visible(); curActive > target; ++itr) {
if (itr == last)
throw torrent::internal_error("Scheduler::update() loop bork.");
// for (View::iterator itr = m_view->begin_visible(), last = m_view->end_visible(); curActive > target; ++itr) {
// if (itr == last)
// throw torrent::internal_error("Scheduler::update() loop bork.");
if ((*itr)->is_active()) {
m_downloadList->pause(*itr);
--curActive;
}
}
// if ((*itr)->is_active()) {
// m_downloadList->pause(*itr);
// --curActive;
// }
// }
m_view->sort();
// m_view->sort();
for (View::iterator itr = m_view->begin_visible(), last = m_view->end_visible(); curActive < m_maxActive; ++itr) {
if (itr == last)
throw torrent::internal_error("Scheduler::update() loop bork.");
// for (View::iterator itr = m_view->begin_visible(), last = m_view->end_visible(); curActive < m_maxActive; ++itr) {
// if (itr == last)
// throw torrent::internal_error("Scheduler::update() loop bork.");
if (!(*itr)->is_active()) {
m_downloadList->start_try(*itr);
++curActive;
}
}
// if (!(*itr)->is_active()) {
// m_downloadList->start_try(*itr);
// ++curActive;
// }
// }
}
}