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 typedef vector<ProgramInfo*> pginfolist_t;
26 typedef vector<EncoderLink*> enclinklist_t;
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  virtual ~ExpireThread() { 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();
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  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_instance_lock);
86  m_main_server = 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  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_dont_expire_set;
113  ExpireThread *m_expire_thread {nullptr}; // protected by instance_lock
114  uint m_desired_freq {15}; // protected by instance_lock
115  bool m_expire_thread_run {false}; // protected by instance_lock
116 
117  QMap<int, int64_t> m_desired_space; // protected by instance_lock
118  QMap<int, int> m_used_encoders; // protected by instance_lock
119 
120  mutable QMutex m_instance_lock;
121  QWaitCondition m_instance_cond; // protected by instance_lock
122 
123  MainServer *m_main_server {nullptr}; // protected by instance_lock
124 
125  // update info
127  QQueue<UpdateEntry> m_update_queue; // protected by update_lock
128 };
129 
130 #endif
131 
132 /* vim: set expandtab tabstop=4 shiftwidth=4: */
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
QSet< QString > m_dont_expire_set
Definition: autoexpire.h:112
unsigned int uint
Definition: compat.h:140
QMutex m_update_lock
Definition: autoexpire.h:126
ExpireThread(AutoExpire *p)
Definition: autoexpire.h:44
void SetMainServer(MainServer *ms)
Definition: autoexpire.h:83
QWaitCondition m_instance_cond
Definition: autoexpire.h:121
QQueue< UpdateEntry > m_update_queue
Definition: autoexpire.h:127
QMap< int, int64_t > m_desired_space
Definition: autoexpire.h:117
ExpireMethodType
Definition: autoexpire.h:28
Holds information on recordings and videos.
Definition: programinfo.h:66
UpdateEntry(int _encoder, int _fsID)
Definition: autoexpire.h:54
QPointer< AutoExpire > m_parent
Definition: autoexpire.h:48
static void Update(bool immediately)
Definition: autoexpire.h:81
Used to expire recordings to make space for new recordings.
Definition: autoexpire.h:61
QMap< int, int > m_used_encoders
Definition: autoexpire.h:118
virtual ~ExpireThread()
Definition: autoexpire.h:45
vector< ProgramInfo * > pginfolist_t
Definition: autoexpire.h:23
vector< EncoderLink * > enclinklist_t
Definition: autoexpire.h:26
QMap< int, EncoderLink * > tvList
QMutex m_instance_lock
Definition: autoexpire.h:120