mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-10 16:19:23 +00:00
rtorrent: Polling http and torrent. Improved the download list.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@247 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -7,7 +7,7 @@ libsub_display_a_SOURCES = \
|
|||||||
manager.h \
|
manager.h \
|
||||||
window.cc \
|
window.cc \
|
||||||
window.h \
|
window.h \
|
||||||
window_downloads.cc \
|
window_download_list.cc \
|
||||||
window_downloads.h
|
window_download_list.h
|
||||||
|
|
||||||
INCLUDES = -I$(srcdir) -I$(srcdir)/.. -I$(top_srcdir)
|
INCLUDES = -I$(srcdir) -I$(srcdir)/.. -I$(top_srcdir)
|
||||||
|
|||||||
@@ -35,6 +35,14 @@ public:
|
|||||||
template <typename A1, typename A2>
|
template <typename A1, typename A2>
|
||||||
void print(int x, int y, const char* str, A1 a1, A2 a2) { mvwprintw(m_window, y, x, str, a1, a2); }
|
void print(int x, int y, const char* str, A1 a1, A2 a2) { mvwprintw(m_window, y, x, str, a1, a2); }
|
||||||
|
|
||||||
|
template <typename A1, typename A2, typename A3>
|
||||||
|
void print(int x, int y, const char* str,
|
||||||
|
A1 a1, A2 a2, A3 a3) { mvwprintw(m_window, y, x, str, a1, a2, a3); }
|
||||||
|
|
||||||
|
template <typename A1, typename A2, typename A3, typename A4>
|
||||||
|
void print(int x, int y, const char* str,
|
||||||
|
A1 a1, A2 a2, A3 a3, A4 a4) { mvwprintw(m_window, y, x, str, a1, a2, a3, a4); }
|
||||||
|
|
||||||
void print_border(chtype ls, chtype rs,
|
void print_border(chtype ls, chtype rs,
|
||||||
chtype ts, chtype bs,
|
chtype ts, chtype bs,
|
||||||
chtype tl, chtype tr,
|
chtype tl, chtype tr,
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "canvas.h"
|
||||||
|
#include "window_download_list.h"
|
||||||
|
|
||||||
|
#include "engine/download_list.h"
|
||||||
|
|
||||||
|
namespace display {
|
||||||
|
|
||||||
|
WindowDownloadList::WindowDownloadList(engine::DownloadList* d) :
|
||||||
|
Window(new Canvas, true),
|
||||||
|
m_downloads(d) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
WindowDownloadList::redraw() {
|
||||||
|
m_canvas->erase();
|
||||||
|
m_canvas->print_border(' ', ' ', '-', '-', ' ', ' ', ' ', ' ');
|
||||||
|
|
||||||
|
int pos = 1;
|
||||||
|
|
||||||
|
for (engine::DownloadList::iterator itr = m_downloads->begin(); itr != m_downloads->end(); ++itr, ++pos)
|
||||||
|
m_canvas->print(1, pos, "Download: %s Open: %c Tracker: %c Active: %c",
|
||||||
|
itr->get_download().get_name().c_str(),
|
||||||
|
itr->get_download().is_open() ? 'Y' : 'N',
|
||||||
|
itr->get_download().is_tracker_busy() ? 'Y' : 'N',
|
||||||
|
itr->get_download().is_active() ? 'Y' : 'N');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef RTORRENT_DISPLAY_WINDOW_DOWNLOAD_LIST_H
|
||||||
|
#define RTORRENT_DISPLAY_WINDOW_DOWNLOAD_LIST_H
|
||||||
|
|
||||||
|
#include "window.h"
|
||||||
|
|
||||||
|
namespace engine {
|
||||||
|
class DownloadList;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace display {
|
||||||
|
|
||||||
|
class WindowDownloadList : public Window {
|
||||||
|
public:
|
||||||
|
WindowDownloadList(engine::DownloadList* d);
|
||||||
|
|
||||||
|
virtual void redraw();
|
||||||
|
|
||||||
|
private:
|
||||||
|
engine::DownloadList* m_downloads;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include "canvas.h"
|
|
||||||
#include "window_downloads.h"
|
|
||||||
|
|
||||||
namespace display {
|
|
||||||
|
|
||||||
WindowDownloads::WindowDownloads(engine::Downloads* d) :
|
|
||||||
Window(new Canvas, true),
|
|
||||||
m_downloads(d) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
WindowDownloads::redraw() {
|
|
||||||
m_canvas->erase();
|
|
||||||
m_canvas->print_border(' ', ' ', '-', '-', ' ', ' ', ' ', ' ');
|
|
||||||
|
|
||||||
int pos = 1;
|
|
||||||
|
|
||||||
for (engine::Downloads::iterator itr = m_downloads->begin(); itr != m_downloads->end(); ++itr, ++pos)
|
|
||||||
m_canvas->print(1, pos, "Download: %s", itr->get_name().c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
#ifndef RTORRENT_DISPLAY_WINDOW_DOWNLOADS_H
|
|
||||||
#define RTORRENT_DISPLAY_WINDOW_DOWNLOADS_H
|
|
||||||
|
|
||||||
#include "window.h"
|
|
||||||
#include "engine/downloads.h"
|
|
||||||
|
|
||||||
namespace display {
|
|
||||||
|
|
||||||
class WindowDownloads : public Window {
|
|
||||||
public:
|
|
||||||
WindowDownloads(engine::Downloads* d);
|
|
||||||
|
|
||||||
virtual void redraw();
|
|
||||||
|
|
||||||
private:
|
|
||||||
engine::Downloads* m_downloads;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -5,8 +5,9 @@ libsub_engine_a_SOURCES = \
|
|||||||
curl_get.h \
|
curl_get.h \
|
||||||
curl_stack.cc \
|
curl_stack.cc \
|
||||||
curl_stack.h \
|
curl_stack.h \
|
||||||
downloads.cc \
|
download.h \
|
||||||
downloads.h \
|
download_list.cc \
|
||||||
|
download_list.h \
|
||||||
poll.cc \
|
poll.cc \
|
||||||
poll.h
|
poll.h
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
#ifndef RTORRENT_ENGINE_DOWNLOAD_H
|
||||||
|
#define RTORRENT_ENGINE_DOWNLOAD_H
|
||||||
|
|
||||||
|
#include <sigc++/connection.h>
|
||||||
|
#include <torrent/download.h>
|
||||||
|
|
||||||
|
namespace engine {
|
||||||
|
|
||||||
|
class Download {
|
||||||
|
public:
|
||||||
|
Download(torrent::Download d) : m_download(d) {}
|
||||||
|
|
||||||
|
std::string get_hash() { return m_download.get_hash(); }
|
||||||
|
torrent::Download& get_download() { return m_download; }
|
||||||
|
|
||||||
|
void open() { m_download.open(); }
|
||||||
|
void close() { m_download.close(); }
|
||||||
|
|
||||||
|
void hash_check(bool resume = false) { m_download.hash_check(resume); }
|
||||||
|
|
||||||
|
bool operator == (const std::string& str) { return str == m_download.get_hash(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
torrent::Download m_download;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <sigc++/bind.h>
|
||||||
|
#include <torrent/exceptions.h>
|
||||||
|
#include <torrent/torrent.h>
|
||||||
|
|
||||||
|
#include "download_list.h"
|
||||||
|
|
||||||
|
namespace engine {
|
||||||
|
|
||||||
|
DownloadList::iterator
|
||||||
|
DownloadList::create(std::istream& str) {
|
||||||
|
iterator itr = Base::insert(end(), torrent::download_create(str));
|
||||||
|
|
||||||
|
itr->get_download().signal_hash_done(sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_hash_done),
|
||||||
|
itr->get_hash()));
|
||||||
|
|
||||||
|
return itr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DownloadList::erase(iterator itr) {
|
||||||
|
torrent::download_remove(itr->get_hash());
|
||||||
|
|
||||||
|
Base::erase(itr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DownloadList::receive_hash_done(const std::string& str) {
|
||||||
|
iterator itr = std::find(begin(), end(), str);
|
||||||
|
|
||||||
|
if (itr == end())
|
||||||
|
throw torrent::client_error("DownloadList received hash check done, but couldn't find the download");
|
||||||
|
|
||||||
|
itr->get_download().start();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
#ifndef RTORRENT_ENGINE_DOWNLOAD_LIST_H
|
||||||
|
#define RTORRENT_ENGINE_DOWNLOAD_LIST_H
|
||||||
|
|
||||||
|
#include <iosfwd>
|
||||||
|
|
||||||
|
#include "download.h"
|
||||||
|
|
||||||
|
namespace engine {
|
||||||
|
|
||||||
|
class DownloadList : private std::list<Download> {
|
||||||
|
public:
|
||||||
|
typedef std::list<Download> Base;
|
||||||
|
|
||||||
|
using Base::iterator;
|
||||||
|
using Base::const_iterator;
|
||||||
|
using Base::reverse_iterator;
|
||||||
|
using Base::const_reverse_iterator;
|
||||||
|
|
||||||
|
using Base::begin;
|
||||||
|
using Base::end;
|
||||||
|
using Base::rbegin;
|
||||||
|
using Base::rend;
|
||||||
|
|
||||||
|
iterator create(std::istream& str);
|
||||||
|
void erase(iterator itr);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void receive_hash_done(const std::string& str);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <torrent/torrent.h>
|
|
||||||
|
|
||||||
#include "downloads.h"
|
|
||||||
|
|
||||||
namespace engine {
|
|
||||||
|
|
||||||
void
|
|
||||||
Downloads::create(std::istream& str) {
|
|
||||||
torrent::Download d = torrent::download_create(str);
|
|
||||||
|
|
||||||
Base::push_back(d);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
Downloads::erase(iterator itr) {
|
|
||||||
torrent::download_remove(itr->get_hash());
|
|
||||||
|
|
||||||
Base::erase(itr);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
#ifndef RTORRENT_ENGINE_DOWNLOADS_H
|
|
||||||
#define RTORRENT_ENGINE_DOWNLOADS_H
|
|
||||||
|
|
||||||
#include <iosfwd>
|
|
||||||
#include <torrent/download.h>
|
|
||||||
|
|
||||||
namespace engine {
|
|
||||||
|
|
||||||
class Downloads : private std::list<torrent::Download> {
|
|
||||||
public:
|
|
||||||
typedef std::list<torrent::Download> Base;
|
|
||||||
|
|
||||||
using Base::iterator;
|
|
||||||
using Base::const_iterator;
|
|
||||||
using Base::reverse_iterator;
|
|
||||||
using Base::const_reverse_iterator;
|
|
||||||
|
|
||||||
using Base::begin;
|
|
||||||
using Base::end;
|
|
||||||
using Base::rbegin;
|
|
||||||
using Base::rend;
|
|
||||||
|
|
||||||
void create(std::istream& str);
|
|
||||||
void erase(iterator itr);
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
+25
-2
@@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
|
#include <sigc++/bind.h>
|
||||||
|
#include <torrent/torrent.h>
|
||||||
|
|
||||||
#include "poll.h"
|
#include "poll.h"
|
||||||
|
#include "curl_get.h"
|
||||||
|
|
||||||
namespace engine {
|
namespace engine {
|
||||||
|
|
||||||
@@ -13,12 +16,22 @@ Poll::poll() {
|
|||||||
FD_ZERO(&m_writeSet);
|
FD_ZERO(&m_writeSet);
|
||||||
FD_ZERO(&m_exceptSet);
|
FD_ZERO(&m_exceptSet);
|
||||||
|
|
||||||
m_maxFd = 1;
|
torrent::mark(&m_readSet, &m_writeSet, &m_exceptSet, &m_maxFd);
|
||||||
|
|
||||||
|
m_maxFd = std::max(m_maxFd, 1);
|
||||||
|
|
||||||
if (m_readStdin)
|
if (m_readStdin)
|
||||||
FD_SET(0, &m_readSet);
|
FD_SET(0, &m_readSet);
|
||||||
|
|
||||||
timeval timeout = {60, 0};
|
if (m_curlStack.is_busy())
|
||||||
|
m_curlStack.fdset(&m_readSet, &m_writeSet, &m_exceptSet, &m_maxFd);
|
||||||
|
|
||||||
|
uint64_t t = torrent::get(torrent::TIME_SELECT);
|
||||||
|
|
||||||
|
if (t > 10000000)
|
||||||
|
t = 10000000;
|
||||||
|
|
||||||
|
timeval timeout = {t / 1000000, t % 1000000};
|
||||||
|
|
||||||
m_maxFd = select(m_maxFd, &m_readSet, &m_writeSet, &m_exceptSet, &timeout);
|
m_maxFd = select(m_maxFd, &m_readSet, &m_writeSet, &m_exceptSet, &timeout);
|
||||||
|
|
||||||
@@ -34,6 +47,16 @@ Poll::work() {
|
|||||||
while ((key = getch()) >= 0)
|
while ((key = getch()) >= 0)
|
||||||
m_readStdin(key);
|
m_readStdin(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_curlStack.is_busy())
|
||||||
|
m_curlStack.perform();
|
||||||
|
|
||||||
|
torrent::work(&m_readSet, &m_writeSet, &m_exceptSet, m_maxFd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Poll::register_http() {
|
||||||
|
torrent::Http::set_factory(sigc::bind(sigc::ptr_fun(&engine::CurlGet::new_object), &m_curlStack));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#include <sigc++/slot.h>
|
#include <sigc++/slot.h>
|
||||||
|
|
||||||
|
#include "curl_stack.h"
|
||||||
|
|
||||||
namespace engine {
|
namespace engine {
|
||||||
|
|
||||||
class Poll {
|
class Poll {
|
||||||
@@ -17,6 +19,8 @@ public:
|
|||||||
void poll();
|
void poll();
|
||||||
void work();
|
void work();
|
||||||
|
|
||||||
|
void register_http();
|
||||||
|
|
||||||
void slot_read_stdin(SlotInt s) { m_readStdin = s; }
|
void slot_read_stdin(SlotInt s) { m_readStdin = s; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -27,6 +31,8 @@ private:
|
|||||||
fd_set m_readSet;
|
fd_set m_readSet;
|
||||||
fd_set m_writeSet;
|
fd_set m_writeSet;
|
||||||
fd_set m_exceptSet;
|
fd_set m_exceptSet;
|
||||||
|
|
||||||
|
CurlStack m_curlStack;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-13
@@ -3,17 +3,14 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <torrent/torrent.h>
|
#include <torrent/torrent.h>
|
||||||
#include <torrent/http.h>
|
|
||||||
#include <sigc++/bind.h>
|
#include <sigc++/bind.h>
|
||||||
|
|
||||||
#include "display/canvas.h"
|
#include "display/canvas.h"
|
||||||
#include "display/manager.h"
|
#include "display/manager.h"
|
||||||
#include "display/window_downloads.h"
|
#include "display/window_download_list.h"
|
||||||
|
|
||||||
#include "engine/poll.h"
|
#include "engine/poll.h"
|
||||||
#include "engine/curl_stack.h"
|
#include "engine/download_list.h"
|
||||||
#include "engine/curl_get.h"
|
|
||||||
#include "engine/downloads.h"
|
|
||||||
|
|
||||||
#include "input/bindings.h"
|
#include "input/bindings.h"
|
||||||
#include "input/manager.h"
|
#include "input/manager.h"
|
||||||
@@ -21,29 +18,32 @@
|
|||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
engine::Poll poll;
|
|
||||||
engine::Downloads downloads;
|
|
||||||
engine::CurlStack curlStack;
|
|
||||||
|
|
||||||
display::Canvas::init();
|
display::Canvas::init();
|
||||||
|
|
||||||
|
engine::Poll poll;
|
||||||
|
engine::DownloadList downloads;
|
||||||
|
|
||||||
display::Manager display;
|
display::Manager display;
|
||||||
|
|
||||||
input::Manager inputManager;
|
input::Manager inputManager;
|
||||||
|
|
||||||
inputManager.push_back(new input::Bindings);
|
inputManager.push_back(new input::Bindings);
|
||||||
|
|
||||||
poll.slot_read_stdin(sigc::mem_fun(inputManager, &input::Manager::pressed));
|
poll.slot_read_stdin(sigc::mem_fun(inputManager, &input::Manager::pressed));
|
||||||
|
poll.register_http();
|
||||||
|
|
||||||
display.push_back(new display::WindowDownloads(&downloads));
|
display.push_back(new display::WindowDownloadList(&downloads));
|
||||||
|
|
||||||
torrent::initialize();
|
torrent::initialize();
|
||||||
torrent::listen_open(6880, 6999);
|
torrent::listen_open(6880, 6999);
|
||||||
|
|
||||||
torrent::Http::set_factory(sigc::bind(sigc::ptr_fun(&engine::CurlGet::new_object), &curlStack));
|
|
||||||
|
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
std::fstream f(argv[i], std::ios::in);
|
std::fstream f(argv[i], std::ios::in);
|
||||||
|
|
||||||
downloads.create(f);
|
engine::DownloadList::iterator itr = downloads.create(f);
|
||||||
|
|
||||||
|
itr->open();
|
||||||
|
itr->hash_check();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (poll.is_running()) {
|
while (poll.is_running()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user