vdr
1.7.27
|
00001 /* 00002 * shutdown.h: Handling of shutdown and inactivity 00003 * 00004 * See the main source file 'vdr.c' for copyright information and 00005 * how to reach the author. 00006 * 00007 * Original version written by Udo Richter <udo_richter@gmx.de>. 00008 * 00009 * $Id: shutdown.h 2.0 2007/02/24 17:23:59 kls Exp $ 00010 */ 00011 00012 #ifndef __SHUTDOWN_H 00013 #define __SHUTDOWN_H 00014 00015 #include <time.h> 00016 00017 class cCountdown { 00018 private: 00019 time_t timeout; 00020 int counter; 00021 bool timedOut; 00022 const char *message; 00023 public: 00024 cCountdown(void); 00025 void Start(const char *Message, int Seconds); 00027 void Cancel(void); 00029 bool Done(void); 00031 operator bool(void) const { return timeout != 0; } 00033 bool Update(void); 00036 }; 00037 00038 class cShutdownHandler { 00039 private: 00040 time_t activeTimeout; 00042 time_t retry; 00044 char *shutdownCommand; 00046 int exitCode; 00048 bool emergencyExitRequested; 00050 public: 00051 cCountdown countdown; 00052 cShutdownHandler(void); 00053 ~cShutdownHandler(); 00054 void Exit(int ExitCode) { exitCode = ExitCode; } 00057 bool DoExit(void) { return exitCode >= 0; } 00059 int GetExitCode(void) { return exitCode >= 0 ? exitCode : 0; } 00061 bool EmergencyExitRequested(void) { return emergencyExitRequested; } 00063 void RequestEmergencyExit(void); 00065 void CheckManualStart(int ManualStart); 00068 void SetShutdownCommand(const char *ShutdownCommand); 00070 void CallShutdownCommand(time_t WakeupTime, int Channel, const char *File, bool UserShutdown); 00072 bool IsUserInactive(time_t AtTime = 0) { return activeTimeout && activeTimeout <= (AtTime ? AtTime : time(NULL)); } 00075 time_t GetUserInactiveTime(void) { return activeTimeout; } 00077 void SetUserInactiveTimeout(int Seconds = -1, bool Force = false); 00083 void SetUserInactive(void) { SetUserInactiveTimeout(0, true); } 00085 bool Retry(time_t AtTime = 0) { return retry <= (AtTime ? AtTime : time(NULL)); } 00088 time_t GetRetry(void) { return retry; } 00090 void SetRetry(int Seconds) { retry = time(NULL) + Seconds; } 00093 bool ConfirmShutdown(bool Ask); 00098 bool ConfirmRestart(bool Ask); 00103 bool DoShutdown(bool Force); 00108 }; 00109 00110 extern cShutdownHandler ShutdownHandler; 00111 00112 #endif