From 3fd7bbc0a3efd4f2fd48eaa0c77fd963c287ebdf Mon Sep 17 00:00:00 2001 From: Andrey Prygunkov Date: Thu, 20 Mar 2014 21:14:39 +0000 Subject: [PATCH] refactor: reducing dependencies between modules --- daemon/connect/WebDownloader.h | 2 +- daemon/feed/FeedCoordinator.cpp | 12 ++++++++---- daemon/feed/FeedCoordinator.h | 8 +++++--- daemon/frontend/Frontend.cpp | 13 ++++++++++--- daemon/nntp/ArticleDownloader.h | 4 ++-- daemon/nntp/ServerPool.cpp | 5 ++++- daemon/nntp/ServerPool.h | 8 +++++--- daemon/queue/DownloadInfo.cpp | 12 ++++++++++++ daemon/queue/DownloadInfo.h | 2 ++ daemon/queue/QueueCoordinator.cpp | 11 ++++------- daemon/queue/QueueCoordinator.h | 9 ++++++--- daemon/queue/UrlCoordinator.cpp | 5 ++++- daemon/queue/UrlCoordinator.h | 10 ++++++---- daemon/remote/BinRpc.cpp | 24 ++++++++++++++++-------- daemon/remote/XmlRpc.cpp | 12 +++++------- daemon/util/Log.cpp | 31 +++++++++++++++++++++++++++++++ daemon/util/Log.h | 16 +++++++++++++++- daemon/util/Observer.cpp | 14 +++++++------- daemon/util/Observer.h | 14 +++++++------- 19 files changed, 150 insertions(+), 62 deletions(-) diff --git a/daemon/connect/WebDownloader.h b/daemon/connect/WebDownloader.h index 1f9322e9..00baeba0 100644 --- a/daemon/connect/WebDownloader.h +++ b/daemon/connect/WebDownloader.h @@ -88,7 +88,7 @@ protected: public: WebDownloader(); - ~WebDownloader(); + virtual ~WebDownloader(); EStatus GetStatus() { return m_eStatus; } virtual void Run(); virtual void Stop(); diff --git a/daemon/feed/FeedCoordinator.cpp b/daemon/feed/FeedCoordinator.cpp index a0e186b1..cb7a0f6a 100644 --- a/daemon/feed/FeedCoordinator.cpp +++ b/daemon/feed/FeedCoordinator.cpp @@ -44,16 +44,13 @@ #include "FeedCoordinator.h" #include "Options.h" #include "WebDownloader.h" -#include "Log.h" #include "Util.h" #include "FeedFile.h" #include "FeedFilter.h" #include "DiskState.h" -#include "UrlCoordinator.h" extern Options* g_pOptions; extern DiskState* g_pDiskState; -extern UrlCoordinator* g_pUrlCoordinator; FeedCoordinator::FeedCacheItem::FeedCacheItem(const char* szUrl, int iCacheTimeSec,const char* szCacheId, time_t tLastUsage, FeedItemInfos* pFeedItemInfos) @@ -79,6 +76,8 @@ FeedCoordinator::FeedCoordinator() m_bForce = false; m_bSave = false; + g_pLog->RegisterDebuggable(this); + m_DownloadQueueObserver.m_pOwner = this; DownloadQueue* pDownloadQueue = DownloadQueue::Lock(); pDownloadQueue->Attach(&m_DownloadQueueObserver); @@ -90,6 +89,8 @@ FeedCoordinator::~FeedCoordinator() debug("Destroying FeedCoordinator"); // Cleanup + g_pLog->UnregisterDebuggable(this); + debug("Deleting FeedDownloaders"); for (ActiveDownloads::iterator it = m_ActiveDownloads.begin(); it != m_ActiveDownloads.end(); it++) { @@ -491,7 +492,10 @@ void FeedCoordinator::DownloadItem(FeedInfo* pFeedInfo, FeedItemInfo* pFeedItemI pNZBInfo->SetDupeScore(pFeedItemInfo->GetDupeScore()); pNZBInfo->SetDupeMode(pFeedItemInfo->GetDupeMode()); - g_pUrlCoordinator->AddUrlToQueue(pNZBInfo, false); + DownloadQueue* pDownloadQueue = DownloadQueue::Lock(); + pDownloadQueue->GetQueue()->Add(pNZBInfo, false); + pDownloadQueue->Save(); + DownloadQueue::Unlock(); } bool FeedCoordinator::ViewFeed(int iID, FeedItemInfos** ppFeedItemInfos) diff --git a/daemon/feed/FeedCoordinator.h b/daemon/feed/FeedCoordinator.h index faad163b..0513e454 100644 --- a/daemon/feed/FeedCoordinator.h +++ b/daemon/feed/FeedCoordinator.h @@ -30,6 +30,7 @@ #include #include +#include "Log.h" #include "Thread.h" #include "WebDownloader.h" #include "DownloadInfo.h" @@ -39,7 +40,7 @@ class FeedDownloader; -class FeedCoordinator : public Thread, public Observer, public Subject +class FeedCoordinator : public Thread, public Observer, public Subject, public Debuggable { private: class DownloadQueueObserver: public Observer @@ -94,6 +95,9 @@ private: void CleanupCache(); void CheckSaveFeeds(); +protected: + virtual void LogDebugInfo(); + public: FeedCoordinator(); virtual ~FeedCoordinator(); @@ -108,8 +112,6 @@ public: void FetchFeed(int iID); bool HasActiveDownloads(); Feeds* GetFeeds() { return &m_Feeds; } - - void LogDebugInfo(); }; class FeedDownloader : public WebDownloader diff --git a/daemon/frontend/Frontend.cpp b/daemon/frontend/Frontend.cpp index 708fdf2c..920782ea 100644 --- a/daemon/frontend/Frontend.cpp +++ b/daemon/frontend/Frontend.cpp @@ -48,12 +48,10 @@ #include "Connection.h" #include "MessageBase.h" #include "QueueCoordinator.h" -#include "PrePostProcessor.h" #include "RemoteClient.h" #include "Util.h" extern QueueCoordinator* g_pQueueCoordinator; -extern PrePostProcessor* g_pPrePostProcessor; extern Options* g_pOptions; Frontend::Frontend() @@ -101,8 +99,17 @@ bool Frontend::PrepareData() m_bPauseDownload = g_pOptions->GetPauseDownload(); m_iDownloadLimit = g_pOptions->GetDownloadRate(); m_iThreadCount = Thread::GetThreadCount(); - m_iPostJobCount = g_pPrePostProcessor->GetJobCount(); g_pQueueCoordinator->CalcStat(&m_iUpTimeSec, &m_iDnTimeSec, &m_iAllBytes, &m_bStandBy); + + DownloadQueue *pDownloadQueue = DownloadQueue::Lock(); + m_iPostJobCount = 0; + for (NZBList::iterator it = pDownloadQueue->GetQueue()->begin(); it != pDownloadQueue->GetQueue()->end(); it++) + { + NZBInfo* pNZBInfo = *it; + m_iPostJobCount += pNZBInfo->GetPostInfo() ? 1 : 0; + } + DownloadQueue::Unlock(); + } } return true; diff --git a/daemon/nntp/ArticleDownloader.h b/daemon/nntp/ArticleDownloader.h index 5ca2ca12..b80279e1 100644 --- a/daemon/nntp/ArticleDownloader.h +++ b/daemon/nntp/ArticleDownloader.h @@ -2,7 +2,7 @@ * This file is part of nzbget * * Copyright (C) 2004 Sven Henkel - * Copyright (C) 2007-2013 Andrey Prygunkov + * Copyright (C) 2007-2014 Andrey Prygunkov * * 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 @@ -89,7 +89,7 @@ private: public: ArticleDownloader(); - ~ArticleDownloader(); + virtual ~ArticleDownloader(); void SetFileInfo(FileInfo* pFileInfo) { m_pFileInfo = pFileInfo; } FileInfo* GetFileInfo() { return m_pFileInfo; } void SetArticleInfo(ArticleInfo* pArticleInfo) { m_pArticleInfo = pArticleInfo; } diff --git a/daemon/nntp/ServerPool.cpp b/daemon/nntp/ServerPool.cpp index 61e3e6b7..61e8c499 100644 --- a/daemon/nntp/ServerPool.cpp +++ b/daemon/nntp/ServerPool.cpp @@ -42,7 +42,6 @@ #include "nzbget.h" #include "ServerPool.h" -#include "Log.h" static const int CONNECTION_HOLD_SECODNS = 5; @@ -59,12 +58,16 @@ ServerPool::ServerPool() m_iMaxNormLevel = 0; m_iTimeout = 60; m_iGeneration = 0; + + g_pLog->RegisterDebuggable(this); } ServerPool::~ ServerPool() { debug("Destroying ServerPool"); + g_pLog->UnregisterDebuggable(this); + m_Levels.clear(); for (Servers::iterator it = m_Servers.begin(); it != m_Servers.end(); it++) diff --git a/daemon/nntp/ServerPool.h b/daemon/nntp/ServerPool.h index 4f46ab68..3b27af44 100644 --- a/daemon/nntp/ServerPool.h +++ b/daemon/nntp/ServerPool.h @@ -30,11 +30,12 @@ #include #include +#include "Log.h" #include "Thread.h" #include "NewsServer.h" #include "NNTPConnection.h" -class ServerPool +class ServerPool : public Debuggable { private: class PooledConnection : public NNTPConnection @@ -65,6 +66,9 @@ private: void NormalizeLevels(); static bool CompareServers(NewsServer* pServer1, NewsServer* pServer2); +protected: + virtual void LogDebugInfo(); + public: ServerPool(); ~ServerPool(); @@ -78,8 +82,6 @@ public: void CloseUnusedConnections(); void Changed(); int GetGeneration() { return m_iGeneration; } - - void LogDebugInfo(); }; #endif diff --git a/daemon/queue/DownloadInfo.cpp b/daemon/queue/DownloadInfo.cpp index 29d33aaf..f7a7fbed 100644 --- a/daemon/queue/DownloadInfo.cpp +++ b/daemon/queue/DownloadInfo.cpp @@ -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); diff --git a/daemon/queue/DownloadInfo.h b/daemon/queue/DownloadInfo.h index db7ba5a9..01f31f8f 100644 --- a/daemon/queue/DownloadInfo.h +++ b/daemon/queue/DownloadInfo.h @@ -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(); diff --git a/daemon/queue/QueueCoordinator.cpp b/daemon/queue/QueueCoordinator.cpp index 661c8434..d31e6988 100644 --- a/daemon/queue/QueueCoordinator.cpp +++ b/daemon/queue/QueueCoordinator.cpp @@ -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() diff --git a/daemon/queue/QueueCoordinator.h b/daemon/queue/QueueCoordinator.h index abdb8f5c..d4b79f55 100644 --- a/daemon/queue/QueueCoordinator.h +++ b/daemon/queue/QueueCoordinator.h @@ -31,6 +31,7 @@ #include #include +#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 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); diff --git a/daemon/queue/UrlCoordinator.cpp b/daemon/queue/UrlCoordinator.cpp index e7e327f7..3b86bbcc 100644 --- a/daemon/queue/UrlCoordinator.cpp +++ b/daemon/queue/UrlCoordinator.cpp @@ -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++) { diff --git a/daemon/queue/UrlCoordinator.h b/daemon/queue/UrlCoordinator.h index d7c986c3..81957f94 100644 --- a/daemon/queue/UrlCoordinator.h +++ b/daemon/queue/UrlCoordinator.h @@ -1,7 +1,7 @@ /* * This file is part of nzbget * - * Copyright (C) 2012-2013 Andrey Prygunkov + * Copyright (C) 2012-2014 Andrey Prygunkov * * 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 #include +#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 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 diff --git a/daemon/remote/BinRpc.cpp b/daemon/remote/BinRpc.cpp index ce3038de..38642e71 100644 --- a/daemon/remote/BinRpc.cpp +++ b/daemon/remote/BinRpc.cpp @@ -47,17 +47,13 @@ #include "Log.h" #include "Options.h" #include "QueueCoordinator.h" -#include "UrlCoordinator.h" #include "QueueEditor.h" -#include "PrePostProcessor.h" #include "Util.h" #include "DownloadInfo.h" #include "Scanner.h" extern Options* g_pOptions; extern QueueCoordinator* g_pQueueCoordinator; -extern UrlCoordinator* g_pUrlCoordinator; -extern PrePostProcessor* g_pPrePostProcessor; extern Scanner* g_pScanner; extern void ExitProc(); extern void Reload(); @@ -286,8 +282,7 @@ void DumpDebugBinCommand::Execute() return; } - g_pQueueCoordinator->LogDebugInfo(); - g_pUrlCoordinator->LogDebugInfo(); + g_pLog->LogDebugInfo(); SendBoolResponse(true, "Debug-Command completed successfully"); } @@ -587,7 +582,17 @@ void ListBinCommand::Execute() ListResponse.m_bPostPaused = htonl(g_pOptions->GetPausePostProcess()); ListResponse.m_bScanPaused = htonl(g_pOptions->GetPauseScan()); ListResponse.m_iThreadCount = htonl(Thread::GetThreadCount() - 1); // not counting itself - ListResponse.m_iPostJobCount = htonl(g_pPrePostProcessor->GetJobCount()); + + DownloadQueue *pDownloadQueue = DownloadQueue::Lock(); + int iPostJobCount = 0; + for (NZBList::iterator it = pDownloadQueue->GetQueue()->begin(); it != pDownloadQueue->GetQueue()->end(); it++) + { + NZBInfo* pNZBInfo = *it; + iPostJobCount += pNZBInfo->GetPostInfo() ? 1 : 0; + } + DownloadQueue::Unlock(); + + ListResponse.m_iPostJobCount = htonl(iPostJobCount); int iUpTimeSec, iDnTimeSec; long long iAllBytes; @@ -1069,7 +1074,10 @@ void DownloadUrlBinCommand::Execute() pNZBInfo->SetPriority(ntohl(DownloadUrlRequest.m_iPriority)); pNZBInfo->SetAddUrlPaused(ntohl(DownloadUrlRequest.m_bAddPaused)); - g_pUrlCoordinator->AddUrlToQueue(pNZBInfo, ntohl(DownloadUrlRequest.m_bAddFirst)); + DownloadQueue* pDownloadQueue = DownloadQueue::Lock(); + pDownloadQueue->GetQueue()->Add(pNZBInfo, ntohl(DownloadUrlRequest.m_bAddFirst)); + pDownloadQueue->Save(); + DownloadQueue::Unlock(); info("Request: Queue url %s", DownloadUrlRequest.m_szURL); diff --git a/daemon/remote/XmlRpc.cpp b/daemon/remote/XmlRpc.cpp index 92be4422..ca4a41e9 100644 --- a/daemon/remote/XmlRpc.cpp +++ b/daemon/remote/XmlRpc.cpp @@ -44,7 +44,6 @@ #include "Log.h" #include "Options.h" #include "QueueCoordinator.h" -#include "UrlCoordinator.h" #include "QueueEditor.h" #include "Scanner.h" #include "FeedCoordinator.h" @@ -55,7 +54,6 @@ extern Options* g_pOptions; extern QueueCoordinator* g_pQueueCoordinator; -extern UrlCoordinator* g_pUrlCoordinator; extern Scanner* g_pScanner; extern FeedCoordinator* g_pFeedCoordinator; extern ServerPool* g_pServerPool; @@ -63,7 +61,6 @@ extern Maintenance* g_pMaintenance; extern void ExitProc(); extern void Reload(); - class ErrorXmlCommand: public XmlCommand { private: @@ -1093,9 +1090,7 @@ void VersionXmlCommand::Execute() void DumpDebugXmlCommand::Execute() { - g_pQueueCoordinator->LogDebugInfo(); - g_pUrlCoordinator->LogDebugInfo(); - g_pFeedCoordinator->LogDebugInfo(); + g_pLog->LogDebugInfo(); BuildBoolResponse(true); } @@ -2530,7 +2525,10 @@ void DownloadUrlXmlCommand::Execute() pNZBInfo->MakeNiceUrlName(szURL, szNZBFileName, szNicename, sizeof(szNicename)); info("Queue %s", szNicename); - g_pUrlCoordinator->AddUrlToQueue(pNZBInfo, bAddTop); + DownloadQueue* pDownloadQueue = DownloadQueue::Lock(); + pDownloadQueue->GetQueue()->Add(pNZBInfo, bAddTop); + pDownloadQueue->Save(); + DownloadQueue::Unlock(); BuildBoolResponse(true); } diff --git a/daemon/util/Log.cpp b/daemon/util/Log.cpp index b5f1dffd..abcc683a 100644 --- a/daemon/util/Log.cpp +++ b/daemon/util/Log.cpp @@ -63,6 +63,23 @@ Log::~Log() free(m_szLogFilename); } +void Log::LogDebugInfo() +{ + debug("--------------------------------------------"); + debug("Dumping debug debug to log"); + debug("--------------------------------------------"); + + m_mutexDebug.Lock(); + for (Debuggables::iterator it = m_Debuggables.begin(); it != m_Debuggables.end(); it++) + { + Debuggable* pDebuggable = *it; + pDebuggable->LogDebugInfo(); + } + m_mutexDebug.Unlock(); + + debug(""); +} + void Log::Filelog(const char* msg, ...) { if (m_szLogFilename) @@ -412,3 +429,17 @@ void Log::InitOptions() } } } + +void Log::RegisterDebuggable(Debuggable* pDebuggable) +{ + m_mutexDebug.Lock(); + m_Debuggables.push_back(pDebuggable); + m_mutexDebug.Unlock(); +} + +void Log::UnregisterDebuggable(Debuggable* pDebuggable) +{ + m_mutexDebug.Lock(); + m_Debuggables.remove(pDebuggable); + m_mutexDebug.Unlock(); +} diff --git a/daemon/util/Log.h b/daemon/util/Log.h index ef1c3199..b2773073 100644 --- a/daemon/util/Log.h +++ b/daemon/util/Log.h @@ -2,7 +2,7 @@ * This file is part of nzbget * * Copyright (C) 2004 Sven Henkel - * Copyright (C) 2007-2009 Andrey Prygunkov + * Copyright (C) 2007-2014 Andrey Prygunkov * * 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 @@ -28,6 +28,7 @@ #define LOG_H #include +#include #include #include "Thread.h" @@ -75,14 +76,24 @@ public: const char* GetText() { return m_szText; } }; +class Debuggable +{ +protected: + virtual void LogDebugInfo() = 0; + friend class Log; +}; + class Log { public: typedef std::deque Messages; + typedef std::list Debuggables; private: Mutex m_mutexLog; Messages m_Messages; + Debuggables m_Debuggables; + Mutex m_mutexDebug; char* m_szLogFilename; unsigned int m_iIDGen; #ifdef DEBUG @@ -113,6 +124,9 @@ public: void Clear(); void ResetLog(); void InitOptions(); + void RegisterDebuggable(Debuggable* pDebuggable); + void UnregisterDebuggable(Debuggable* pDebuggable); + void LogDebugInfo(); }; #ifdef DEBUG diff --git a/daemon/util/Observer.cpp b/daemon/util/Observer.cpp index 142824cc..0b7af324 100644 --- a/daemon/util/Observer.cpp +++ b/daemon/util/Observer.cpp @@ -2,7 +2,7 @@ * This file if part of nzbget * * Copyright (C) 2004 Sven Henkel - * Copyright (C) 2007 Andrey Prygunkov + * Copyright (C) 2007-2014 Andrey Prygunkov * * 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 @@ -40,23 +40,23 @@ Subject::Subject() m_Observers.clear(); } -void Subject::Attach(Observer* Observer) +void Subject::Attach(Observer* pObserver) { - m_Observers.push_back(Observer); + m_Observers.push_back(pObserver); } -void Subject::Detach(Observer* Observer) +void Subject::Detach(Observer* pObserver) { - m_Observers.remove(Observer); + m_Observers.remove(pObserver); } -void Subject::Notify(void* Aspect) +void Subject::Notify(void* pAspect) { debug("Notifying observers"); for (std::list::iterator it = m_Observers.begin(); it != m_Observers.end(); it++) { Observer* Observer = *it; - Observer->Update(this, Aspect); + Observer->Update(this, pAspect); } } diff --git a/daemon/util/Observer.h b/daemon/util/Observer.h index 26eb7696..92b24cae 100644 --- a/daemon/util/Observer.h +++ b/daemon/util/Observer.h @@ -2,7 +2,7 @@ * This file if part of nzbget * * Copyright (C) 2004 Sven Henkel - * Copyright (C) 2007 Andrey Prygunkov + * Copyright (C) 2007-2014 Andrey Prygunkov * * 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 @@ -38,16 +38,16 @@ private: public: Subject(); - void Attach(Observer* Observer); - void Detach(Observer* Observer); - void Notify(void* Aspect); + void Attach(Observer* pObserver); + void Detach(Observer* pObserver); + void Notify(void* pAspect); }; class Observer { -public: - virtual ~Observer() {}; - virtual void Update(Subject* Caller, void* Aspect) = 0; +protected: + virtual void Update(Subject* pCaller, void* pAspect) = 0; + friend class Subject; }; #endif