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 
7 #include <QWaitCondition>
8 #include <QDateTime>
9 #include <QPointer>
10 #include <QObject>
11 #include <QString>
12 #include <QMutex>
13 #include <QQueue>
14 #include <QSet>
15 #include <QMap>
16 
17 #include "mthread.h"
18 
19 class ProgramInfo;
20 class EncoderLink;
21 class FileSystemInfo;
22 class MainServer;
23 
24 using pginfolist_t = std::vector<ProgramInfo*>;
25 using enclinklist_t = std::vector<EncoderLink*>;
26 
36 };
37 
38 class AutoExpire;
39 
40 class ExpireThread : public MThread
41 {
42  public:
43  explicit ExpireThread(AutoExpire *p) : MThread("Expire"), m_parent(p) {}
44  ~ExpireThread() override { wait(); }
45  void run(void) override; // MThread
46  private:
47  QPointer<AutoExpire> m_parent;
48 };
49 
51 {
52  public:
53  UpdateEntry(int _encoder, int _fsID)
54  : m_encoder(_encoder), m_fsID(_fsID) {};
55 
56  int m_encoder;
57  int m_fsID;
58 };
59 
60 class AutoExpire : public QObject
61 {
62  Q_OBJECT
63 
64  friend class ExpireThread;
65  public:
66  explicit AutoExpire(QMap<int, EncoderLink *> *tvList);
67  AutoExpire() = default;
68  ~AutoExpire() override;
69 
70  void CalcParams(void);
71  void PrintExpireList(const QString& expHost = "ALL");
72 
73  uint64_t GetDesiredSpace(int fsID) const;
74 
75  void GetAllExpiring(QStringList &strList);
76  void GetAllExpiring(pginfolist_t &list);
77  static void ClearExpireList(pginfolist_t &expireList, bool deleteProg = true);
78 
79  static void Update(int encoder, int fsID, bool immediately);
80  static void Update(bool immediately) { Update(0, -1, immediately); }
81 
83  {
84  QMutexLocker locker(&m_instanceLock);
85  m_mainServer = ms;
86  }
87 
88  QMap<int, EncoderLink *> *m_encoderList {nullptr};
89 
90  protected:
91  void RunExpirer(void);
92 
93  private:
94  void ExpireLiveTV(int type);
95  void ExpireOldDeleted(void);
96  void ExpireQuickDeleted(void);
97  void ExpireRecordings(void);
98  void ExpireEpisodesOverMax(void);
99 
100  void FillExpireList(pginfolist_t &expireList);
101  void FillDBOrdered(pginfolist_t &expireList, int expMethod);
102  static void SendDeleteMessages(pginfolist_t &deleteList);
103  void Sleep(int sleepTime /*ms*/);
104 
105  void UpdateDontExpireSet(void);
106  bool IsInDontExpireSet(uint chanid, const QDateTime &recstartts) const;
107  static bool IsInExpireList(const pginfolist_t &expireList,
108  uint chanid, const QDateTime &recstartts);
109 
110  // main expire info
111  QSet<QString> m_dontExpireSet;
112  ExpireThread *m_expireThread {nullptr}; // protected by m_instanceLock
113  uint m_desiredFreq {15}; // protected by m_instanceLock
114  bool m_expireThreadRun {false}; // protected by m_instanceLock
115 
116  QMap<int, int64_t> m_desiredSpace; // protected by m_instanceLock
117  QMap<int, int> m_usedEncoders; // protected by m_instanceLock
118 
119  mutable QMutex m_instanceLock;
120  QWaitCondition m_instanceCond; // protected by m_instanceLock
121 
122  MainServer *m_mainServer {nullptr}; // protected by m_instanceLock
123 
124  // update info
125  QMutex m_updateLock;
126  QQueue<UpdateEntry> m_updateQueue; // protected by m_updateLock
127 };
128 
129 #endif
130 
131 /* vim: set expandtab tabstop=4 shiftwidth=4: */
AutoExpire::m_instanceCond
QWaitCondition m_instanceCond
Definition: autoexpire.h:120
AutoExpire::PrintExpireList
void PrintExpireList(const QString &expHost="ALL")
Prints a summary of the files that can be deleted.
Definition: autoexpire.cpp:788
ExpireThread::ExpireThread
ExpireThread(AutoExpire *p)
Definition: autoexpire.h:43
AutoExpire::IsInExpireList
static bool IsInExpireList(const pginfolist_t &expireList, uint chanid, const QDateTime &recstartts)
Definition: autoexpire.cpp:1110
AutoExpire::Update
static void Update(int encoder, int fsID, bool immediately)
This is used to update the global AutoExpire instance "expirer".
Definition: autoexpire.cpp:1030
ExpireThread::m_parent
QPointer< AutoExpire > m_parent
Definition: autoexpire.h:47
AutoExpire::ClearExpireList
static void ClearExpireList(pginfolist_t &expireList, bool deleteProg=true)
Clears expireList, freeing any ProgramInfo's if necessary.
Definition: autoexpire.cpp:873
tvList
QMap< int, EncoderLink * > tvList
Definition: backendcontext.cpp:7
AutoExpire::Sleep
void Sleep(int sleepTime)
Sleeps for sleepTime milliseconds; unless the expire thread is told to quit. Must be called with inst...
Definition: autoexpire.cpp:342
MainServer
Definition: mainserver.h:113
AutoExpire
Used to expire recordings to make space for new recordings.
Definition: autoexpire.h:60
AutoExpire::ExpireOldDeleted
void ExpireOldDeleted(void)
This expires deleted programs older than DeletedMaxAge.
Definition: autoexpire.cpp:372
emLowestPriorityFirst
@ emLowestPriorityFirst
Definition: autoexpire.h:29
AutoExpire::ExpireEpisodesOverMax
void ExpireEpisodesOverMax(void)
This deletes programs exceeding the maximum number of episodes of that program desired....
Definition: autoexpire.cpp:648
AutoExpire::GetAllExpiring
void GetAllExpiring(QStringList &strList)
Gets the full list of programs that can expire in expiration order.
Definition: autoexpire.cpp:827
ExpireThread::run
void run(void) override
This calls AutoExpire::RunExpirer() from within a new thread.
Definition: autoexpire.cpp:55
AutoExpire::m_desiredSpace
QMap< int, int64_t > m_desiredSpace
Definition: autoexpire.h:116
AutoExpire::m_updateLock
QMutex m_updateLock
Definition: autoexpire.h:125
ExpireThread::~ExpireThread
~ExpireThread() override
Definition: autoexpire.h:44
AutoExpire::m_desiredFreq
uint m_desiredFreq
Definition: autoexpire.h:113
emOldDeletedPrograms
@ emOldDeletedPrograms
Definition: autoexpire.h:33
AutoExpire::m_instanceLock
QMutex m_instanceLock
Definition: autoexpire.h:119
UpdateEntry::UpdateEntry
UpdateEntry(int _encoder, int _fsID)
Definition: autoexpire.h:53
AutoExpire::m_expireThreadRun
bool m_expireThreadRun
Definition: autoexpire.h:114
UpdateEntry::m_encoder
int m_encoder
Definition: autoexpire.h:54
hardwareprofile.config.p
p
Definition: config.py:33
AutoExpire::m_usedEncoders
QMap< int, int > m_usedEncoders
Definition: autoexpire.h:117
AutoExpire::ExpireRecordings
void ExpireRecordings(void)
This expires normal recordings.
Definition: autoexpire.cpp:399
AutoExpire::IsInDontExpireSet
bool IsInDontExpireSet(uint chanid, const QDateTime &recstartts) const
Definition: autoexpire.cpp:1101
pginfolist_t
std::vector< ProgramInfo * > pginfolist_t
Definition: autoexpire.h:24
emNormalLiveTVPrograms
@ emNormalLiveTVPrograms
Definition: autoexpire.h:32
ExpireThread
Definition: autoexpire.h:40
AutoExpire::SetMainServer
void SetMainServer(MainServer *ms)
Definition: autoexpire.h:82
AutoExpire::SendDeleteMessages
static void SendDeleteMessages(pginfolist_t &deleteList)
This sends delete message to main event thread.
Definition: autoexpire.cpp:611
uint
unsigned int uint
Definition: compat.h:141
AutoExpire::AutoExpire
AutoExpire()=default
AutoExpire::FillExpireList
void FillExpireList(pginfolist_t &expireList)
Uses the "AutoExpireMethod" setting in the database to fill the list of files that are deletable.
Definition: autoexpire.cpp:766
AutoExpire::m_dontExpireSet
QSet< QString > m_dontExpireSet
Definition: autoexpire.h:111
emNormalDeletedPrograms
@ emNormalDeletedPrograms
Definition: autoexpire.h:34
UpdateEntry
Definition: autoexpire.h:50
AutoExpire::RunExpirer
void RunExpirer(void)
This contains the main loop for the auto expire process.
Definition: autoexpire.cpp:266
AutoExpire::CalcParams
void CalcParams(void)
Definition: autoexpire.cpp:121
ProgramInfo
Holds information on recordings and videos.
Definition: programinfo.h:67
AutoExpire::FillDBOrdered
void FillDBOrdered(pginfolist_t &expireList, int expMethod)
Creates a list of programs to delete using the database to order list.
Definition: autoexpire.cpp:892
AutoExpire::m_expireThread
ExpireThread * m_expireThread
Definition: autoexpire.h:112
FileSystemInfo
Definition: filesysteminfo.h:15
emOldestFirst
@ emOldestFirst
Definition: autoexpire.h:28
AutoExpire::~AutoExpire
~AutoExpire() override
AutoExpire destructor stops auto delete thread if it is running.
Definition: autoexpire.cpp:83
MThread
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:48
emShortLiveTVPrograms
@ emShortLiveTVPrograms
Definition: autoexpire.h:31
mthread.h
AutoExpire::m_mainServer
MainServer * m_mainServer
Definition: autoexpire.h:122
emQuickDeletedPrograms
@ emQuickDeletedPrograms
Definition: autoexpire.h:35
AutoExpire::ExpireQuickDeleted
void ExpireQuickDeleted(void)
This expires deleted programs within a few minutes.
Definition: autoexpire.cpp:385
AutoExpire::ExpireLiveTV
void ExpireLiveTV(int type)
This expires LiveTV programs.
Definition: autoexpire.cpp:359
ExpireMethodType
ExpireMethodType
Definition: autoexpire.h:27
AutoExpire::GetDesiredSpace
uint64_t GetDesiredSpace(int fsID) const
Used by the scheduler to select the next recording dir.
Definition: autoexpire.cpp:110
MThread::wait
bool wait(unsigned long time=ULONG_MAX)
Wait for the MThread to exit, with a maximum timeout.
Definition: mthread.cpp:305
AutoExpire::m_encoderList
QMap< int, EncoderLink * > * m_encoderList
Definition: autoexpire.h:88
enclinklist_t
std::vector< EncoderLink * > enclinklist_t
Definition: autoexpire.h:25
AutoExpire::m_updateQueue
QQueue< UpdateEntry > m_updateQueue
Definition: autoexpire.h:126
AutoExpire::UpdateDontExpireSet
void UpdateDontExpireSet(void)
Definition: autoexpire.cpp:1065
emWeightedTimePriority
@ emWeightedTimePriority
Definition: autoexpire.h:30
AutoExpire::Update
static void Update(bool immediately)
Definition: autoexpire.h:80
UpdateEntry::m_fsID
int m_fsID
Definition: autoexpire.h:57