vdr  2.2.0
shutdown.h
Go to the documentation of this file.
1 /*
2  * shutdown.h: Handling of shutdown and inactivity
3  *
4  * See the main source file 'vdr.c' for copyright information and
5  * how to reach the author.
6  *
7  * Original version written by Udo Richter <udo_richter@gmx.de>.
8  *
9  * $Id: shutdown.h 3.0 2013/02/18 10:35:27 kls Exp $
10  */
11 
12 #ifndef __SHUTDOWN_H
13 #define __SHUTDOWN_H
14 
15 #include <time.h>
16 
17 class cCountdown {
18 private:
19  time_t timeout;
20  int counter;
21  bool timedOut;
22  const char *message;
23 public:
24  cCountdown(void);
25  void Start(const char *Message, int Seconds);
27  void Cancel(void);
29  bool Done(void);
31  operator bool(void) const { return timeout != 0; }
33  bool Update(void);
36  };
37 
39 private:
40  time_t activeTimeout;
42  time_t retry;
46  int exitCode;
50 public:
52  cShutdownHandler(void);
54  void Exit(int ExitCode) { exitCode = ExitCode; }
57  bool DoExit(void) { return exitCode >= 0; }
59  int GetExitCode(void) { return exitCode >= 0 ? exitCode : 0; }
61  bool EmergencyExitRequested(void) { return emergencyExitRequested; }
63  void RequestEmergencyExit(void);
65  void CheckManualStart(int ManualStart);
68  void SetShutdownCommand(const char *ShutdownCommand);
70  void CallShutdownCommand(time_t WakeupTime, int Channel, const char *File, bool UserShutdown);
72  bool IsUserInactive(time_t AtTime = 0) { return activeTimeout && activeTimeout <= (AtTime ? AtTime : time(NULL)); }
75  time_t GetUserInactiveTime(void) { return activeTimeout; }
77  void SetUserInactiveTimeout(int Seconds = -1, bool Force = false);
86  void SetUserInactive(void) { SetUserInactiveTimeout(0, true); }
88  bool Retry(time_t AtTime = 0) { return retry <= (AtTime ? AtTime : time(NULL)); }
91  time_t GetRetry(void) { return retry; }
93  void SetRetry(int Seconds) { retry = time(NULL) + Seconds; }
96  bool ConfirmShutdown(bool Ask);
101  bool ConfirmRestart(bool Ask);
106  bool DoShutdown(bool Force);
111  };
112 
114 
115 #endif
bool IsUserInactive(time_t AtTime=0)
Check whether VDR is in interactive mode or non-interactive mode (waiting for shutdown).
Definition: shutdown.h:72
time_t GetRetry(void)
Time when shutdown retry block ends.
Definition: shutdown.h:91
int counter
last shown time in 10s units
Definition: shutdown.h:20
bool timedOut
countdown did run down to 0 and was not canceled
Definition: shutdown.h:21
time_t retry
Time for retrying the shutdown.
Definition: shutdown.h:42
void SetUserInactive(void)
Set VDR manually into non-interactive mode from now on.
Definition: shutdown.h:86
bool Update(void)
Update status display of the countdown.
Definition: shutdown.c:64
bool EmergencyExitRequested(void)
Returns true if an emergency exit was requested.
Definition: shutdown.h:61
void Exit(int ExitCode)
Set VDR exit code and initiate end of VDR main loop.
Definition: shutdown.h:54
char * shutdownCommand
Command for shutting down VDR.
Definition: shutdown.h:44
cCountdown countdown
Definition: shutdown.h:51
time_t activeTimeout
Time when VDR will become non-interactive. 0 means never, 1 means unknown time ago.
Definition: shutdown.h:40
void Start(const char *Message, int Seconds)
Start the 5 minute shutdown warning countdown.
Definition: shutdown.c:37
time_t GetUserInactiveTime(void)
Time when user will become non-inactive, or 0 if never, 1 if a long time ago.
Definition: shutdown.h:75
int GetExitCode(void)
Get the currently set exit code of VDR.
Definition: shutdown.h:59
const char * message
message to display, s is placeholder for time
Definition: shutdown.h:22
int exitCode
Exit code, if VDR exit was requested, or -1 if not requested.
Definition: shutdown.h:46
bool DoExit(void)
Check if an exit code was set, and VDR should exit.
Definition: shutdown.h:57
cCountdown(void)
Definition: shutdown.c:29
bool Retry(time_t AtTime=0)
Check whether its time to re-try the shutdown.
Definition: shutdown.h:88
cShutdownHandler ShutdownHandler
Definition: shutdown.c:27
void SetRetry(int Seconds)
Set shutdown retry so that VDR will not try to automatically shut down within Seconds.
Definition: shutdown.h:93
bool emergencyExitRequested
The requested exit is an emergency exit.
Definition: shutdown.h:48
time_t timeout
5-minute countdown timer
Definition: shutdown.h:19
void Cancel(void)
Cancel the 5 minute shutdown warning countdown.
Definition: shutdown.c:46
bool Done(void)
Check if countdown timer has run out without canceling.
Definition: shutdown.c:55