From abcb2cea480192bd61941f793baf0af47ab16cb5 Mon Sep 17 00:00:00 2001 From: rakshasa Date: Thu, 6 Aug 2009 16:21:36 +0000 Subject: [PATCH] * Added simple scheduler. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1096 e378c898-3ddf-0310-93e7-cc216c733640 --- configure.ac | 4 +-- src/command_scheduler.cc | 57 +++++++++++++++++++++++++++++++++++++-- src/core/download_list.cc | 1 + 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 8e773189..8efb9e33 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT(rtorrent, 0.8.4, jaris@ifi.uio.no) +AC_INIT(rtorrent, 0.8.5, jaris@ifi.uio.no) AM_INIT_AUTOMAKE AM_CONFIG_HEADER(config.h) @@ -34,7 +34,7 @@ PKG_CHECK_MODULES(libcurl, libcurl >= 7.15.4, CXXFLAGS="$CXXFLAGS $libcurl_CFLAGS"; LIBS="$LIBS $libcurl_LIBS") -PKG_CHECK_MODULES(libtorrent, libtorrent >= 0.12.4, +PKG_CHECK_MODULES(libtorrent, libtorrent >= 0.12.5, CXXFLAGS="$CXXFLAGS $libtorrent_CFLAGS"; LIBS="$LIBS $libtorrent_LIBS") diff --git a/src/command_scheduler.cc b/src/command_scheduler.cc index c43d7d19..5a63d6c0 100644 --- a/src/command_scheduler.cc +++ b/src/command_scheduler.cc @@ -37,7 +37,10 @@ #include "config.h" #include "core/manager.h" +#include "core/download.h" #include "core/download_list.h" +#include "core/view.h" +#include "core/view_manager.h" #include "rpc/command_variable.h" #include "globals.h" @@ -46,7 +49,11 @@ torrent::Object cmd_scheduler_simple_added(core::Download* download, const torrent::Object& rawArgs) { - control->core()->download_list()->resume(download); + unsigned int numActive = (*control->view_manager()->find("active"))->size_visible(); + int64_t maxActive = rpc::call_command("scheduler.max_active", torrent::Object()).as_value(); + + if (numActive < (uint64_t)maxActive) + control->core()->download_list()->resume(download); return torrent::Object(); } @@ -55,6 +62,51 @@ torrent::Object cmd_scheduler_simple_removed(core::Download* download, const torrent::Object& rawArgs) { control->core()->download_list()->pause(download); + core::View* viewActive = *control->view_manager()->find("active"); + int64_t maxActive = rpc::call_command("scheduler.max_active", torrent::Object()).as_value(); + + if (viewActive->size_visible() >= maxActive) + return torrent::Object(); + + // The 'started' view contains all the views we may choose amongst. + core::View* viewStarted = *control->view_manager()->find("started"); + + for (core::View::iterator itr = viewStarted->begin_visible(), last = viewStarted->end_visible(); itr != last; itr++) { + if ((*itr)->is_active()) + continue; + + control->core()->download_list()->resume(*itr); + } + + return torrent::Object(); +} + +torrent::Object +cmd_scheduler_simple_update(core::Download* download, const torrent::Object& rawArgs) { + core::View* viewActive = *control->view_manager()->find("active"); + core::View* viewStarted = *control->view_manager()->find("started"); + + unsigned int numActive = viewActive->size_visible(); + uint64_t maxActive = rpc::call_command("scheduler.max_active", torrent::Object()).as_value(); + + if (viewActive->size_visible() < maxActive) { + + for (core::View::iterator itr = viewStarted->begin_visible(), last = viewStarted->end_visible(); itr != last; itr++) { + if ((*itr)->is_active()) + continue; + + control->core()->download_list()->resume(*itr); + + if (++numActive >= maxActive) + break; + } + + } else if (viewActive->size_visible() > maxActive) { + + while (viewActive->size_visible() > maxActive) + control->core()->download_list()->pause(*viewActive->begin_visible()); + } + return torrent::Object(); } @@ -64,8 +116,9 @@ initialize_command_scheduler() { // CMD_G("scheduler.active", rak::bind_ptr_fn(&cmd_call, "view.size=active")); - CMD_V("scheduler.", "max_active", value, (int64_t)-1); + rpc::commands.call("system.method.insert", rpc::create_object_list("scheduler.max_active", "value", (int64_t)-1)); CMD_D_ANY("scheduler.simple.added", rak::ptr_fn(&cmd_scheduler_simple_added)); CMD_D_ANY("scheduler.simple.removed", rak::ptr_fn(&cmd_scheduler_simple_removed)); + CMD_D_ANY("scheduler.simple.update", rak::ptr_fn(&cmd_scheduler_simple_update)); } diff --git a/src/core/download_list.cc b/src/core/download_list.cc index 7272397b..9bffabf5 100644 --- a/src/core/download_list.cc +++ b/src/core/download_list.cc @@ -468,6 +468,7 @@ DownloadList::hash_done(Download* download) { if (rpc::call_command_value("d.get_state", rpc::make_target(download)) == 1) resume(download, download->resume_flags()); + //rpc::commands.call_catch("scheduler.simple.resume", rpc::make_target(download), torrent::Object(), "Download event action failed: "); break;