Cleaned up old log code.

This commit is contained in:
rakshasa
2012-03-12 20:55:29 +09:00
parent 7e0d5956b5
commit 3d1b0b5971
8 changed files with 13 additions and 184 deletions
-2
View File
@@ -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 \
+2 -2
View File
@@ -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;
+4 -8
View File
@@ -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();
}
-65
View File
@@ -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 <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#include "config.h"
#include <algorithm>
#include <rak/functional.h>
#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<rak::timer>(), t)));
}
}
-88
View File
@@ -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 <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#ifndef RTORRENT_CORE_LOG_H
#define RTORRENT_CORE_LOG_H
#include <deque>
#include <string>
#include <sigc++/signal.h>
#include <rak/timer.h>
namespace core {
class Log : private std::deque<std::pair<rak::timer, std::string> > {
public:
typedef std::pair<rak::timer, std::string> Type;
typedef std::deque<Type> Base;
typedef sigc::signal0<void> 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
-3
View File
@@ -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);
}
+2 -9
View File
@@ -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;
};
+5 -7
View File
@@ -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.");