~ubuntu-branches/debian/experimental/nzbget/experimental

« back to all changes in this revision

Viewing changes to QueueCoordinator.h

  • Committer: Package Import Robot
  • Author(s): Andreas Moog
  • Date: 2014-12-25 12:58:06 UTC
  • mfrom: (1.2.1) (3.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20141225125806-vnzgajhm7mju9933
Tags: 14.1+dfsg-1
* New Upstream release (Closes: #768863)
* debian/patches:
  - Remove 0010_unnecessary_gcryptdep.patch, included upstream
  - Refresh remaining patches
* debian/control:
  - Remove no longer needed build-depends on libpar2-dev and libsigc++-dev
* debian/nzbget.conf
  - Update sample configuration file to include new options introduced by
    new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  This file is part of nzbget
3
 
 *
4
 
 *  Copyright (C) 2004 Sven Henkel <sidddy@users.sourceforge.net>
5
 
 *  Copyright (C) 2007-2010 Andrey Prygunkov <hugbug@users.sourceforge.net>
6
 
 *
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.
11
 
 *
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.
16
 
 *
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.
20
 
 *
21
 
 * $Revision: 695 $
22
 
 * $Date: 2013-05-26 22:42:15 +0200 (Sun, 26 May 2013) $
23
 
 *
24
 
 */
25
 
 
26
 
 
27
 
#ifndef QUEUECOORDINATOR_H
28
 
#define QUEUECOORDINATOR_H
29
 
 
30
 
#include <deque>
31
 
#include <list>
32
 
#include <time.h>
33
 
 
34
 
#include "Thread.h"
35
 
#include "NZBFile.h"
36
 
#include "ArticleDownloader.h"
37
 
#include "DownloadInfo.h"
38
 
#include "Observer.h"
39
 
#include "QueueEditor.h"
40
 
#include "NNTPConnection.h"
41
 
                                            
42
 
class QueueCoordinator : public Thread, public Observer, public Subject, public DownloadSpeedMeter, public DownloadQueueHolder
43
 
{
44
 
public:
45
 
        typedef std::list<ArticleDownloader*>   ActiveDownloads;
46
 
        enum EAspectAction
47
 
        {
48
 
                eaNZBFileAdded,
49
 
                eaFileCompleted,
50
 
                eaFileDeleted
51
 
        };
52
 
        struct Aspect
53
 
        {
54
 
                EAspectAction eAction;
55
 
                DownloadQueue* pDownloadQueue;
56
 
                NZBInfo* pNZBInfo;
57
 
                FileInfo* pFileInfo;
58
 
        };
59
 
 
60
 
private:
61
 
        DownloadQueue                   m_DownloadQueue;
62
 
        ActiveDownloads                 m_ActiveDownloads;
63
 
        QueueEditor                             m_QueueEditor;
64
 
        Mutex                                   m_mutexDownloadQueue;
65
 
        bool                                    m_bHasMoreJobs;
66
 
        int                                             m_iDownloadsLimit;
67
 
 
68
 
        // statistics
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;
76
 
#ifdef HAVE_SPINLOCK
77
 
        SpinLock                                m_spinlockSpeed;
78
 
#else
79
 
        Mutex                                   m_mutexSpeed;
80
 
#endif
81
 
 
82
 
    int                                         m_iSpeedBytesIndex;
83
 
        long long                               m_iAllBytes;
84
 
        time_t                                  m_tStartServer;
85
 
        time_t                                  m_tLastCheck;
86
 
        time_t                                  m_tStartDownload;
87
 
        time_t                                  m_tPausedFrom;
88
 
        bool                                    m_bStandBy;
89
 
        Mutex                                   m_mutexStat;
90
 
 
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();
100
 
 
101
 
public:
102
 
                                                        QueueCoordinator();                
103
 
        virtual                                 ~QueueCoordinator();
104
 
        virtual void                    Run();
105
 
        virtual void                    Stop();
106
 
        void                                    Update(Subject* Caller, void* Aspect);
107
 
 
108
 
        // statistics
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);
113
 
 
114
 
        // Editing the queue
115
 
        DownloadQueue*                  LockQueue();
116
 
        void                                    UnlockQueue() ;
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; }
127
 
 
128
 
        void                                    LogDebugInfo();
129
 
};
130
 
 
131
 
#endif