MythTV  master
autoexpire.h
Go to the documentation of this file.
1 #ifndef AUTOEXPIRE_H_
2 #define AUTOEXPIRE_H_
3 
4 #include <cstdint>
5 #include <vector>
6 using namespace std;
7 
8 #include <QWaitCondition>
9 #include <QDateTime>
10 #include <QPointer>
11 #include <QObject>
12 #include <QString>
13 #include <QMutex>
14 #include <QQueue>
15 #include <QSet>
16 #include <QMap>
17 
18 #include "mthread.h"
19 
20 class ProgramInfo;
21 class EncoderLink;
22 class FileSystemInfo;
23 class MainServer;
24 
25 using pginfolist_t = vector<ProgramInfo*>;
26 using enclinklist_t = vector<EncoderLink*>;
27 
37 };
38 
39 class AutoExpire;
40 
41 class ExpireThread : public MThread
42 {
43  public:
44  explicit ExpireThread(AutoExpire *p) : MThread("Expire"), m_parent(p) {}
45  ~ExpireThread() override { wait(); }
46  void run(void) override; // MThread
47  private:
48  QPointer<AutoExpire> m_parent;
49 };
50 
52 {
53  public:
54  UpdateEntry(int _encoder, int _fsID)
55  : m_encoder(_encoder), m_fsID(_fsID) {};
56 
57  int m_encoder;
58  int m_fsID;
59 };
60 
61 class AutoExpire : public QObject
62 {
63  Q_OBJECT
64 
65  friend class ExpireThread;
66  public:
67  explicit AutoExpire(QMap<int, EncoderLink *> *tvList);
68  AutoExpire() = default;
69  ~AutoExpire() override;
70 
71  void CalcParams(void);
72  void PrintExpireList(const QString& expHost = "ALL");
73 
74  uint64_t GetDesiredSpace(int fsID) const;
75 
76  void GetAllExpiring(QStringList &strList);
77  void GetAllExpiring(pginfolist_t &list);
78  static void ClearExpireList(pginfolist_t &expireList, bool deleteProg = true);
79 
80  static void Update(int encoder, int fsID, bool immediately);
81  static void Update(bool immediately) { Update(0, -1, immediately); }
82 
84  {
85  QMutexLocker locker(&m_instanceLock);
86  m_mainServer = ms;
87  }
88 
89  QMap<int, EncoderLink *> *m_encoderList {nullptr};
90 
91  protected:
92  void RunExpirer(void);
93 
94  private:
95  void ExpireLiveTV(int type);
96  void ExpireOldDeleted(void);
97  void ExpireQuickDeleted(void);
98  void ExpireRecordings(void);
99  void ExpireEpisodesOverMax(void);
100 
101  void FillExpireList(pginfolist_t &expireList);
102  void FillDBOrdered(pginfolist_t &expireList, int expMethod);
103  static void SendDeleteMessages(pginfolist_t &deleteList);
104  void Sleep(int sleepTime /*ms*/);
105 
106  void UpdateDontExpireSet(void);
107  bool IsInDontExpireSet(uint chanid, const QDateTime &recstartts) const;
108  static bool IsInExpireList(const pginfolist_t &expireList,
109  uint chanid, const QDateTime &recstartts);
110 
111  // main expire info
112  QSet<QString> m_dontExpireSet;
113  ExpireThread *m_expireThread {nullptr}; // protected by m_instanceLock
114  uint m_desiredFreq {15}; // protected by m_instanceLock
115  bool m_expireThreadRun {false}; // protected by m_instanceLock
116 
117  QMap<int, int64_t> m_desiredSpace; // protected by m_instanceLock
118  QMap<int, int> m_usedEncoders; // protected by m_instanceLock
119 
120  mutable QMutex m_instanceLock;
121  QWaitCondition m_instanceCond; // protected by m_instanceLock
122 
123  MainServer *m_mainServer {nullptr}; // protected by m_instanceLock
124 
125  // update info
126  QMutex m_updateLock;
127  QQueue<UpdateEntry> m_updateQueue; // protected by m_updateLock
128 };
129 
130 #endif
131 
132 /* vim: set expandtab tabstop=4 shiftwidth=4: */
AutoExpire::m_instanceCond
QWaitCondition m_instanceCond
Definition: autoexpire.h:121
ExpireThread::ExpireThread
ExpireThread(AutoExpire *p)
Definition: autoexpire.h:44
ExpireThread::m_parent
QPointer< AutoExpire > m_parent
Definition: autoexpire.h:48
tvList
QMap< int, EncoderLink * > tvList
Definition: backendcontext.cpp:7
MainServer
Definition: mainserver.h:115
AutoExpire
Used to expire recordings to make space for new recordings.
Definition: autoexpire.h:62
emLowestPriorityFirst
@ emLowestPriorityFirst
Definition: autoexpire.h:30
enclinklist_t
vector< EncoderLink * > enclinklist_t
Definition: autoexpire.h:26
AutoExpire::m_desiredSpace
QMap< int, int64_t > m_desiredSpace
Definition: autoexpire.h:117
AutoExpire::m_updateLock
QMutex m_updateLock
Definition: autoexpire.h:126
ExpireThread::~ExpireThread
~ExpireThread() override
Definition: autoexpire.h:45
emOldDeletedPrograms
@ emOldDeletedPrograms
Definition: autoexpire.h:34
AutoExpire::m_instanceLock
QMutex m_instanceLock
Definition: autoexpire.h:120
UpdateEntry::UpdateEntry
UpdateEntry(int _encoder, int _fsID)
Definition: autoexpire.h:54
UpdateEntry::m_encoder
int m_encoder
Definition: autoexpire.h:55
hardwareprofile.config.p
p
Definition: config.py:33
AutoExpire::m_usedEncoders
QMap< int, int > m_usedEncoders
Definition: autoexpire.h:118
pginfolist_t
vector< ProgramInfo * > pginfolist_t
Definition: autoexpire.h:25
emNormalLiveTVPrograms
@ emNormalLiveTVPrograms
Definition: autoexpire.h:33
ExpireThread
Definition: autoexpire.h:42
AutoExpire::SetMainServer
void SetMainServer(MainServer *ms)
Definition: autoexpire.h:83
uint
unsigned int uint
Definition: compat.h:140
AutoExpire::AutoExpire
AutoExpire()=default
AutoExpire::m_dontExpireSet
QSet< QString > m_dontExpireSet
Definition: autoexpire.h:112
emNormalDeletedPrograms
@ emNormalDeletedPrograms
Definition: autoexpire.h:35
UpdateEntry
Definition: autoexpire.h:52
ProgramInfo
Holds information on recordings and videos.
Definition: programinfo.h:68
FileSystemInfo
Definition: filesysteminfo.h:16
emOldestFirst
@ emOldestFirst
Definition: autoexpire.h:29
MThread
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:49
emShortLiveTVPrograms
@ emShortLiveTVPrograms
Definition: autoexpire.h:32
mthread.h
emQuickDeletedPrograms
@ emQuickDeletedPrograms
Definition: autoexpire.h:36
ExpireMethodType
ExpireMethodType
Definition: autoexpire.h:28
AutoExpire::m_updateQueue
QQueue< UpdateEntry > m_updateQueue
Definition: autoexpire.h:127
emWeightedTimePriority
@ emWeightedTimePriority
Definition: autoexpire.h:31
AutoExpire::Update
static void Update(bool immediately)
Definition: autoexpire.h:81
UpdateEntry::m_fsID
int m_fsID
Definition: autoexpire.h:58