From a5f23adc7b57627b538eb31b9c64f04ff311a215 Mon Sep 17 00:00:00 2001 From: rakshasa Date: Sat, 19 Feb 2005 17:27:29 +0000 Subject: [PATCH] Reorganized, moing stuff to src/utils subdir. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@290 e378c898-3ddf-0310-93e7-cc216c733640 --- configure.ac | 3 ++- src/Makefile.am | 12 +++++------- src/core/curl_stack.cc | 2 +- src/core/hash_queue.cc | 2 +- src/core/http_queue.cc | 3 +-- src/display/manager.cc | 2 +- src/display/window.h | 4 ++-- src/display/window_download_list.cc | 4 ++-- src/display/window_download_statusbar.cc | 4 ++-- src/display/window_http_queue.cc | 10 +++++----- src/display/window_http_queue.h | 2 +- src/display/window_input.cc | 2 +- src/display/window_peer_info.cc | 10 +++++----- src/display/window_peer_list.cc | 4 ++-- src/display/window_statusbar.cc | 4 ++-- src/display/window_title.cc | 4 ++-- src/main.cc | 6 +++--- src/utils/Makefile.am | 9 +++++++++ src/{ => utils}/functional.h | 0 src/{ => utils}/parse.cc | 6 +++++- src/{ => utils}/parse.h | 8 ++++++-- src/{ => utils}/timer.h | 4 ++++ 22 files changed, 62 insertions(+), 43 deletions(-) create mode 100644 src/utils/Makefile.am rename src/{ => utils}/functional.h (100%) rename src/{ => utils}/parse.cc (92%) rename src/{ => utils}/parse.h (60%) rename src/{ => utils}/timer.h (98%) diff --git a/configure.ac b/configure.ac index 5ef2eafa..c3a17f1e 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT(rtorrent, 0.0.2, jaris@ifi.uio.no) +AC_INIT(rtorrent, 0.0.3, jaris@ifi.uio.no) AM_INIT_AUTOMAKE AM_CONFIG_HEADER(config.h) @@ -52,4 +52,5 @@ AC_OUTPUT([ src/display/Makefile src/input/Makefile src/ui/Makefile + src/utils/Makefile ]) diff --git a/src/Makefile.am b/src/Makefile.am index c9d45910..49848088 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,7 +2,8 @@ SUBDIRS = \ core \ display \ input \ - ui + ui \ + utils bin_PROGRAMS = rtorrent @@ -10,15 +11,12 @@ rtorrent_LDADD = \ $(top_srcdir)/src/ui/libsub_ui.a \ $(top_srcdir)/src/core/libsub_core.a \ $(top_srcdir)/src/display/libsub_display.a \ - $(top_srcdir)/src/input/libsub_input.a + $(top_srcdir)/src/input/libsub_input.a \ + $(top_srcdir)/src/utils/libsub_utils.a rtorrent_SOURCES = \ - functional.h \ main.cc \ option_parser.cc \ option_parser.h \ - parse.cc \ - parse.h \ signal_handler.cc \ - signal_handler.h \ - timer.h + signal_handler.h diff --git a/src/core/curl_stack.cc b/src/core/curl_stack.cc index 0ab075cf..ca8ff968 100644 --- a/src/core/curl_stack.cc +++ b/src/core/curl_stack.cc @@ -4,7 +4,7 @@ #include #include -#include "functional.h" +#include "utils/functional.h" #include "curl_get.h" #include "curl_stack.h" diff --git a/src/core/hash_queue.cc b/src/core/hash_queue.cc index ef99486e..6ea2605a 100644 --- a/src/core/hash_queue.cc +++ b/src/core/hash_queue.cc @@ -5,7 +5,7 @@ #include #include "download.h" -#include "functional.h" +#include "utils/functional.h" #include "hash_queue.h" namespace core { diff --git a/src/core/http_queue.cc b/src/core/http_queue.cc index a4fc59ea..8b23a01c 100644 --- a/src/core/http_queue.cc +++ b/src/core/http_queue.cc @@ -2,12 +2,11 @@ #include #include -#include #include #include #include -#include "functional.h" +#include "utils/functional.h" #include "http_queue.h" #include "curl_get.h" diff --git a/src/display/manager.cc b/src/display/manager.cc index 828be52a..c6b42e1b 100644 --- a/src/display/manager.cc +++ b/src/display/manager.cc @@ -3,7 +3,7 @@ #include #include -#include "functional.h" +#include "utils/functional.h" #include "canvas.h" #include "manager.h" diff --git a/src/display/window.h b/src/display/window.h index c14b621d..d1207770 100644 --- a/src/display/window.h +++ b/src/display/window.h @@ -1,7 +1,7 @@ #ifndef RTORRENT_WINDOW_BASE_H #define RTORRENT_WINDOW_BASE_H -#include "timer.h" +#include "utils/timer.h" namespace display { @@ -40,7 +40,7 @@ protected: bool m_dynamic; int m_minHeight; - Timer m_lastDraw; + utils::Timer m_lastDraw; }; } diff --git a/src/display/window_download_list.cc b/src/display/window_download_list.cc index eda2edb5..4d07d4dd 100644 --- a/src/display/window_download_list.cc +++ b/src/display/window_download_list.cc @@ -14,10 +14,10 @@ WindowDownloadList::WindowDownloadList(DList* l, DList::iterator* f) : void WindowDownloadList::redraw() { - if (Timer::cache() - m_lastDraw < 1000000) + if (utils::Timer::cache() - m_lastDraw < 1000000) return; - m_lastDraw = Timer::cache(); + m_lastDraw = utils::Timer::cache(); m_canvas->erase(); diff --git a/src/display/window_download_statusbar.cc b/src/display/window_download_statusbar.cc index 247dbe04..f70f5970 100644 --- a/src/display/window_download_statusbar.cc +++ b/src/display/window_download_statusbar.cc @@ -15,10 +15,10 @@ WindowDownloadStatusbar::WindowDownloadStatusbar(core::Download* d) : void WindowDownloadStatusbar::redraw() { - if (Timer::cache() - m_lastDraw < 1000000) + if (utils::Timer::cache() - m_lastDraw < 1000000) return; - m_lastDraw = Timer::cache(); + m_lastDraw = utils::Timer::cache(); m_canvas->erase(); diff --git a/src/display/window_http_queue.cc b/src/display/window_http_queue.cc index 24ca3097..4ee571e3 100644 --- a/src/display/window_http_queue.cc +++ b/src/display/window_http_queue.cc @@ -6,7 +6,7 @@ #include "core/http_queue.h" #include "canvas.h" -#include "functional.h" +#include "utils/functional.h" #include "window_http_queue.h" namespace display { @@ -22,10 +22,10 @@ WindowHttpQueue::WindowHttpQueue(core::HttpQueue* q) : void WindowHttpQueue::redraw() { - if (Timer::cache() - m_lastDraw < 1000000) + if (utils::Timer::cache() - m_lastDraw < 1000000) return; - m_lastDraw = Timer::cache(); + m_lastDraw = utils::Timer::cache(); cleanup_list(); @@ -62,7 +62,7 @@ WindowHttpQueue::redraw() { void WindowHttpQueue::cleanup_list() { for (Container::iterator itr = m_container.begin(); itr != m_container.end();) - if (itr->m_http == NULL && itr->m_timer < Timer::cache()) + if (itr->m_http == NULL && itr->m_timer < utils::Timer::cache()) itr = m_container.erase(itr); else ++itr; @@ -112,7 +112,7 @@ WindowHttpQueue::receive_erase(core::CurlGet* h) { throw std::logic_error("WindowHttpQueue::receive_erase(...) tried to remove an object we don't have"); itr->m_http = NULL; - itr->m_timer = Timer::cache() + 10000000; + itr->m_timer = utils::Timer::cache() + 10000000; mark_dirty(); } diff --git a/src/display/window_http_queue.h b/src/display/window_http_queue.h index ec6da5d7..bcc2491b 100644 --- a/src/display/window_http_queue.h +++ b/src/display/window_http_queue.h @@ -32,7 +32,7 @@ private: core::CurlGet* m_http; std::string m_name; - Timer m_timer; + utils::Timer m_timer; }; typedef std::list Container; diff --git a/src/display/window_input.cc b/src/display/window_input.cc index dbc71924..c2d7360b 100644 --- a/src/display/window_input.cc +++ b/src/display/window_input.cc @@ -18,7 +18,7 @@ WindowInput::redraw() { if (!is_dirty()) return; - m_lastDraw = Timer::cache(); + m_lastDraw = utils::Timer::cache(); m_canvas->erase(); m_canvas->print(0, 0, "> %s", m_input->c_str()); diff --git a/src/display/window_peer_info.cc b/src/display/window_peer_info.cc index 06c8ab27..0637577b 100644 --- a/src/display/window_peer_info.cc +++ b/src/display/window_peer_info.cc @@ -4,7 +4,7 @@ #include "core/download.h" -#include "parse.h" +#include "utils/parse.h" #include "canvas.h" #include "window_peer_info.h" @@ -19,15 +19,15 @@ WindowPeerInfo::WindowPeerInfo(core::Download* d, PList* l, PList::iterator* f) void WindowPeerInfo::redraw() { - if (Timer::cache() - m_lastDraw < 1000000) + if (utils::Timer::cache() - m_lastDraw < 1000000) return; - m_lastDraw = Timer::cache(); + m_lastDraw = utils::Timer::cache(); m_canvas->erase(); int y = 0; - m_canvas->print(0, y++, "Hash: %s", escape_string(m_download->get_download().get_hash()).c_str()); + m_canvas->print(0, y++, "Hash: %s", utils::escape_string(m_download->get_download().get_hash()).c_str()); m_canvas->print(0, y++, "Chunks: %u / %u * %u", m_download->get_download().get_chunks_done(), m_download->get_download().get_chunks_total(), @@ -42,7 +42,7 @@ WindowPeerInfo::redraw() { } m_canvas->print(0, y++, "DNS: %s:%hu", (*m_focus)->get_dns().c_str(), (*m_focus)->get_port()); - m_canvas->print(0, y++, "Id: %s" , escape_string((*m_focus)->get_id()).c_str()); + m_canvas->print(0, y++, "Id: %s" , utils::escape_string((*m_focus)->get_id()).c_str()); m_canvas->print(0, y++, "Snubbed: %s", (*m_focus)->get_snubbed() ? "Yes" : "No"); m_canvas->print(0, y++, "Done: %i%", (*m_focus)->get_chunks_done()); diff --git a/src/display/window_peer_list.cc b/src/display/window_peer_list.cc index 1b8d1102..180b9875 100644 --- a/src/display/window_peer_list.cc +++ b/src/display/window_peer_list.cc @@ -15,10 +15,10 @@ WindowPeerList::WindowPeerList(PList* l, PList::iterator* f) : void WindowPeerList::redraw() { - if (Timer::cache() - m_lastDraw < 1000000) + if (utils::Timer::cache() - m_lastDraw < 1000000) return; - m_lastDraw = Timer::cache(); + m_lastDraw = utils::Timer::cache(); m_canvas->erase(); int x = 2; diff --git a/src/display/window_statusbar.cc b/src/display/window_statusbar.cc index dbdd5230..5cc5bb2a 100644 --- a/src/display/window_statusbar.cc +++ b/src/display/window_statusbar.cc @@ -16,10 +16,10 @@ void WindowStatusbar::redraw() { m_counter++; - if (Timer::cache() - m_lastDraw < 10000000) + if (utils::Timer::cache() - m_lastDraw < 10000000) return; - m_lastDraw = Timer::cache(); + m_lastDraw = utils::Timer::cache(); m_canvas->erase(); m_canvas->print(0, 0, "Throttle: %i Listen: %s:%i Handshakes: %i Select: %u", diff --git a/src/display/window_title.cc b/src/display/window_title.cc index 394d66d4..65c0e0ff 100644 --- a/src/display/window_title.cc +++ b/src/display/window_title.cc @@ -12,10 +12,10 @@ WindowTitle::WindowTitle(const std::string& s) : void WindowTitle::redraw() { - if (Timer::cache() - m_lastDraw < 10000000) + if (utils::Timer::cache() - m_lastDraw < 10000000) return; - m_lastDraw = Timer::cache(); + m_lastDraw = utils::Timer::cache(); m_canvas->erase(); m_canvas->print(std::max(0, (m_canvas->get_width() - (int)m_title.size()) / 2 - 4), 0, diff --git a/src/main.cc b/src/main.cc index fb50fae3..6b114ee3 100644 --- a/src/main.cc +++ b/src/main.cc @@ -17,12 +17,12 @@ #include "ui/control.h" #include "ui/download_list.h" #include "input/bindings.h" +#include "utils/timer.h" -#include "timer.h" #include "signal_handler.h" #include "option_parser.h" -int64_t Timer::m_cache; +int64_t utils::Timer::m_cache; bool start_shutdown = false; bool is_shutting_down = false; @@ -114,7 +114,7 @@ main(int argc, char** argv) { if (start_shutdown) do_shutdown(&uiControl); - Timer::update(); + utils::Timer::update(); uiControl.get_display().do_update(); diff --git a/src/utils/Makefile.am b/src/utils/Makefile.am new file mode 100644 index 00000000..677ad837 --- /dev/null +++ b/src/utils/Makefile.am @@ -0,0 +1,9 @@ +noinst_LIBRARIES = libsub_utils.a + +libsub_utils_a_SOURCES = \ + functional.h \ + parse.cc \ + parse.h \ + timer.h + +INCLUDES = -I$(srcdir) -I$(srcdir)/.. -I$(top_srcdir) diff --git a/src/functional.h b/src/utils/functional.h similarity index 100% rename from src/functional.h rename to src/utils/functional.h diff --git a/src/parse.cc b/src/utils/parse.cc similarity index 92% rename from src/parse.cc rename to src/utils/parse.cc index 765b9988..3fa1d82f 100644 --- a/src/parse.cc +++ b/src/utils/parse.cc @@ -2,7 +2,9 @@ #include -#include "parse.h" +#include "utils/parse.h" + +namespace utils { std::string escape_string(const std::string& src) { @@ -22,3 +24,5 @@ escape_string(const std::string& src) { return stream.str(); } + +} diff --git a/src/parse.h b/src/utils/parse.h similarity index 60% rename from src/parse.h rename to src/utils/parse.h index 6bad0a24..9af051b7 100644 --- a/src/parse.h +++ b/src/utils/parse.h @@ -1,10 +1,14 @@ -#ifndef RTORRENT_PARSE_H -#define RTORRENT_PARSE_H +#ifndef RTORRENT_UTILS_PARSE_H +#define RTORRENT_UTILS_PARSE_H #include +namespace utils { + // Various functinos for manipulating strings. std::string escape_string(const std::string& src); +} + #endif diff --git a/src/timer.h b/src/utils/timer.h similarity index 98% rename from src/timer.h rename to src/utils/timer.h index 56bb483a..c5edbe48 100644 --- a/src/timer.h +++ b/src/utils/timer.h @@ -4,6 +4,8 @@ #include #include +namespace utils { + // Don't convert negative Timer to timeval. class Timer { public: @@ -53,4 +55,6 @@ class Timer { static int64_t m_cache; }; +} + #endif // LIBTORRENT_TIMER_H