vdr  2.4.1
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 4.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
cCountdown::cCountdown
cCountdown(void)
Definition: shutdown.c:29
cShutdownHandler::ConfirmRestart
bool ConfirmRestart(bool Ask)
Check for background activity that blocks restart.
Definition: shutdown.c:209
cCountdown::Start
void Start(const char *Message, int Seconds)
Start the 5 minute shutdown warning countdown.
Definition: shutdown.c:37
cCountdown::message
const char * message
message to display, s is placeholder for time
Definition: shutdown.h:22
cShutdownHandler::exitCode
int exitCode
Exit code, if VDR exit was requested, or -1 if not requested.
Definition: shutdown.h:46
cShutdownHandler::~cShutdownHandler
~cShutdownHandler()
Definition: shutdown.c:88
cShutdownHandler::emergencyExitRequested
bool emergencyExitRequested
The requested exit is an emergency exit.
Definition: shutdown.h:48
cShutdownHandler::ConfirmShutdown
bool ConfirmShutdown(bool Ask)
Check for background activity that blocks shutdown.
Definition: shutdown.c:157
cCountdown
Definition: shutdown.h:17
cShutdownHandler::CheckManualStart
void CheckManualStart(int ManualStart)
Check whether the next timer is in ManualStart time window.
Definition: shutdown.c:104
cShutdownHandler::SetUserInactiveTimeout
void SetUserInactiveTimeout(int Seconds=-1, bool Force=false)
Set the time in the future when VDR will switch into non-interactive mode or power down.
Definition: shutdown.c:141
cShutdownHandler
Definition: shutdown.h:38
cCountdown::counter
int counter
last shown time in 10s units
Definition: shutdown.h:20
cCountdown::Update
bool Update(void)
Update status display of the countdown.
Definition: shutdown.c:64
ShutdownHandler
cShutdownHandler ShutdownHandler
Definition: shutdown.c:27
cCountdown::timedOut
bool timedOut
countdown did run down to 0 and was not canceled
Definition: shutdown.h:21
cShutdownHandler::retry
time_t retry
Time for retrying the shutdown.
Definition: shutdown.h:42
cShutdownHandler::RequestEmergencyExit
void RequestEmergencyExit(void)
Requests an emergency exit of the VDR main loop.
Definition: shutdown.c:93
cShutdownHandler::shutdownCommand
char * shutdownCommand
Command for shutting down VDR.
Definition: shutdown.h:44
cCountdown::timeout
time_t timeout
5-minute countdown timer
Definition: shutdown.h:19
cShutdownHandler::activeTimeout
time_t activeTimeout
Time when VDR will become non-interactive. 0 means never, 1 means unknown time ago.
Definition: shutdown.h:40
cShutdownHandler::SetShutdownCommand
void SetShutdownCommand(const char *ShutdownCommand)
Set the command string for shutdown command.
Definition: shutdown.c:121
cCountdown::Done
bool Done(void)
Check if countdown timer has run out without canceling.
Definition: shutdown.c:55
cCountdown::Cancel
void Cancel(void)
Cancel the 5 minute shutdown warning countdown.
Definition: shutdown.c:46
cShutdownHandler::CallShutdownCommand
void CallShutdownCommand(time_t WakeupTime, int Channel, const char *File, bool UserShutdown)
Call the shutdown command with the given parameters.
Definition: shutdown.c:127
cShutdownHandler::cShutdownHandler
cShutdownHandler(void)
Definition: shutdown.c:79
cShutdownHandler::DoShutdown
bool DoShutdown(bool Force)
Call the shutdown script with data of the next pending timer.
Definition: shutdown.c:233
cShutdownHandler::countdown
cCountdown countdown
Definition: shutdown.h:51