vdr 2.6.1
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.8 2021/04/20 13:22:37 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 int id;
35 mutable time_t startTime, stopTime;
39 mutable time_t deferred;
40 bool pending, inVpsMargin;
41 uint flags;
42 const cChannel *channel;
43 mutable time_t day;
44 int weekdays;
45 int start;
46 int stop;
47 int priority;
48 int lifetime;
49 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
50 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
51 char *aux;
52 char *remote;
53 const cEvent *event;
54public:
55 cTimer(bool Instant = false, bool Pause = false, const cChannel *Channel = NULL);
56 cTimer(const cEvent *Event, const char *FileName = NULL, const cTimer *PatternTimer = NULL);
57 cTimer(const cTimer &Timer);
58 virtual ~cTimer();
59 cTimer& operator= (const cTimer &Timer);
60 void CalcMargins(int &MarginStart, int &MarginStop, const cEvent *Event);
61 virtual int Compare(const cListObject &ListObject) const;
62 int Id(void) const { return id; }
63 bool Recording(void) const { return HasFlags(tfRecording); }
64 bool Pending(void) const { return pending; }
65 bool InVpsMargin(void) const { return inVpsMargin; }
66 uint Flags(void) const { return flags; }
67 const cChannel *Channel(void) const { return channel; }
68 time_t Day(void) const { return day; }
69 int WeekDays(void) const { return weekdays; }
70 int Start(void) const { return start; }
71 int Stop(void) const { return stop; }
72 int Priority(void) const { return priority; }
73 int Lifetime(void) const { return lifetime; }
74 const char *Pattern(void) const { return pattern; }
75 const char *File(void) const { return file; }
76 time_t FirstDay(void) const { return weekdays ? day : 0; }
77 const char *Aux(void) const { return aux; }
78 const char *Remote(void) const { return remote; }
79 bool Local(void) const { return !remote; } // convenience
80 time_t Deferred(void) const { return deferred; }
82 cString ToText(bool UseChannelID = false) const;
83 cString ToDescr(void) const;
84 const cEvent *Event(void) const { return event; }
85 bool Parse(const char *s);
86 bool Save(FILE *f);
87 bool IsSingleEvent(void) const;
88 static int GetMDay(time_t t);
89 static int GetWDay(time_t t);
90 bool DayMatches(time_t t) const;
91 static time_t IncDay(time_t t, int Days);
92 static time_t SetTime(time_t t, int SecondsFromMidnight);
93 void SetPattern(const char *Pattern);
94 void SetFile(const char *File);
95 bool IsPatternTimer(void) const { return *pattern; }
96 bool Matches(time_t t = 0, bool Directly = false, int Margin = 0) const;
97 eTimerMatch Matches(const cEvent *Event, int *Overlap = NULL) const;
98 bool Expired(void) const;
99 time_t StartTime(void) const;
100 time_t StopTime(void) const;
101 time_t StartTimeEvent(void) const;
102 time_t StopTimeEvent(void) const;
103 void SetId(int Id);
105 bool SpawnPatternTimers(const cSchedules *Schedules, cTimers *Timers);
107 void TriggerRespawn(void);
108 bool SetEventFromSchedule(const cSchedules *Schedules);
109 bool SetEvent(const cEvent *Event);
111 void SetPending(bool Pending);
113 void SetDay(time_t Day);
115 void SetStart(int Start);
116 void SetStop(int Stop);
119 void SetAux(const char *Aux);
120 void SetRemote(const char *Remote);
121 void SetDeferred(int Seconds);
122 void SetFlags(uint Flags);
123 void ClrFlags(uint Flags);
124 void InvFlags(uint Flags);
125 bool HasFlags(uint Flags) const;
126 void Skip(void);
127 void OnOff(void);
129 static int TimeToInt(int t);
130 static bool ParseDay(const char *s, time_t &Day, int &WeekDays);
131 static cString PrintDay(time_t Day, int WeekDays, bool SingleByteChars);
132 };
133
134class cTimers : public cConfig<cTimer> {
135private:
136 static cTimers timers;
137 static int lastTimerId;
138 time_t lastDeleteExpired;
139public:
140 cTimers(void);
141 static const cTimers *GetTimersRead(cStateKey &StateKey, int TimeoutMs = 0);
163 static cTimers *GetTimersWrite(cStateKey &StateKey, int TimeoutMs = 0);
187 static bool Load(const char *FileName);
188 static int NewTimerId(void);
189 const cTimer *GetById(int Id, const char *Remote = NULL) const;
190 cTimer *GetById(int Id, const char *Remote = NULL) { return const_cast<cTimer *>(static_cast<const cTimers *>(this)->GetById(Id, Remote)); };
191 const cTimer *GetTimer(const cTimer *Timer) const;
192 cTimer *GetTimer(const cTimer *Timer) { return const_cast<cTimer *>(static_cast<const cTimers *>(this)->GetTimer(Timer)); };
193 const cTimer *GetMatch(time_t t) const;
194 cTimer *GetMatch(time_t t) { return const_cast<cTimer *>(static_cast<const cTimers *>(this)->GetMatch(t)); };
195 const cTimer *GetMatch(const cEvent *Event, eTimerMatch *Match = NULL) const;
196 cTimer *GetMatch(const cEvent *Event, eTimerMatch *Match = NULL) { return const_cast<cTimer *>(static_cast<const cTimers *>(this)->GetMatch(Event, Match)); }
197 const cTimer *GetTimerForEvent(const cEvent *Event, eTimerFlags Flags = tfNone);
198 int GetMaxPriority(void) const;
201 const cTimer *GetNextActiveTimer(void) const;
202 const cTimer *UsesChannel(const cChannel *Channel) const;
203 bool SetEvents(const cSchedules *Schedules);
204 bool SpawnPatternTimers(const cSchedules *Schedules);
206 bool DeleteExpired(bool Force);
207 void Add(cTimer *Timer, cTimer *After = NULL);
208 void Ins(cTimer *Timer, cTimer *Before = NULL);
209 void Del(cTimer *Timer, bool DeleteObject = true);
210 bool StoreRemoteTimers(const char *ServerName = NULL, const cStringList *RemoteTimers = NULL);
218 };
219
220bool HandleRemoteTimerModifications(cTimer *NewTimer, cTimer *OldTimer = NULL, cString *Msg = NULL);
235
236// Provide lock controlled access to the list:
237
239
240// These macros provide a convenient way of locking the global timers list
241// and making sure the lock is released as soon as the current scope is left
242// (note that these macros wait forever to obtain the lock!):
243
244#define LOCK_TIMERS_READ USE_LIST_LOCK_READ(Timers)
245#define LOCK_TIMERS_WRITE USE_LIST_LOCK_WRITE(Timers)
246
247class cSortedTimers : public cVector<const cTimer *> {
248public:
249 cSortedTimers(const cTimers *Timers);
250 };
251
252#endif //__TIMERS_H
const char * FileName(void)
Definition: config.h:126
Definition: epg.h:73
cSortedTimers(const cTimers *Timers)
int Stop(void) const
Definition: timers.h:71
void SetAux(const char *Aux)
time_t stopTime
the time_t value calculated from 'day', 'start' and 'stop'
const char * Aux(void) const
Definition: timers.h:77
void OnOff(void)
static time_t IncDay(time_t t, int Days)
void SetLifetime(int Lifetime)
const char * File(void) const
Definition: timers.h:75
cString PrintFirstDay(void) const
time_t Deferred(void) const
Definition: timers.h:80
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...
int weekdays
bitmask, lowest bits: SSFTWTM (the 'M' is the LSB)
bool IsSingleEvent(void) const
char pattern[NAME_MAX *2+1]
void SetPending(bool Pending)
cTimer(bool Instant=false, bool Pause=false, const cChannel *Channel=NULL)
time_t StopTime(void) const
the stop time as given by the user
time_t FirstDay(void) const
Definition: timers.h:76
cString PatternAndFile(void) const
bool Recording(void) const
Definition: timers.h:63
char * remote
void SetStart(int Start)
static cString PrintDay(time_t Day, int WeekDays, bool SingleByteChars)
bool Expired(void) const
void ClrFlags(uint Flags)
void SetFile(const char *File)
void SetFlags(uint Flags)
int Start(void) const
Definition: timers.h:70
virtual ~cTimer()
const cEvent * event
int start
the start and stop time of this timer as given by the user,
void SetPriority(int Priority)
void SetDeferred(int Seconds)
void SetId(int Id)
time_t StopTimeEvent(void) const
or by the user (for normal timers)
bool AdjustSpawnedTimer(void)
void SetInVpsMargin(bool InVpsMargin)
char file[NAME_MAX *2+1]
bool Save(FILE *f)
bool IsPatternTimer(void) const
Definition: timers.h:95
const char * Pattern(void) const
Definition: timers.h:74
int WeekDays(void) const
Definition: timers.h:69
void TriggerRespawn(void)
bool DayMatches(time_t t) const
time_t Day(void) const
Definition: timers.h:68
void SetDay(time_t Day)
void SetRemote(const char *Remote)
bool InVpsMargin(void) const
Definition: timers.h:65
static int GetWDay(time_t t)
static int GetMDay(time_t t)
bool SetEvent(const cEvent *Event)
static bool ParseDay(const char *s, time_t &Day, int &WeekDays)
void InvFlags(uint Flags)
void SetStop(int Stop)
int stop
in the form hhmm, with hh (00..23) and mm (00..59) added as hh*100+mm
bool Local(void) const
Definition: timers.h:79
int scheduleStateSpawn
const cEvent * Event(void) const
cTimer(const cTimer &Timer)
uint Flags(void) const
Definition: timers.h:66
void Skip(void)
cTimer * SpawnPatternTimer(const cEvent *Event, cTimers *Timers)
time_t StartTime(void) const
the start time as given by the user
const cChannel * Channel(void) const
bool Pending(void) const
Definition: timers.h:64
static int TimeToInt(int t)
void CalcMargins(int &MarginStart, int &MarginStop, const cEvent *Event)
cString ToDescr(void) const
int scheduleStateSet
int scheduleStateAdjust
bool SetEventFromSchedule(const cSchedules *Schedules)
int Priority(void) const
Definition: timers.h:72
void SetRecording(bool Recording)
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...
void SetPattern(const char *Pattern)
cTimer(const cEvent *Event, const char *FileName=NULL, const cTimer *PatternTimer=NULL)
time_t startTime
time_t deferred
Matches(time_t, ...) will return false if the current time is before this value.
virtual int Compare(const cListObject &ListObject) const
Must return 0 if this object is equal to ListObject, a positive value if it is "greater",...
bool HasFlags(uint Flags) const
Definition: timers.c:1010
const char * Remote(void) const
Definition: timers.h:78
cTimer & operator=(const cTimer &Timer)
Definition: timers.c:240
const cChannel * channel
eTimerMatch Matches(const cEvent *Event, int *Overlap=NULL) const
void SetWeekDays(int WeekDays)
bool inVpsMargin
int Id(void) const
Definition: timers.h:62
bool Matches(time_t t=0, bool Directly=false, int Margin=0) const
int Lifetime(void) const
Definition: timers.h:73
bool Parse(const char *s)
cString ToText(bool UseChannelID=false) const
static time_t SetTime(time_t t, int SecondsFromMidnight)
bool SpawnPatternTimers(const cSchedules *Schedules, cTimers *Timers)
static int lastTimerId
int GetMaxPriority(void) const
Returns the maximum priority of all local timers that are currently recording.
const cTimer * UsesChannel(const cChannel *Channel) const
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.
const cTimer * GetTimerForEvent(const cEvent *Event, eTimerFlags Flags=tfNone)
const cTimer * GetById(int Id, const char *Remote=NULL) const
void Add(cTimer *Timer, cTimer *After=NULL)
const cTimer * GetMatch(const cEvent *Event, eTimerMatch *Match=NULL) const
cTimer * GetMatch(time_t t)
Definition: timers.h:194
void Del(cTimer *Timer, bool DeleteObject=true)
const cTimer * GetTimer(const cTimer *Timer) const
const cTimer * GetMatch(time_t t) const
static cTimers * GetTimersWrite(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of timers for write access.
cTimer * GetTimer(const cTimer *Timer)
Definition: timers.h:192
static int NewTimerId(void)
void Ins(cTimer *Timer, cTimer *Before=NULL)
static const cTimers * GetTimersRead(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of timers for read access.
time_t lastDeleteExpired
bool SpawnPatternTimers(const cSchedules *Schedules)
const cTimer * GetNextActiveTimer(void) const
cTimer * GetById(int Id, const char *Remote=NULL)
Definition: timers.h:190
cTimer * GetMatch(const cEvent *Event, eTimerMatch *Match=NULL)
Definition: timers.h:196
static cTimers timers
bool DeleteExpired(bool Force)
bool SetEvents(const cSchedules *Schedules)
bool AdjustSpawnedTimers(void)
static bool Load(const char *FileName)
cTimers(void)
eTimerFlags
eTimerMatch
DEF_LIST_LOCK(Timers)
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:1382
@ 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
@ tmPartial
Definition: timers.h:27
@ tmFull
Definition: timers.h:27
@ tmNone
Definition: timers.h:27