/
scheduler.h
223 lines (177 loc) · 6.91 KB
/
scheduler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#ifndef SCHEDULER_H_
#define SCHEDULER_H_
// C++ headers
#include <deque>
#include <vector>
using namespace std;
// Qt headers
#include <QWaitCondition>
#include <QObject>
#include <QString>
#include <QMutex>
#include <QMap>
#include <QSet>
// MythTV headers
#include "filesysteminfo.h"
#include "recordinginfo.h"
#include "remoteutil.h"
#include "inputgroupmap.h"
#include "mythdeque.h"
#include "mythscheduler.h"
#include "mthread.h"
class EncoderLink;
class MainServer;
class AutoExpire;
class Scheduler;
class Scheduler : public MThread, public MythScheduler
{
public:
Scheduler(bool runthread, QMap<int, EncoderLink *> *tvList,
QString recordTbl = "record", Scheduler *master_sched = NULL);
~Scheduler();
void Stop(void);
void Wait(void) { MThread::wait(); }
void SetExpirer(AutoExpire *autoExpirer) { m_expirer = autoExpirer; }
void Reschedule(int recordid);
void AddRecording(const RecordingInfo&);
void FillRecordListFromDB(int recordid = -1);
void FillRecordListFromMaster(void);
void UpdateRecStatus(RecordingInfo *pginfo);
void UpdateRecStatus(uint cardid, uint chanid,
const QDateTime &startts, RecStatusType recstatus,
const QDateTime &recendts);
// Returns a list of all pending recordings and returns
// true iff there are conflicts
bool GetAllPending(RecList &retList) const;
virtual void GetAllPending(QStringList &strList) const;
virtual QMap<QString,ProgramInfo*> GetRecording(void) const;
void getAllScheduled(QStringList &strList);
void getConflicting(RecordingInfo *pginfo, QStringList &strlist);
void getConflicting(RecordingInfo *pginfo, RecList *retlist);
void PrintList(bool onlyFutureRecordings = false)
{ PrintList(reclist, onlyFutureRecordings); };
void PrintList(RecList &list, bool onlyFutureRecordings = false);
void PrintRec(const RecordingInfo *p, const char *prefix = NULL);
void SetMainServer(MainServer *ms);
void SlaveConnected(RecordingList &slavelist);
void SlaveDisconnected(uint cardid);
void DisableScheduling(void) { schedulingEnabled = false; }
void EnableScheduling(void) { schedulingEnabled = true; }
void GetNextLiveTVDir(uint cardid);
void ResetIdleTime(void);
bool WasStartedAutomatically();
RecStatusType GetRecStatus(const ProgramInfo &pginfo);
int GetError(void) const { return error; }
protected:
virtual void run(void); // MThread
private:
QString recordTable;
QString priorityTable;
bool VerifyCards(void);
bool FillRecordList(void);
void UpdateMatches(int recordid);
void UpdateManuals(int recordid);
void BuildWorkList(void);
bool ClearWorkList(void);
void AddNewRecords(void);
void AddNotListed(void);
void BuildNewRecordsQueries(int recordid, QStringList &from, QStringList &where,
MSqlBindings &bindings);
void PruneOverlaps(void);
void BuildListMaps(void);
void ClearListMaps(void);
bool IsBusyRecording(const RecordingInfo *rcinfo);
bool IsSameProgram(const RecordingInfo *a, const RecordingInfo *b) const;
bool FindNextConflict(const RecList &cardlist,
const RecordingInfo *p, RecConstIter &iter,
int openEnd = 0) const;
const RecordingInfo *FindConflict(const QMap<int, RecList> &reclists,
const RecordingInfo *p, int openEnd = 0) const;
void MarkOtherShowings(RecordingInfo *p);
void MarkShowingsList(RecList &showinglist, RecordingInfo *p);
void BackupRecStatus(void);
void RestoreRecStatus(void);
bool TryAnotherShowing(RecordingInfo *p, bool samePriority,
bool preserveLive = false);
void SchedNewRecords(void);
void MoveHigherRecords(bool move_this = true);
void SchedPreserveLiveTV(void);
void PruneRedundants(void);
void UpdateNextRecord(void);
bool ChangeRecordingEnd(RecordingInfo *oldp, RecordingInfo *newp);
void findAllScheduledPrograms(RecList &proglist);
bool CheckShutdownServer(int prerollseconds, QDateTime &idleSince,
bool &blockShutdown);
void ShutdownServer(int prerollseconds, QDateTime &idleSince);
void PutInactiveSlavesToSleep(void);
bool WakeUpSlave(QString slaveHostname, bool setWakingStatus = true);
void WakeUpSlaves(void);
int FillRecordingDir(const QString &title,
const QString &hostname,
const QString &storagegroup,
const QDateTime &recstartts,
const QDateTime &recendts,
uint cardid,
QString &recording_dir,
const RecList &reclist);
void FillDirectoryInfoCache(bool force = false);
int CalcTimeToNextHandleRecordingEvent(
const QDateTime &curtime,
RecConstIter startIter, const RecList &reclist,
int prerollseconds, int max_sleep /*ms*/);
void OldRecordedFixups(void);
bool HandleReschedule(void);
bool HandleRunSchedulerStartup(
int prerollseconds, int idleWaitForRecordingTime);
void HandleWakeSlave(RecordingInfo &ri, int prerollseconds);
bool HandleRecording(
RecordingInfo &ri, bool &statuschanged, int prerollseconds);
void HandleTuning(
RecordingInfo &ri, bool &statuschanged);
void HandleRecordingStatusChange(
RecordingInfo &ri, RecStatusTypes recStatus, const QString &details);
void HandleIdleShutdown(
bool &blockShutdown, QDateTime &idleSince, int prerollseconds,
int idleTimeoutSecs, int idleWaitForRecordingTime,
bool &statuschanged);
MythDeque<int> reschedQueue;
mutable QMutex schedLock;
QMutex recordmatchLock;
QWaitCondition reschedWait;
RecList reclist;
RecList worklist;
RecList retrylist;
QMap<int, RecList> cardlistmap;
QMap<int, RecList> recordidlistmap;
QMap<QString, RecList> titlelistmap;
InputGroupMap igrp;
QDateTime schedTime;
bool reclist_changed;
bool specsched;
bool schedMoveHigher;
bool schedulingEnabled;
QMap<int, bool> schedAfterStartMap;
QMap<int, EncoderLink *> *m_tvList;
AutoExpire *m_expirer;
QMap<QString, bool> recPendingList;
bool doRun;
MainServer *m_mainServer;
QMutex resetIdleTime_lock;
bool resetIdleTime;
bool m_isShuttingDown;
MSqlQueryInfo dbConn;
QDateTime fsInfoCacheFillTime;
QMap<QString, FileSystemInfo> fsInfoCache;
int error;
QSet<QString> sysEvents[4];
// Try to avoid LiveTV sessions until this time
QDateTime livetvTime;
int livetvpriority;
int prefinputpri;
QMap<QString, bool> hasLaterList;
// cache IsSameProgram()
typedef pair<const RecordingInfo*,const RecordingInfo*> IsSameKey;
typedef QMap<IsSameKey,bool> IsSameCacheType;
mutable IsSameCacheType cache_is_same_program;
};
#endif