diff -rupa /config.h.in /config.h.in --- config.h.in 2011-06-21 16:16:53.000000000 +0900 +++ config.h.in 2011-09-03 00:33:09.000000000 +0900 @@ -75,6 +75,9 @@ /* Support for XMLRPC-C. */ #undef HAVE_XMLRPC_C +/* Support for NO_GUI. */ +#undef NO_GUI + /* Define to the sub-directory in which libtool stores uninstalled libraries. */ #undef LT_OBJDIR diff -rupa /configure /configure --- configure 2011-09-03 02:20:47.000000000 +0900 +++ configure 2011-09-03 00:35:35.000000000 +0900 @@ -765,6 +765,7 @@ with_ncursesw with_statvfs with_statfs with_xmlrpc_c +with_no_gui ' ac_precious_vars='build_alias host_alias @@ -1476,6 +1477,7 @@ Optional Packages: --with-ncurses force the use of Ncurses or NcursesW --without-ncursesw do not use NcursesW (wide character support) --with-xmlrpc-c=PATH enable XMLRPC-C support + --with-no-gui disable GUI. Some influential environment variables: CXX C++ compiler command @@ -16633,6 +16635,17 @@ ac_link='$CXX -o conftest$ac_exeext $CXX ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + { $as_echo "$as_me:$LINENO: No GUI support configured" >&5 +$as_echo_n "No GUI support configured... " >&6; } + +# Check whether --with-no-gui was given. +if test "${with_no_gui+set}" = set; then +cat >>confdefs.h <<\_ACEOF +#define NO_GUI 1 +_ACEOF +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for XMLRPC-C" >&5 $as_echo_n "checking for XMLRPC-C... " >&6; } diff -rupa src/command_network.cc src/command_network.cc --- src/command_network.cc 2011-06-21 15:46:48.000000000 +0900 +++ src/command_network.cc 2011-09-03 01:17:50.000000000 +0900 @@ -54,7 +54,6 @@ #include "core/download.h" #include "core/manager.h" #include "rpc/scgi.h" -#include "ui/root.h" #include "rpc/parse.h" #include "rpc/parse_commands.h" diff -rupa src/command_peer.cc src/command_peer.cc --- src/command_peer.cc 2011-04-07 16:50:52.000000000 +0900 +++ src/command_peer.cc 2011-09-03 00:48:04.000000000 +0900 @@ -47,7 +47,9 @@ #include #include "core/manager.h" -#include "display/utils.h" +#ifndef NO_GUI + #include "display/utils.h" +#endif #include "globals.h" #include "control.h" @@ -79,9 +81,26 @@ retrieve_p_port(torrent::Peer* peer) { torrent::Object retrieve_p_client_version(torrent::Peer* peer) { +#ifndef NO_GUI char buf[128]; + display::print_client_version(buf, buf + 128, peer->peer_info()->client_info()); - +#else + char buf[128]={0}; + + torrent::ClientInfo clientInfo=peer->peer_info()->client_info(); + switch (torrent::ClientInfo::version_size(clientInfo.type())){ + case 4: + snprintf(buf, sizeof(buf), "%s %hhu.%hhu.%hhu.%hhu", clientInfo.short_description(), clientInfo.version()[0], clientInfo.version()[1], clientInfo.version()[2], clientInfo.version()[3]); + break; + case 3: + snprintf(buf, sizeof(buf), "%s %hhu.%hhu.%hhu", clientInfo.short_description(), clientInfo.version()[0], clientInfo.version()[1], clientInfo.version()[2]); + break; + default: + snprintf(buf, sizeof(buf), "%s", clientInfo.short_description()); + break; + } +#endif return std::string(buf); } diff -rupa src/command_ui.cc src/command_ui.cc --- src/command_ui.cc 2011-06-04 13:01:19.000000000 +0900 +++ src/command_ui.cc 2011-09-03 00:50:10.000000000 +0900 @@ -45,8 +45,10 @@ #include "core/manager.h" #include "core/view_manager.h" -#include "ui/root.h" -#include "ui/download_list.h" +#ifndef NO_GUI + #include "ui/root.h" + #include "ui/download_list.h" +#endif #include "rpc/parse.h" #include "globals.h" @@ -485,13 +487,17 @@ cmd_view_persistent(const torrent::Objec // TODO: These don't need wrapper functions anymore... torrent::Object cmd_ui_set_view(const torrent::Object::string_type& args) { +#ifndef NO_GUI control->ui()->download_list()->set_current_view(args); +#endif return torrent::Object(); } torrent::Object cmd_ui_unfocus_download(core::Download* download) { +#ifndef NO_GUI control->ui()->download_list()->unfocus_download(download); +#endif return torrent::Object(); } diff -rupa src/control.cc src/control.cc --- src/control.cc 2011-04-05 19:26:02.000000000 +0900 +++ src/control.cc 2011-09-03 00:55:37.000000000 +0900 @@ -45,24 +45,30 @@ #include "core/view_manager.h" #include "core/dht_manager.h" -#include "display/canvas.h" -#include "display/window.h" -#include "display/manager.h" -#include "input/manager.h" -#include "input/input_event.h" +#ifndef NO_GUI + #include "display/canvas.h" + #include "display/window.h" + #include "display/manager.h" + #include "input/manager.h" + #include "input/input_event.h" +#endif #include "rpc/command_scheduler.h" #include "rpc/parse_commands.h" #include "rpc/scgi.h" #include "rpc/object_storage.h" -#include "ui/root.h" +#ifndef NO_GUI + #include "ui/root.h" +#endif #include "control.h" Control::Control() : +#ifndef NO_GUI m_ui(new ui::Root()), m_display(new display::Manager()), m_input(new input::Manager()), m_inputStdin(new input::InputEvent(STDIN_FILENO)), +#endif m_commandScheduler(new rpc::CommandScheduler()), m_objectStorage(new rpc::object_storage()), @@ -75,7 +81,9 @@ m_viewManager = new core::ViewManager(); m_dhtManager = new core::DhtManager(); +#ifndef NO_GUI m_inputStdin->slot_pressed(std::tr1::bind(&input::Manager::pressed, m_input, std::tr1::placeholders::_1)); +#endif m_taskShutdown.slot() = std::tr1::bind(&Control::handle_shutdown, this); @@ -83,13 +91,17 @@ } Control::~Control() { +#ifndef NO_GUI delete m_inputStdin; delete m_input; +#endif delete m_viewManager; +#ifndef NO_GUI delete m_ui; delete m_display; +#endif delete m_core; delete m_dhtManager; @@ -99,10 +111,12 @@ void Control::initialize() { +#ifndef NO_GUI display::Canvas::initialize(); display::Window::slot_schedule(rak::make_mem_fun(m_display, &display::Manager::schedule)); display::Window::slot_unschedule(rak::make_mem_fun(m_display, &display::Manager::unschedule)); display::Window::slot_adjust(rak::make_mem_fun(m_display, &display::Manager::adjust_layout)); +#endif m_core->http_stack()->set_user_agent(USER_AGENT); @@ -112,9 +126,11 @@ m_core->set_hashing_view(*m_viewManager->find_throw("hashing")); +#ifndef NO_GUI m_ui->init(this); m_inputStdin->insert(torrent::main_thread()->poll()); +#endif } void @@ -124,24 +140,32 @@ priority_queue_erase(&taskScheduler, &m_taskShutdown); +#ifndef NO_GUI m_inputStdin->remove(torrent::main_thread()->poll()); +#endif m_core->download_store()->disable(); +#ifndef NO_GUI m_ui->cleanup(); +#endif + m_core->cleanup(); - + +#ifndef NO_GUI display::Canvas::erase_std(); display::Canvas::refresh_std(); display::Canvas::do_update(); display::Canvas::cleanup(); +#endif } void Control::cleanup_exception() { // delete m_scgi; m_scgi = NULL; - +#ifndef NO_GUI display::Canvas::cleanup(); +#endif } bool diff -rupa src/main.cc src/main.cc --- src/main.cc 2011-06-12 15:43:04.000000000 +0900 +++ src/main.cc 2011-09-03 00:59:01.000000000 +0900 @@ -61,10 +61,12 @@ #include "core/download_factory.h" #include "core/download_store.h" #include "core/manager.h" -#include "display/canvas.h" -#include "display/window.h" -#include "display/manager.h" -#include "input/bindings.h" +#ifndef NO_GUI + #include "display/canvas.h" + #include "display/window.h" + #include "display/manager.h" + #include "input/bindings.h" +#endif #include "rpc/command_scheduler.h" #include "rpc/command_scheduler_item.h" @@ -194,7 +196,10 @@ SignalHandler::set_ignore(SIGPIPE); SignalHandler::set_handler(SIGINT, std::tr1::bind(&Control::receive_normal_shutdown, control)); SignalHandler::set_handler(SIGTERM, std::tr1::bind(&Control::receive_quick_shutdown, control)); +#ifndef NO_GUI SignalHandler::set_handler(SIGWINCH, std::tr1::bind(&display::Manager::force_redraw, control->display())); +#endif + SignalHandler::set_handler(SIGSEGV, std::tr1::bind(&do_panic, SIGSEGV)); SignalHandler::set_handler(SIGILL, std::tr1::bind(&do_panic, SIGILL)); SignalHandler::set_handler(SIGFPE, std::tr1::bind(&do_panic, SIGFPE)); @@ -864,8 +869,10 @@ // Make sure we update the display before any scheduled tasks can // run, so that loading of torrents doesn't look like it hangs on // startup. +#ifndef NO_GUI control->display()->adjust_layout(); control->display()->receive_update(); +#endif worker_thread->start_thread(); @@ -895,7 +902,9 @@ do_panic(signum); SignalHandler::set_default(signum); +#ifndef NO_GUI display::Canvas::cleanup(); +#endif // Use printf here instead... @@ -959,7 +968,9 @@ // Use the default signal handler in the future to avoid infinit // loops. SignalHandler::set_default(signum); +#ifndef NO_GUI display::Canvas::cleanup(); +#endif // Use printf here instead... diff -rupa src/command_throttle.cc src/command_throttle.cc --- src/command_throttle.cc.orig 2012-04-16 00:43:20.000000000 +0900 +++ src/command_throttle.cc 2012-07-12 01:38:51.000000000 +0900 @@ -43,7 +43,9 @@ #include #include "core/manager.h" -#include "ui/root.h" +#ifndef NO_GUI + #include "ui/root.h" +#endif #include "rpc/parse.h" #include "rpc/parse_commands.h" @@ -166,11 +168,79 @@ throttle_update(const char* variable, int64_t value) { rpc::commands.call_command(variable, value); +#ifndef NO_GUI control->ui()->adjust_up_throttle(0); control->ui()->adjust_down_throttle(0); +#endif return torrent::Object(); } + + +#ifdef NO_GUI +void set_down_throttle(unsigned int throttle); +void set_up_throttle(unsigned int throttle); +void set_down_throttle_i64(int64_t throttle) { set_down_throttle(throttle >> 10); } +void set_up_throttle_i64(int64_t throttle) { set_up_throttle(throttle >> 10); } + +void +set_down_throttle(unsigned int throttle) { + + torrent::down_throttle_global()->set_max_rate(throttle * 1024); + + unsigned int div = std::max(rpc::call_command_value("throttle.max_downloads.div"), 0); + unsigned int global = std::max(rpc::call_command_value("throttle.max_downloads.global"), 0); + + if (throttle == 0 || div == 0) { + torrent::resource_manager()->set_max_download_unchoked(global); + return; + } + + throttle /= div; + + unsigned int maxUnchoked; + + if (throttle <= 10) + maxUnchoked = 1 + throttle / 1; + else + maxUnchoked = 10 + throttle / 5; + + if (global != 0) + torrent::resource_manager()->set_max_download_unchoked(std::min(maxUnchoked, global)); + else + torrent::resource_manager()->set_max_download_unchoked(maxUnchoked); +} + +void +set_up_throttle(unsigned int throttle) { + + torrent::up_throttle_global()->set_max_rate(throttle * 1024); + + unsigned int div = std::max(rpc::call_command_value("throttle.max_uploads.div"), 0); + unsigned int global = std::max(rpc::call_command_value("throttle.max_uploads.global"), 0); + + if (throttle == 0 || div == 0) { + torrent::resource_manager()->set_max_upload_unchoked(global); + return; + } + + throttle /= div; + + unsigned int maxUnchoked; + + if (throttle <= 10) + maxUnchoked = 1 + throttle / 1; + else + maxUnchoked = 10 + throttle / 5; + + if (global != 0) + torrent::resource_manager()->set_max_upload_unchoked(std::min(maxUnchoked, global)); + else + torrent::resource_manager()->set_max_upload_unchoked(maxUnchoked); +} +#endif + + void initialize_command_throttle() { CMD2_ANY ("throttle.unchoked_uploads", tr1::bind(&torrent::ResourceManager::currently_upload_unchoked, torrent::resource_manager())); @@ -205,13 +275,23 @@ CMD2_ANY ("throttle.global_up.rate", tr1::bind(&torrent::Rate::rate, torrent::up_rate())); CMD2_ANY ("throttle.global_up.total", tr1::bind(&torrent::Rate::total, torrent::up_rate())); CMD2_ANY ("throttle.global_up.max_rate", tr1::bind(&torrent::Throttle::max_rate, torrent::up_throttle_global())); +#ifndef NO_GUI CMD2_ANY_VALUE_V ("throttle.global_up.max_rate.set", tr1::bind(&ui::Root::set_up_throttle_i64, control->ui(), tr1::placeholders::_2)); CMD2_ANY_VALUE_KB("throttle.global_up.max_rate.set_kb", tr1::bind(&ui::Root::set_up_throttle_i64, control->ui(), tr1::placeholders::_2)); +#else + CMD2_ANY_VALUE_V ("throttle.global_up.max_rate.set", tr1::bind(&set_up_throttle_i64, tr1::placeholders::_2)); + CMD2_ANY_VALUE_KB("throttle.global_up.max_rate.set_kb", tr1::bind(&set_up_throttle_i64, tr1::placeholders::_2)); +#endif CMD2_ANY ("throttle.global_down.rate", tr1::bind(&torrent::Rate::rate, torrent::down_rate())); CMD2_ANY ("throttle.global_down.total", tr1::bind(&torrent::Rate::total, torrent::down_rate())); CMD2_ANY ("throttle.global_down.max_rate", tr1::bind(&torrent::Throttle::max_rate, torrent::down_throttle_global())); +#ifndef NO_GUI CMD2_ANY_VALUE_V ("throttle.global_down.max_rate.set", tr1::bind(&ui::Root::set_down_throttle_i64, control->ui(), tr1::placeholders::_2)); CMD2_ANY_VALUE_KB("throttle.global_down.max_rate.set_kb", tr1::bind(&ui::Root::set_down_throttle_i64, control->ui(), tr1::placeholders::_2)); +#else + CMD2_ANY_VALUE_V ("throttle.global_down.max_rate.set", tr1::bind(&set_down_throttle_i64, tr1::placeholders::_2)); + CMD2_ANY_VALUE_KB("throttle.global_down.max_rate.set_kb", tr1::bind(&set_down_throttle_i64, tr1::placeholders::_2)); +#endif // Temporary names, need to change this to accept real rates rather // than kB.