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

« back to all changes in this revision

Viewing changes to daemon/feed/FeedCoordinator.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) 2013-2014 Andrey Prygunkov <hugbug@users.sourceforge.net>
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
19
 *
 
20
 * $Revision: 1016 $
 
21
 * $Date: 2014-05-17 23:39:49 +0200 (Sat, 17 May 2014) $
 
22
 *
 
23
 */
 
24
 
 
25
 
 
26
#ifndef FEEDCOORDINATOR_H
 
27
#define FEEDCOORDINATOR_H
 
28
 
 
29
#include <deque>
 
30
#include <list>
 
31
#include <time.h>
 
32
 
 
33
#include "Log.h"
 
34
#include "Thread.h"
 
35
#include "WebDownloader.h"
 
36
#include "DownloadInfo.h"
 
37
#include "FeedInfo.h"
 
38
#include "Observer.h"
 
39
 
 
40
 
 
41
class FeedDownloader;
 
42
 
 
43
class FeedCoordinator : public Thread, public Observer, public Subject, public Debuggable
 
44
{
 
45
private:
 
46
        class DownloadQueueObserver: public Observer
 
47
        {
 
48
        public:
 
49
                FeedCoordinator*        m_pOwner;
 
50
                virtual void            Update(Subject* pCaller, void* pAspect) { m_pOwner->DownloadQueueUpdate(pCaller, pAspect); }
 
51
        };
 
52
 
 
53
        class FeedCacheItem
 
54
        {
 
55
        private:
 
56
                char*                           m_szUrl;
 
57
                int                                     m_iCacheTimeSec;
 
58
                char*                           m_szCacheId;
 
59
                time_t                          m_tLastUsage;
 
60
                FeedItemInfos*          m_pFeedItemInfos;
 
61
 
 
62
        public:
 
63
                                                        FeedCacheItem(const char* szUrl, int iCacheTimeSec,const char* szCacheId,
 
64
                                                                time_t tLastUsage, FeedItemInfos* pFeedItemInfos);
 
65
                                                        ~FeedCacheItem();
 
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; }
 
72
        };
 
73
 
 
74
        typedef std::deque<FeedCacheItem*>      FeedCache;
 
75
        typedef std::list<FeedDownloader*>      ActiveDownloads;
 
76
 
 
77
private:
 
78
        Feeds                                   m_Feeds;
 
79
        ActiveDownloads                 m_ActiveDownloads;
 
80
        FeedHistory                             m_FeedHistory;
 
81
        Mutex                                   m_mutexDownloads;
 
82
        DownloadQueueObserver   m_DownloadQueueObserver;
 
83
        bool                                    m_bForce;
 
84
        bool                                    m_bSave;
 
85
        FeedCache                               m_FeedCache;
 
86
 
 
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();
 
95
        void                                    CleanupCache();
 
96
        void                                    CheckSaveFeeds();
 
97
 
 
98
protected:
 
99
        virtual void                    LogDebugInfo();
 
100
 
 
101
public:
 
102
                                                        FeedCoordinator();                
 
103
        virtual                                 ~FeedCoordinator();
 
104
        virtual void                    Run();
 
105
        virtual void                    Stop();
 
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; }
 
115
};
 
116
 
 
117
class FeedDownloader : public WebDownloader
 
118
{
 
119
private:
 
120
        FeedInfo*                               m_pFeedInfo;
 
121
 
 
122
public:
 
123
        void                                    SetFeedInfo(FeedInfo* pFeedInfo) { m_pFeedInfo = pFeedInfo; }
 
124
        FeedInfo*                               GetFeedInfo() { return m_pFeedInfo; }
 
125
};
 
126
 
 
127
#endif