2
* This file is part of nzbget
4
* Copyright (C) 2013-2014 Andrey Prygunkov <hugbug@users.sourceforge.net>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
* $Date: 2014-05-17 23:39:49 +0200 (Sat, 17 May 2014) $
26
#ifndef FEEDCOORDINATOR_H
27
#define FEEDCOORDINATOR_H
35
#include "WebDownloader.h"
36
#include "DownloadInfo.h"
43
class FeedCoordinator : public Thread, public Observer, public Subject, public Debuggable
46
class DownloadQueueObserver: public Observer
49
FeedCoordinator* m_pOwner;
50
virtual void Update(Subject* pCaller, void* pAspect) { m_pOwner->DownloadQueueUpdate(pCaller, pAspect); }
60
FeedItemInfos* m_pFeedItemInfos;
63
FeedCacheItem(const char* szUrl, int iCacheTimeSec,const char* szCacheId,
64
time_t tLastUsage, FeedItemInfos* pFeedItemInfos);
66
const char* GetUrl() { return m_szUrl; }
67
int GetCacheTimeSec() { return m_iCacheTimeSec; }
68
const char* GetCacheId() { return m_szCacheId; }
69
time_t GetLastUsage() { return m_tLastUsage; }
70
void SetLastUsage(time_t tLastUsage) { m_tLastUsage = tLastUsage; }
71
FeedItemInfos* GetFeedItemInfos() { return m_pFeedItemInfos; }
74
typedef std::deque<FeedCacheItem*> FeedCache;
75
typedef std::list<FeedDownloader*> ActiveDownloads;
79
ActiveDownloads m_ActiveDownloads;
80
FeedHistory m_FeedHistory;
81
Mutex m_mutexDownloads;
82
DownloadQueueObserver m_DownloadQueueObserver;
85
FeedCache m_FeedCache;
87
void StartFeedDownload(FeedInfo* pFeedInfo, bool bForce);
88
void FeedCompleted(FeedDownloader* pFeedDownloader);
89
void FilterFeed(FeedInfo* pFeedInfo, FeedItemInfos* pFeedItemInfos);
90
void ProcessFeed(FeedInfo* pFeedInfo, FeedItemInfos* pFeedItemInfos, NZBList* pAddedNZBs);
91
NZBInfo* CreateNZBInfo(FeedInfo* pFeedInfo, FeedItemInfo* pFeedItemInfo);
92
void ResetHangingDownloads();
93
void DownloadQueueUpdate(Subject* pCaller, void* pAspect);
94
void CleanupHistory();
96
void CheckSaveFeeds();
99
virtual void LogDebugInfo();
103
virtual ~FeedCoordinator();
106
void Update(Subject* pCaller, void* pAspect);
107
void AddFeed(FeedInfo* pFeedInfo);
108
bool PreviewFeed(const char* szName, const char* szUrl, const char* szFilter,
109
bool bPauseNzb, const char* szCategory, int iPriority,
110
int iCacheTimeSec, const char* szCacheId, FeedItemInfos** ppFeedItemInfos);
111
bool ViewFeed(int iID, FeedItemInfos** ppFeedItemInfos);
112
void FetchFeed(int iID);
113
bool HasActiveDownloads();
114
Feeds* GetFeeds() { return &m_Feeds; }
117
class FeedDownloader : public WebDownloader
120
FeedInfo* m_pFeedInfo;
123
void SetFeedInfo(FeedInfo* pFeedInfo) { m_pFeedInfo = pFeedInfo; }
124
FeedInfo* GetFeedInfo() { return m_pFeedInfo; }