From 3d1b0b59712f680ccbe4ee271d97ebb2d5d8ecf3 Mon Sep 17 00:00:00 2001 From: rakshasa Date: Mon, 12 Mar 2012 20:55:29 +0900 Subject: [PATCH] Cleaned up old log code. --- src/core/Makefile.am | 2 - src/core/dht_manager.cc | 4 +- src/core/download_factory.cc | 12 ++--- src/core/log.cc | 65 -------------------------- src/core/log.h | 88 ------------------------------------ src/core/manager.cc | 3 -- src/core/manager.h | 11 +---- src/core/poll_manager.cc | 12 ++--- 8 files changed, 13 insertions(+), 184 deletions(-) delete mode 100644 src/core/log.cc delete mode 100644 src/core/log.h diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 57a2a49f..c71f1ce0 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -20,8 +20,6 @@ libsub_core_a_SOURCES = \ download_store.h \ http_queue.cc \ http_queue.h \ - log.cc \ - log.h \ manager.cc \ manager.h \ poll_manager.cc \ diff --git a/src/core/dht_manager.cc b/src/core/dht_manager.cc index 0472d686..a3ca8930 100644 --- a/src/core/dht_manager.cc +++ b/src/core/dht_manager.cc @@ -248,7 +248,7 @@ DhtManager::log_statistics(bool force) { if (m_dhtPrevCycle == 1) { char buffer[128]; snprintf(buffer, sizeof(buffer), "DHT bootstrap complete, have %d nodes in %d buckets.", stats.num_nodes, stats.num_buckets); - control->core()->get_log_complete().push_front(buffer); + control->core()->push_log_complete(buffer); m_dhtPrevCycle = stats.cycle; return false; }; @@ -271,7 +271,7 @@ DhtManager::log_statistics(bool force) { stats.max_peers, stats.num_trackers); - control->core()->get_log_complete().push_front(buffer); + control->core()->push_log_complete(buffer); m_dhtPrevCycle = stats.cycle; m_dhtPrevQueriesSent = stats.queries_sent; diff --git a/src/core/download_factory.cc b/src/core/download_factory.cc index 3f63dc4b..facf9326 100644 --- a/src/core/download_factory.cc +++ b/src/core/download_factory.cc @@ -326,10 +326,8 @@ DownloadFactory::receive_success() { } catch (torrent::input_error& e) { std::string msg = "Command on torrent creation failed: " + std::string(e.what()); - if (m_printLog) { - m_manager->get_log_important().push_front(msg); - m_manager->get_log_complete().push_front(msg); - } + if (m_printLog) + m_manager->push_log_std(msg); if (m_manager->download_list()->find(infohash) != m_manager->download_list()->end()) { // Should stop it, mark it bad. Perhaps even delete it? @@ -345,10 +343,8 @@ DownloadFactory::receive_success() { void DownloadFactory::receive_failed(const std::string& msg) { // Add message to log. - if (m_printLog) { - m_manager->get_log_important().push_front(msg + ": \"" + m_uri + "\""); - m_manager->get_log_complete().push_front(msg + ": \"" + m_uri + "\""); - } + if (m_printLog) + m_manager->push_log_std(msg + ": \"" + m_uri + "\""); m_slotFinished(); } diff --git a/src/core/log.cc b/src/core/log.cc deleted file mode 100644 index 432f69cb..00000000 --- a/src/core/log.cc +++ /dev/null @@ -1,65 +0,0 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - -#include "config.h" - -#include -#include - -#include "globals.h" -#include "log.h" - -namespace core { - -void -Log::push_front(const std::string& msg) { - if (!m_enabled) - return; - - Base::push_front(Type(cachedTime, msg)); - - if (size() > 50) - Base::pop_back(); - - m_signalUpdate.emit(); -} - -Log::iterator -Log::find_older(rak::timer t) { - return std::find_if(begin(), end(), rak::on(rak::mem_ref(&Type::first), std::bind2nd(std::less_equal(), t))); -} - -} diff --git a/src/core/log.h b/src/core/log.h deleted file mode 100644 index 372cdaae..00000000 --- a/src/core/log.h +++ /dev/null @@ -1,88 +0,0 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - -#ifndef RTORRENT_CORE_LOG_H -#define RTORRENT_CORE_LOG_H - -#include -#include -#include - -#include - -namespace core { - -class Log : private std::deque > { -public: - typedef std::pair Type; - typedef std::deque Base; - typedef sigc::signal0 Signal; - - 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; - - Log() : m_enabled(true) {} - - bool is_enabled() const { return m_enabled; } - - void enable() { m_enabled = true; } - void disable() { m_enabled = false; } - - void push_front(const std::string& msg); - - iterator find_older(rak::timer t); - - Signal& signal_update() { return m_signalUpdate; } - -private: - bool m_enabled; - - Signal m_signalUpdate; -}; - -} - -#endif diff --git a/src/core/manager.cc b/src/core/manager.cc index 75b717bd..1348fbf5 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -140,9 +140,6 @@ Manager::push_log(const char* msg) { if (!pthread_equal(pthread_self(), torrent::main_thread()->pthread())) throw torrent::internal_error("Manager::push_log(...): Cannot call this function from other threads than 'main'."); - m_logImportant.push_front(msg); - push_log_complete(msg); - m_log_important->lock_and_push_log(msg, strlen(msg), 0); m_log_complete->lock_and_push_log(msg, strlen(msg), 0); } diff --git a/src/core/manager.h b/src/core/manager.h index d7031f97..cfdae66e 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -46,7 +46,6 @@ #include "download_list.h" #include "poll_manager.h" #include "range_map.h" -#include "log.h" namespace torrent { class Bencode; @@ -86,9 +85,6 @@ public: View* hashing_view() { return m_hashingView; } void set_hashing_view(View* v); - Log& get_log_important() { return m_logImportant; } - Log& get_log_complete() { return m_logComplete; } - torrent::log_buffer* log_important() { return m_log_important; } torrent::log_buffer* log_complete() { return m_log_complete; } @@ -117,8 +113,8 @@ public: void shutdown(bool force); void push_log(const char* msg); - void push_log_std(const std::string& msg) { m_logImportant.push_front(msg); m_logComplete.push_front(msg); } - void push_log_complete(const std::string& msg) { m_logComplete.push_front(msg); } + void push_log_std(const std::string& msg) { m_log_important->lock_and_push_log(msg.c_str(), msg.size(), 0); m_log_complete->lock_and_push_log(msg.c_str(), msg.size(), 0); } + void push_log_complete(const std::string& msg) { m_log_complete->lock_and_push_log(msg.c_str(), msg.size(), 0); } void handshake_log(const sockaddr* sa, int msg, int err, const torrent::HashString* hash); @@ -156,9 +152,6 @@ private: ThrottleMap m_throttles; AddressThrottleMap m_addressThrottles; - Log m_logImportant; - Log m_logComplete; - torrent::log_buffer* m_log_important; torrent::log_buffer* m_log_complete; }; diff --git a/src/core/poll_manager.cc b/src/core/poll_manager.cc index 1023b0f1..1a3a0a51 100644 --- a/src/core/poll_manager.cc +++ b/src/core/poll_manager.cc @@ -52,8 +52,6 @@ namespace core { torrent::Poll* create_poll() { - Log* log = &control->core()->get_log_important(); - const char* poll_name = getenv("RTORRENT_POLL"); int maxOpen = sysconf(_SC_OPEN_MAX); @@ -69,20 +67,20 @@ create_poll() { poll = torrent::PollSelect::create(maxOpen); if (poll == NULL) - log->push_front(std::string("Cannot enable '") + poll_name + "' based polling."); + control->core()->push_log_std(std::string("Cannot enable '") + poll_name + "' based polling."); } if (poll != NULL) - log->push_front(std::string("Using '") + poll_name + "' based polling."); + control->core()->push_log_std(std::string("Using '") + poll_name + "' based polling."); else if ((poll = torrent::PollEPoll::create(maxOpen)) != NULL) - log->push_front("Using 'epoll' based polling."); + control->core()->push_log_std("Using 'epoll' based polling."); else if ((poll = torrent::PollKQueue::create(maxOpen)) != NULL) - log->push_front("Using 'kqueue' based polling."); + control->core()->push_log_std("Using 'kqueue' based polling."); else if ((poll = torrent::PollSelect::create(maxOpen)) != NULL) - log->push_front("Using 'select' based polling."); + control->core()->push_log_std("Using 'select' based polling."); else throw torrent::internal_error("Could not create any Poll object.");