2
* This file is part of nzbget
4
* Copyright (C) 2004 Sven Henkel <sidddy@users.sourceforge.net>
5
* Copyright (C) 2007-2010 Andrey Prygunkov <hugbug@users.sourceforge.net>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
* $Date: 2013-05-26 22:42:15 +0200 (Sun, 26 May 2013) $
27
#ifndef QUEUECOORDINATOR_H
28
#define QUEUECOORDINATOR_H
36
#include "ArticleDownloader.h"
37
#include "DownloadInfo.h"
39
#include "QueueEditor.h"
40
#include "NNTPConnection.h"
42
class QueueCoordinator : public Thread, public Observer, public Subject, public DownloadSpeedMeter, public DownloadQueueHolder
45
typedef std::list<ArticleDownloader*> ActiveDownloads;
54
EAspectAction eAction;
55
DownloadQueue* pDownloadQueue;
61
DownloadQueue m_DownloadQueue;
62
ActiveDownloads m_ActiveDownloads;
63
QueueEditor m_QueueEditor;
64
Mutex m_mutexDownloadQueue;
66
int m_iDownloadsLimit;
69
static const int SPEEDMETER_SLOTS = 30;
70
static const int SPEEDMETER_SLOTSIZE = 1; //Split elapsed time into this number of secs.
71
int m_iSpeedBytes[SPEEDMETER_SLOTS];
72
int m_iSpeedTotalBytes;
73
int m_iSpeedTime[SPEEDMETER_SLOTS];
74
int m_iSpeedStartTime;
75
time_t m_tSpeedCorrection;
77
SpinLock m_spinlockSpeed;
82
int m_iSpeedBytesIndex;
83
long long m_iAllBytes;
84
time_t m_tStartServer;
86
time_t m_tStartDownload;
91
bool GetNextArticle(FileInfo* &pFileInfo, ArticleInfo* &pArticleInfo);
92
void StartArticleDownload(FileInfo* pFileInfo, ArticleInfo* pArticleInfo, NNTPConnection* pConnection);
93
bool IsDupe(FileInfo* pFileInfo);
94
void ArticleCompleted(ArticleDownloader* pArticleDownloader);
95
void DeleteFileInfo(FileInfo* pFileInfo, bool bCompleted);
96
void ResetHangingDownloads();
97
void ResetSpeedStat();
98
void EnterLeaveStandBy(bool bEnter);
99
void AdjustStartTime();
103
virtual ~QueueCoordinator();
106
void Update(Subject* Caller, void* Aspect);
109
long long CalcRemainingSize();
110
virtual int CalcCurrentDownloadSpeed();
111
virtual void AddSpeedReading(int iBytes);
112
void CalcStat(int* iUpTimeSec, int* iDnTimeSec, long long* iAllBytes, bool* bStandBy);
115
DownloadQueue* LockQueue();
117
void AddNZBFileToQueue(NZBFile* pNZBFile, bool bAddFirst);
118
bool HasMoreJobs() { return m_bHasMoreJobs; }
119
bool GetStandBy() { return m_bStandBy; }
120
bool DeleteQueueEntry(FileInfo* pFileInfo);
121
bool SetQueueEntryNZBCategory(NZBInfo* pNZBInfo, const char* szCategory);
122
bool SetQueueEntryNZBName(NZBInfo* pNZBInfo, const char* szName);
123
bool MergeQueueEntries(NZBInfo* pDestNZBInfo, NZBInfo* pSrcNZBInfo);
124
bool SplitQueueEntries(FileQueue* pFileList, const char* szName, NZBInfo** pNewNZBInfo);
125
void DiscardDiskFile(FileInfo* pFileInfo);
126
QueueEditor* GetQueueEditor() { return &m_QueueEditor; }