MythTV  master
mythpower.h
Go to the documentation of this file.
1 #ifndef MYTHPOWER_H
2 #define MYTHPOWER_H
3 
4 // Qt
5 #include <QMutex>
6 #include <QObject>
7 #include <QDateTime>
8 #include <QTimer>
9 
10 // MythTV
11 #include "mythbaseexp.h"
12 #include "referencecounter.h"
13 
14 // Seconds
15 #define DEFAULT_SHUTDOWN_WAIT 5
16 #define MAXIMUM_SHUTDOWN_WAIT 30
17 
18 class MBASE_PUBLIC MythPower : public QObject, public ReferenceCounter
19 {
20  Q_OBJECT
21 
22  public:
24  {
25  UPS = -2,
26  ACPower = -1,
27  BatteryEmpty = 0,
28  BatteryLow = 10,
29  BatteryFull = 100,
30  UnknownPower = 101,
31  Unset
32  };
33 
34  enum Feature
35  {
36  FeatureNone = 0x00,
37  FeatureShutdown = 0x01,
38  FeatureSuspend = 0x02,
39  FeatureHibernate = 0x04,
40  FeatureRestart = 0x08,
41  FeatureHybridSleep = 0x10
42  };
43 
44  Q_DECLARE_FLAGS(Features, Feature)
45 
46  static MythPower* AcquireRelease(void* Reference, bool Acquire, uint MinimumDelay = 0);
47  virtual bool RequestFeature (Feature Request, bool Delay = true);
48  Features GetFeatures (void);
49  bool IsFeatureSupported(Feature Supported);
50  int GetPowerLevel (void) const;
51  QStringList GetFeatureList (void);
52 
53  public slots:
54  virtual void CancelFeature (void);
55 
56  signals:
57  void ShuttingDown (void);
58  void Suspending (void);
59  void Hibernating (void);
60  void Restarting (void);
61  void HybridSleeping (void);
62  void WillShutDown (uint MilliSeconds = 0);
63  void WillSuspend (uint MilliSeconds = 0);
64  void WillHibernate (uint MilliSeconds = 0);
65  void WillRestart (uint MilliSeconds = 0);
66  void WillHybridSleep(uint MilliSeconds = 0);
67  void WokeUp (qint64 SecondsAsleep);
68  void LowBattery (void);
69 
70  protected slots:
71  void FeatureTimeout (void);
72  virtual void Refresh (void) { }
73 
74  protected:
75  static QMutex s_lock;
76 
77  MythPower();
78  ~MythPower() override = default;
79 
80  virtual void Init (void);
81  virtual bool DoFeature (bool /*Delayed*/ = false) { return false; }
82  virtual void DidWakeUp (void);
83  virtual void FeatureHappening (Feature Spontaneous = FeatureNone);
84  virtual bool ScheduleFeature (enum Feature Type, uint Delay);
85  void SetRequestedDelay (uint Delay);
86  void PowerLevelChanged (int Level);
87  static QString FeatureToString (enum Feature Type);
88  static bool FeatureIsEquivalent(Feature First, Feature Second);
89 
90  Features m_features { FeatureNone };
91  Feature m_scheduledFeature { FeatureNone };
92  bool m_isSpontaneous { false };
93  uint m_maxRequestedDelay { 0 };
94  uint m_maxSupportedDelay { MAXIMUM_SHUTDOWN_WAIT };
95  QTimer m_featureTimer { };
96  QDateTime m_sleepTime { };
97  int m_powerLevel { Unset };
98  bool m_warnForLowBattery { false };
99 
100  private:
101  Q_DISABLE_COPY(MythPower)
102 };
103 
104 Q_DECLARE_OPERATORS_FOR_FLAGS(MythPower::Features)
105 
106 #endif // MYTHPOWER_H
MythPower::WokeUp
void WokeUp(qint64 SecondsAsleep)
MythPower::ShuttingDown
void ShuttingDown(void)
MythPower
Definition: mythpower.h:19
slots
std::array< unsigned int, 4 > slots
Definition: element.cpp:38
mythbaseexp.h
MythPower::WillHybridSleep
void WillHybridSleep(uint MilliSeconds=0)
MythPower::WillSuspend
void WillSuspend(uint MilliSeconds=0)
MythPower::Hibernating
void Hibernating(void)
MythPower::Restarting
void Restarting(void)
MythPower::WillHibernate
void WillHibernate(uint MilliSeconds=0)
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
MythPower::~MythPower
~MythPower() override=default
MythPower::PowerLevel
PowerLevel
Definition: mythpower.h:24
uint
unsigned int uint
Definition: compat.h:140
MythPower::Feature
Feature
Definition: mythpower.h:35
referencecounter.h
MythPower::s_lock
static QMutex s_lock
Definition: mythpower.h:75
hardwareprofile.distros.mythtv_data.request.Request
def Request(url=None)
Definition: distros/mythtv_data/request.py:64
MythPower::LowBattery
void LowBattery(void)
MythPower::DoFeature
virtual bool DoFeature(bool=false)
Definition: mythpower.h:81
MythPower::HybridSleeping
void HybridSleeping(void)
MythPower::Refresh
virtual void Refresh(void)
Definition: mythpower.h:72
MythPower::WillRestart
void WillRestart(uint MilliSeconds=0)
MAXIMUM_SHUTDOWN_WAIT
#define MAXIMUM_SHUTDOWN_WAIT
Definition: mythpower.h:16
MythPower::WillShutDown
void WillShutDown(uint MilliSeconds=0)
ReferenceCounter
General purpose reference counter.
Definition: referencecounter.h:27
MythPower::Suspending
void Suspending(void)