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: */
QMutex m_updateLock
Definition: autoexpire.h:126
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
QMutex m_instanceLock
Definition: autoexpire.h:120
vector< EncoderLink * > enclinklist_t
Definition: autoexpire.h:26
QMap< int, int > m_usedEncoders
Definition: autoexpire.h:118
QQueue< UpdateEntry > m_updateQueue
Definition: autoexpire.h:127
ExpireThread(AutoExpire *p)
Definition: autoexpire.h:44
void SetMainServer(MainServer *ms)
Definition: autoexpire.h:83
QSet< QString > m_dontExpireSet
Definition: autoexpire.h:112
ExpireMethodType
Definition: autoexpire.h:28
Holds information on recordings and videos.
Definition: programinfo.h:67
UpdateEntry(int _encoder, int _fsID)
Definition: autoexpire.h:54
unsigned int uint
Definition: compat.h:140
QMap< int, int64_t > m_desiredSpace
Definition: autoexpire.h:117
QPointer< AutoExpire > m_parent
Definition: autoexpire.h:48
QWaitCondition m_instanceCond
Definition: autoexpire.h:121
~ExpireThread() override
Definition: autoexpire.h:45
static void Update(bool immediately)
Definition: autoexpire.h:81
vector< ProgramInfo * > pginfolist_t
Definition: autoexpire.h:25
Used to expire recordings to make space for new recordings.
Definition: autoexpire.h:61
QMap< int, EncoderLink * > tvList