mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-13 05:32:31 +00:00
Starting work on core::Manager, working for file/http inserts.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@267 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -11,6 +11,8 @@ libsub_core_a_SOURCES = \
|
||||
download.h \
|
||||
download_list.cc \
|
||||
download_list.h \
|
||||
manager.cc \
|
||||
manager.h \
|
||||
poll.cc \
|
||||
poll.h
|
||||
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <istream>
|
||||
#include <sigc++/bind.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/http.h>
|
||||
|
||||
#include "manager.h"
|
||||
|
||||
|
||||
namespace core {
|
||||
|
||||
void
|
||||
Manager::insert(const std::string& uri) {
|
||||
if (std::strncmp(uri.c_str(), "http://", 7))
|
||||
create_file(uri);
|
||||
else
|
||||
create_http(uri);
|
||||
}
|
||||
|
||||
void
|
||||
Manager::create_file(const std::string& uri) {
|
||||
DownloadList::iterator itr = m_downloadList.end();
|
||||
|
||||
try {
|
||||
std::fstream f(uri.c_str(), std::ios::in);
|
||||
|
||||
itr = m_downloadList.insert(&f);
|
||||
|
||||
itr->open();
|
||||
itr->hash_check();
|
||||
|
||||
} catch (torrent::local_error& e) {
|
||||
// What to do? Keep in list for now.
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Manager::create_http(const std::string& uri) {
|
||||
core::HttpQueue::iterator itr = m_httpQueue.insert(uri);
|
||||
|
||||
(*itr)->signal_done().slots().push_front(sigc::bind(sigc::mem_fun(*this, &core::Manager::receive_http_done), *itr));
|
||||
// Add the failed signal here.
|
||||
}
|
||||
|
||||
void
|
||||
Manager::receive_http_done(torrent::Http* http) {
|
||||
DownloadList::iterator itr = m_downloadList.end();
|
||||
|
||||
try {
|
||||
itr = m_downloadList.insert(http->get_stream());
|
||||
|
||||
itr->open();
|
||||
itr->hash_check();
|
||||
|
||||
} catch (torrent::local_error& e) {
|
||||
// What to do? Keep in list for now.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef RTORRENT_CORE_MANAGER_H
|
||||
#define RTORRENT_CORE_MANAGER_H
|
||||
|
||||
#include "download_list.h"
|
||||
#include "http_queue.h"
|
||||
|
||||
namespace core {
|
||||
|
||||
class Manager {
|
||||
public:
|
||||
typedef sigc::slot1<void, DownloadList::iterator> SlotReady;
|
||||
typedef sigc::slot0<void> SlotFailed;
|
||||
|
||||
DownloadList& get_download_list() { return m_downloadList; }
|
||||
HttpQueue& get_http_queue() { return m_httpQueue; }
|
||||
|
||||
void insert(const std::string& uri);
|
||||
|
||||
private:
|
||||
void receive_http_done(torrent::Http* http);
|
||||
|
||||
void create_file(const std::string& uri);
|
||||
void create_http(const std::string& uri);
|
||||
|
||||
DownloadList m_downloadList;
|
||||
HttpQueue m_httpQueue;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user