2
* This file is part of nzbget
4
* Copyright (C) 2004 Sven Henkel <sidddy@users.sourceforge.net>
5
* Copyright (C) 2007-2010 Andrei Prygounkov <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., 675 Mass Ave, Cambridge, MA 02139, USA.
22
* $Date: 2010-01-29 10:34:44 +0100 (Fri, 29 Jan 2010) $
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;
68
static const int SPEEDMETER_SLOTS = 30;
69
static const int SPEEDMETER_SLOTSIZE = 1; //Split elapsed time into this number of secs.
70
int m_iSpeedBytes[SPEEDMETER_SLOTS];
71
int m_iSpeedTotalBytes;
72
int m_iSpeedTime[SPEEDMETER_SLOTS];
73
int m_iSpeedStartTime;
75
int m_iSpeedBytesIndex;
76
long long m_iAllBytes;
77
time_t m_tStartServer;
79
time_t m_tStartDownload;
84
bool GetNextArticle(FileInfo* &pFileInfo, ArticleInfo* &pArticleInfo);
85
void StartArticleDownload(FileInfo* pFileInfo, ArticleInfo* pArticleInfo, NNTPConnection* pConnection);
86
void BuildArticleFilename(ArticleDownloader* pArticleDownloader, FileInfo* pFileInfo, ArticleInfo* pArticleInfo);
87
bool IsDupe(FileInfo* pFileInfo);
88
void ArticleCompleted(ArticleDownloader* pArticleDownloader);
89
void DeleteFileInfo(FileInfo* pFileInfo, bool bCompleted);
90
void ResetHangingDownloads();
91
void ResetSpeedStat();
92
void EnterLeaveStandBy(bool bEnter);
93
void AdjustStartTime();
97
virtual ~QueueCoordinator();
100
void Update(Subject* Caller, void* Aspect);
103
long long CalcRemainingSize();
104
virtual float CalcCurrentDownloadSpeed();
105
virtual void AddSpeedReading(int iBytes);
106
void CalcStat(int* iUpTimeSec, int* iDnTimeSec, long long* iAllBytes, bool* bStandBy);
109
DownloadQueue* LockQueue();
111
void AddNZBFileToQueue(NZBFile* pNZBFile, bool bAddFirst);
112
bool HasMoreJobs() { return m_bHasMoreJobs; }
113
bool GetStandBy() { return m_bStandBy; }
114
bool DeleteQueueEntry(FileInfo* pFileInfo);
115
bool SetQueueEntryNZBCategory(NZBInfo* pNZBInfo, const char* szCategory);
116
bool MergeQueueEntries(NZBInfo* pDestNZBInfo, NZBInfo* pSrcNZBInfo);
117
void DiscardDiskFile(FileInfo* pFileInfo);
118
QueueEditor* GetQueueEditor() { return &m_QueueEditor; }