vdr 2.7.7
timers.h
Go to the documentation of this file.
1/*
2 * timers.h: Timer handling
3 *
4 * See the main source file 'vdr.c' for copyright information and
5 * how to reach the author.
6 *
7 * $Id: timers.h 5.14 2025/07/10 19:12:24 kls Exp $
8 */
9
10#ifndef __TIMERS_H
11#define __TIMERS_H
12
13#include "channels.h"
14#include "config.h"
15#include "epg.h"
16#include "tools.h"
17
18enum eTimerFlags { tfNone = 0x0000,
19 tfActive = 0x0001,
20 tfInstant = 0x0002,
21 tfVps = 0x0004,
22 tfRecording = 0x0008,
23 tfSpawned = 0x0010,
24 tfAvoid = 0x0020,
25 tfAll = 0xFFFF,
26 };
28
29class cTimers;
30
31class cTimer : public cListObject {
32 friend class cMenuEditTimer;
33private:
34 mutable cMutex mutex;
35 int id;
36 mutable time_t startTime, stopTime;
40 mutable time_t deferred;
41 mutable time_t vpsNotRunning;
42 mutable bool vpsActive;
44 uint flags;
46 mutable time_t day;
48 int start;
49 int stop;
52 mutable char pattern[NAME_MAX * 2 + 1]; // same size as 'file', to be able to initially fill 'pattern' with 'file' in the 'Edit timer' menu
53 mutable char file[NAME_MAX * 2 + 1]; // *2 to be able to hold 'title' and 'episode', which can each be up to 255 characters long
54 char *aux;
55 char *remote;
56 const cEvent *event;
57public:
58 cTimer(bool Instant = false, bool Pause = false, const cChannel *Channel = NULL);
59 cTimer(const cEvent *Event, const char *FileName = NULL, const cTimer *PatternTimer = NULL);
60 cTimer(const cTimer &Timer);
61 virtual ~cTimer() override;
62 cTimer& operator= (const cTimer &Timer);
63 void CalcMargins(int &MarginStart, int &MarginStop, const cEvent *Event);
64 virtual int Compare(const cListObject &ListObject) const override;
65 int Id(void) const { return id; }
66 bool Recording(void) const { return HasFlags(tfRecording); }
67 bool Pending(void) const { return pending; }
68 bool InVpsMargin(void) const { return inVpsMargin; }
69 uint Flags(void) const { return flags; }
70 const cChannel *Channel(void) const { return channel; }
71 time_t Day(void) const { return day; }
72 int WeekDays(void) const { return weekdays; }
73 int Start(void) const { return start; }
74 int Stop(void) const { return stop; }
75 int Priority(void) const { return priority; }
76 int Lifetime(void) const { return lifetime; }
77 const char *Pattern(void) const { return pattern; }
78 const char *File(void) const { return file; }
79 time_t FirstDay(void) const { return weekdays ? day : 0; }
80 const char *Aux(void) const { return aux; }
81 const char *Remote(void) const { return remote; }
82 bool Local(void) const { return !remote; } // convenience
83 time_t Deferred(void) const { return deferred; }
84 cString PatternAndFile(void) const;
85 cString ToText(bool UseChannelID = false) const;
86 cString ToDescr(void) const;
87 const cEvent *Event(void) const { return event; }
88 bool Parse(const char *s);
89 bool Save(FILE *f);
90 bool IsSingleEvent(void) const;
91 static int GetMDay(time_t t);
92 static int GetWDay(time_t t);
93 bool DayMatches(time_t t) const;
94 static time_t IncDay(time_t t, int Days);
95 static time_t SetTime(time_t t, int SecondsFromMidnight);
96 void SetPattern(const char *Pattern);
97 void SetFile(const char *File);
98 bool IsPatternTimer(void) const { return *pattern; }
99 void CalcStartStopTime(time_t &startTime, time_t &stopTime, time_t t = 0) const;
103 time_t VpsTime(time_t t = 0) const;
106#define DEPRECATED_TIMER_MATCHES 1
107#if DEPRECATED_TIMER_MATCHES
108 // for backwards compatibility, remove these functions once Matches(time_t ...) has default parameters:
109 bool Matches(void) const { return Matches(0, 0); }
110 bool Matches(time_t t) const { return Matches(t, 0); }
111 [[deprecated("use CalcStartStopTime() instead")]] bool Matches(time_t t, bool Directly) const;
112 [[deprecated("use CalcStartStopTime() instead")]] bool Matches(time_t t, bool Directly, int Margin) const;
113 bool Matches(time_t t, int Margin) const;
114#else
115 bool Matches(time_t t = 0, int Margin = 0) const;
123#endif
124 eTimerMatch Matches(const cEvent *Event, int *Overlap = NULL) const;
125 bool Expired(void) const;
126 time_t StartTime(void) const;
129 time_t StopTime(void) const;
132 time_t StartTimeEvent(void) const;
133 time_t StopTimeEvent(void) const;
134 void SetId(int Id);
135 cTimer *SpawnPatternTimer(const cEvent *Event, cTimers *Timers);
136 bool SpawnPatternTimers(const cSchedules *Schedules, cTimers *Timers);
137 bool AdjustSpawnedTimer(void);
138 void TriggerRespawn(void);
139 bool SetEventFromSchedule(const cSchedules *Schedules);
140 bool SetEvent(const cEvent *Event);
141 void SetRecording(bool Recording);
142 void SetPending(bool Pending);
143 void SetInVpsMargin(bool InVpsMargin);
144 void SetDay(time_t Day);
145 void SetWeekDays(int WeekDays);
146 void SetStart(int Start);
147 void SetStop(int Stop);
148 void SetPriority(int Priority);
149 void SetLifetime(int Lifetime);
150 void SetAux(const char *Aux);
151 void SetRemote(const char *Remote);
152 void SetDeferred(int Seconds);
153 void SetFlags(uint Flags);
154 void ClrFlags(uint Flags);
155 void InvFlags(uint Flags);
156 bool HasFlags(uint Flags) const;
157 void Skip(void);
158 void OnOff(void);
159 cString PrintFirstDay(void) const;
160 static int TimeToInt(int t);
161 static bool ParseDay(const char *s, time_t &Day, int &WeekDays);
162 static cString PrintDay(time_t Day, int WeekDays, bool SingleByteChars);
163 };
164
165class cTimers : public cConfig<cTimer> {
166private:
168 static int lastTimerId;
170public:
171 cTimers(void);
172 static const cTimers *GetTimersRead(cStateKey &StateKey, int TimeoutMs = 0);
194 static cTimers *GetTimersWrite(cStateKey &StateKey, int TimeoutMs = 0);
218 static bool Load(const char *FileName);
219 static int NewTimerId(void);
220 const cTimer *GetById(int Id, const char *Remote = NULL) const;
221 cTimer *GetById(int Id, const char *Remote = NULL) { return const_cast<cTimer *>(static_cast<const cTimers *>(this)->GetById(Id, Remote)); };
222 const cTimer *GetTimer(const cTimer *Timer) const;
223 cTimer *GetTimer(const cTimer *Timer) { return const_cast<cTimer *>(static_cast<const cTimers *>(this)->GetTimer(Timer)); };
224 const cTimer *GetMatch(time_t t) const;
225 cTimer *GetMatch(time_t t) { return const_cast<cTimer *>(static_cast<const cTimers *>(this)->GetMatch(t)); };
226 const cTimer *GetMatch(const cEvent *Event, eTimerMatch *Match = NULL) const;
227 cTimer *GetMatch(const cEvent *Event, eTimerMatch *Match = NULL) { return const_cast<cTimer *>(static_cast<const cTimers *>(this)->GetMatch(Event, Match)); }
228 const cTimer *GetTimerForEvent(const cEvent *Event, eTimerFlags Flags = tfNone) const;
229 int GetMaxPriority(void) const;
232 const cTimer *GetNextActiveTimer(void) const;
233 const cTimer *UsesChannel(const cChannel *Channel) const;
234 bool SetEvents(const cSchedules *Schedules);
235 bool SpawnPatternTimers(const cSchedules *Schedules);
236 bool AdjustSpawnedTimers(void);
237 bool DeleteExpired(bool Force);
238 void Add(cTimer *Timer, cTimer *After = NULL);
239 void Ins(cTimer *Timer, cTimer *Before = NULL);
240 void Del(cTimer *Timer, bool DeleteObject = true);
241 bool StoreRemoteTimers(const char *ServerName = NULL, const cStringList *RemoteTimers = NULL);
249 };
250
251bool HandleRemoteTimerModifications(cTimer *NewTimer, cTimer *OldTimer = NULL, cString *Msg = NULL);
266
267// Provide lock controlled access to the list:
268
270
271// These macros provide a convenient way of locking the global timers list
272// and making sure the lock is released as soon as the current scope is left
273// (note that these macros wait forever to obtain the lock!):
274
275#define LOCK_TIMERS_READ USE_LIST_LOCK_READ(Timers)
276#define LOCK_TIMERS_WRITE USE_LIST_LOCK_WRITE(Timers)
277
278class cSortedTimers : public cVector<const cTimer *> {
279public:
280 cSortedTimers(const cTimers *Timers);
281 };
282
283#endif //__TIMERS_H
cConfig(const char *NeedsLocking=NULL)
Definition config.h:132
const char * FileName(void)
Definition config.h:134
Definition epg.h:73
cListObject(const cListObject &ListObject)
Definition tools.h:534
cSortedTimers(const cTimers *Timers)
Definition timers.c:1575
int Stop(void) const
Definition timers.h:74
void SetAux(const char *Aux)
Definition timers.c:1102
time_t stopTime
the time_t value calculated from 'day', 'start' and 'stop'
Definition timers.h:36
const char * Aux(void) const
Definition timers.h:80
void OnOff(void)
Definition timers.c:1148
void SetLifetime(int Lifetime)
Definition timers.c:1097
const char * File(void) const
Definition timers.h:78
cString PrintFirstDay(void) const
Definition timers.c:436
char * aux
Definition timers.h:54
time_t Deferred(void) const
Definition timers.h:83
time_t day
midnight of the day this timer shall hit, or of the first day it shall hit in case of a repeating tim...
Definition timers.h:46
int weekdays
bitmask, lowest bits: SSFTWTM (the 'M' is the LSB)
Definition timers.h:47
bool IsSingleEvent(void) const
Definition timers.c:513
void SetPending(bool Pending)
Definition timers.c:1060
virtual ~cTimer() override
Definition timers.c:240
cTimer(bool Instant=false, bool Pause=false, const cChannel *Channel=NULL)
Definition timers.c:28
time_t StopTime(void) const
The stop time of this timer, which is the time as given by the user (for normal timers) or the end ti...
Definition timers.c:836
time_t FirstDay(void) const
Definition timers.h:79
cString PatternAndFile(void) const
Definition timers.c:316
bool Recording(void) const
Definition timers.h:66
void SetStart(int Start)
Definition timers.c:1082
static time_t SetTime(time_t t, int SecondsFromMidnight)
Definition timers.c:548
int priority
Definition timers.h:50
bool Expired(void) const
Definition timers.c:787
void ClrFlags(uint Flags)
Definition timers.c:1125
char file[NAME_MAX *2+1]
Definition timers.h:53
void SetFile(const char *File)
Definition timers.c:564
void SetFlags(uint Flags)
Definition timers.c:1120
int Start(void) const
Definition timers.h:73
int id
Definition timers.h:35
int start
the start and stop time of this timer as given by the user,
Definition timers.h:48
void SetPriority(int Priority)
Definition timers.c:1092
void SetDeferred(int Seconds)
Definition timers.c:1114
void SetId(int Id)
Definition timers.c:869
time_t StopTimeEvent(void) const
or by the user (for normal timers)
Definition timers.c:855
bool AdjustSpawnedTimer(void)
Definition timers.c:932
void SetInVpsMargin(bool InVpsMargin)
Definition timers.c:1065
bool Save(FILE *f)
Definition timers.c:506
bool IsPatternTimer(void) const
Definition timers.h:98
static int GetWDay(time_t t)
Definition timers.c:524
const char * Pattern(void) const
Definition timers.h:77
int WeekDays(void) const
Definition timers.h:72
static cString PrintDay(time_t Day, int WeekDays, bool SingleByteChars)
Definition timers.c:402
void TriggerRespawn(void)
Definition timers.c:967
bool DayMatches(time_t t) const
Definition timers.c:531
time_t Day(void) const
Definition timers.h:71
void SetDay(time_t Day)
Definition timers.c:1072
void SetRemote(const char *Remote)
Definition timers.c:1108
bool InVpsMargin(void) const
Definition timers.h:68
char * remote
Definition timers.h:55
bool SetEvent(const cEvent *Event)
Definition timers.c:1031
const cChannel * channel
Definition timers.h:45
void InvFlags(uint Flags)
Definition timers.c:1130
void SetStop(int Stop)
Definition timers.c:1087
int stop
in the form hhmm, with hh (00..23) and mm (00..59) added as hh*100+mm
Definition timers.h:49
bool Local(void) const
Definition timers.h:82
int scheduleStateSpawn
Definition timers.h:38
const cEvent * Event(void) const
Definition timers.h:87
static bool ParseDay(const char *s, time_t &Day, int &WeekDays)
Definition timers.c:343
friend class cMenuEditTimer
Definition timers.h:32
uint Flags(void) const
Definition timers.h:69
bool vpsActive
true if this is a VPS timer and the event is current
Definition timers.h:42
void Skip(void)
Definition timers.c:1140
cTimer * SpawnPatternTimer(const cEvent *Event, cTimers *Timers)
Definition timers.c:874
const cEvent * event
Definition timers.h:56
time_t StartTime(void) const
The start time of this timer, which is the time as given by the user (for normal timers) or the start...
Definition timers.c:828
const cChannel * Channel(void) const
Definition timers.h:70
bool Pending(void) const
Definition timers.h:67
void CalcMargins(int &MarginStart, int &MarginStop, const cEvent *Event)
Definition timers.c:283
cString ToDescr(void) const
Definition timers.c:333
int scheduleStateSet
Definition timers.h:37
virtual int Compare(const cListObject &ListObject) const override
Must return 0 if this object is equal to ListObject, a positive value if it is "greater",...
Definition timers.c:297
int scheduleStateAdjust
Definition timers.h:39
bool SetEventFromSchedule(const cSchedules *Schedules)
Definition timers.c:981
int Priority(void) const
Definition timers.h:75
void SetRecording(bool Recording)
Definition timers.c:1051
time_t StartTimeEvent(void) const
the start/stop times as given by the event (for VPS timers), by event plus margins (for spawned non-V...
Definition timers.c:844
bool Matches(void) const
Definition timers.h:109
void SetPattern(const char *Pattern)
Definition timers.c:559
bool Matches(time_t t) const
Definition timers.h:110
char pattern[NAME_MAX *2+1]
Definition timers.h:52
bool pending
Definition timers.h:43
time_t startTime
Definition timers.h:36
static int TimeToInt(int t)
Definition timers.c:338
time_t deferred
Matches(time_t, ...) will return false if the current time is before this value.
Definition timers.h:40
static int GetMDay(time_t t)
Definition timers.c:518
bool HasFlags(uint Flags) const
Definition timers.c:1135
void CalcStartStopTime(time_t &startTime, time_t &stopTime, time_t t=0) const
Calculates the raw start and stop time of this timer, as given by the user in the timer definition.
Definition timers.c:573
const char * Remote(void) const
Definition timers.h:81
cTimer & operator=(const cTimer &Timer)
Definition timers.c:248
time_t vpsNotRunning
the time when a VPS event's running status changed to "not running"
Definition timers.h:41
void SetWeekDays(int WeekDays)
Definition timers.c:1077
bool inVpsMargin
Definition timers.h:43
cMutex mutex
Definition timers.h:34
time_t VpsTime(time_t t=0) const
Returns the VPS time of this timer.
Definition timers.c:611
int lifetime
Definition timers.h:51
int Id(void) const
Definition timers.h:65
int Lifetime(void) const
Definition timers.h:76
bool Parse(const char *s)
Definition timers.c:446
uint flags
Definition timers.h:44
cString ToText(bool UseChannelID=false) const
Definition timers.c:323
static time_t IncDay(time_t t, int Days)
Definition timers.c:536
bool SpawnPatternTimers(const cSchedules *Schedules, cTimers *Timers)
Definition timers.c:886
static cTimers timers
Definition timers.h:167
static bool Load(const char *FileName)
Definition timers.c:1177
int GetMaxPriority(void) const
Returns the maximum priority of all local timers that are currently recording.
Definition timers.c:1272
const cTimer * UsesChannel(const cChannel *Channel) const
Definition timers.c:1325
bool StoreRemoteTimers(const char *ServerName=NULL, const cStringList *RemoteTimers=NULL)
Stores the given list of RemoteTimers, which come from the VDR ServerName, in this list.
Definition timers.c:1391
const cTimer * GetById(int Id, const char *Remote=NULL) const
Definition timers.c:1197
void Add(cTimer *Timer, cTimer *After=NULL)
Definition timers.c:1305
static cTimers * GetTimersWrite(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of timers for write access.
Definition timers.c:1300
cTimer * GetMatch(time_t t)
Definition timers.h:225
void Del(cTimer *Timer, bool DeleteObject=true)
Definition timers.c:1319
static const cTimers * GetTimersRead(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of timers for read access.
Definition timers.c:1295
const cTimer * GetTimer(const cTimer *Timer) const
Definition timers.c:1208
const cTimer * GetMatch(time_t t) const
Definition timers.c:1221
const cTimer * GetTimerForEvent(const cEvent *Event, eTimerFlags Flags=tfNone) const
Definition timers.c:1261
static int lastTimerId
Definition timers.h:168
cTimer * GetTimer(const cTimer *Timer)
Definition timers.h:223
void Ins(cTimer *Timer, cTimer *Before=NULL)
Definition timers.c:1313
time_t lastDeleteExpired
Definition timers.h:169
bool SpawnPatternTimers(const cSchedules *Schedules)
Definition timers.c:1344
const cTimer * GetNextActiveTimer(void) const
Definition timers.c:1282
cTimer * GetById(int Id, const char *Remote=NULL)
Definition timers.h:221
cTimer * GetMatch(const cEvent *Event, eTimerMatch *Match=NULL)
Definition timers.h:227
bool DeleteExpired(bool Force)
Definition timers.c:1370
bool SetEvents(const cSchedules *Schedules)
Definition timers.c:1334
bool AdjustSpawnedTimers(void)
Definition timers.c:1356
static int NewTimerId(void)
Definition timers.c:1192
cTimers(void)
Definition timers.c:1171
cVector(const cVector &Vector)
Definition tools.h:707
bool HandleRemoteTimerModifications(cTimer *NewTimer, cTimer *OldTimer=NULL, cString *Msg=NULL)
Performs any operations necessary to synchronize changes to a timer between peer VDR machines.
Definition timers.c:1509
eTimerFlags
Definition timers.h:18
@ tfNone
Definition timers.h:18
@ tfAvoid
Definition timers.h:24
@ tfInstant
Definition timers.h:20
@ tfActive
Definition timers.h:19
@ tfVps
Definition timers.h:21
@ tfRecording
Definition timers.h:22
@ tfAll
Definition timers.h:25
@ tfSpawned
Definition timers.h:23
eTimerMatch
Definition timers.h:27
@ tmPartial
Definition timers.h:27
@ tmFull
Definition timers.h:27
@ tmNone
Definition timers.h:27
#define DEF_LIST_LOCK(Class)
Definition tools.h:686