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