2002-10-20 12:28:55 +02:00
|
|
|
/*
|
|
|
|
* timers.h: Timer handling
|
|
|
|
*
|
|
|
|
* See the main source file 'vdr.c' for copyright information and
|
|
|
|
* how to reach the author.
|
|
|
|
*
|
2016-12-23 09:49:31 +01:00
|
|
|
* $Id: timers.h 4.6 2016/12/23 09:49:31 kls Exp $
|
2002-10-20 12:28:55 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __TIMERS_H
|
|
|
|
#define __TIMERS_H
|
|
|
|
|
|
|
|
#include "channels.h"
|
|
|
|
#include "config.h"
|
2003-12-22 13:29:24 +01:00
|
|
|
#include "epg.h"
|
2002-10-20 12:28:55 +02:00
|
|
|
#include "tools.h"
|
|
|
|
|
2004-02-29 14:21:22 +01:00
|
|
|
enum eTimerFlags { tfNone = 0x0000,
|
|
|
|
tfActive = 0x0001,
|
|
|
|
tfInstant = 0x0002,
|
|
|
|
tfVps = 0x0004,
|
2005-05-07 11:10:56 +02:00
|
|
|
tfRecording = 0x0008,
|
2004-02-29 14:21:22 +01:00
|
|
|
tfAll = 0xFFFF,
|
|
|
|
};
|
|
|
|
enum eTimerMatch { tmNone, tmPartial, tmFull };
|
2002-10-20 12:28:55 +02:00
|
|
|
|
|
|
|
class cTimer : public cListObject {
|
|
|
|
friend class cMenuEditTimer;
|
|
|
|
private:
|
2015-09-06 09:14:53 +02:00
|
|
|
int id;
|
2004-11-01 10:40:38 +01:00
|
|
|
mutable time_t startTime, stopTime;
|
2015-09-01 11:14:27 +02:00
|
|
|
int scheduleState;
|
2011-08-06 13:20:07 +02:00
|
|
|
mutable time_t deferred; ///< Matches(time_t, ...) will return false if the current time is before this value
|
2015-09-01 11:14:27 +02:00
|
|
|
bool pending, inVpsMargin;
|
2006-01-06 14:31:57 +01:00
|
|
|
uint flags;
|
2015-09-01 11:14:27 +02:00
|
|
|
const cChannel *channel;
|
2005-03-20 15:15:42 +01:00
|
|
|
mutable time_t day; ///< midnight of the day this timer shall hit, or of the first day it shall hit in case of a repeating timer
|
|
|
|
int weekdays; ///< bitmask, lowest bits: SSFTWTM (the 'M' is the LSB)
|
2002-10-20 12:28:55 +02:00
|
|
|
int start;
|
|
|
|
int stop;
|
|
|
|
int priority;
|
|
|
|
int lifetime;
|
2013-03-11 11:07:59 +01:00
|
|
|
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
|
2006-02-25 12:09:22 +01:00
|
|
|
char *aux;
|
2015-09-01 11:14:27 +02:00
|
|
|
char *remote;
|
2004-02-29 14:21:22 +01:00
|
|
|
const cEvent *event;
|
2002-10-20 12:28:55 +02:00
|
|
|
public:
|
2015-09-01 11:14:27 +02:00
|
|
|
cTimer(bool Instant = false, bool Pause = false, const cChannel *Channel = NULL);
|
2003-12-22 13:29:24 +01:00
|
|
|
cTimer(const cEvent *Event);
|
2006-09-08 15:06:09 +02:00
|
|
|
cTimer(const cTimer &Timer);
|
2002-10-20 12:28:55 +02:00
|
|
|
virtual ~cTimer();
|
|
|
|
cTimer& operator= (const cTimer &Timer);
|
2004-11-01 10:40:38 +01:00
|
|
|
virtual int Compare(const cListObject &ListObject) const;
|
2015-09-06 09:14:53 +02:00
|
|
|
int Id(void) const { return id; }
|
2015-09-01 11:14:27 +02:00
|
|
|
bool Recording(void) const { return HasFlags(tfRecording); }
|
2005-03-20 15:15:42 +01:00
|
|
|
bool Pending(void) const { return pending; }
|
|
|
|
bool InVpsMargin(void) const { return inVpsMargin; }
|
2006-01-06 14:31:57 +01:00
|
|
|
uint Flags(void) const { return flags; }
|
2005-03-20 15:15:42 +01:00
|
|
|
const cChannel *Channel(void) const { return channel; }
|
|
|
|
time_t Day(void) const { return day; }
|
|
|
|
int WeekDays(void) const { return weekdays; }
|
|
|
|
int Start(void) const { return start; }
|
|
|
|
int Stop(void) const { return stop; }
|
|
|
|
int Priority(void) const { return priority; }
|
|
|
|
int Lifetime(void) const { return lifetime; }
|
|
|
|
const char *File(void) const { return file; }
|
|
|
|
time_t FirstDay(void) const { return weekdays ? day : 0; }
|
2006-02-25 12:09:22 +01:00
|
|
|
const char *Aux(void) const { return aux; }
|
2015-09-01 11:14:27 +02:00
|
|
|
const char *Remote(void) const { return remote; }
|
2015-09-10 10:39:45 +02:00
|
|
|
bool Local(void) const { return !remote; } // convenience
|
2011-08-06 13:20:07 +02:00
|
|
|
time_t Deferred(void) const { return deferred; }
|
2008-02-16 15:04:49 +01:00
|
|
|
cString ToText(bool UseChannelID = false) const;
|
2005-03-20 15:15:42 +01:00
|
|
|
cString ToDescr(void) const;
|
|
|
|
const cEvent *Event(void) const { return event; }
|
2002-10-20 12:28:55 +02:00
|
|
|
bool Parse(const char *s);
|
|
|
|
bool Save(FILE *f);
|
2004-11-01 10:40:38 +01:00
|
|
|
bool IsSingleEvent(void) const;
|
2004-11-14 16:27:27 +01:00
|
|
|
static int GetMDay(time_t t);
|
|
|
|
static int GetWDay(time_t t);
|
2004-11-01 10:40:38 +01:00
|
|
|
bool DayMatches(time_t t) const;
|
2002-10-20 12:28:55 +02:00
|
|
|
static time_t IncDay(time_t t, int Days);
|
|
|
|
static time_t SetTime(time_t t, int SecondsFromMidnight);
|
2012-02-20 15:53:33 +01:00
|
|
|
void SetFile(const char *File);
|
2006-04-09 09:12:47 +02:00
|
|
|
bool Matches(time_t t = 0, bool Directly = false, int Margin = 0) const;
|
2012-12-08 11:05:39 +01:00
|
|
|
eTimerMatch Matches(const cEvent *Event, int *Overlap = NULL) const;
|
2005-03-20 15:15:42 +01:00
|
|
|
bool Expired(void) const;
|
2004-11-01 10:40:38 +01:00
|
|
|
time_t StartTime(void) const;
|
|
|
|
time_t StopTime(void) const;
|
2015-09-06 09:14:53 +02:00
|
|
|
void SetId(int Id);
|
2015-09-01 11:14:27 +02:00
|
|
|
bool SetEventFromSchedule(const cSchedules *Schedules);
|
|
|
|
bool SetEvent(const cEvent *Event);
|
2002-10-20 12:28:55 +02:00
|
|
|
void SetRecording(bool Recording);
|
|
|
|
void SetPending(bool Pending);
|
2004-02-29 14:21:22 +01:00
|
|
|
void SetInVpsMargin(bool InVpsMargin);
|
2012-02-20 15:37:01 +01:00
|
|
|
void SetDay(time_t Day);
|
|
|
|
void SetWeekDays(int WeekDays);
|
|
|
|
void SetStart(int Start);
|
|
|
|
void SetStop(int Stop);
|
2006-01-03 11:46:57 +01:00
|
|
|
void SetPriority(int Priority);
|
2012-02-20 15:37:01 +01:00
|
|
|
void SetLifetime(int Lifetime);
|
|
|
|
void SetAux(const char *Aux);
|
2015-09-01 11:14:27 +02:00
|
|
|
void SetRemote(const char *Remote);
|
2011-08-06 13:20:07 +02:00
|
|
|
void SetDeferred(int Seconds);
|
2006-01-06 14:31:57 +01:00
|
|
|
void SetFlags(uint Flags);
|
|
|
|
void ClrFlags(uint Flags);
|
|
|
|
void InvFlags(uint Flags);
|
|
|
|
bool HasFlags(uint Flags) const;
|
2002-10-20 12:28:55 +02:00
|
|
|
void Skip(void);
|
|
|
|
void OnOff(void);
|
2005-03-20 15:15:42 +01:00
|
|
|
cString PrintFirstDay(void) const;
|
2002-10-20 12:28:55 +02:00
|
|
|
static int TimeToInt(int t);
|
2005-03-19 15:38:43 +01:00
|
|
|
static bool ParseDay(const char *s, time_t &Day, int &WeekDays);
|
2007-06-10 13:02:43 +02:00
|
|
|
static cString PrintDay(time_t Day, int WeekDays, bool SingleByteChars);
|
2002-10-20 12:28:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class cTimers : public cConfig<cTimer> {
|
2003-02-09 13:14:44 +01:00
|
|
|
private:
|
2015-09-01 11:14:27 +02:00
|
|
|
static cTimers timers;
|
2015-09-06 09:14:53 +02:00
|
|
|
static int lastTimerId;
|
2006-03-26 14:38:46 +02:00
|
|
|
time_t lastDeleteExpired;
|
2002-10-20 12:28:55 +02:00
|
|
|
public:
|
2004-10-24 15:01:50 +02:00
|
|
|
cTimers(void);
|
2015-09-01 11:14:27 +02:00
|
|
|
static const cTimers *GetTimersRead(cStateKey &StateKey, int TimeoutMs = 0);
|
|
|
|
///< Gets the list of timers for read access. If TimeoutMs is given,
|
2016-12-22 14:31:50 +01:00
|
|
|
///< it will wait that long to get a read lock before giving up.
|
2015-09-01 11:14:27 +02:00
|
|
|
///< Otherwise it will wait indefinitely. If no read lock can be
|
|
|
|
///< obtained within the given timeout, NULL will be returned.
|
|
|
|
///< The list is locked and a pointer to it is returned if the state
|
|
|
|
///< of the list is different than the state of the given StateKey.
|
|
|
|
///< If both states are equal, the list of timers has not been modified
|
|
|
|
///< since the last call with the same StateKey, and NULL will be
|
|
|
|
///< returned (and the list is not locked). After the returned list of
|
|
|
|
///< timers is no longer needed, the StateKey's Remove() function must
|
|
|
|
///< be called to release the list. The time between calling
|
|
|
|
///< cTimers::GetTimersRead() and StateKey.Remove() should be as short
|
|
|
|
///< as possible. After calling StateKey.Remove() the list returned from
|
|
|
|
///< this call must not be accessed any more. If you need to access the
|
|
|
|
///< timers again later, a new call to GetTimersRead() must be made.
|
|
|
|
///< A typical code sequence would look like this:
|
|
|
|
///< cStateKey StateKey;
|
|
|
|
///< if (const cTimers *Timers = cTimers::GetTimersRead(StateKey)) {
|
|
|
|
///< // access the timers
|
|
|
|
///< StateKey.Remove();
|
|
|
|
///< }
|
|
|
|
static cTimers *GetTimersWrite(cStateKey &StateKey, int TimeoutMs = 0);
|
|
|
|
///< Gets the list of timers for write access. If TimeoutMs is given,
|
|
|
|
///< it will wait that long to get a write lock before giving up.
|
|
|
|
///< Otherwise it will wait indefinitely. If no write lock can be
|
|
|
|
///< obtained within the given timeout, NULL will be returned.
|
|
|
|
///< If a write lock can be obtained, the list of timers will be
|
|
|
|
///< returned, regardless of the state values of the timers or the
|
|
|
|
///< given StateKey. After the returned list of timers is no longer
|
|
|
|
///< needed, the StateKey's Remove() function must be called to release
|
|
|
|
///< the list. The time between calling cTimers::GetTimersWrite() and
|
|
|
|
///< StateKey.Remove() should be as short as possible. After calling
|
|
|
|
///< StateKey.Remove() the list returned from this call must not be
|
|
|
|
///< accessed any more. If you need to access the timers again later,
|
|
|
|
///< a new call to GetTimersWrite() must be made. The call
|
|
|
|
///< to StateKey.Remove() will increment the state of the list of
|
|
|
|
///< timers and will copy the new state value to the StateKey. You can
|
|
|
|
///< suppress this by using 'false' as the parameter to the call, in
|
|
|
|
///< which case the state values are left untouched.
|
|
|
|
///< A typical code sequence would look like this:
|
|
|
|
///< cStateKey StateKey;
|
|
|
|
///< if (cTimers *Timers = cTimers::GetTimersWrite(StateKey)) {
|
|
|
|
///< // access the timers
|
|
|
|
///< StateKey.Remove();
|
|
|
|
///< }
|
|
|
|
static bool Load(const char *FileName);
|
2015-09-10 10:39:45 +02:00
|
|
|
static int NewTimerId(void);
|
2015-09-06 09:14:53 +02:00
|
|
|
const cTimer *GetById(int Id) const;
|
|
|
|
cTimer *GetById(int Id) { return const_cast<cTimer *>(static_cast<const cTimers *>(this)->GetById(Id)); };
|
2016-12-22 14:27:01 +01:00
|
|
|
const cTimer *GetTimer(const cTimer *Timer) const;
|
2016-12-23 09:49:31 +01:00
|
|
|
cTimer *GetTimer(const cTimer *Timer) { return const_cast<cTimer *>(static_cast<const cTimers *>(this)->GetTimer(Timer)); };
|
2015-09-01 11:14:27 +02:00
|
|
|
const cTimer *GetMatch(time_t t) const;
|
|
|
|
cTimer *GetMatch(time_t t) { return const_cast<cTimer *>(static_cast<const cTimers *>(this)->GetMatch(t)); };
|
|
|
|
const cTimer *GetMatch(const cEvent *Event, eTimerMatch *Match = NULL) const;
|
|
|
|
cTimer *GetMatch(const cEvent *Event, eTimerMatch *Match = NULL) { return const_cast<cTimer *>(static_cast<const cTimers *>(this)->GetMatch(Event, Match)); }
|
|
|
|
const cTimer *GetNextActiveTimer(void) const;
|
|
|
|
const cTimer *UsesChannel(const cChannel *Channel) const;
|
|
|
|
bool SetEvents(const cSchedules *Schedules);
|
|
|
|
bool DeleteExpired(void);
|
2008-02-16 15:04:49 +01:00
|
|
|
void Add(cTimer *Timer, cTimer *After = NULL);
|
|
|
|
void Ins(cTimer *Timer, cTimer *Before = NULL);
|
|
|
|
void Del(cTimer *Timer, bool DeleteObject = true);
|
2015-09-01 11:14:27 +02:00
|
|
|
bool GetRemoteTimers(const char *ServerName = NULL);
|
|
|
|
///< Gets the timers from the given remote machine and adds them to this
|
|
|
|
///< list. If no ServerName is given, all timers from all known remote
|
|
|
|
///< machines will be fetched. This function calls DelRemoteTimers() with
|
|
|
|
///< the given ServerName first.
|
|
|
|
///< Returns true if any remote timers have been added or deleted
|
|
|
|
bool DelRemoteTimers(const char *ServerName = NULL);
|
|
|
|
///< Deletes all timers of the given remote machine from this list (leaves
|
|
|
|
///< them untouched on the remote machine). If no ServerName is given, the
|
|
|
|
///< timers of all remote machines will be deleted from the list.
|
|
|
|
///< Returns true if any remote timers have been deleted.
|
|
|
|
void TriggerRemoteTimerPoll(const char *ServerName = NULL);
|
|
|
|
///< Sends an SVDRP POLL command to the given remote machine.
|
|
|
|
///< If no ServerName is given, the POLL command will be sent to all
|
|
|
|
///< known remote machines.
|
2002-10-20 12:28:55 +02:00
|
|
|
};
|
|
|
|
|
2015-09-01 11:14:27 +02:00
|
|
|
// Provide lock controlled access to the list:
|
|
|
|
|
|
|
|
DEF_LIST_LOCK(Timers);
|
|
|
|
|
|
|
|
// These macros provide a convenient way of locking the global timers list
|
|
|
|
// and making sure the lock is released as soon as the current scope is left
|
|
|
|
// (note that these macros wait forever to obtain the lock!):
|
|
|
|
|
|
|
|
#define LOCK_TIMERS_READ USE_LIST_LOCK_READ(Timers)
|
|
|
|
#define LOCK_TIMERS_WRITE USE_LIST_LOCK_WRITE(Timers)
|
2002-10-20 12:28:55 +02:00
|
|
|
|
2012-06-02 12:10:36 +02:00
|
|
|
class cSortedTimers : public cVector<const cTimer *> {
|
|
|
|
public:
|
2015-09-01 11:14:27 +02:00
|
|
|
cSortedTimers(const cTimers *Timers);
|
2012-06-02 12:10:36 +02:00
|
|
|
};
|
|
|
|
|
2002-10-20 12:28:55 +02:00
|
|
|
#endif //__TIMERS_H
|