refactor: reducing dependencies between modules

This commit is contained in:
Andrey Prygunkov
2014-03-20 21:14:39 +00:00
parent bf66500aac
commit 3fd7bbc0a3
19 changed files with 150 additions and 62 deletions

View File

@@ -734,6 +734,18 @@ void NZBList::Clear()
clear();
}
void NZBList::Add(NZBInfo* pNZBInfo, bool bAddTop)
{
if (bAddTop)
{
push_front(pNZBInfo);
}
else
{
push_back(pNZBInfo);
}
}
void NZBList::Remove(NZBInfo* pNZBInfo)
{
iterator it = std::find(begin(), end(), pNZBInfo);

View File

@@ -576,6 +576,7 @@ public:
NZBList(bool bOwnObjects = false) { m_bOwnObjects = bOwnObjects; }
~NZBList();
void Clear();
void Add(NZBInfo* pNZBInfo, bool bAddTop);
void Remove(NZBInfo* pNZBInfo);
};
@@ -822,6 +823,7 @@ protected:
static void Loaded() { g_bLoaded = true; }
public:
virtual ~DownloadQueue() {};
static bool IsLoaded() { return g_bLoaded; }
static DownloadQueue* Lock();
static void Unlock();

View File

@@ -48,7 +48,6 @@
#include "ServerPool.h"
#include "ArticleDownloader.h"
#include "DiskState.h"
#include "Log.h"
#include "Util.h"
#include "Decoder.h"
@@ -90,6 +89,8 @@ QueueCoordinator::QueueCoordinator()
m_bStandBy = true;
m_iServerConfigGeneration = 0;
g_pLog->RegisterDebuggable(this);
m_DownloadQueue.m_pOwner = this;
CoordinatorDownloadQueue::Init(&m_DownloadQueue);
YDecoder::Init();
@@ -100,6 +101,8 @@ QueueCoordinator::~QueueCoordinator()
debug("Destroying QueueCoordinator");
// Cleanup
g_pLog->UnregisterDebuggable(this);
debug("Deleting ArticleDownloaders");
for (ActiveDownloads::iterator it = m_ActiveDownloads.begin(); it != m_ActiveDownloads.end(); it++)
{
@@ -906,10 +909,6 @@ void QueueCoordinator::CheckHealth(DownloadQueue* pDownloadQueue, FileInfo* pFil
void QueueCoordinator::LogDebugInfo()
{
debug("--------------------------------------------");
debug("Dumping debug debug to log");
debug("--------------------------------------------");
debug(" SpeedMeter");
debug(" ----------");
float fSpeed = (float)(CalcCurrentDownloadSpeed() / 1024.0);
@@ -939,8 +938,6 @@ void QueueCoordinator::LogDebugInfo()
DownloadQueue::Unlock();
debug("");
g_pServerPool->LogDebugInfo();
}
void QueueCoordinator::ResetHangingDownloads()

View File

@@ -31,6 +31,7 @@
#include <list>
#include <time.h>
#include "Log.h"
#include "Thread.h"
#include "NZBFile.h"
#include "ArticleDownloader.h"
@@ -39,7 +40,7 @@
#include "QueueEditor.h"
#include "NNTPConnection.h"
class QueueCoordinator : public Thread, public Observer, public DownloadSpeedMeter
class QueueCoordinator : public Thread, public Observer, public DownloadSpeedMeter, public Debuggable
{
public:
typedef std::list<ArticleDownloader*> ActiveDownloads;
@@ -53,7 +54,7 @@ private:
public:
virtual bool EditEntry(int ID, EEditAction eAction, int iOffset, const char* szText);
virtual bool EditList(IDList* pIDList, NameList* pNameList, EMatchMode eMatchMode, EEditAction eAction, int iOffset, const char* szText);
virtual void Save();
virtual void Save();
};
private:
@@ -99,6 +100,9 @@ private:
void AdjustStartTime();
void AdjustDownloadsLimit();
protected:
virtual void LogDebugInfo();
public:
QueueCoordinator();
virtual ~QueueCoordinator();
@@ -111,7 +115,6 @@ public:
virtual int CalcCurrentDownloadSpeed();
virtual void AddSpeedReading(int iBytes);
void CalcStat(int* iUpTimeSec, int* iDnTimeSec, long long* iAllBytes, bool* bStandBy);
void LogDebugInfo();
// editing queue
void AddNZBFileToQueue(NZBFile* pNZBFile, NZBInfo* pUrlInfo, bool bAddFirst);

View File

@@ -44,7 +44,6 @@
#include "UrlCoordinator.h"
#include "Options.h"
#include "WebDownloader.h"
#include "Log.h"
#include "Util.h"
#include "NZBFile.h"
#include "Scanner.h"
@@ -106,6 +105,8 @@ UrlCoordinator::UrlCoordinator()
debug("Creating UrlCoordinator");
m_bHasMoreJobs = true;
g_pLog->RegisterDebuggable(this);
}
UrlCoordinator::~UrlCoordinator()
@@ -113,6 +114,8 @@ UrlCoordinator::~UrlCoordinator()
debug("Destroying UrlCoordinator");
// Cleanup
g_pLog->UnregisterDebuggable(this);
debug("Deleting UrlDownloaders");
for (ActiveDownloads::iterator it = m_ActiveDownloads.begin(); it != m_ActiveDownloads.end(); it++)
{

View File

@@ -1,7 +1,7 @@
/*
* This file is part of nzbget
*
* Copyright (C) 2012-2013 Andrey Prygunkov <hugbug@users.sourceforge.net>
* Copyright (C) 2012-2014 Andrey Prygunkov <hugbug@users.sourceforge.net>
*
* 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
@@ -30,6 +30,7 @@
#include <list>
#include <time.h>
#include "Log.h"
#include "Thread.h"
#include "WebDownloader.h"
#include "DownloadInfo.h"
@@ -37,7 +38,7 @@
class UrlDownloader;
class UrlCoordinator : public Thread, public Observer
class UrlCoordinator : public Thread, public Observer, public Debuggable
{
private:
typedef std::list<UrlDownloader*> ActiveDownloads;
@@ -52,6 +53,9 @@ private:
void UrlCompleted(UrlDownloader* pUrlDownloader);
void ResetHangingDownloads();
protected:
virtual void LogDebugInfo();
public:
UrlCoordinator();
virtual ~UrlCoordinator();
@@ -63,8 +67,6 @@ public:
void AddUrlToQueue(NZBInfo* pNZBInfo, bool bAddTop);
bool HasMoreJobs() { return m_bHasMoreJobs; }
bool DeleteQueueEntry(DownloadQueue* pDownloadQueue, NZBInfo* pNZBInfo, bool bAvoidHistory);
void LogDebugInfo();
};
class UrlDownloader : public WebDownloader