Working on sessions.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@291 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-02-19 21:45:36 +00:00
parent a5f23adc7b
commit 5b050b594b
8 changed files with 168 additions and 1 deletions
+35
View File
@@ -0,0 +1,35 @@
#include "config.h"
#include "download.h"
#include "session_manager.h"
namespace core {
void
SessionManager::activate(const std::string& path) {
m_path = path;
if (m_path.empty())
throw std::logic_error("core::SessionManager::activate(...) received an empty path");
if (m_path.rbegin() != '/')
m_path += '/';
}
void
SessionManager::disable() {
m_path = "";
}
void
SessionManager::save(Download* d) {
std::fstream f(
}
void
SessionManager::remove(Download* d) {
}
}
+27
View File
@@ -0,0 +1,27 @@
#ifndef RTORRENT_CORE_SESSION_MANAGER_H
#define RTORRENT_CORE_SESSION_MANAGER_H
#include <string>
namespace core {
class Download;
class SessionManager {
public:
void activate(const std::string& path);
void disable();
bool is_active() { return !m_path.empty(); }
void save(Download* d);
void remove(Download* d);
private:
std::string m_path;
};
}
#endif
+18
View File
@@ -18,6 +18,7 @@
#include "ui/download_list.h"
#include "input/bindings.h"
#include "utils/timer.h"
#include "utils/directory.h"
#include "signal_handler.h"
#include "option_parser.h"
@@ -69,6 +70,20 @@ do_shutdown(ui::Control* c) {
start_shutdown = false;
}
void
test_dir(const std::string& s) {
utils::Directory d(s);
d.update();
std::cout << "Listing dir \"" << s << '"' << std::endl;
for (utils::Directory::iterator itr = d.begin(); itr != d.end(); ++itr)
std::cout << '"' << *itr << '"' << std::endl;
exit(0);
}
int
main(int argc, char** argv) {
ui::Control uiControl;
@@ -83,6 +98,9 @@ main(int argc, char** argv) {
optionParser.insert_flag('h', sigc::ptr_fun(&print_help));
optionParser.insert_option('p', sigc::bind(sigc::ptr_fun(OptionParser::call_int_pair),
sigc::mem_fun(uiControl.get_core(), &core::Manager::set_port_range)));
// Test function.
optionParser.insert_option('s', sigc::ptr_fun(&test_dir));
int firstArg = optionParser.process(argc, argv);
+2
View File
@@ -1,6 +1,8 @@
noinst_LIBRARIES = libsub_utils.a
libsub_utils_a_SOURCES = \
directory.cc \
directory.h \
functional.h \
parse.cc \
parse.h \
+34
View File
@@ -0,0 +1,34 @@
#include "config.h"
#include <algorithm>
#include <functional>
#include <stdexcept>
#include <dirent.h>
#include "directory.h"
namespace utils {
void
Directory::update() {
if (m_path.empty())
throw std::logic_error("Directory::update() tried to open an empty path");
DIR* d = opendir(m_path.c_str());
if (d == NULL)
throw std::runtime_error("Directory::update() could not open directory");
struct dirent* ent;
while ((ent = readdir(d)) != NULL) {
std::string de(ent->d_name);
if (de != "." && de != "..")
Base::push_back(ent->d_name);
}
std::sort(begin(), end(), std::less<std::string>());
}
}
+39
View File
@@ -0,0 +1,39 @@
#ifndef RTORRENT_UTILS_DIRECTORY_H
#define RTORRENT_UTILS_DIRECTORY_H
#include <string>
#include <vector>
namespace utils {
class Directory : private std::vector<std::string> {
public:
typedef std::vector<std::string> 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;
using Base::empty;
using Base::size;
Directory() {}
Directory(const std::string& path) : m_path(path) {}
void update();
const std::string& get_path() { return m_path; }
private:
std::string m_path;
};
}
#endif
+12 -1
View File
@@ -10,7 +10,6 @@ std::string
escape_string(const std::string& src) {
std::stringstream stream;
// TODO: Correct would be to save the state.
stream << std::hex << std::uppercase;
for (std::string::const_iterator itr = src.begin(); itr != src.end(); ++itr)
@@ -25,4 +24,16 @@ escape_string(const std::string& src) {
return stream.str();
}
std::string
string_to_hex(const std::string& src) {
std::stringstream stream;
stream << std::hex << std::uppercase;
for (std::string::const_iterator itr = src.begin(); itr != src.end(); ++itr)
stream << ((unsigned char)*itr >> 4) << ((unsigned char)*itr & 0xf);
return stream.str();
}
}
+1
View File
@@ -8,6 +8,7 @@ namespace utils {
// Various functinos for manipulating strings.
std::string escape_string(const std::string& src);
std::string string_to_hex(const std::string& src);
}