vdr  2.2.0
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 3.0 2013/03/11 10:35:53 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 
18 enum eTimerFlags { tfNone = 0x0000,
19  tfActive = 0x0001,
20  tfInstant = 0x0002,
21  tfVps = 0x0004,
22  tfRecording = 0x0008,
23  tfAll = 0xFFFF,
24  };
26 
27 class cTimer : public cListObject {
28  friend class cMenuEditTimer;
29 private:
30  mutable time_t startTime, stopTime;
31  time_t lastSetEvent;
32  mutable time_t deferred;
34  uint flags;
36  mutable time_t day;
37  int weekdays;
38  int start;
39  int stop;
40  int priority;
41  int lifetime;
42  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
43  char *aux;
44  const cEvent *event;
45 public:
46  cTimer(bool Instant = false, bool Pause = false, cChannel *Channel = NULL);
47  cTimer(const cEvent *Event);
48  cTimer(const cTimer &Timer);
49  virtual ~cTimer();
50  cTimer& operator= (const cTimer &Timer);
51  virtual int Compare(const cListObject &ListObject) const;
52  bool Recording(void) const { return recording; }
53  bool Pending(void) const { return pending; }
54  bool InVpsMargin(void) const { return inVpsMargin; }
55  uint Flags(void) const { return flags; }
56  const cChannel *Channel(void) const { return channel; }
57  time_t Day(void) const { return day; }
58  int WeekDays(void) const { return weekdays; }
59  int Start(void) const { return start; }
60  int Stop(void) const { return stop; }
61  int Priority(void) const { return priority; }
62  int Lifetime(void) const { return lifetime; }
63  const char *File(void) const { return file; }
64  time_t FirstDay(void) const { return weekdays ? day : 0; }
65  const char *Aux(void) const { return aux; }
66  time_t Deferred(void) const { return deferred; }
67  cString ToText(bool UseChannelID = false) const;
68  cString ToDescr(void) const;
69  const cEvent *Event(void) const { return event; }
70  bool Parse(const char *s);
71  bool Save(FILE *f);
72  bool IsSingleEvent(void) const;
73  static int GetMDay(time_t t);
74  static int GetWDay(time_t t);
75  bool DayMatches(time_t t) const;
76  static time_t IncDay(time_t t, int Days);
77  static time_t SetTime(time_t t, int SecondsFromMidnight);
78  void SetFile(const char *File);
79  bool Matches(time_t t = 0, bool Directly = false, int Margin = 0) const;
80  eTimerMatch Matches(const cEvent *Event, int *Overlap = NULL) const;
81  bool Expired(void) const;
82  time_t StartTime(void) const;
83  time_t StopTime(void) const;
84  void SetEventFromSchedule(const cSchedules *Schedules = NULL);
85  void SetEvent(const cEvent *Event);
86  void SetRecording(bool Recording);
87  void SetPending(bool Pending);
88  void SetInVpsMargin(bool InVpsMargin);
89  void SetDay(time_t Day);
90  void SetWeekDays(int WeekDays);
91  void SetStart(int Start);
92  void SetStop(int Stop);
93  void SetPriority(int Priority);
94  void SetLifetime(int Lifetime);
95  void SetAux(const char *Aux);
96  void SetDeferred(int Seconds);
97  void SetFlags(uint Flags);
98  void ClrFlags(uint Flags);
99  void InvFlags(uint Flags);
100  bool HasFlags(uint Flags) const;
101  void Skip(void);
102  void OnOff(void);
103  cString PrintFirstDay(void) const;
104  static int TimeToInt(int t);
105  static bool ParseDay(const char *s, time_t &Day, int &WeekDays);
106  static cString PrintDay(time_t Day, int WeekDays, bool SingleByteChars);
107  };
108 
109 class cTimers : public cConfig<cTimer> {
110 private:
111  int state;
115 public:
116  cTimers(void);
117  cTimer *GetTimer(cTimer *Timer);
118  cTimer *GetMatch(time_t t);
119  cTimer *GetMatch(const cEvent *Event, eTimerMatch *Match = NULL);
120  cTimer *GetNextActiveTimer(void);
121  int BeingEdited(void) { return beingEdited; }
122  void IncBeingEdited(void) { beingEdited++; }
123  void DecBeingEdited(void) { if (!--beingEdited) lastSetEvents = 0; }
124  void SetModified(void);
125  bool Modified(int &State);
129  void SetEvents(void);
130  void DeleteExpired(void);
131  void Add(cTimer *Timer, cTimer *After = NULL);
132  void Ins(cTimer *Timer, cTimer *Before = NULL);
133  void Del(cTimer *Timer, bool DeleteObject = true);
134  };
135 
136 extern cTimers Timers;
137 
138 class cSortedTimers : public cVector<const cTimer *> {
139 public:
140  cSortedTimers(void);
141  };
142 
143 #endif //__TIMERS_H
time_t stopTime
Definition: timers.h:30
Definition: epg.h:71
time_t lastSetEvents
Definition: timers.h:113
void SetWeekDays(int WeekDays)
Definition: timers.c:612
eTimerFlags
Definition: timers.h:18
void OnOff(void)
Definition: timers.c:676
void SetRecording(bool Recording)
Definition: timers.c:585
void SetEvent(const cEvent *Event)
Definition: timers.c:574
char file[NAME_MAX *2+1]
Definition: timers.h:42
int stop
Definition: timers.h:39
char * aux
Definition: timers.h:43
int WeekDays(void) const
Definition: timers.h:58
static int TimeToInt(int t)
Definition: timers.c:184
Definition: timers.h:18
bool Expired(void) const
Definition: timers.c:492
int start
Definition: timers.h:38
bool DayMatches(time_t t) const
Definition: timers.c:364
cString PrintFirstDay(void) const
Definition: timers.c:282
const cEvent * Event(void) const
Definition: timers.h:69
void SetStop(int Stop)
Definition: timers.c:622
void Skip(void)
Definition: timers.c:669
bool Matches(time_t t=0, bool Directly=false, int Margin=0) const
Definition: timers.c:400
bool Parse(const char *s)
Definition: timers.c:292
void SetInVpsMargin(bool InVpsMargin)
Definition: timers.c:600
cChannel * channel
Definition: timers.h:35
time_t Deferred(void) const
Definition: timers.h:66
void SetPending(bool Pending)
Definition: timers.c:595
time_t StartTime(void) const
Definition: timers.c:497
int weekdays
bitmask, lowest bits: SSFTWTM (the &#39;M&#39; is the LSB)
Definition: timers.h:37
Definition: timers.h:25
bool inVpsMargin
Definition: timers.h:33
void SetStart(int Start)
Definition: timers.c:617
virtual ~cTimer()
Definition: timers.c:128
const cEvent * event
Definition: timers.h:44
const cChannel * Channel(void) const
Definition: timers.h:56
Definition: timers.h:27
eTimerMatch
Definition: timers.h:25
virtual int Compare(const cListObject &ListObject) const
Must return 0 if this object is equal to ListObject, a positive value if it is "greater", and a negative value if it is "smaller".
Definition: timers.c:160
static time_t SetTime(time_t t, int SecondsFromMidnight)
Definition: timers.c:381
int Lifetime(void) const
Definition: timers.h:62
void SetEventFromSchedule(const cSchedules *Schedules=NULL)
Definition: timers.c:514
Definition: tools.h:498
bool Recording(void) const
Definition: timers.h:52
void DecBeingEdited(void)
Definition: timers.h:123
uint Flags(void) const
Definition: timers.h:55
static int GetMDay(time_t t)
Definition: timers.c:351
int lifetime
Definition: timers.h:41
bool HasFlags(uint Flags) const
Definition: timers.c:664
bool Pending(void) const
Definition: timers.h:53
void SetLifetime(int Lifetime)
Definition: timers.c:632
int beingEdited
Definition: timers.h:112
time_t lastSetEvent
Definition: timers.h:31
cTimers Timers
Definition: timers.c:694
void IncBeingEdited(void)
Definition: timers.h:122
void SetAux(const char *Aux)
Definition: timers.c:637
Definition: timers.h:23
cTimer & operator=(const cTimer &Timer)
Definition: timers.c:133
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:36
static time_t IncDay(time_t t, int Days)
Definition: timers.c:369
bool InVpsMargin(void) const
Definition: timers.h:54
bool recording
Definition: timers.h:33
static int GetWDay(time_t t)
Definition: timers.c:357
void SetPriority(int Priority)
Definition: timers.c:627
int BeingEdited(void)
Definition: timers.h:121
time_t deferred
Matches(time_t, ...) will return false if the current time is before this value.
Definition: timers.h:32
int Stop(void) const
Definition: timers.h:60
cString ToDescr(void) const
Definition: timers.c:179
uint flags
Definition: timers.h:34
Definition: timers.h:25
time_t StopTime(void) const
Definition: timers.c:504
void InvFlags(uint Flags)
Definition: timers.c:659
time_t lastDeleteExpired
Definition: timers.h:114
int state
Definition: timers.h:111
void SetFlags(uint Flags)
Definition: timers.c:649
void SetDeferred(int Seconds)
Definition: timers.c:643
bool pending
Definition: timers.h:33
Definition: timers.h:21
const char * File(void) const
Definition: timers.h:63
time_t startTime
Definition: timers.h:30
bool IsSingleEvent(void) const
Definition: timers.c:346
cTimer(bool Instant=false, bool Pause=false, cChannel *Channel=NULL)
Definition: timers.c:26
static bool ParseDay(const char *s, time_t &Day, int &WeekDays)
Definition: timers.c:189
bool Save(FILE *f)
Definition: timers.c:341
void ClrFlags(uint Flags)
Definition: timers.c:654
int priority
Definition: timers.h:40
time_t Day(void) const
Definition: timers.h:57
int Priority(void) const
Definition: timers.h:61
time_t FirstDay(void) const
Definition: timers.h:64
cString ToText(bool UseChannelID=false) const
Definition: timers.c:171
const char * Aux(void) const
Definition: timers.h:65
void SetFile(const char *File)
Definition: timers.c:392
void SetDay(time_t Day)
Definition: timers.c:607
int Start(void) const
Definition: timers.h:59
Definition: tools.h:168
static cString PrintDay(time_t Day, int WeekDays, bool SingleByteChars)
Definition: timers.c:248